Accerciser Plugin Tutorial
Accerciser supports three basic types of plugins.
Base plugins - These plugins are derived from the Plugin base class. They do not provide a visible interface, but could provide additional functionality to Accerciser.
Console plugins - These plugins provide simple console output in to a text area in a plugin tab. Not to be confused with the packaged IPython console.
Viewport plugins - The majority of Accerciser plugins. They provide a custom graphical interface in a tab.
Plugin python source files will automatically be loaded by Accerciser from two locations, either in prefix/share/accerciser/plugins, or in ~/.accerciser/plugins.
In the following sections we will demonstrate how to use each plugin type.
We will create a simplified version of the Quick Select plugin. This plugin will select the last focused accessible when pressing control+alt+e. The entire plugin source could be downloaded here: selector_plugin.py.
First off, here are the import lines we will use:
Next we will derive a new class from the Plugin base class, and assign some mandatory class attributes:
We will now override the init method, in it we will set a global key action for selecting the last focused accessible, register an event listener for the "focus" event, and set the last_focused instance variable to None.
Notice that the global_hotkeys instance variable is a list of tuples, each tuple is one global hotkey action, and it is a list of an action description, desired method to call, key symbol of keypress, and a key modifier mask.
In the "focus" event callback we assign the last_focused instance variable with the accessible that just just emitted the "focus" event.
In the hotkey action callback we update the application wide node with the last focused accessible, if we have recorded it:
The console plugin type allows the display of output on any kind of event, an Accerciser selection change, a gobject timeout, or an AT-SPI event. In this example we will use this plugin type to display focus changes that are emitted by an accessible with a "push button" role. The complete plugin source could be downloaded here: pushbutton_event.py.
The needed import lines:
The class definition, with a plugin name and description:
The init method override, here we connect any signals, or register listeners:
The event callback, if the event source is a push button, print the event.
We will create a plugin that allows quick testing of the "click" action in accessibles that support the Action interface, and have an action named "click". It will be a simple button that could be clicked, and guess what happens when you click it? That's right, it does the "click" action in the accessible. The full source of this plugin could be found here: clicker plugin.py.
First off, some mandatory import lines:
Next, a class definition, with a name and description:
We override the init method with some UI building, and connecting a callback to a signal for the button. We use the alignment container to allow the button to be centered in the plugin tab, and not monstrously take up the entire plugin space. Notice the plugin_area instance variable, this contains a gtk.Frame that could be populated with all the plugin's widgets.
We also created a convenience method that returns a list of supported actions of the currently selected accessible, of course if the accessible does not support the Action interface, it returns an empty list:
The base plugin class has a method call onAccChanged that is called every time the main application's selected accessible changes, we could override it for our own needs, in this case we need to set the button to sensitive only when the current accessible has the "click" action.
The button "clicked" callback performs the "click" action on the accessible. Since this callback could only be called when the button is sensitive, we don't need to worry about checking if the current accessible has the "click" action.