How to add a configuration dialog to your plugin
Imports
import gtk from Plugin import Option, ConfigWindow
Option list
Create a list and append Option objects. The parameters for the option class are, in this order:
- name: an internal identifier
- optionType: python type, see below.
- label: The text that goes next to the option.
- description: Some descriptive text
- value: Default value
- options: List of possible values, if optionType is list (optional)
- changedcb: A function, see below. (optional)
For example:
l = [] l.append( Option( 'time', str, 'the time for something:', 'some description', '500') ) l.append( Option( 'active', bool, 'active something?', 'some description', True) ) l.append( Option( 'options', list, 'select something', 'some description', 'default value', [ 'foo','default value', 'bar' ]) )
Display the dialog
Create a ConfigWindow class, and pass the window title and the options list as parameters. To get the result, call the run() method.
ConfigResult = ConfigWindow( 'this is the title', l ).run() print ConfigResult
Valid option types
- str: a gtk.Label
- bool: a gtk.CheckButton
- list: a gtk.ComboBox. An additional parameter, "options", a list, is used to fill the list store.
- dict: a ConfigList, see below. Available since rev 760
- 'passwd': gtk.Entry() with set_visibility(False). Available since rev 871
- gtk.Widget: any widget, see below. Available since rev ###
- Fallback ("else:"): gtk.Label
changed callbacks
TODO: document this and add examples. Available since rev 760
If the "changedcb" parameter is specified, it is connected to the widget
dict option types
TODO: document this and add examples. Available since rev 760
gtk.TreeView? with Key/Value columns. The Value column has editable fields.
gtk.Widget option types
TODO: document this and add examples. Available since rev 969
The gtk.Widget option type adds a widget (specified in the "value" parameter) directly to the window.
This is a lower level interface, so:
- Changed callbacks won't work here. You have to connect the signals to your widget.
- Widget value (like label.get_text()) won't be included in the run() return value. That means that you have to connect your own changed callbacks and store the value locally.
Tip: If the label parameter is an empty string, the descriptive gtk.Label won't be added
