pyworkflow.gui.form module

This modules implements the automatic creation of protocol form GUI from its params definition.

class pyworkflow.gui.form.Binding(paramName, var, protocol, *callbacks)[source]

Bases: object

class pyworkflow.gui.form.BoolVar(value=None)[source]

Bases: object

Wrapper around tk.IntVar

get()[source]
set(value)[source]
class pyworkflow.gui.form.ComboVar(enum)[source]

Bases: object

Create a variable that display strings (for combobox) but the values are integers (for the underlying EnumParam).

get()[source]
set(value)[source]
class pyworkflow.gui.form.FormWindow(title, protocol, callback, master=None, **kwargs)[source]

Bases: Window

This class will create the Protocol params GUI to fill in the parameters. The creation of input parameters will be based on the Protocol Form definition. This class will serve as a connection between the GUI variables (tk vars) and the Protocol variables.

Layout:

There are 4 main blocks that goes each one in a different row1. 1. Header: will contain the logo, title and some link buttons. 2. Common: common execution parameters of each run. 3. Params: the expert level and tabs with the Protocol parameters. 4. Buttons: buttons at bottom for close, save and execute.

Constructor of the Form window. Params:

title: title string of the windows. protocol: protocol from which the form will be generated. callback: callback function to call when Save or Execute are press.

adjustSections()[source]
adjustSize()[source]
execute(e=None)[source]
getVarValue(varName)[source]

This method should retrieve a value from

getWidgetValue(protVar, param)[source]
resize(frame)[source]
save(e=None)[source]
schedule()[source]
setParamFromVar(paramName)[source]
setVar(paramName, value)[source]
setVarFromParam(paramName)[source]
takeScreenShot()[source]

Method to take a screenshot of itself. The idea is to, in the future, take a screenshot and collect parameter to either create a page of the protocol in rst or send it to the Scipion site and have there one page per protocol.

For now this is not used.

updateLabelAndCommentVars()[source]

Read the label and comment first line to update the entry boxes in the form.

updateProtocolLabel()[source]
updateProtocolParams()[source]

This method is only used from WEB, since in Tk all params are updated when they are changed.

class pyworkflow.gui.form.GroupWidget(row, paramName, param, window, parent)[source]

Bases: ParamWidget

hide()[source]
show()[source]

Grid the label and content in the specified row

class pyworkflow.gui.form.LineWidget(row, paramName, param, window, parent, value, callback=None, visualizeCallback=None, column=0, showButtons=True)[source]

Bases: ParamWidget

show()[source]

Grid the label and content in the specified row

class pyworkflow.gui.form.MultiPointerTreeProvider(mapper)[source]

Bases: TreeProvider

Store several pointers to objects to be used in a BoundTree and as storage from MultiPointerVar.

addObject(obj)[source]
clear()[source]
getColumns()[source]

Return a list of tuples (c, w) where: c: is the column name and index w: is the column width

getObjectInfo(obj)[source]

This function will be called by the Tree with each object that will be inserted. A dictionary should be returned with the possible following entries: ‘key’: the key value to insert in the Tree ‘text’: text of the object to be displayed

(if not passed the ‘key’ will be used)

‘image’: image path to be displayed as icon (optional) ‘parent’: the object’s parent in which insert this object (optional) ‘tags’: list of tags names (optional)

getObjects()[source]

Return the objects that will be inserted in the Tree

removeObject(obj)[source]
class pyworkflow.gui.form.MultiPointerVar(provider, tree)[source]

Bases: object

Wrapper around tk.StringVar to hold object pointers. This class is related with MultiPointerTreeProvider, which stores the list of pointed objects and have the logic to add and remove from the list.

clear()[source]
get()[source]
getSelectedObjects()[source]
remove()[source]

Remove first element selected.

set(value)[source]
class pyworkflow.gui.form.ParamWidget(row, paramName, param, window, parent, value, callback=None, visualizeCallback=None, column=0, showButtons=True)[source]

Bases: object

For each one in the Protocol parameters, there will be one of this in the Form GUI. It is mainly composed by: A Label: put in the left column A Frame(content): in the middle column and container

of the specific components for this parameter

A Frame(buttons): a container for available actions buttons It will also have a Variable that should be set when creating

the specific components

clear()[source]
static createBoolWidget(parent, display=1, **args)[source]

Return a BoolVar associated with a yes/no selection. **args: extra arguments passed to tk.Radiobutton and tk.Frame

constructors.

param checkbox

will use a Checkbutton instead.

display(condition)[source]

show or hide depending on the condition.

get()[source]
hide()[source]
isMultiPointer()[source]

True if dealing with MultiPointer params

set(value)[source]
show()[source]

Grid the label and content in the specified row

class pyworkflow.gui.form.PointerVar(protocol)[source]

Bases: object

Wrapper around tk.StringVar to hold object pointers.

get()[source]
getPointer()[source]
remove()[source]
set(value)[source]
class pyworkflow.gui.form.ProtocolClassTreeProvider(protocolClassName)[source]

Bases: TreeProvider

Will implement the methods to provide the object info of subclasses objects(of className) found by mapper

getColumns()[source]

Return a list of tuples (c, w) where: c: is the column name and index w: is the column width

getObjectInfo(obj)[source]

This function will be called by the Tree with each object that will be inserted. A dictionary should be returned with the possible following entries: ‘key’: the key value to insert in the Tree ‘text’: text of the object to be displayed

(if not passed the ‘key’ will be used)

‘image’: image path to be displayed as icon (optional) ‘parent’: the object’s parent in which insert this object (optional) ‘tags’: list of tags names (optional)

getObjects()[source]

Return the objects that will be inserted in the Tree

class pyworkflow.gui.form.QueueDialog(window, queueDict)[source]

Bases: Dialog

Dialog to entry the queue parameters.

Initialize a dialog. Arguments:

parent – a parent window (the application window) title – the dialog title

**args accepts:

buttons – list of buttons tuples containing which buttons to display

apply()[source]

process the data This method is called automatically to process the data, after the dialog is destroyed. By default, it does nothing.

body(bodyFrame)[source]

create dialog body. return widget that should have initial focus. This method should be overridden, and is called by the __init__ method.

validate()[source]

validate the data This method is called automatically to validate the data before the dialog is destroyed. By default, it always validates OK.

class pyworkflow.gui.form.RelationsTreeProvider(protocol, relationParam, selected=None)[source]

Bases: SubclassesTreeProvider

Will implement the methods to provide the object info of subclasses objects(of className) found by mapper

getObjects()[source]

Return the objects that will be inserted in the Tree

class pyworkflow.gui.form.ScalarTreeProvider(protocol, scalarParam, selected=None)[source]

Bases: TreeProvider

Will implement the methods to provide the object info of scalar outputs

CREATION_COLUMN = 'Creation'
INFO_COLUMN = 'Info'
getColumns()[source]

Return a list of tuples (c, w) where: c: is the column name and index w: is the column width

getObjectInfo(pobj)[source]

This function will be called by the Tree with each object that will be inserted. A dictionary should be returned with the possible following entries: ‘key’: the key value to insert in the Tree ‘text’: text of the object to be displayed

(if not passed the ‘key’ will be used)

‘image’: image path to be displayed as icon (optional) ‘parent’: the object’s parent in which insert this object (optional) ‘tags’: list of tags names (optional)

getObjects()[source]

Return the objects that will be inserted in the Tree

isSelected(obj)[source]

Check if an object is selected or not.

objectKey(pobj)[source]
class pyworkflow.gui.form.ScalarWithPointerVar(protocol, changeListener)[source]

Bases: StringVar

tk.StringVar to hold object pointers and scalars.

Construct a string variable.

MASTER can be given as master widget. VALUE is an optional value (defaults to “”) NAME is an optional Tcl name (defaults to PY_VARnum).

If NAME matches an existing variable and VALUE is omitted then the existing value is retained.

get()[source]

Return value of variable as string.

getPointer()[source]
hasPointer()[source]
set(value)[source]

Set the variable to VALUE.

trace(mode, callback)[source]

Define a trace callback for the variable.

MODE is one of “r”, “w”, “u” for read, write, undefine. CALLBACK must be a function which is called when the variable is read, written or undefined.

Return the name of the callback.

This deprecated method wraps a deprecated Tcl method that will likely be removed in the future. Use trace_add() instead.

class pyworkflow.gui.form.SectionFrame(master, label, callback=None, height=15, **args)[source]

Bases: Frame

This class will be used to create a frame for the Section That will have a header with red color and a content frame with white background

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

adjustContent()[source]
class pyworkflow.gui.form.SectionWidget(form, master, section, height, callback=None, **args)[source]

Bases: SectionFrame

This class will be used to create a section in FormWindow

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

get()[source]

Return boolean value if is selected

hide()[source]
set(value)[source]
show()[source]
class pyworkflow.gui.form.SubclassesTreeProvider(protocol, pointerParam, selected=None)[source]

Bases: TreeProvider

Will implement the methods to provide the object info of subclasses objects(of className) found by mapper

CREATION_COLUMN = 'Creation'
ID_COLUMN = 'Protocol Id'
INFO_COLUMN = 'Info'
getColumns()[source]

Return a list of tuples (c, w) where: c: is the column name and index w: is the column width

getObjectActions(pobj)[source]

Return a list of tuples (key, action) were keys are the string options that will be display in the context menu and the actions are the functions to call when the specific action is selected. The first action in the list will be taken as the default one when the element is double-clicked.

getObjectInfo(pobj)[source]

This function will be called by the Tree with each object that will be inserted. A dictionary should be returned with the possible following entries: ‘key’: the key value to insert in the Tree ‘text’: text of the object to be displayed

(if not passed the ‘key’ will be used)

‘image’: image path to be displayed as icon (optional) ‘parent’: the object’s parent in which insert this object (optional) ‘tags’: list of tags names (optional)

getObjects()[source]

Return the objects that will be inserted in the Tree

isSelected(obj)[source]

Check if an object is selected or not.

objectKey(pobj)[source]

Returns the value to be evaluated during sorting based on _sortingColumnName

class pyworkflow.gui.form.TextVar(text, value='')[source]

Bases: object

Wrapper around tk.StringVar to bind the value of a Text widget.

Params:

text: Text widget associated with this variable. value: initial value for the widget.

get()[source]
set(value)[source]
class pyworkflow.gui.form.VerticalScrolledFrame(parent, *args, **kw)[source]

Bases: Frame

A pure Tkinter scrollable frame that actually works! * Use the ‘interior’ attribute to place widgets inside the scrollable frame * Construct and pack/place/grid normally * This frame only allows vertical scrolling

Construct a frame widget with the parent MASTER.

Valid resource names: background, bd, bg, borderwidth, class, colormap, container, cursor, height, highlightbackground, highlightcolor, highlightthickness, relief, takefocus, visual, width.

pyworkflow.gui.form.editObject(self, title, root, obj, mapper)[source]

Show a Text area to edit the protocol label and comment.

pyworkflow.gui.form.getObjectLabel(pobj, mapper)[source]

We will try to show in the list the string representation that is more readable for the user to pick the desired object.

pyworkflow.gui.form.getPointerLabelAndInfo(pobj, mapper)[source]

Return a string to represent selected objects that are stored by pointers. This function will be used from PointerVar and MultiPointerVar.