diff --git a/EDMarketConnector.py b/EDMarketConnector.py index c820daf0..0b9d013b 100755 --- a/EDMarketConnector.py +++ b/EDMarketConnector.py @@ -116,7 +116,12 @@ class AppWindow: for plugname in plug.PLUGINS: appitem = plug.get_plugin_app(plugname, frame) if appitem: - appitem.grid(columnspan=2, sticky=tk.W) + if isinstance(appitem, tuple) and len(appitem)==2: + row = frame.grid_size()[1] + appitem[0].grid(row=row, column=0, sticky=tk.W) + appitem[1].grid(row=row, column=1, sticky=tk.EW) + else: + appitem.grid(columnspan=2, sticky=tk.W) self.button = ttk.Button(frame, text=_('Update'), width=28, default=tk.ACTIVE, state=tk.DISABLED) # Update button in main window self.theme_button = tk.Label(frame, width = platform == 'darwin' and 32 or 28, state=tk.DISABLED) diff --git a/PLUGINS.md b/PLUGINS.md index 2a26117b..e6396e12 100644 --- a/PLUGINS.md +++ b/PLUGINS.md @@ -22,14 +22,15 @@ def plugin_start(): Load this plugin into EDMC """ print "I am loaded!" + return "Test" ``` # Plugin Hooks ## Configuration -If you want your plugin to be configurable via the GUI you can define a frame (panel) to be displayed on its own tab in EDMC's settings dialog. Use widgets from EDMC's myNotebook.py for the correct look-and-feel. +If you want your plugin to be configurable via the GUI you can define a frame (panel) to be displayed on its own tab in EDMC's settings dialog. The tab title will be the value that you returned from `plugin_start`. Use widgets from EDMC's myNotebook.py for the correct look-and-feel. You can be notified when the settings dialog is closed so you can save your settings. -You can use `set()`, `get()` and `getint()` from EDMC's config object to store and retrieve your plugin's settings in a platform-independent way. +You can use `set()`, `get()` and `getint()` from EDMC's config object to retrieve your plugin's settings in a platform-independent way. ``` import myNotebook as nb @@ -46,20 +47,28 @@ def plugin_prefs(parent): return frame ``` +def notify_prefs_changed(): + """ + Save settings. + """ + config.setint('MyPluginSetting', 1) +``` + ## Display -You can also have your plugin add an item to the EDMC main window and update it if you need to from your event hooks. This works in the same way as `plugin_prefs()`. For a simple one-line item return a ttk.Label widget. For a more complicated item create a ttk.Frame widget and populate it with other ttk widgets. +You can also have your plugin add an item to the EDMC main window and update it if you need to from your event hooks. This works in the same way as `plugin_prefs()`. For a simple one-line item return a tk.Label widget or a pair of widgets as a tuple. For a more complicated item create a ttk.Frame widget and populate it with other ttk widgets. ``` def plugin_app(parent): """ Create a TK widget for the EDMC main window """ - plugin_app.status = tk.Label(parent, text="Status:") - return plugin_app.status + label = tk.Label(parent, text="Status:") + plugin_app.status = tk.Label(parent, anchor=tk.W, text="") + return (label, plugin_app.status) # later on your event functions can directly update plugin_app.status["text"] -plugin_app.status['text'] = "Status: Happy!" +plugin_app.status['text'] = "Happy!" ``` ## Events diff --git a/plug.py b/plug.py index 7f96c354..73a34205 100644 --- a/plug.py +++ b/plug.py @@ -40,11 +40,11 @@ def load_plugins(): plugmod = imp.load_module(plugname, plugfile, found[plugname], (".py", "r", imp.PY_SOURCE)) if "plugin_start" in dir(plugmod): - plugmod.plugin_start() - PLUGINS[plugname] = plugmod + newname = plugmod.plugin_start() + PLUGINS[newname and unicode(newname) or plugname] = plugmod except Exception as plugerr: - sys.stderr.write('%s\n' % plugerr) # appears in %TMP%/EDMarketConnector.log in packaged Windows app + sys.stderr.write('%s: %s\n' % (plugname, plugerr)) # appears in %TMP%/EDMarketConnector.log in packaged Windows app imp.release_lock() @@ -74,7 +74,7 @@ def get_plugin_app(plugname, parent): return None -def get_plugin_pref(plugname, parent): +def get_plugin_prefs(plugname, parent): """ If the plugin provides a prefs frame, create and return it. :param plugname: name of the plugin @@ -87,6 +87,20 @@ def get_plugin_pref(plugname, parent): return None +def notify_prefs_changed(): + """ + Notify each plugin that the settings dialog has been closed. + :return: + """ + for plugname in PLUGINS: + prefs_changed = _get_plugin_func(plugname, "prefs_changed") + if prefs_changed: + try: + prefs_changed() + except Exception as plugerr: + print plugerr + + def notify_journal_entry(cmdr, system, station, entry): """ Send a journal entry to each plugin. diff --git a/plugins/About/load.py b/plugins/About/load.py index 1dbc2e02..b7c6b432 100644 --- a/plugins/About/load.py +++ b/plugins/About/load.py @@ -12,9 +12,10 @@ import myNotebook as nb def plugin_start(): """ Start this plugin - :return: + :return: Plugin name """ sys.stderr.write("example plugin started\n") # appears in %TMP%/EDMarketConnector.log in packaged Windows app + return 'About' def plugin_prefs(parent): diff --git a/prefs.py b/prefs.py index 8a5f54b8..c9dd25b6 100644 --- a/prefs.py +++ b/prefs.py @@ -196,6 +196,12 @@ class PreferencesDialog(tk.Toplevel): notebook.add(edsmframe, text='EDSM') # Not translated + # build plugin prefs tabs + for plugname in plug.PLUGINS: + plugframe = plug.get_plugin_prefs(plugname, notebook) + if plugframe: + notebook.add(plugframe, text=plugname) + configframe = nb.Frame(notebook) configframe.columnconfigure(1, weight=1) @@ -278,12 +284,6 @@ class PreferencesDialog(tk.Toplevel): notebook.add(themeframe, text=_('Appearance')) # Tab heading in settings - # build plugin prefs tabs - for plugname in plug.PLUGINS: - plugframe = plug.get_plugin_pref(plugname, notebook) - if plugframe: - notebook.add(plugframe, text=plugname) - if platform=='darwin': self.protocol("WM_DELETE_WINDOW", self.apply) # close button applies changes else: @@ -505,6 +505,8 @@ class PreferencesDialog(tk.Toplevel): config.set('anonymous', self.out_anon.get()) + plug.notify_prefs_changed() + self._destroy() if self.callback: self.callback()