diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 6bdd3ca7..9a107691 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -92,7 +92,7 @@ class AppWindow: self.w.rowconfigure(0, weight=1) self.w.columnconfigure(0, weight=1) - plug.load_plugins() + plug.load_plugins(master) if platform != 'darwin': if platform == 'win32': @@ -276,6 +276,7 @@ class AppWindow: self.w.bind_all('<>', self.getandsend) # Hotkey monitoring self.w.bind_all('<>', self.journal_event) # Journal monitoring self.w.bind_all('<>', self.interaction_event) # cmdrHistory monitoring + self.w.bind_all('<>', self.plugin_error) # Statusbar self.w.bind_all('<>', self.onexit) # Updater # Load updater after UI creation (for WinSparkle) @@ -725,6 +726,15 @@ class AppWindow: if not config.getint('hotkey_mute'): hotkeymgr.play_bad() + # Display asynchronous error from plugin + def plugin_error(self, event=None): + if plug.last_error['msg']: + self.status['text'] = plug.last_error + self.w.update_idletasks() + if not config.getint('hotkey_mute'): + hotkeymgr.play_bad() + plug.last_error = None + def shipyard_url(self, shipname=None): if not monitor.cmdr or not monitor.mode: diff --git a/PLUGINS.md b/PLUGINS.md index 410433bb..ef21e224 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -155,6 +155,12 @@ def cmdr_data(data, is_beta): The data is a dictionary and full of lots of wonderful stuff! +## Error messages + +You can display an error in EDMC's status area by returning a string from your `journal_entry()`, `interaction()` or `cmdr_data()` function, or asynchronously (e.g. from a "worker" thread that is performing a long running operation) by calling `plug.show_error()`. Either method will cause the "bad" sound to be played (unless the user has muted sound). + +The status area is shared between EDMC itself and all other plugins, so your message won't be displayed for very long. Create a dedicated widget if you need to display routine status information. + # Distributing a Plugin To package your plugin for distribution simply create a `.zip` archive of your plugin's folder: diff --git a/plug.py b/plug.py index 452d2951..2701c8d9 100644 --- a/plug.py +++ b/plug.py @@ -17,6 +17,12 @@ from config import config, appname # List of loaded Plugins PLUGINS = [] +# For asynchronous error display +last_error = { + 'msg': None, + 'root': None, +} + class Plugin(object): @@ -95,11 +101,13 @@ class Plugin(object): return None -def load_plugins(): +def load_plugins(master): """ Find and load all plugins :return: """ + last_error['root'] = master + imp.acquire_lock() internal = [] @@ -283,3 +291,14 @@ def notify_newdata(data, is_beta): except: print_exc() return error + + +def show_error(err): + """ + Display an error message in the status line of the main window. + :param err: + versionadded:: 2.3.7 + """ + if err and last_error['root']: + last_error['msg'] = unicode(err) + last_error['root'].event_generate('<>', when="tail")