def populateButtons(self): """ Create taurus commandbuttons for everything in modelcommand """ for modelcommand in self._modelcommands: button = TaurusCommandButton(self.frame) button.setCommand(modelcommand['command']) if 'model' in modelcommand: button.setModel(modelcommand['model']) else: button.setUseParentModel(True) if 'customtext' in modelcommand: button.setCustomText(modelcommand['customtext']) if 'dangermessage' in modelcommand: button.setDangerMessage(modelcommand['dangermessage']) if 'parameters' in modelcommand: button.setParameters(modelcommand['parameters']) if 'timeout' in modelcommand: button.setTimeout(modelcommand['timeout']) self.connect(button, Qt.SIGNAL('commandExecuted'), self.onCommandExectued) # Make button expand vertically button.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.frame.layout().addWidget(button) self._buttons.append(button)
def _updateCommandWidgets(self, *args): ''' Inserts command buttons and parameter widgets in the layout, according to the commands from the model ''' #self.debug('In TaurusCommandsForm._updateCommandWidgets())') dev = self.getModelObj() if dev is None or dev.state != TaurusDevState.Ready: self.debug('Cannot connect to device') self._clearFrame() return commands = sorted(dev.command_list_query(), key=self._sortKey) for f in self.getViewFilters(): commands = filter(f, commands) self._clearFrame() layout = self._frame.layout() for row, c in enumerate(commands): self.debug('Adding button for command %s' % c.cmd_name) button = TaurusCommandButton(command=c.cmd_name, text=c.cmd_name) layout.addWidget(button, row, 0) button.setUseParentModel(True) self._cmdWidgets.append(button) self.connect(button, Qt.SIGNAL('commandExecuted'), self._onCommandExecuted) if c.in_type != PyTango.CmdArgType.DevVoid: self.debug('Adding arguments for command %s' % c.cmd_name) pwidget = ParameterCB() if c.cmd_name.lower() in self._defaultParameters: for par in self._defaultParameters.get( c.cmd_name.lower(), []): pwidget.addItem(par) #pwidget.setEditable( (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '' ) if (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '': pwidget.setEditable(True) else: pwidget.setEditable(False) button.setParameters( self._defaultParameters[c.cmd_name.lower()][0]) self.connect(pwidget, Qt.SIGNAL('editTextChanged (const QString&)'), button.setParameters) self.connect(pwidget, Qt.SIGNAL('currentIndexChanged (const QString&)'), button.setParameters) self.connect(pwidget, Qt.SIGNAL('activated (int)'), button.setFocus) self.connect(button, Qt.SIGNAL('commandExecuted'), pwidget.rememberCurrentText) layout.addWidget(pwidget, row, 1) self._paramWidgets.append(pwidget)
def _updateCommandWidgets(self, *args): ''' Inserts command buttons and parameter widgets in the layout, according to the commands from the model ''' #self.debug('In TaurusCommandsForm._updateCommandWidgets())') dev = self.getModelObj() if dev is None or dev.state != TaurusDevState.Ready: self.debug('Cannot connect to device') self._clearFrame() return commands = sorted(dev.command_list_query(), key=self._sortKey) for f in self.getViewFilters(): commands = filter(f, commands) self._clearFrame() layout = self._frame.layout() for row, c in enumerate(commands): self.debug('Adding button for command %s' % c.cmd_name) button = TaurusCommandButton(command=c.cmd_name, text=c.cmd_name) layout.addWidget(button, row, 0) button.setUseParentModel(True) self._cmdWidgets.append(button) button.commandExecuted.connect(self._onCommandExecuted) if c.in_type != PyTango.CmdArgType.DevVoid: self.debug('Adding arguments for command %s' % c.cmd_name) pwidget = ParameterCB() if c.cmd_name.lower() in self._defaultParameters: for par in self._defaultParameters.get(c.cmd_name.lower(), []): pwidget.addItem(par) #pwidget.setEditable( (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '' ) if (self._defaultParameters[c.cmd_name.lower()] or [''])[0] == '': pwidget.setEditable(True) else: pwidget.setEditable(False) button.setParameters(self._defaultParameters[ c.cmd_name.lower()][0]) pwidget.editTextChanged.connect(button.setParameters) pwidget.currentIndexChanged.connect(button.setParameters) pwidget.activated.connect(button.setFocus) button.commandExecuted.connect(pwidget.rememberCurrentText) layout.addWidget(pwidget, row, 1) self._paramWidgets.append(pwidget)
class YAGScreenTVWriteWidget(TaurusWidget): def __init__(self, *args): TaurusWidget.__init__(self, *args) self.setLayout(QtGui.QHBoxLayout()) self.layout().setMargin(0) self.moveInButton = TaurusCommandButton(self) self.moveInButton.setUseParentModel(True) self.moveInButton.setCommand('MoveIn') self.moveInButton.setCustomText('Move In') self.moveOutButton = TaurusCommandButton(self) self.moveOutButton.setUseParentModel(True) self.moveOutButton.setCommand('MoveOut') self.moveOutButton.setCustomText('Move Out') self.layout().addWidget(self.moveInButton) self.layout().addWidget(self.moveOutButton)
class CyclePanel(TaurusWidget): "Panel for controlling the cycling functionality" trend_trigger = QtCore.pyqtSignal(bool) attrs = [ "CyclingTimePlateau", "CyclingIterations", "CyclingSteps", "CyclingRampTime", "NominalSetPoint" ] scale_factor = 1.1 def __init__(self, parent=None): TaurusWidget.__init__(self, parent) self._setup_ui() print('CyclePanel juste avant setmodel') # self.setModel('sys/tg_test/1') def scaleSize(self): size = self.form.scrollArea.widget().frameSize() return QtCore.QSize(size.width(), size.height() * self.scale_factor) def _setup_ui(self): vbox = QtGui.QVBoxLayout(self) self.setLayout(vbox) grid = QtGui.QGridLayout() self.form = MAXForm(withButtons=False) grid.addWidget(self.form, 0, 0, 2, 1) # rescale taurus form methode self.form.scrollArea.sizeHint = self.scaleSize self.status_label = StatusArea() grid.addWidget(self.status_label, 0, 1, 1, 1) commandbox = QtGui.QVBoxLayout(self) self.start_button = TaurusCommandButton(command="StartCycle") self.start_button.setUseParentModel(True) self.stop_button = TaurusCommandButton(command="StopCycle") self.stop_button.setUseParentModel(True) commandbox.addWidget(self.start_button) commandbox.addWidget(self.stop_button) grid.addLayout(commandbox, 1, 1, 1, 1) vbox.addLayout(grid) self.trend = TaurusTrend() vbox.addWidget(self.trend, stretch=1) self.trend_trigger.connect(self.set_trend_paused) self.cyclingState = None def setModel(self, device): print self.__class__.__name__, "setModel", device TaurusWidget.setModel(self, device) # self.state_button.setModel(device) if device: self.form.setModel( ["%s/%s" % (device, attribute) for attribute in self.attrs]) self.status_label.setModel("%s/cyclingStatus" % device) ps = str(PyTango.Database().get_device_property( device, "PowerSupplyProxy")["PowerSupplyProxy"][0]) self.trend.setPaused() self.trend.setModel(["%s/Current" % ps]) self.trend.setForcedReadingPeriod(0.2) self.trend.showLegend(True) # let's pause the trend when not cycling self.cyclingState = self.getModelObj().getAttribute("cyclingState") self.cyclingState.addListener(self.handle_cycling_state) else: if self.cyclingState: self.cyclingState.removeListener(self.handle_cycling_state) self.trend.setModel(None) self.status_label.setModel(None) def handle_cycling_state(self, evt_src, evt_type, evt_value): if evt_type in [ PyTango.EventType.CHANGE_EVENT, PyTango.EventType.PERIODIC_EVENT ]: self.trend_trigger.emit(evt_value.value) def set_trend_paused(self, value): self.trend.setForcedReadingPeriod(0.2 if value else -1) self.trend.setPaused(not value)
class BinpPowerSupplyPanel(TaurusWidget): "Allows directly controlling the BINP power supply connected to the circuit" attrs = ["Voltage"] def __init__(self, parent=None): TaurusWidget.__init__(self, parent) self._setup_ui() def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) form_vbox = QtGui.QVBoxLayout(self) # devicename label hbox2 = QtGui.QVBoxLayout(self) self.device_and_state = DevnameAndState(self) hbox2.addWidget(self.device_and_state, stretch=2) # commands commandbox = QtGui.QHBoxLayout(self) self.start_button = TaurusCommandButton(command="Start") self.start_button.setUseParentModel(True) self.stop_button = TaurusCommandButton(command="Stop") self.stop_button.setUseParentModel(True) self.init_button = TaurusCommandButton(command="Init") self.init_button.setUseParentModel(True) self.on_button = TaurusCommandButton(command="On") self.on_button.setUseParentModel(True) self.off_button = TaurusCommandButton(command="Off") self.off_button.setUseParentModel(True) self.enable_trigger_button = TaurusCommandButton( command="EnableTrigger") self.enable_trigger_button.setUseParentModel(True) self.disable_trigger_button = TaurusCommandButton( command="DisableTrigger") self.disable_trigger_button.setUseParentModel(True) self.reset_button = TaurusCommandButton(command="Reset") self.reset_button.setUseParentModel(True) commandbox.addWidget(self.start_button) commandbox.addWidget(self.stop_button) commandbox.addWidget(self.init_button) commandbox.addWidget(self.on_button) commandbox.addWidget(self.off_button) commandbox.addWidget(self.enable_trigger_button) commandbox.addWidget(self.disable_trigger_button) commandbox.addWidget(self.reset_button) hbox2.addLayout(commandbox, stretch=1) form_vbox.addLayout(hbox2) # attributes self.form = MAXForm(withButtons=False) form_vbox.addLayout(commandbox) form_vbox.addWidget(self.form, stretch=1) self.status_area = StatusArea() form_vbox.addWidget(self.status_area) hbox.addLayout(form_vbox) # value bar self.valuebar = MAXValueBar(self) slider_vbox = QtGui.QVBoxLayout(self) slider_vbox.setContentsMargins(10, 10, 10, 10) hbox.addLayout(slider_vbox) self.current_label = TaurusLabel() self.current_label.setAlignment(QtCore.Qt.AlignCenter) slider_vbox.addWidget(self.valuebar, 1) slider_vbox.addWidget(self.current_label) def setModel(self, device): print self.__class__.__name__, "setModel", device TaurusWidget.setModel(self, device) self.device_and_state.setModel(device) self.status_area.setModel(device) if device: self.form.setModel( ["%s/%s" % (device, attribute) for attribute in self.attrs]) attrname = "%s/%s" % (device, "Voltage") self.valuebar.setModel(attrname) # self.state_button.setModel(device) attr = Attribute(attrname) self.current_label.setText("%s [%s]" % (attr.label, attr.unit)) else: self.form.setModel(None) self.valuebar.setModel(None)
class PowerSupplyPanel(TaurusWidget): "Allows directly controlling the power supply connected to the circuit" attrs = ["long_scalar", "double_scalar", "float_scalar"] # attrs = ["Current", "Voltage", "Resistance"] def __init__(self, parent=None): print('ddddddddddddddddd') TaurusWidget.__init__(self, parent) self._setup_ui() print('juste avant setmodel') self.setModel('sys/tg_test/1') def _setup_ui(self): print('-----------voici ') hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) form_vbox = QtGui.QVBoxLayout(self) # devicename label hbox2 = QtGui.QVBoxLayout(self) self.device_and_state = DevnameAndState(self) hbox2.addWidget(self.device_and_state, stretch=2) # commands commandbox = QtGui.QHBoxLayout(self) self.start_button = TaurusCommandButton(command="On") self.start_button.setUseParentModel(True) self.stop_button = TaurusCommandButton(command="Off") self.stop_button.setUseParentModel(True) self.init_button = TaurusCommandButton(command="Init") self.init_button.setUseParentModel(True) commandbox.addWidget(self.start_button) commandbox.addWidget(self.stop_button) commandbox.addWidget(self.init_button) hbox2.addLayout(commandbox, stretch=1) form_vbox.addLayout(hbox2) # attributes self.form = MAXForm(withButtons=False) form_vbox.addLayout(commandbox) form_vbox.addWidget(self.form, stretch=1) self.status_area = StatusArea() form_vbox.addWidget(self.status_area) hbox.addLayout(form_vbox) # value bar self.valuebar = MAXValueBar(self) slider_vbox = QtGui.QVBoxLayout(self) slider_vbox.setContentsMargins(10, 10, 10, 10) hbox.addLayout(slider_vbox) self.current_label = TaurusLabel() self.current_label.setAlignment(QtCore.Qt.AlignCenter) slider_vbox.addWidget(self.valuebar, 1) slider_vbox.addWidget(self.current_label) def setModel(self, device): print self.__class__.__name__, "setModel", device TaurusWidget.setModel(self, device) self.device_and_state.setModel(device) self.status_area.setModel(device) if device: self.form.setModel( ["%s/%s" % (device, attribute) for attribute in self.attrs]) attrname = "%s/%s" % (device, "Current") self.valuebar.setModel(attrname) # self.state_button.setModel(device) attr = Attribute(attrname) self.current_label.setText("%s [%s]" % (attr.label, attr.unit)) else: self.form.setModel(None) self.valuebar.setModel(None)