Added debugger setup, cleanup
This commit is contained in:
3
plugins/py_run/__init__.py
Normal file
3
plugins/py_run/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
3
plugins/py_run/__main__.py
Normal file
3
plugins/py_run/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
13
plugins/py_run/manifest.json
Normal file
13
plugins/py_run/manifest.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"manifest": {
|
||||
"name": "PyRun",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {
|
||||
"ui_target": "plugin_control_list",
|
||||
"pass_fm_events": "true",
|
||||
"bind_keys": ["PyRun||send_message:<Shift><Control>r"]
|
||||
}
|
||||
}
|
||||
}
|
71
plugins/py_run/plugin.py
Normal file
71
plugins/py_run/plugin.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# Python imports
|
||||
import os
|
||||
import threading
|
||||
import subprocess
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from plugins.plugin_base import PluginBase
|
||||
|
||||
|
||||
# NOTE: Threads WILL NOT die with parent's destruction.
|
||||
def threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=False).start()
|
||||
return wrapper
|
||||
|
||||
# NOTE: Threads WILL die with parent's destruction.
|
||||
def daemon_threaded(fn):
|
||||
def wrapper(*args, **kwargs):
|
||||
threading.Thread(target=fn, args=args, kwargs=kwargs, daemon=True).start()
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginBase):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
self.name = "PyRun" # NOTE: Need to remove after establishing private bidirectional 1-1 message bus
|
||||
# where self.name should not be needed for message comms
|
||||
|
||||
|
||||
def run(self):
|
||||
...
|
||||
|
||||
def generate_reference_ui_element(self):
|
||||
button = Gtk.Button(label=self.name)
|
||||
button.connect("button-release-event", self.start_run)
|
||||
button.set_image( Gtk.Image(stock=Gtk.STOCK_MEDIA_PLAY ) )
|
||||
button.set_always_show_image(True)
|
||||
return button
|
||||
|
||||
def start_run(self, widget=None, eve=None):
|
||||
self._event_system.emit("get_current_state")
|
||||
state = self._fm_state
|
||||
current_dir = state.tab.get_current_directory()
|
||||
isValid = False
|
||||
command = ["terminator", "-x", f"bash -c 'python . && bash'"]
|
||||
|
||||
if not state.uris:
|
||||
for file in os.listdir(current_dir):
|
||||
path = os.path.join(current_dir, file)
|
||||
if os.path.isfile(path) and file == "__main__.py":
|
||||
isValid = True
|
||||
break
|
||||
elif state.uris and len(state.uris) == 1:
|
||||
file = state.uris[0]
|
||||
if os.path.isfile(file) and file.endswith(".py"):
|
||||
command = ["terminator", "-x", f"bash -c 'python {state.uris[0]} && bash'"]
|
||||
isValid = True
|
||||
|
||||
if isValid:
|
||||
self.launch(current_dir, command)
|
||||
|
||||
def launch(self, current_dir = "/", command = []):
|
||||
subprocess.Popen(command, cwd=current_dir, shell=False, start_new_session=True, stdout=None, stderr=None, close_fds=True)
|
Reference in New Issue
Block a user