mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-18 01:52:20 +03:00
Fix documentation of prefs_changed
plugin hook
This commit is contained in:
parent
f09d1837e3
commit
0625ed1d49
32
PLUGINS.md
32
PLUGINS.md
@ -33,27 +33,25 @@ If you want your plugin to be configurable via the GUI you can define a frame (p
|
||||
You can use `set()`, `get()` and `getint()` from EDMC's config object to retrieve your plugin's settings in a platform-independent way.
|
||||
|
||||
```
|
||||
import Tkinter as tk
|
||||
import myNotebook as nb
|
||||
from config import config
|
||||
|
||||
this = sys.modules[__name__] # For holding module globals
|
||||
|
||||
def plugin_prefs(parent):
|
||||
"""
|
||||
Return a TK Frame for adding to the EDMC settings dialog.
|
||||
"""
|
||||
this.mysetting = tk.IntVar(value=config.get("MyPluginSetting")) # Retrieve saved value from config
|
||||
frame = nb.Frame(parent)
|
||||
nb.Label(frame, text="Hello").grid()
|
||||
nb.Label(frame, text="Commander").grid()
|
||||
nb.Checkbutton(frame, text="My Setting", variable=this.mysetting).grid()
|
||||
|
||||
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 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.
|
||||
@ -64,16 +62,16 @@ def plugin_app(parent):
|
||||
Create a TK widget for the EDMC main window
|
||||
"""
|
||||
label = tk.Label(parent, text="Status:")
|
||||
plugin_app.status = tk.Label(parent, anchor=tk.W, text="")
|
||||
this.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'] = "Happy!"
|
||||
# later on your event functions can directly update this.status["text"]
|
||||
this.status["text"] = "Happy!"
|
||||
```
|
||||
|
||||
## Events
|
||||
|
||||
Once you have created your plugin and EDMC has loaded it there are two other functions you can define to be notified by EDMC when something happens: `system_changed()` and `cmdr_data()`.
|
||||
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()`, `cmdr_data()` and `prefs_changed()`.
|
||||
|
||||
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
|
||||
|
||||
@ -105,6 +103,18 @@ def cmdr_data(data):
|
||||
|
||||
The data is a dictionary and full of lots of wonderful stuff!
|
||||
|
||||
### Configuration
|
||||
|
||||
This gets called when the user dismisses the settings dialog.
|
||||
|
||||
```
|
||||
def prefs_changed():
|
||||
"""
|
||||
Save settings.
|
||||
"""
|
||||
config.setint('MyPluginSetting', this.mysetting.get()) # Store new value in config
|
||||
```
|
||||
|
||||
# Distributing a Plugin
|
||||
|
||||
To package your plugin for distribution simply create a `.zip` archive of your plugin's folder:
|
||||
|
Loading…
x
Reference in New Issue
Block a user