| 1 |
Plugins |
|---|
| 2 |
------- |
|---|
| 3 |
|
|---|
| 4 |
Gaphor is growing and the need arises to add optional modules: plugins. |
|---|
| 5 |
|
|---|
| 6 |
A plugin is loaded on startup of the application (and possibly on demand). |
|---|
| 7 |
|
|---|
| 8 |
Before a plugin is loaded an xml file is read which contains some definitions |
|---|
| 9 |
for the plugin: |
|---|
| 10 |
- information such as author, version, and of course the name |
|---|
| 11 |
- requirements: other plugins this one depends on, modules |
|---|
| 12 |
- definitions of Actions |
|---|
| 13 |
- Code that should be ran before and after installation, before and after |
|---|
| 14 |
removal. |
|---|
| 15 |
|
|---|
| 16 |
A typical plugin.xml file looks like this: |
|---|
| 17 |
|
|---|
| 18 |
<?xml version="1.0"?> |
|---|
| 19 |
<plugin name="UML metamodel sanity check" |
|---|
| 20 |
version="0.1" |
|---|
| 21 |
author="Arjan Molenaar"> |
|---|
| 22 |
<description> |
|---|
| 23 |
A description of what this thing does. |
|---|
| 24 |
</description> |
|---|
| 25 |
|
|---|
| 26 |
<require> |
|---|
| 27 |
<!-- |
|---|
| 28 |
Define modules and plugins that are needed for this plugin to function |
|---|
| 29 |
properly. |
|---|
| 30 |
--> |
|---|
| 31 |
<module name="os.path"/> |
|---|
| 32 |
<plugin name="anotherPlugin"/> |
|---|
| 33 |
</require> |
|---|
| 34 |
|
|---|
| 35 |
<provide> |
|---|
| 36 |
<!-- |
|---|
| 37 |
Actions should be defined on the module's toplevel (like in __init__.py). |
|---|
| 38 |
--> |
|---|
| 39 |
<action id="MyPlugin" |
|---|
| 40 |
label="Do a typical thing with the plugin" |
|---|
| 41 |
icon-file="myicon.png" |
|---|
| 42 |
tooltip="bla bla" |
|---|
| 43 |
class="MyPluginAction" slot="WindowSlot"> |
|---|
| 44 |
<!-- |
|---|
| 45 |
Add optional dependencies to this action. The action is then updated |
|---|
| 46 |
when actions defined in the depends tag are executed. |
|---|
| 47 |
--> |
|---|
| 48 |
<depends action="ItemFocus"/> |
|---|
| 49 |
</action> |
|---|
| 50 |
</provide> |
|---|
| 51 |
</plugin> |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
A plugin contains three sections: |
|---|
| 55 |
description |
|---|
| 56 |
A description of the plugin (could be shown in a plugin browser for example) |
|---|
| 57 |
This is just a text field. |
|---|
| 58 |
require |
|---|
| 59 |
Prerequisits for this plugin (such as exptic modules and other plugins) |
|---|
| 60 |
provide |
|---|
| 61 |
Actions that are provided by this plugin |
|---|
| 62 |
|
|---|
| 63 |
The require section can contain modules and plugins that are needed for this plugin |
|---|
| 64 |
to work. |
|---|
| 65 |
|
|---|
| 66 |
The <provide> section contains the actions that can be added to the application. |
|---|
| 67 |
An action is a Python class that extends gaphor.plugin.Action (or CheckAction for |
|---|
| 68 |
checkbox actions or RadioAction for radiobutton actions). An action has an |
|---|
| 69 |
id |
|---|
| 70 |
Id is a unique identifier for the action |
|---|
| 71 |
label |
|---|
| 72 |
A label that is shown in the menu |
|---|
| 73 |
tooltip |
|---|
| 74 |
some extra information |
|---|
| 75 |
icon-file |
|---|
| 76 |
A file containing a nice (24x24) image, preferbly a PNG image. |
|---|
| 77 |
class |
|---|
| 78 |
The Action class to load from the module. The Action class should be |
|---|
| 79 |
visible through __init__.py (class names like 'test.TestAction' do not |
|---|
| 80 |
work) |
|---|
| 81 |
slot |
|---|
| 82 |
Slots are predefined places in a menu where new actions can be added. |
|---|
| 83 |
|
|---|
| 84 |
Slots |
|---|
| 85 |
----- |
|---|
| 86 |
Currently the following slots are defined: |
|---|
| 87 |
|
|---|
| 88 |
Main window |
|---|
| 89 |
|
|---|
| 90 |
main menu: |
|---|
| 91 |
slot name menu comment |
|---|
| 92 |
FileOpenSlot File after the 'Open' item |
|---|
| 93 |
FileSaveSlot File after the 'Save' item |
|---|
| 94 |
FileExportSlot File/Export |
|---|
| 95 |
FileSlot File After the 'Close' item |
|---|
| 96 |
EditSlot Edit |
|---|
| 97 |
DiagramSlot Diagram |
|---|
| 98 |
WindowSlot Window |
|---|
| 99 |
HelpSlot Help |
|---|
| 100 |
|
|---|
| 101 |
Items in a diagram can have additional actions too: |
|---|
| 102 |
|
|---|
| 103 |
item: slot name: |
|---|
| 104 |
Class ClassPopupSlot |
|---|
| 105 |
|
|---|
| 106 |
More slots are likely to be defined in the future. |
|---|
| 107 |
|
|---|