diff --git a/EDMarketConnector.py b/EDMarketConnector.py index 3b9fd737..6bdd3ca7 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -819,6 +819,7 @@ class AppWindow: hotkeymgr.unregister() interactions.close() monitor.close() + plug.notify_stop() self.eddn.close() self.updater.close() self.session.close() diff --git a/PLUGINS.md b/PLUGINS.md index d76ac2a3..410433bb 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -32,6 +32,18 @@ def plugin_start(): Any errors or print statements from your plugin will appear in `%TMP%\EDMarketConnector.log` on Windows or `$TMPDIR/EDMarketConnector.log` on Mac. +This gets called when the user closes the program: + +```python +def plugin_stop(): + """ + EDMC is closing + """ + print "Farewell cruel world!" +``` + +If your plugin uses one or more threads to handle Events then stop and join() the threads before returning from this function. + # Plugin Hooks ## Configuration @@ -94,7 +106,7 @@ this.status["text"] = "Happy!" ## Events -Once you have created your plugin and EDMC has loaded it there are four other functions you can define to be notified by EDMC when something happens: `journal_entry()`, `interaction()`, `cmdr_data()` and `prefs_changed()`. +Once you have created your plugin and EDMC has loaded it there are three other functions you can define to be notified by EDMC when something happens: `journal_entry()`, `interaction()` and `cmdr_data()`. Your events all get called on the main tkinter loop so be sure not to block for very long or the EDMC will appear to freeze. If you have a long running operation then you should take a look at how to do background updates in tkinter - http://effbot.org/zone/tkinter-threads.htm diff --git a/plug.py b/plug.py index 4966a82c..452d2951 100644 --- a/plug.py +++ b/plug.py @@ -132,6 +132,24 @@ def load_plugins(): imp.release_lock() +def notify_stop(): + """ + Notify each plugin that the program is closing. + If your plugin uses threads then stop and join() them before returning. + versionadded:: 2.3.7 + """ + error = None + for plugin in PLUGINS: + plugin_stop = plugin._get_func('plugin_stop') + if plugin_stop: + try: + newerror = plugin_stop() + error = error or newerror + except: + print_exc() + return error + + def notify_prefs_cmdr_changed(cmdr, is_beta): """ Notify each plugin that the Cmdr has been changed while the settings dialog is open.