AYAB API

Main AYAB GUI module

Provides an Interface for users to operate AYAB using a GUI.

class ayab.ayab.GenericThread(function, *args, **kwargs)[source]

A generic thread wrapper for functions on threads.

class ayab.ayab.GuiMain[source]

GuiMain is the main object that handles the instance of AYAB’s GUI from ayab_gui.UiForm .

GuiMain inherits from QMainWindow and instanciates a window with the form components form ayab_gui.UiForm.

apply_image_transform(transform_type, *args)[source]

Executes an image transform specified by key and args.

Calls a function from transform_dict, forwarding args and the image, and replaces the QtImage on scene.

flip_image()[source]

Public mirror current Image function.

getSerialPorts()[source]

Returns a list of all USB Serial Ports

invert_image()[source]

Public invert current Image function.

load_image_from_string(image_str)[source]

Loads an image into self.ui.image_pattern_view using a temporary QGraphicsScene

load_pil_image_on_scene(image_obj)[source]

Loads the PIL image on a QtScene and sets it as the current scene on the Image View.

mirror_image()[source]

Public mirror current Image function.

rotate_left()[source]

Public rotate left current Image function.

rotate_right()[source]

Public rotate right current Image function.

set_enabled_plugin(plugin_name=None)[source]

Enables plugin, sets up gui and returns the plugin_object from the plugin selected on module_dropdown.

smart_resize()[source]

Executes the smart resize process including dialog .

updateProgress(progress)[source]

Updates the Progress Bar.

update_file_selected_text_field(route)[source]

‘Sets self.image_file_route and ui.filename_lineedit to route.

Knitting Plugin API

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.

AYAB Control Plugin

Handles the serial communication protocol.

This module handles serial communication, currently works in a synchronous way. AyabCommunication uses an internal PySerial.Serial object to connect to the device. The initializer can also be overriden with a dummy serial object.

class ayab.plugins.ayab_plugin.ayab_communication.AyabCommunication(serial=None)[source]

Class Handling the serial communication protocol.

__del__()[source]

Handles on delete behaviour closing serial port object.

close_serial()[source]

Closes serial port.

cnf_line(lineNumber, lineData, flags, crc8)[source]

Sends a line of data via the serial port.

Sends a line of data to the serial port, all arguments are mandatory. The data sent here is parsed by the Arduino controller which sets the knitting needles accordingly.

Parameters:
  • lineNumber (int) – The line number to be sent.
  • lineData (bytes) – The bytearray to be sent to needles.
  • flags (bytes) – The flags sent to the controller.
  • crc8 (bytes, optional) – The CRC-8 checksum for transmission.
open_serial(pPortname=None)[source]

Opens serial port communication with a portName.

read_line()[source]

Reads a line from serial communication.

req_info()[source]

Sends a request for information to controller.

req_start(startNeedle, stopNeedle)[source]

Sends a start message to the controller.