diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-12-06 19:52:37 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-12-06 19:52:37 (GMT) |
commit | 9a76c53c8e8808c46aaa61914f625e29a7b6cc58 (patch) | |
tree | cb18e546b7cd352b1fdf563d9d452dccc45a4b34 /plugins/python/scripting/manager.py | |
parent | aa7cbdda718efd7ec41f0ce580847a0d0c31cfd3 (diff) |
Added a panel to display recently used Python scripts.
Diffstat (limited to 'plugins/python/scripting/manager.py')
-rw-r--r-- | plugins/python/scripting/manager.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/python/scripting/manager.py b/plugins/python/scripting/manager.py new file mode 100644 index 0000000..6b27b48 --- /dev/null +++ b/plugins/python/scripting/manager.py @@ -0,0 +1,53 @@ + +import os + +from gi.repository import GLib, Gtk + + +_manager = None + + +def get_recent_python_script_manager(xbel = None): + """Provide the manager for the recently run Python scripts.""" + + global _manager + + # As a first panel creation is forced by the Chrysalide core to register + # its final GType, xbel is not defined at the first call of this function. + # Thus relying on the definition of xbel is a better filter than relying + # on the existence of _manager. + # + # In that special initial case, result is None + + if not(xbel is None): + + assert(_manager is None) + + _manager = Gtk.RecentManager(filename=xbel) + + return _manager + + +def remember_python_script(filename): + """Register a Python script into the recents list.""" + + uri = GLib.filename_to_uri(filename) + + recent_data = Gtk.RecentData() + recent_data.app_name = 'Chrysalide Python plugin' + recent_data.app_exec = 'chrysalide' + recent_data.display_name = os.path.basename(filename) + recent_data.description = 'Python script run inside Chrysalide' + recent_data.mime_type = 'text/x-python' + + manager = get_recent_python_script_manager() + manager.add_full(uri, recent_data) + + +def forget_python_script(filename): + """Unregister a Python script from the recents list.""" + + uri = GLib.filename_to_uri(filename) + + manager = get_recent_python_script_manager() + manager.remove_item(uri) |