Plugin API Overview

Plugin Class

AYAB features a simple but powerful API for implementing APIs for Knitting Machine hacks. Plugins are based on Yapsy. While knowledge in Yapsy is useful, it is not complex to get started.

Plugin modules are specified by a .yapsy-plugin file, and a Python module, specified in said file.

A class extending KnittingPlugin is required to create a plugin. Methods not overriden on subclasses will raise NotImplementedError.

class ayab.plugins.knitting_plugin.KnittingPlugin(callbacks_dict)[source]

A generic plugin implementing a state machine for knitting.

Subclasses inherit the basic State Machine defined in __init__.

cleanup_ui(ui)[source]

Cleans up and reverts changes to ui done by setup_ui.

get_configuration_from_ui(ui)[source]

Loads options dict with a given parent QtGui object. Required for save-load functionality.

Returns:A dict with configuration.
Return type:dict
onconfigure(e)[source]

Callback when state machine executes configure(parent_ui = parent, options={})

This state gets called to configure the plugin for knitting. It can either be called when first configuring the plugin, when an error had happened and reset is necessary. The parent ui is expected to hold an object with properties.

Parameters:parent_ui – An object having already been set up by setup_ui.
onfinish(e)[source]

Callback when state machine executes finish().

When finish() gets called, the plugin is expected to be able to restore it’s state back when configure() gets called. Finish should trigger a Process Completed notification so the user can operate accordingly.

onknit(e)[source]

Callback when state machine executes knit().

Starts the knitting process, this is the only function call that can block indefinitely, as it is called from an instance of QThread, allowing for processes that require timing and/or blocking behaviour.

setup_ui(parent_ui)[source]

Sets up UI, usually as a child of parent_ui.ui.knitting_options_dock.

While the whole parent_ui object is available for the plugin to modify, plugins authors are strongly encouraged to only manipulate the knitting_options_dock, plugins have full access to the parent UI as a way to fully customize the GUI experience.

Parameters:parent_ui – A PyQt.QMainWindow with the property parent_ui.ui.knitting_options_dock, an instance of QDockWidget to hold the plugin’s UI.

Building UIs

The setup_ui function gets called when the plugin gets selected on the main UI dropdown. The function clean_ui gets called on disposal. Usually the parent UI will only modify parent_ui.ui.knitting_options_dock, as it is the specified container for the knitting options. You can load generated modules using pyuic, by instanciating the dock, setting up autogenerated UI and then setting up behaviour.

UIs are expected to have a limited horizontal width, as children of the dock are not expected to overflow horizontally.