mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-14 00:07:14 +03:00
Allow plugins to show error in status area asynchronously
This commit is contained in:
parent
91ee6f3722
commit
8bc117ff32
@ -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('<<Invoke>>', self.getandsend) # Hotkey monitoring
|
||||
self.w.bind_all('<<JournalEvent>>', self.journal_event) # Journal monitoring
|
||||
self.w.bind_all('<<InteractionEvent>>', self.interaction_event) # cmdrHistory monitoring
|
||||
self.w.bind_all('<<PluginError>>', self.plugin_error) # Statusbar
|
||||
self.w.bind_all('<<Quit>>', 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:
|
||||
|
@ -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:
|
||||
|
21
plug.py
21
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('<<PluginError>>', when="tail")
|
||||
|
Loading…
x
Reference in New Issue
Block a user