# Graphical user interfaces (GUI)¶

Qt4 graphical user interface for the controllers.

pyhard2.ctrlr.Config(section, title='Controller', description='pyhard2 GUI configuration')

Handle command line arguments and configuration files to initialize Controllers.

Command line arguments:
• -t, --title: The name of the controller.
• -p, --port: The port where the hardware is connected.
• -n, --nodes: A space-separated list of nodes at port.
• -m, --names: A corresponding list of names for the nodes.
• -v, --virtual: Load the virtual offline driver.
• file: The path to a configuration file.

Launching a controller from the command line with:

python pyhard2/ctrlr/MODULE -p COM1 -n 1 2 3 -m first second third


or by pointing to a file containing

MODULE:
COM1:
- node: 1
name: first

- node: 2
name: second

- node: 3
name: third


Example

From the root directory of a working installation of pyhard2, the following line starts a virtual controller with three nodes:

python pyhard2/ctrlr/pfeiffer -v -n 1 2 3 -m gauge1 gauge2

class pyhard2.ctrlr.DashboardConfig(filename)

Extend the config file format described in Config() to launch the Dashboard interface.

The config files are extended with a dashboard section such as

dashboard:
name: Dashboard
image: :/img/gaslines.svg
labels:
- name: LABEL1
pos: [0.25, 0.25]
- name: LABEL2
pos: [0.5, 0.25]
- name: LABEL3
pos: [0.75, 0.25]


Where Dashboard is the name of the window. image: points to an svg file that will be displayed in the background of the window. labels: is a list of text labels containing the text LABEL1, LABEL2, and LABEL3 displayed at the position given by pos: as (x,y) pairs of relative coordinates. x and y can be any value between 0 and 1.

The other nodes also require the pos data in the format specified above, and optional scale and angle data may be passed as well. Such as the previous file may become

MODULE:
COM1:
- node: 1
name: first
pos: [0.25, 0.5]

- node: 2
name: second
pos: [0.5, 0.5]
scale: 0.5
angle: 180

- node: 3
name: third
pos: [0.75, 0.5]

• pos gives the position as [x, y] pairs of relative coordinates (x and y are values between 0 and 1) for the widget of the corresponding node.
• scale scales the widget by the given amount.
• angle rotates the widget by the given amount, in degree.

Example

From the root directory of a working installation of pyhard2, the following line starts a dashboard containing virtual instruments:

python pyhard2.ctrlr.__init__.py circat.yml -v

class pyhard2.ctrlr.ScientificSpinBox(parent=None)

QDoubleSpinBox with a scientific display.

textFromValue(value)

Return the formatted value.

valueFromText(text)

Return the text as a float.

class pyhard2.ctrlr.ListData

Custom QwtData mapping a list onto x,y values.

__len__()

Return length of data.

__iter__()

Iterate on the data.

__getitem__(i)

Return x,y values at i.

sample(i)

Return x,y values at i.

copy()

Return self.

historySize()

How many points of history to display after exportAndTrim.

setHistorySize(historySize)

Set how many points of history to display after exportAndTrim.

x(i)

Return x value.

y(i)

Return y value.

append(xy)

Add x,y values to the data.

Does nothing if None is in xy.

clear()

Clear the data in place.

exportAndTrim(csvfile)

Export the data to csvfile and trim it.

The data acquired since the previous call is saved to csvfile and historySize points are kept. The rest of the data is deleted.

class pyhard2.ctrlr.TimeSeriesData

A ListData to plot values against time.

Note

The time is set to zero upon instantiation.

append(value)

Append time, value to the list.

class pyhard2.ctrlr.ProfileData(rootItem)

Custom QwtData handling a QStandardItemModel with two columns as x, y values.

Parameters: rootItem (QStandardItem) – The root item of the model.
__iter__()

Iterate on the model.

copy()

Return self.

size()

Return the number of rows under rootItem.

Note

Rows where values cannot be converted to float are not counted.

sample(i)

Return x,y values at i.

Raises: IndexError – if i is invalid. ValueError – if the data at i do not convert to float.
x(i)

Return x value at i.

sample() for the exceptions.

y(i)

Return y value at i.

sample() for the exceptions.

class pyhard2.ctrlr.PlotZoomer(canvas)

QwtPlotZoomer for zooming on QwtPlot.

clearZoomStack()

Force autoscaling and clear the zoom stack.

class pyhard2.ctrlr.SingleShotProgram

Program that sends new values at predefined times.

Note

The program has its own timer so that the events will fire precisely at the given times.

started

The signal is emitted when the program starts.

finished

The signal is emitted when the program has finished executing.

value

The signal is emitted with the value generated by the program.

interval()
setInterval(msec)

This property holds the timeout interval in milliseconds.

profile()

Return the profile.

setProfile(profile)

Set the profile to profile.

isRunning()

Returns whether the program is running.

start()

Start or restart the program.

stop()

Stop the program.

class pyhard2.ctrlr.SetpointRampProgram

Program that performs setpoint ramps.

setProfile(profile)

Set the profile to profile.

class pyhard2.ctrlr.DoubleClickEventFilter(parent)

Emit doubleClicked signal on MouseButtonDblClick event.

class pyhard2.ctrlr.FormatTextDelegate(format='%.2f', parent=None)

QStyledItemDelegate formatting the text displayed.

class pyhard2.ctrlr.DoubleSpinBoxDelegate(spinBox=None, parent=None)

Item delegate for editing models with a spin box.

Every property of the spin box can be set on the delegate with the methods from QDoubleSpinBox.

Parameters: spinBox – A spin box prototype to use for editing, defaults to QDoubleSpinBox if not given.
decimals()
setDecimals(prec)

This property holds the precision of the spin box, in decimals.

minimum()
setMinimum(min)

This property holds the minimum value of the spin box.

maximum()
setMaximum(max)

This property holds the maximum value of the spin box.

setRange(minimum, maximum)

Convenience function to set the minimum and maximum values with a single function call.

singleStep()
setSingleStep(val)

This property holds the step value.

prefix()
setPrefix(prefix)

This property holds the spin box’s prefix.

suffix()
setSuffix(suffix)

This property holds the spin box’s suffix.

__getattr__(name)

Set properties on the spin box.

createEditor(parent, option, index)

Return a QDoubleSpinBox.

setEditorData(spinBox, index)

Set spin box value to index.data().

setModelData(spinBox, model, index)

Set model data to spinBox.value().

class pyhard2.ctrlr.ItemRangedSpinBoxDelegate(spinBox=None, parent=None)

Item delegate for editing models in a spin box.

Every property of the spin box can be set on the delegate with the methods from QDoubleSpinBox.

The minimum and maximum properties are set from the item to be edited.

Inherits DoubleSpinBoxDelegate.

createEditor(parent, option, index)

Return a QDoubleSpinBox.

• The minimum property of the spin box is set to item.minimum() if this value has been set.
• The maximum property of the spin box is set to item.maximum() if this value has been set.
class pyhard2.ctrlr.ButtonDelegate(button=None, parent=None)

Item delegate for editing models with a button.

Parameters: button – The button prototype to use for editing, defaults to QPushButton if not given.
editorEvent(event, model, option, index)

Change the state of the editor and the data in the model when the user presses the left mouse button, Key_Space or Key_Select iff the cell is editable.

class pyhard2.ctrlr.ItemSelectionModel(model, parent=None)

QItemSelectionModel with copy/paste and a part of the QTableWidget interface.

currentRow()

Return the row of the current item.

currentColumn()

Return the column of the current item.

insertRow()

Insert an empty row into the table at the current row.

insertColumn()

Insert an empty column into the table at the current column.

removeRows()

Remove the selected rows.

removeColumns()

Remove the selected columns.

copy()

Copy the values in the selection to the clipboard.

paste()

Paste values in the clipboard at the current item.

Raises: IndexError – if the data in the clipboard does not fit in the model.

Horizontal header item for the driver view.

type()

Return QStandardItem.UserType.

clone()

Reimplemented from QStandardItem.

command()

Return the command for this column.

setCommand(command)

Set the command for this column to command.

defaultPollingState()

Return True if the column defaults to polling; otherwise return False.

setDefaultPollingState(state)

Set the default polling state for this column to state.

defaultLoggingState()

Return True if the column defaults to logging; otherwise return False.

setDefaultLoggingState(state)

Set the default logging state for this column to state.

Item to use in vertical header of the driver model.

type()

Return QtGui.QStandardItem.UserType.

clone()

Reimplemented from QtGui.QStandardItem.

node()

Return the node for this row.

setNode(node)

Set the node for this row to node.

class pyhard2.ctrlr.SignalProxy(parent=None)

Proxy class for Qt4 signals.

SignalProxy can be used in place of a Signal in classes that do not inherit QObject.

class pyhard2.ctrlr.DriverItem

QStandardItem handling communication with the driver.

type()

Return QtGui.QStandardItem.UserType.

clone()

Reimplemented from QStandardItem.

isPolling()

Return True if polling is enabled for this item; otherwise return False.

setPolling(state)

Set polling to state for this item.

isLogging()

Return True if logging is enabled for this item; otherwise return False.

setLogging(state)

Set logging to state for this item.

command()

Return the Command object for this column.

node()

Return the node for this row, if any.

minimum()

Return the minimum value for this item.

The value is read in the driver.

maximum()

Return the maximum value for this item.

The value is read in the driver

Return the read only value for this item.

The value is read in the driver.

queryData()

Request reading data in the driver.

Note

• The query is constructed from the Command set on this item’s column and the node (if any) set for this item’s row.
• If the driver raises a HardwareError, the error is logged but execution continues.
data(role=0)

Default to Qt.DisplayRole.

setData(value, role=2)

Default to Qt.EditRole.

class pyhard2.ctrlr.DriverModel(driver, parent=None)

Model to handle the driver.

__iter__()

Iterate on items.

driver()

Return the driver for this model.

node(row)

Return node for row, if any.

Add node as a new row with label.

Add command as a new column with label.

populate()

Fill the model with DriverItem.

closeEvent(event)

Let the driver thread exit cleanly.

class pyhard2.ctrlr.ControllerUi(uifile=None)

QMainWindow for the controllers.

This class loads uifile if one is provided or defaults to the ui/controller.ui designer file and sets UI properties that are not accessible in designer.

setDataPlotLogScale(state)

Change the scale of dataPlot to log or linear.

class pyhard2.ctrlr.Controller(config, driver, uifile='', parent=None)

Implement the behavior of the GUI.

windowTitle()
setWindowTitle(title)

This property holds the window title (caption).

show()

Show the widget and its child widgets.

close()

Close the widget.

isColumnHidden()

Return True if the given column is hidden; otherwise return False.

setColumnHidden()

if hide is True, the given column will be hidden; otherwise it will be shown.

autoSave()

Export the data in the dataPlot to an archive.

startProgram(row)

Start the program at row.

startAllPrograms()

Start or restart every program.

stopAllPrograms()

Stop every program.

classmethod virtualInstrumentController(config, driver)

Initialize controller for the virtual instrument driver.

addCommand(command, label='', hide=False, poll=False, log=False, specialColumn='')

Add command as a new column in the driver table.

Parameters: hide (bool) – Hide the column. poll (bool) – Set the default polling state. log – Set the default logging state.

Add node as a new row in the driver table.

programmableColumn()

Return the index of the programmable column.

setProgrammableColumn(column)

Set the programmable column to column.

setPidPColumn(column)

Set the pid P column to column.

setPidIColumn(column)

Set the pid I column to column.

setPidDColumn(column)

Set the pid D column to column.

populate()

Populate the driver table.

class pyhard2.ctrlr.DashboardUi(uifile='')

QMainWindow for the dashboard.

This class loads uifile if one is provided or default to the ui/dashboard.ui designer file.

class pyhard2.ctrlr.Dashboard(uifile='', parent=None)

Implement the behavior of the GUI.

windowTitle()
setWindowTitle(title)

This property holds the window title (caption).

show()

Show the widget and its child widgets.

close()

Close the widget.

setBackgroundItem(backgroundItem)

Set the SVG image to use as a background.

Add the text to the scene.