1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-14 00:07:14 +03:00

Notify plugins on program closing

This commit is contained in:
Jonathan Harris 2017-08-12 19:49:48 +01:00
parent c8ff0a9701
commit 91ee6f3722
3 changed files with 32 additions and 1 deletions

View File

@ -819,6 +819,7 @@ class AppWindow:
hotkeymgr.unregister()
interactions.close()
monitor.close()
plug.notify_stop()
self.eddn.close()
self.updater.close()
self.session.close()

View File

@ -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

18
plug.py
View File

@ -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.