summaryrefslogtreecommitdiff
path: root/plugins/python/scripting/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/python/scripting/core.py')
-rw-r--r--plugins/python/scripting/core.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/plugins/python/scripting/core.py b/plugins/python/scripting/core.py
index 7aff551..71afaf2 100644
--- a/plugins/python/scripting/core.py
+++ b/plugins/python/scripting/core.py
@@ -4,8 +4,12 @@ from gi.repository import Gtk
from pychrysalide import PluginModule
from pychrysalide import core
from pychrysalide.gui import core as gcore
+from pychrysalide.gui import MenuBar
from pychrysalide.gtkext import EasyGtk
+from .manager import get_recent_python_script_manager, remember_python_script
+from .panel import ScriptPanel
+
class ScriptingEngine(PluginModule):
"""Extend the GUI to run external Python scripts."""
@@ -15,7 +19,7 @@ class ScriptingEngine(PluginModule):
_version = '0.1'
_url = 'https://www.chrysalide.re/'
- _actions = ( )
+ _actions = ( PluginModule.PluginAction.PLUGINS_LOADED, PluginModule.PluginAction.PANEL_CREATION )
def __init__(self):
@@ -23,9 +27,13 @@ class ScriptingEngine(PluginModule):
super(ScriptingEngine, self).__init__()
+ # Scripts panel
+
+ gcore.register_panel(ScriptPanel)
+
# Insert the new menu item into 'File' submenu
- bar = gcore.find_editor_item_by_key('menubar')
+ bar = gcore.find_editor_item_by_type(MenuBar)
builder = gcore.get_editor_builder()
@@ -54,6 +62,25 @@ class ScriptingEngine(PluginModule):
file_menu.insert(item, index)
+ def _notify_plugins_loaded(self, action):
+ """Ack the full loading of all plugins."""
+
+ if action == PluginModule.PluginAction.PLUGINS_LOADED:
+
+ filename = self.build_config_filename('recents.xbel', True)
+
+ get_recent_python_script_manager(filename)
+
+
+ def _on_panel_creation(self, action, item):
+ """Get notified of a new panel creation."""
+
+ if type(item) == ScriptPanel:
+
+ item.connect('run-requested', self._on_run_requested)
+ item.connect('ask-for-new-script', lambda x: self._on_file_run_script_activate(None))
+
+
def _on_file_run_script_activate(self, widget):
"""Look for a new script to run."""
@@ -87,7 +114,9 @@ class ScriptingEngine(PluginModule):
def _run_script_file(self, filename):
"""Run a given script file."""
- core.log_message(core.LogMessageType.INFO, 'Execute the script file \'%s\'' % filename)
+ self.log_message(core.LogMessageType.INFO, 'Execute the script file \'%s\'' % filename)
+
+ remember_python_script(filename)
try:
with open(filename, 'r') as fd:
@@ -98,4 +127,10 @@ class ScriptingEngine(PluginModule):
eval(code)
except Exception as e:
- core.log_message(core.LogMessageType.EXT_ERROR, 'Error while running the script: %s' % str(e))
+ self.log_message(core.LogMessageType.EXT_ERROR, 'Error while running the script: %s' % str(e))
+
+
+ def _on_run_requested(self, panel, filename):
+ """Run a script file from the recents panel."""
+
+ self._run_script_file(filename)