ToolsPlugins - veusz/veusz GitHub Wiki
Tools plugins are introduced in Veusz 1.9 to allow the user to add code to Veusz to automate the manipulation of documents. The user can do anything, including
- Adding, changing or manipulating widgets
- Change settings inside widgets
- Import data
- Save files and export plots The Python code for any plugins can be added in the preferences dialog box.
A tools plugin uses the standard Veusz embedding interface to manipulate the document. The standard Veusz commands can be accessed with the interface object (e.g. interface.Export('page.png')). The object-based API can be accessed from the interface.Root object, as described in EmbeddingPython. Here is an example tools plugin which searches and replaces markers in xy widgets (point plotters):
import veusz.plugins as plugins class ReplaceMarkerPlugin(plugins.ToolsPlugin): """Replace marker with another marker in XY widgets.""" # a tuple of strings building up menu to place plugin on menu = ('Replace marker',) # unique name for plugin name = 'Replace marker' # name to appear on status tool bar description_short = 'Replace a marker with a different marker' # text to appear in dialog box description_full = 'Search and replace a marker with a different marker.' def __init__(self): """Make list of fields.""" self.fields = [ plugins.FieldWidget("widget", descr="Start from widget", default="/"), plugins.FieldMarker("markersearch", descr="Search for marker"), plugins.FieldMarker("markerreplace", descr="Replace with marker"), ] def apply(self, interface, fields): """Do the work of the plugin. interface: veusz command line interface object (exporting commands) fields: dict mapping field names to values """ # get the Node corresponding to the widget path given fromwidget = interface.Root.fromPath(fields['widget']) search = fields['markersearch'] replace = fields['markerreplace'] # loop over every xy widget including and below fromwidget for node in fromwidget.WalkWidgets(widgettype='xy'): # if marker is value given, replace if node.marker.val == search: node.marker.val = replace plugins.toolspluginregistry.append(ReplaceMarkerPlugin)
A tools plugin should inherit ToolsPlugin.