pylab_ml.gui.instruments.template_instrument.Gui
- class Gui(parent=None, name='scope', channel=None)[source]
Bases:
GuiTemplate Gui.
- Inherited from base_instrument
status
- __init__(parent=None, name='scope', channel=None)[source]
Initialize the GUI, load the UI file, adjust the UI elements, and set up MQTT connections.
- Parameters:
parent (object, optional) – The parent object to which this GUI belongs. Default is None.
name (str, optional) – The name of the instrument. Default is ‘scope’.
channel (int, optional) – The channel number. Default is None.
Methods
__init__([parent, name, channel])Initialize the GUI, load the UI file, adjust the UI elements, and set up MQTT connections.
add_menue(menue, connect, enabled[, ...])Add a menue item to Setup
add_menuicon(typ[, connect])Add icon and action to the menu.
adjustUI()Adjust the UI, set the title and icons and connect the quit action.
close([event])Close the GUI, publish an 'off' message, and call the close method of the base class.
dprint(msg)Print a debug message if debugging is enabled.
filtersubtopic(value)Filter the subtopic from the value, if the value starts with the topinstname.
gui2mqtt(widget)Function connect a Gui-widget to mqtt, it sends a mqtt set command with the value from the Gui-widget.
Disconnect the GUI, set the MQTT status to "disconnect" and disable the frame.
hide()Hide the GUI.
Return whether the GUI is currently visible.
mqttConnectSVGWidget(filename, name[, channel])Create an InteractiveSvgWidget and load the filname.
Connect all object which start with MQTT_ to the function gui2mqtt().
mqttreceive(instName, msg)Common MQTT receive messages, get raw MQTT data for more information.
Adjust the UI elements, set icons, create and connect menu entries, and connect MQTT widgets.
objectName2mqttName(name)Filter from the object name the right MQTT name.
publish(cmd[, value, instName])Publish a command and value over MQTT.
retranslateUi(Form)Retranslate the UI, set the text of the widgets.
setLabel(Label, value[, ext])Set the text of a label.
set_Geometry(geometry)Set the geometry of the GUI, check if the geometry is on the actual screen.
show()Show the GUI.
svg2mqtt(name, value)Publish the name and value over mqtt.
unitOfMeasurement(value[, unit])Convert a value with a unit to its numerical representation.
Attributes
Return the id of the instrument, which is used for MQTT topics.
Return the MQTT status of the instrument, which is either "connect" or "disconnect".
Return the current status message from the status bar.
Return the subtopic of the instrument, which is the part after the topinstname.
Add a menue item to Setup
- Parameters:
menue (string) – The text of the menu item.
connect (function) – The function to be called when the menu item is triggered.
enabled (bool) – Whether the menu item is enabled.
checkable (bool, optional) – Whether the menu item is checkable. The default is False.
checked (bool, optional) – Whether the menu item is checked. The default is False.
Add icon and action to the menu.
- Parameters:
typ (string) – The type of the menu item.
connect (function, optional) – The function to be called when the menu item is triggered. The default is None.W
“onoff” : on/off
- close(event=None)[source]
Close the GUI, publish an ‘off’ message, and call the close method of the base class.
- filtersubtopic(value)[source]
Filter the subtopic from the value, if the value starts with the topinstname.
- gui2mqtt(widget)[source]
Function connect a Gui-widget to mqtt, it sends a mqtt set command with the value from the Gui-widget.
- Parameters:
widget (QtWidgets.QWidget) – The GUI widget that triggered the MQTT command, expected to have an objectName that follows the
- Return type:
None.
- gui_disconnect()[source]
Disconnect the GUI, set the MQTT status to “disconnect” and disable the frame.
- property id
Return the id of the instrument, which is used for MQTT topics.
- mqttConnectSVGWidget(filename, name, channel=None)[source]
Create an InteractiveSvgWidget and load the filname. Connect all clicks to the text id’s to the function svg2mqtt().
- Parameters:
filename (string) – The path to the SVG file to be loaded into the widget.
name (string) – The base name for the widget, used for MQTT topic construction.
channel (string, optional) – An optional channel identifier to be appended to the name for MQTT topic construction. The default is None.
- Returns:
svgWidget – The created InteractiveSvgWidget with the loaded SVG file and connected signals.
- Return type:
- mqttConnectWidgets()[source]
Connect all object which start with MQTT_ to the function gui2mqtt().
Create a list with all commands in self.mqtt_cmds
- property mqtt_status
Return the MQTT status of the instrument, which is either “connect” or “disconnect”.
- mqttreceive(instName, msg)[source]
Common MQTT receive messages, get raw MQTT data for more information.
- Parameters:
instName (str) – The name of the instrument that received the MQTT message.
msg (dict) – The MQTT message received, expected to contain ‘cmd’ and ‘payload’ keys for processing.
- myadjustUI()[source]
Adjust the UI elements, set icons, create and connect menu entries, and connect MQTT widgets.
- objectName2mqttName(name)[source]
Filter from the object name the right MQTT name.
- eg. objectname = MQTT_voltage -> Voltage listen on get and set
= MQTT_set_I_limit -> I_limit listen only on set = MQTT_get_I_limit -> I_limit listen only on get = TAB_ch -> Name for a tab-name
- Parameters:
name (string) – The object name to be filtered.
- Returns:
listen (string) – The type of MQTT command to listen for (“set”, “get”, or “”).
result (string) – The filtered MQTT name extracted from the object name.
- publish(cmd, value='', instName=None)[source]
Publish a command and value over MQTT.
- Parameters:
cmd (string) – The command to be published.
value (string, optional) – The value associated with the command. The default is an empty string.
instName (string, optional) – The name of the instrument. If None, the instance’s name is used. The default is None.
- setLabel(Label, value, ext=None)[source]
Set the text of a label.
- Parameters:
Label (object) – the label object.
value (string) – this text will be displayed.
ext (string, optional) – extention, The default is None.
- Return type:
None.
- set_Geometry(geometry)[source]
Set the geometry of the GUI, check if the geometry is on the actual screen.
- Parameters:
geometry (tuple) – A tuple of the form (x, y, width, height) representing the geometry of the GUI.
- property status
Return the current status message from the status bar.
- property subtopic
Return the subtopic of the instrument, which is the part after the topinstname.
- svg2mqtt(name, value)[source]
Publish the name and value over mqtt. Overwrite this function if you need a more complex form.
- Parameters:
name (string) – The name of the SVG element that was changed.
value (string) – The new value of the SVG element.
- unitOfMeasurement(value, unit=None)[source]
Convert a value with a unit to its numerical representation.
- Parameters:
value (string) – The value with a unit (e.g., “10 k”).
unit (string, optional) – The unit to use for conversion. If None, the unit is inferred from the value.
- Returns:
The numerical representation of the value.
- Return type:
float