121 | | All model classes inherit from the AbstractPlugin class (defined in the papywizard/common/ package). |
122 | | |
123 | | Then, plugins implementing 'yawAxis' and 'pitchAxis' capacities can inherit from AbstractAxisPlugin, and plugins implementing the 'shutter' capacity can inherits from AbstractShutterPlugin (defined in the papywizard/hardware/ package). |
124 | | |
125 | | |
126 | | |
127 | | Controller classes inherits from AbstractPluginController class (defined in the papywizard/controller/ package). This abstract class inherits from other classes, which are responsible to load the .ui GUI defining file. |
128 | | |
129 | | _defineGui() |
130 | | |
131 | | Last, a plugin has to implement a register() function, which will be called at startup to register the plugin in Papywizard. |
132 | | |
133 | | In you case, you need to implement the 'shutter' capacity. |
134 | | |
135 | | Have a look at the default plugins, in the papywizard/plugins/ package to see concrete examples. |
| 125 | ==== Plugin model ==== |
| 126 | |
| 127 | All model classes inherit from the '''{{{AbstractPlugin}}}''' class (defined in {{{the papywizard.common.abstractPlugin}}} module). |
| 128 | |
| 129 | Then, plugins implementing 'yawAxis' and 'pitchAxis' capacities must inherit from '''{{{AbstractAxisPlugin}}}''', and plugins implementing the 'shutter' capacity must inherit from '''{{{AbstractShutterPlugin}}}''' (defined in the {{{papywizard.hardware.abstractShutterPlugin}}} module). Depending of the implemented capacity, the plugin must overload some methods for Papywizard to work. Have a look at the above classes to see which ones. |
| 130 | |
| 131 | The plugin model may need some user parameters in order to work. These parameters must be defined in the '''{{{_defineConfig()}}}''' method. For example: |
| 132 | |
| 133 | {{{ |
| 134 | def _defineConfig(self): |
| 135 | self._addConfigKey('_myParam', 'MY_PARAM', default='a value') |
| 136 | }}} |
| 137 | |
| 138 | will add a config param named '''{{{MY_PARAM}}}'''. All plugins user params are saved in the config. file. If there is no previous value defined there, the '''{{{default}}}''' argument tells Papywizard which value to use. This config param will be saved using '''{{{MY_PARAM}}}''' as key. |
| 139 | |
| 140 | In the plugin, this config param can be used through '''{{{self._config['MY_PARAM']}}}''' (in a future release, it will be automatically binded to '''{{{self._myParam}}}'''). It should not be modified from the model (see below). |
| 141 | |
| 142 | ==== Plugin controller ==== |
| 143 | |
| 144 | Controller classes inherits from '''{{{AbstractPluginController}}}''' class (defined in the {{{papywizard/controller/}}} package). This abstract class inherits from other classes, which are responsible to load the .ui GUI defining file (see previous chapters). The only method which needs to be oversloaded is '''{{{_defineGui()}}}'''. This is where the dialog interface is defined. For example: |
| 145 | |
| 146 | {{{ |
| 147 | def _defineGui(self): |
| 148 | self._addWidget('Main', "My param", LineEditField, (), 'MY_PARAM') |
| 149 | }}} |
| 150 | |
| 151 | will create an entry to customize our previous config param. The first argument is the ''notebook widget tab'' under which the param will be displayed ('''Main''' is the first default ''tab''). The second argument is the label for the config param. The third argument is the field type to use. Availabe fields are defined in the '''{{{papywizard.view.pluginFields}}}''' module. The 4th argument is a tuple containing the init arguments of the field. The last argument is the name of the config param, as defined in the plugin model. |
| 152 | |
| 153 | Here is another example: |
| 154 | |
| 155 | {{{ |
| 156 | def _defineGui(self): |
| 157 | self._addTab('Driver') |
| 158 | self._addWidget('Driver', "Type", ComboBoxField, (['bluetooth', 'serial', 'ethernet'],), 'DRIVER_TYPE') |
| 159 | }}} |
| 160 | |
| 161 | The main addition is that we first create a new ''tab'', and then add a '''{{{ComboBoxField}}}'''. |
| 162 | |
| 163 | ==== Plugin registration ==== |
| 164 | |
| 165 | Both previous classes must be defined in the same module. To register the plugin, the module also has to implement a '''{{{register()}}}''' function, which will be called at startup. For example: |
| 166 | |
| 167 | {{{ |
| 168 | def register(): |
| 169 | PluginManager().register(MyModelClass, MyModelController) |
| 170 | }}} |
| 171 | |
| 172 | If the plugin module implements several model/controller capacities, just put additional PluginManager().register() calls. |
| 173 | |
| 174 | ==== Complete example ==== |
| 175 | |
| 176 | Here is the '''Tethered''' plugin, defined in the '''{{{papywizard/plugins/tetheredPlugins}}}''' module: |
| 177 | |