Skip to content

Class reference

yadizhou edited this page Nov 20, 2017 · 12 revisions

labpype.widget has the following classes for making new widgets. You can directly import them from labpype.widget. Alternatively, you can also import them from their own modules.

The documentation of some of the classes has three parts: "Inheritance Guide", "Example", and "APIs". "Inheritance Guide" lists all the class attributes and instance methods need to be implemented when creating a subclass. "Example" shows a simple case. "APIs" lists all the useful methods that you may need when implementing the methods for the subclasses.

Widget class

Widget is the common base class of all the widgets. You will need to specify some class attributes and implement some methods for the child classes to create new widgets.

Inheritance Guide

For convenience, we will use the name Widget as the class name for all the following class attributes and widget as the corresponding object name for the methods, while they actually mean the child class that you inherit from Widget and the object from that child class. For example, we can create a widget class called FirstWidget whose class attribute FirstWidget.NAME is "Awesome Widget". Here, FirstWidget is the class you inherit from Widget and whose class attributes are assigned.

class FirstWidget(Widget):
    NAME = "Awesome Widget"

Note that you should never change the values of class attributes of Widget.

class attribute Widget.NAME

Default: ""

class attribute Widget.DIALOG

Default: None

class attribute Widget.THREAD

Default: False

class attribute Widget.INTERNAL

Default: None

class attribute Widget.INCOMING

Default: None

class attribute Widget.OUTGOING

Default: None

class attribute Widget.SINGLETON

Default: False

instance method widget.Name()

Default behavior: return Widget.NAME

instance method widget.Save()

Default behavior: return JSON formatted str from dumping all the data

instance method widget.Load(f)

Default behavior: return the parsed JSON document

instance method widget.Init()

Default behavior: none

instance method widget.Exit()

Default behavior: none

instance method widget.Reset()

Default behavior: none

instance method widget.Task()

Default behavior: return False

Example

APIs

instance method widget.IsState(state)

instance method widget.IsOutgoingAvailable()

instance method widget.IsIncomingAvailable()

instance method widget.IsInternalAvailable()

Dialog class

Dialog is the common base class of all the dialogs. You will need to specify some class attributes and implement some methods for the child classes to create new dialogs.

Inheritance Guide

For convenience, we will use the name Dialog as the class name for all the following class attributes and dialog as the corresponding object name for the methods, while they actually mean the child class that you inherit from Dialog and the object from that child class.

class attribute Dialog.AUTO

Default: True

class attribute Dialog.SIZE

Default: None

class attribute Dialog.ORIENTATION

Default: wx.VERTICAL

class attribute Dialog.MARGIN

Default: 2

class attribute Dialog.LABEL_WIDTH

Default: 80

class attribute Dialog.LINE_HEIGHT

Default: 20

instance method dialog.Initialize(Sizer)

Default behavior: none

instance method dialog.Finalize(Sizer)

Default behavior: add standard buttons. See Dialog.AddStdButton(sizer)

instance method dialog.GetData()

Default behavior: none

instance method dialog.SetData()

Default behavior: none

Example

APIs

instance method dialog.DisableCanvas()

Disable the main canvas. This method is used together with dialog.EnableCanvas()

instance method dialog.EnableCanvas()

Enable the main canvas. This method is used together with dialog.DisableCanvas()

instance method dialog.AddStdButton(sizer)

Add standard buttons to the dialog. This is the default behavior of dialog.Finalize(Sizer). Therefore, you normally wouln't need to call this method unless you override dialog.Finalize(Sizer).

instance method dialog.AddSeparator(sizer)

instance method dialog.AddSectionHead

dialog.AddSectionHead(sizer,
    orientation=wx.HORIZONTAL,
    label="",
    shape="B")

instance method dialog.AddButton

dialog.AddButton(sizer,
    label="",
    tag="",
    width=80,
    onClick=None,
    **kwargs)

instance method dialog.AddButtonToggle

dialog.AddButtonToggle(sizer,
    label="",
    tags=(),
    width=80,
    toggle=False,
    onClick=None,
    **kwargs)

instance method dialog.AddButtonBundle

dialog.AddButtonBundle(sizer,
    label="",
    tags=(),
    width=80,
    rows=1,
    toggled=0,
    group="",
    onClick=None,
    **kwargs)

instance method dialog.AddPickerValue

dialog.AddPickerValue(sizer,
    label="",
    choices=(),
    selected=-1,
    width=80,
    **kwargs)

instance method dialog.AddStaticText

dialog.AddStaticText(sizer,
    label="",
    value="",
    width=-1)

instance method dialog.AddLineCtrl

dialog.AddLineCtrl(sizer,
    label="",
    value="",
    width=-1,
    style=0,
    onInput=None,
    hint="",
    font=None)

instance method dialog.AddTextCtrl

dialog.AddTextCtrl(sizer,
    label="",
    value="",
    width=-1,
    height=-1,
    style=0,
    inline=True,
    onInput=None,
    hint="",
    font=None)

instance method dialog.AddListBox

dialog.AddListBox(sizer,
    label="",
    choices=(),
    selected=-1,
    width=-1,
    height=-1,
    onClick=None,
    onDClick=None,
    inline=True)

instance method dialog.AddFilePicker

dialog.AddFilePicker(sizer, 
    label="",
    value="",
    width=-1,
    mode="S",
    wildcard="All files (*.*)|*.*",
    style=0,
    onSelect=Ab.DoNothing)

Anchor types

Anchor types are used for defining legit connections. A widget has one or more anchors, each anchor has an attribute aType whose value is an anchor type class. For two anchors to be able to connect, their aType pair should be defined to be legit beforehand.

Anchor types are empty classes used as keys in some dictionary that contains all the legit connections. The reason that a class is chosen as the key over str, int or any other hashable object is that classes are inheritable, and this feature makes it elegant to define legit links. For example, if connections between ANCHOR_STRING and ANCHOR_SEQUENCE is defined to be legit, then connections between ANCHOR_STRING and ANCHOR_DNA, or ANCHOR_STRING and ANCHOR_PROTEIN are also legit automatically, given that ANCHOR_DNA and ANCHOR_PROTEIN are subclasses of ANCHOR_SEQUENCE.

ANCHOR_REGULAR class

The base class for all user-defined anchor types.

ANCHOR_SPECIAL class

The base class for special anchor types (e.g., ANCHOR_ALL and ANCHOR_NONE). The connection between two special anchor types is considered not legit.

ANCHOR_ALL class

Anchors whose aType are ANCHOR_ALL can connect to any anchors whose aType are subclasses of ANCHOR_REGULAR

ANCHOR_NONE class

Anchors whose aType are ANCHOR_NONE cannot connect to anything.

Example

class ANCHOR_SEQUENCE(ANCHOR_REGULAR): pass
class ANCHOR_DNA(ANCHOR_SEQUENCE): pass
class ANCHOR_PROTEIN(ANCHOR_SEQUENCE): pass

Data fields

BaseField class

BaseField(key, label, **kwargs)

BooleanField class

BooleanField(key, label,
    tag1,
    tag2,
    **kwargs)

LineField class

LineField(key, label,
    maxLength=None,
    minLength=None,
    **kwargs)

TextField class

TextField(key, label,
    maxLine=None,
    minLine=None,
    maxLength=None,
    minLength=None,
    **kwargs)

IntegerField class

IntegerField(key, label,
    maxValue=None,
    minValue=None,
    **kwargs)

FloatField class

FloatField(key, label,
    maxValue=None,
    minValue=None,
    **kwargs)

ChoiceField class

ChoiceField(key, label,
    choices=(),
    widget="C",
    **kwargs)