Changes between Version 76 and Version 77 of DevelopGuide


Ignore:
Timestamp:
Mar 31, 2009, 3:23:57 PM (16 years ago)
Author:
Frédéric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DevelopGuide

    v76 v77  
    107107You seems to be familiar with programing. So, I will explain you the way to develop plugins for Papywizard. First, I suggest you use the svn repository:
    108108
    109     svn co http://svn.gbiloba.org/papywizard/trunk papywizard
    110 
    111 Plugins implements one or more 'capacity'. Possible capacities are:
     109{{{
     110$ svn co http://svn.gbiloba.org/papywizard/trunk papywizard
     111}}}
     112
     113''Note: under Windows, you can use [http://tortoisesvn.tigris.org TortoiseSVN].''
     114
     115Plugins implements one or more 'capacity'. Available capacities are:
    112116
    113117 * ''yawAxis''
     
    119123A plugin needs to implement 2 classes (for each implemented capacity): one for the model (real work), and one for the controller (configuration dialog).
    120124
    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
     127All model classes inherit from the '''{{{AbstractPlugin}}}''' class (defined in {{{the papywizard.common.abstractPlugin}}} module).
     128
     129Then, 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
     131The plugin model may need some user parameters in order to work. These parameters must be defined in the '''{{{_defineConfig()}}}''' method. For example:
     132
     133{{{
     134def _defineConfig(self):
     135    self._addConfigKey('_myParam', 'MY_PARAM', default='a value')
     136}}}
     137
     138will 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
     140In 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
     144Controller 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{{{
     147def _defineGui(self):
     148    self._addWidget('Main', "My param", LineEditField, (), 'MY_PARAM')
     149}}}
     150
     151will 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
     153Here is another example:
     154
     155{{{
     156def _defineGui(self):
     157    self._addTab('Driver')
     158    self._addWidget('Driver', "Type", ComboBoxField, (['bluetooth', 'serial', 'ethernet'],), 'DRIVER_TYPE')
     159}}}
     160
     161The main addition is that we first create a new ''tab'', and then add a '''{{{ComboBoxField}}}'''.
     162
     163==== Plugin registration ====
     164
     165Both 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{{{
     168def register():
     169    PluginManager().register(MyModelClass, MyModelController)
     170}}}
     171
     172If the plugin module implements several model/controller capacities, just put additional PluginManager().register() calls.
     173
     174==== Complete example ====
     175
     176Here is the '''Tethered''' plugin, defined in the '''{{{papywizard/plugins/tetheredPlugins}}}''' module:
     177
    136178
    137179