class MotorConfigPanel(TaurusWidget): """Widget for motor""" def __init__(self, parent=None): TaurusWidget.__init__(self, parent) self._setup_ui() def _setup_ui(self): self.gridLayout = QtGui.QGridLayout(self) self.taurusForm = TaurusForm(self) self.taurusForm.setWithButtons(False) self.gridLayout.addWidget(self.taurusForm, 0, 0, 1, 2) def setModel(self, mot): attributes = [mot+"/Status", mot+"/State", mot+"/Step_per_unit", mot+"/Offset", mot+"/Sign", mot+"/Position", mot+"/DialPosition", ] self.taurusForm.setModel(attributes)
class AttributesPreview(Qt.QFrame): def __init__(self, model='', parent=None, source=None): Qt.QWidget.__init__(self, parent) self.model = model self.source = source self.test = panic.current()._eval self.test._trace = True self.initStyle() self.updateAttributes(self.model) def initStyle(self): print 'In AttributesPreview.initStyle()' try: self.setLayout(Qt.QGridLayout()) self.redobt = Qt.QPushButton() self.redobt.setIcon(getThemeIcon('view-refresh')) self.redobt.setToolTip('Update result') self.taurusForm = TaurusForm() self.taurusForm.setWithButtons(False) self.taurusForm.setWindowTitle('Preview') self.layout().addWidget(self.redobt, 0, 6, 1, 1) self.layout().addWidget( Qt.QLabel('Values of attributes used in the Alarm formula:'), 0, 0, 1, 1) self.layout().addWidget(self.taurusForm, 1, 0, 1, 7) self.connect(self.redobt, Qt.SIGNAL('pressed()'), self.updateAttributes) except: print traceback.format_exc() @Catched def updateAttributes(self, model=None): print('AttributesPreview.updateAttributes(%s)' % model) if not model and self.source: try: if hasattr(self.source, 'formula'): model = self.source.formula elif hasattr(self.source, '__call__'): model = self.source() else: model = str(self.source or '') except: print(traceback.format_exc()) if not fandango.isSequence(model): ms, model = self.test.parse_variables(model or ''), set() for var in ms: dev, attr = var[0], var[1] if ':' in dev and not dev.startswith('tango://'): dev = 'tango://' + dev model.add(dev + '/' + attr) self.model = sorted(model) print('In AttributesPreview.updateAttributes(%s)' % model) self.taurusForm.setModel(model) [ tvalue.setLabelConfig("<attr_fullname>") for tvalue in self.taurusForm.getItems() ]
def setModel(self, model): TaurusForm.setModel(self, model) # a hack to replace taurus lineedit widgets with ours... for widget in self: if isinstance(widget.writeWidget(), TaurusValueLineEdit): widget.writeWidgetClass = MAXLineEdit # widget.writeWidget().setAutoApply(True) # this causes issues widget.writeWidget().setForcedApply(True) widget.writeWidget().setEnableWheelEvent(True)
def test_form(): from taurus.qt.qtgui.panel import TaurusForm tgclass_map = {'IORegister': PoolIORegisterTV} form = TaurusForm() form.setCustomWidgetMap(tgclass_map) model = 'tango://controls02:10000/ioregister/gc_tgiorctrl/1' if len(sys.argv) > 1: model = sys.argv[1] form.setModel([model]) form.show()
def test2(): import sys from taurus.qt.qtgui.application import TaurusApplication from taurus.qt.qtgui.panel import TaurusForm app = TaurusApplication() w = TaurusForm() attrname = 'eval:@taurus.core.evaluation.test.res.dev_example.FreeSpaceDevice/getFreeSpace("/")' w.setModel(attrname) w.show() sys.exit(app.exec_())
def test_form_itemFactory(qtbot): """Checks that the TaurusForm itemFactory API works""" lines = ["test_Form_ItemFactory={}:_DummyItemFactory".format(__name__)] group = "taurus.form.item_factories" mock_entry_point(lines, group=group) w = TaurusForm() qtbot.addWidget(w) w.setModel([ "eval://localhost/@dummy/'test_itemfactory'", "eval://localhost/@dummy/'test_itemfactory2'", ]) qtbot.wait_until(lambda: len(w) == 2, timeout=3200) # The first item should get a customized _DummyTV widget assert type(w[0]) is _DummyTV # The second item shoud get the default form widget assert type(w[1]) is w._defaultFormWidget
class IORConfigPanel(TaurusWidget): """Widget to configure the IOR""" config_trigger = QtCore.pyqtSignal() def __init__(self, userwidget, parent=None): self.userwidget = userwidget TaurusWidget.__init__(self, parent) self._setup_ui() self.oldvalue = {} def updateBoxes(self): self.userwidget.updateBoxes(True) def _setup_ui(self): self.gridLayout = QtGui.QGridLayout(self) self.taurusForm = TaurusForm(self) self.taurusForm.setWithButtons(False) self.gridLayout.addWidget(self.taurusForm, 0, 0, 1, 2) def setModel(self, ior): attributes = [ior+"/Labels", ior+"/Calibration", ] self.taurusForm.setModel(attributes) #Need listeners on these attributes to update user widget #for a in attributes: # taurus.Attribute(a).addListener(self.configListener) #self.config_trigger.connect(self.updateBoxes) def configListener(self, src, evt_type, attr_val): #is this going to emit every 3 seconds irrespective of whether attribute actually changes? if isinstance(src,taurus.core.tango.tangoattribute.TangoAttribute): if src not in self.oldvalue: self.oldvalue[src] = attr_val.value else: if self.oldvalue[src] != attr_val.value: self.oldvalue[src] = attr_val.value self.config_trigger.emit()
def configure_form(dev, form=None): """ Creates a TauForm and configures its Status fields """ if form is None: form = FORM_CLASS() elif hasattr(form, 'setModel'): form.setModel([]) ##Configuring the TauForm: form.setWithButtons(False) form.setWindowTitle(dev) form.setModel('%s/%s' % (dev, a) for a in get_dev_attrs(dev)) ##Adapting the status widget to show properly an status status = form.getItemByModel( dev + '/status') #A TauValue object (containing label and value widgets) sw = status.readWidget() #A TauStatusLabel object sw.setAlignment(Qt.Qt.AlignLeft) sw.setMinimumHeight(STATUS_HEIGHT) #sw.setShowQuality(False) #It didn't work as expected return form
def test_form_cwidget_bck_compat(qtbot): """check that the cusomWidgetMap bck-compat works""" w = TaurusForm() qtbot.addWidget(w) # check that custom widget map is empty by default assert w.getCustomWidgetMap() == {} w.setItemFactories(include=()) try: # check that an explicit call to setCustomWidgetMap works dummy = ("taurus.qt.qtgui.panel.test.test_taurusform._DummyTV", (), {}) w.setCustomWidgetMap({"DataBase": dummy}) w.setModel(["tango:sys/database/2", "tango:sys/tg_test/1"]) qtbot.wait_until(lambda: len(w) == 2, timeout=3200) assert type(w[0]) == _DummyTV assert type(w[1]) == TaurusValue assert w.getCustomWidgetMap() == {"DataBase": dummy} # check that the custom widget map can be restored w.setCustomWidgetMap({}) w.setModel(["tango:sys/database/2", "tango:sys/tg_test/1"]) qtbot.wait_until(lambda: len(w) == 2, timeout=3200) assert type(w[0]) == TaurusValue assert type(w[1]) == TaurusValue assert w.getCustomWidgetMap() == {} finally: # set model to None as an attempt to avoid problems in atexit() w.setModel(None) qtbot.wait_until(lambda: len(w) == 0, timeout=3200)
def main(): from taurus.core.util import argparse from taurus.qt.qtgui.application import TaurusApplication from taurus.qt.qtgui.panel import TaurusForm parser = argparse.get_taurus_parser() parser.set_usage("%prog [options] [model1 [model2 ...]]") app = TaurusApplication(cmd_line_parser=parser) args = app.get_command_line_args() if not args: parser.print_usage() sys.exit(1) form = TaurusForm() form.setFormWidget(GammaSPCeTV) form.setModel(args) form.setModifiableByUser(True) form.show() sys.exit(app.exec_())
def test_form_itemFactory_loading(qtbot): """ check that the factory loading is robust against unloadable plugins and badly-implemented item factories """ w = TaurusForm() qtbot.addWidget(w) w.setItemFactories(include=(_BadEntryPoint, _BadFactory, _DummyItemFactory)) w.setModel([ "eval://localhost/@dummy/'test_itemfactory'", "eval://localhost/@dummy/'test_badfactory'", "eval:1", ]) qtbot.wait_until(lambda: len(w) == 3, timeout=3200) # handled by _DummyItemFactory assert type(w[0]) == _DummyTV # handled in _BadFactory (even if with wrong return value) assert type(w[1]) == _DummyTV # errored in _BadFactory, ignored by _DummyItemFactory assert type(w[2]) == TaurusValue
#tmw.addToolBar(toolbar) #toolbar.setIconSize(Qt.QSize(30,30)) #toolbar.addAction(Qt.QIcon(":/actions/media-record.svg"),"SnapApp",snap) #toolbar.setMovable(True) #toolbar.setFloatable(True) #toolbar.setToolTip("ToolBarrrrrrrr") #menubar=tmw.menuBar() #dupa=menubar.addMenu('&Dupa') #dupa.addAction(Qt.QIcon(":/actions/media-record.svg"),"SnapApp",snap) contextAttributes = [ attr['full_name'] for attr in context.get_attributes().values() ] taurusForm = TaurusForm(tmw) taurusForm.setModel(contextAttributes) tmw.setCentralWidget(taurusForm) tmw.statusBar().showMessage('Ready') s = tmw.splashScreen() s.finish(tmw) tmw.show() toolbar2 = snapToolbar(tmw) toolbar2.setRefreshTime(5) tmw.addToolBar(toolbar2) #widgets=tmw.findChildren(taurus.qt.qtgui.base.TaurusBaseComponent) #att_table=[] #for w in widgets: #if type(w.getModelObj()).__name__ == 'TangoAttribute':
import sys, PyTango from PyQt4 import Qt from taurus.qt.qtgui import container from taurus.qt.qtgui.panel import TaurusForm import panic from panic.widgets import * if __name__ == "__main__": qapp = Qt.QApplication([]) device = sys.argv[1] if sys.argv else 'sys/tg_test/1' attr_list = ['%s/%s'%(device,a) for a in PyTango.DeviceProxy(device).get_attribute_list()] tmw = container.TaurusMainWindow() taurusForm = TaurusForm(tmw) taurusForm.setModel(attr_list) tmw.setCentralWidget(taurusForm) tmw.statusBar().showMessage('Ready') tmw.show() s=tmw.splashScreen() s.finish(tmw) print '*'*80 toolbar = PanicToolbar(tmw) tmw.addToolBar(toolbar) sys.exit(qapp.exec_())
def setModel(self, model): attrList = [ "%s/%s" % (model, attrName) for attrName in self._attributes ] TaurusForm.setModel(attrList) self._PhCtModel = model
def setModel(self,model): attrList = ["%s/%s"%(model,attrName) for attrName in self._attributes] TaurusForm.setModel(attrList) self._PhCtModel = model
class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") self._Form=Form self.font=QtGui.QFont() self.font.setBold(True) self.gridLayout_2 = QtGui.QGridLayout(Form) self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout = QtGui.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.chooseLabel=Qt.QLabel() self.chooseLabel.setObjectName("chooseLabel") self.chooseLabel.setFont(self.font) self.chooseLabel.setAlignment(QtCore.Qt.AlignCenter); self.gridLayout.addWidget(self.chooseLabel, 0, 0, 1, 1) self.tac=attributeChooser() self.tac.setObjectName("taurusAttributeChooser") self.gridLayout.addWidget(self.tac, 1, 0, 6, 1) self.selectedLabel=Qt.QLabel() self.selectedLabel.setObjectName("selectedLabel") self.selectedLabel.setFont(self.font) self.selectedLabel.setAlignment(QtCore.Qt.AlignCenter); self.selectedLabel.hide() self.gridLayout.addWidget(self.selectedLabel, 0, 1, 1, 6) self.tf=TaurusForm() self.tf.setWithButtons(False) self.tf.setObjectName("taurusForm") self.tf.hide() self.gridLayout.addWidget(self.tf, 1, 1, 1, 6) self.label=Qt.QLabel() self.label.setObjectName("label") self.label.setFont(self.font) self.label.setAlignment(QtCore.Qt.AlignCenter); self.gridLayout.addWidget(self.label, 1, 1, 1, 6) spacerItem = QtGui.QSpacerItem(1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout.addItem(spacerItem, 1, 1, 1, 1) self.modepLabel = QtGui.QLabel(Form) self.modepLabel.setObjectName("modepLabel") self.modepLabel.setText('Period [s]:') self.gridLayout.addWidget(self.modepLabel, 2, 1, 1, 1) self.modepLineEdit = QtGui.QLineEdit(Form) self.modepLineEdit.setObjectName("modepLineEdit") self.modepLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.modepLineEdit.setMaxLength(7) self.modepLineEdit.setMaximumWidth(60) self.modepLineEdit.setText('60.0') self.gridLayout.addWidget(self.modepLineEdit, 2, 2, 1, 1) self.modeaLabel = QtGui.QLabel(Form) self.modeaLabel.setObjectName("modeaLabel") self.modeaLabel.setText('Absolute Period [s]:') self.gridLayout.addWidget(self.modeaLabel, 3, 1, 1, 1) self.modeaLineEdit = QtGui.QLineEdit(Form) self.modeaLineEdit.setObjectName("modeaLineEdit") self.modeaLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.modeaLineEdit.setMaxLength(7) self.modeaLineEdit.setMaximumWidth(60) self.modeaLineEdit.setText('15.0') self.gridLayout.addWidget(self.modeaLineEdit, 3, 2, 1, 1) self.modeaLowerLimitLabel = QtGui.QLabel(Form) self.modeaLowerLimitLabel.setObjectName("modeaLowerLimitLabel") self.modeaLowerLimitLabel.setText('Lower Limit (decr.):') self.gridLayout.addWidget(self.modeaLowerLimitLabel, 3, 3, 1, 1) self.modeaLowerLimitLineEdit = QtGui.QLineEdit(Form) self.modeaLowerLimitLineEdit.setObjectName("modeaLowerLimitLineEdit") self.modeaLowerLimitLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 2, Form)) self.modeaLowerLimitLineEdit.setMaxLength(7) self.modeaLowerLimitLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.modeaLowerLimitLineEdit, 3, 4, 1, 1) self.modeaUpperLimitLabel = QtGui.QLabel(Form) self.modeaUpperLimitLabel.setObjectName("modeaUpperLimitLabel") self.modeaUpperLimitLabel.setText('Upper Limit (incr.):') self.gridLayout.addWidget(self.modeaUpperLimitLabel, 3, 5, 1, 1) self.modeaUpperLimitLineEdit = QtGui.QLineEdit(Form) self.modeaUpperLimitLineEdit.setObjectName("modeaUpperLimitLineEdit") self.modeaUpperLimitLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 2, Form)) self.modeaUpperLimitLineEdit.setMaxLength(7) self.modeaUpperLimitLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.modeaUpperLimitLineEdit, 3, 6, 1, 1) self.moderLabel = QtGui.QLabel(Form) self.moderLabel.setObjectName("moderLabel") self.moderLabel.setText('Relative Period [s]:') self.gridLayout.addWidget(self.moderLabel, 4, 1, 1, 1) self.moderLineEdit = QtGui.QLineEdit(Form) self.moderLineEdit.setObjectName("moderLineEdit") self.moderLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.moderLineEdit.setMaxLength(7) self.moderLineEdit.setMaximumWidth(60) self.moderLineEdit.setText('15.0') self.gridLayout.addWidget(self.moderLineEdit, 4, 2, 1, 1) self.moderLowerLimitPercentLabel = QtGui.QLabel(Form) self.moderLowerLimitPercentLabel.setObjectName("moderLowerLimitPercentLabel") self.moderLowerLimitPercentLabel.setText('Lower % Limit (decr.):') self.gridLayout.addWidget(self.moderLowerLimitPercentLabel, 4, 3, 1, 1) self.moderLowerLimitPercentLineEdit = QtGui.QLineEdit(Form) self.moderLowerLimitPercentLineEdit.setObjectName("moderLowerLimitPercentLineEdit") self.moderLowerLimitPercentLineEdit.setValidator(QtGui.QDoubleValidator(0, 1, 2, Form)) self.moderLowerLimitPercentLineEdit.setMaxLength(7) self.moderLowerLimitPercentLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.moderLowerLimitPercentLineEdit, 4, 4, 1, 1) self.moderUpperLimitPercentLabel = QtGui.QLabel(Form) self.moderUpperLimitPercentLabel.setObjectName("moderUpperLimitPercentLabel") self.moderUpperLimitPercentLabel.setText('Upper % Limit (incr.):') self.gridLayout.addWidget(self.moderUpperLimitPercentLabel, 4, 5, 1, 1) self.moderUpperLimitPercentLineEdit = QtGui.QLineEdit(Form) self.moderUpperLimitPercentLineEdit.setObjectName("moderUpperLimitPercentLineEdit") self.moderUpperLimitPercentLineEdit.setValidator(Qt.QDoubleValidator(0, 1, 2, Form)) self.moderUpperLimitPercentLineEdit.setMaxLength(7) self.moderUpperLimitPercentLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.moderUpperLimitPercentLineEdit, 4, 6, 1, 1) self.gridButtonLayout = QtGui.QGridLayout() self.gridButtonLayout.setObjectName("gridButtonLayout") spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridButtonLayout.addItem(spacerItem, 0, 1, 1, 1) self.pushButtonStart = QtGui.QPushButton(Form) self.pushButtonStart.setObjectName("pushButtonStart") self.pushButtonStart.setEnabled(False) self.gridButtonLayout.addWidget(self.pushButtonStart, 0, 2, 1, 1) self.pushButtonStop = QtGui.QPushButton(Form) self.pushButtonStop.setObjectName("pushButtonStop") self.pushButtonStop.setEnabled(False) self.gridButtonLayout.addWidget(self.pushButtonStop, 0, 3, 1, 1) self.pushButtonCancel = QtGui.QPushButton(Form) self.pushButtonCancel.setObjectName("pushButtonCancel") self.gridButtonLayout.addWidget(self.pushButtonCancel, 0, 4, 1, 1) self.gridLayout.addLayout(self.gridButtonLayout, 5, 1, 1, 6) self.gridLayout_2.addLayout(self.gridLayout, 1, 0, 1, 1) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): Form.setWindowTitle(QtGui.QApplication.translate("Form", "Archiving Widget", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonStart.setText(QtGui.QApplication.translate("Form", "Start Archiving", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonStop.setText(QtGui.QApplication.translate("Form", "Stop", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonCancel.setText(QtGui.QApplication.translate("Form", "Close", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText(QtGui.QApplication.translate("Form", "Nothing to display", None, QtGui.QApplication.UnicodeUTF8)) self.selectedLabel.setText(QtGui.QApplication.translate("Form", "Press start to start archiving selected attributes:", None, QtGui.QApplication.UnicodeUTF8)) self.chooseLabel.setText(QtGui.QApplication.translate("Form", "Choose attributes to archive and hit apply to move attributes to selection", None, QtGui.QApplication.UnicodeUTF8)) self.tf.connect(self.tac, Qt.SIGNAL("UpdateAttrs"), self.onUpdate) QtCore.QObject.connect(self.pushButtonStart, Qt.SIGNAL("clicked()"), self.onStart) QtCore.QObject.connect(self.pushButtonStop, Qt.SIGNAL("clicked()"), self.onStop) QtCore.QObject.connect(self.pushButtonCancel, Qt.SIGNAL("clicked()"), self.onCancel) QtCore.QObject.connect(self.modepLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.modepTextChanged) QtCore.QObject.connect(self.modeaLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.modeaTextChanged) QtCore.QObject.connect(self.moderLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.moderTextChanged) #QtCore.QObject.connect(self.moderUpperLimitPercentLineEdit, Qt.SIGNAL('editingFinished()'), self.moderUpperLimitPercentTextChanged) #QtCore.QObject.connect(self.moderLowerLimitPercentLineEdit, Qt.SIGNAL('editingFinished()'), self.moderLowerLimitPercentTextChanged) #QtCore.QObject.connect(self.modeaUpperLimitLineEdit, Qt.SIGNAL('editingFinished()'), self.modeaUpperLimitTextChanged) #QtCore.QObject.connect(self.modeaLowerLimitLineEdit, Qt.SIGNAL('editingFinished()'), self.modeaLowerLimitTextChanged) def modepTextChanged(self): if self.modepLineEdit.text(): if (float(self.modepLineEdit.text()) < 1 or float(self.modepLineEdit.text()) > 14400): Qt.QMessageBox.critical(self._Form,'Error','Value ranges between 1 and 14400', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) if float(self.modepLineEdit.text()) > 14400: self.modepLineEdit.setText('14400') else: self.modepLineEdit.setText('1') else: Qt.QMessageBox.critical(self._Form,'Error','Value ranges between 1 and 14400', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modepLineEdit.setText('1') def modeaTextChanged(self): if self.modeaLineEdit.text(): if (float(self.modeaLineEdit.text()) > float(self.modepLineEdit.text())): Qt.QMessageBox.critical(self._Form,'Error','Value cannot be higher than '+self.modepLineEdit.text(), QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modeaLineEdit.setText('0') def moderTextChanged(self): if self.moderLineEdit.text(): if (float(self.moderLineEdit.text()) > float(self.modepLineEdit.text())): Qt.QMessageBox.critical(self._Form,'Error','Value cannot be higher than '+self.modepLineEdit.text(), QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.moderLineEdit.setText('0') def validate(self, modep, modea, moder): if (modep < modea or modep < moder): Qt.QMessageBox.critical(self._Form,'Error','Period value has to be higher than the others', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modepLineEdit.setText(str(10*max(int(self.moderLineEdit.text()), int(self.modeaLineEdit.text())))) return False return True def floatValidation(self, line): val = line.text() try: float(val) return True except: Qt.QMessageBox.critical(self._Form,'Error in '+str(line.objectName()),'Wrong value !\nSetting value to 0!', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) line.setText('0') return False def onStart(self): self.floatValidation(self.moderUpperLimitPercentLineEdit) self.floatValidation(self.moderLowerLimitPercentLineEdit) self.floatValidation(self.modeaUpperLimitLineEdit) self.floatValidation(self.modeaLowerLimitLineEdit) try: self.modep=int(1000*self.modepLineEdit.text()) self.modea=(int(1000*self.modeaLineEdit.text()) if self.modeaLineEdit.text() else None) self.modeaLowerLimit=(float(self.modeaLowerLimitLineEdit.text()) if self.modeaLowerLimitLineEdit.text() else None) self.modeaUpperLimit=(float(self.modeaUpperLimitLineEdit.text()) if self.modeaUpperLimitLineEdit.text() else None) self.moder=(int(1000*self.moderLineEdit.text()) if self.moderLineEdit.text() else None) self.moderLowerLimit=(float(self.moderLowerLimitPercentLineEdit.text()) if self.moderLowerLimitPercentLineEdit.text() else None) self.moderUpperLimit=(float(self.moderUpperLimitPercentLineEdit.text()) if self.moderUpperLimitPercentLineEdit.text() else None) if self.validate(self.modep, self.modea, self.moder): reply=Qt.QMessageBox.question(self._Form,"Warning","Do you want to start archiving selected attributes?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) if reply == QtGui.QMessageBox.Yes: command={'MODE_P':[self.modep]} if (self.modea and self.modeaUpperLimit and self.modeaLowerLimit): command['MODE_A']=[self.modea, self.modeaUpperLimit, self.modeaLowerLimit] if (self.moder and self.moderUpperLimit and self.moderLowerLimit): command['MODE_R']=[self.moder, self.moderUpperLimit, self.moderLowerLimit] attrs=[a for a in self.tf.getModel()] cmd=self.tac.tdb.check_modes('tdb', command) toStop=[a for a in attrs if a in self.tac.beingArchived] try: if toStop: self.tac.tdb.api.start_archiving(attrs, cmd, kill=True) else: self.tac.tdb.api.start_archiving(attrs, cmd) except: Qt.QMessageBox.critical(self._Form,"Error",'Cannot start archiving process.\nCheck the state of archiving managers.', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) print(traceback.format_exc()) self.tac.beingArchived=[a.lower() for a in self.tac.tdb if self.tac.tdb.is_attribute_archived(a.lower())] #update archived list self.onUpdate(attrs) self.tac.setNewDevName() except: print(traceback.format_exc()) def onStop(self): toStop=[att.lower() for att in self.tf.getModel() if att.lower() in self.tac.beingArchived] reply=Qt.QMessageBox.question(self._Form,"Warning","Do you want to stop archiving "+str(len(toStop))+" attributes?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) if reply == QtGui.QMessageBox.Yes: self.tac.tdb.api.stop_archiving(toStop) self.tac.beingArchived=[a.lower() for a in self.tac.tdb if self.tac.tdb.is_attribute_archived(a.lower())] #update archived list self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') self.tac.setNewDevName() self.clearParams() def onUpdate(self, attrs): self.clearParams() if not attrs: self.tf.hide() self.label.show() self.selectedLabel.hide() self.pushButtonStart.setEnabled(False) self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') else: self.label.hide() self.selectedLabel.show() self.tf.show() self.tf.setModel(attrs) for i in range(len(attrs)): item=self.tf.getItemByIndex(i) if item.getModel().lower() in self.tac.beingArchived: item.setExtraWidgetClass(historyButton) historyButton().setModel(item.getModel()) self.pushButtonStart.setEnabled(True) toStop=[att.lower() for att in attrs if att.lower() in self.tac.beingArchived] if toStop: self.pushButtonStop.setEnabled(True) self.pushButtonStop.setText('Stop ('+str(len(toStop))+')') modes=self.tac.tdb.get(toStop[0]).modes if 'MODE_P' in modes.keys(): self.modepLineEdit.setText(str(int(modes['MODE_P'][0]/1000))) if 'MODE_R' in modes.keys(): if len(modes['MODE_R']) == 3: self.moderLineEdit.setText(str(int(modes['MODE_R'][0]/1000))) self.moderLowerLimitPercentLineEdit.setText(str(float(modes['MODE_R'][1]))) self.moderUpperLimitPercentLineEdit.setText(str(float(modes['MODE_R'][2]))) if 'MODE_A' in modes.keys(): if len(modes['MODE_A']) == 3: self.modeaLineEdit.setText(str(int(modes['MODE_A'][0]/1000))) self.modeaLowerLimitLineEdit.setText(str(int(modes['MODE_A'][1]))) self.modeaUpperLimitLineEdit.setText(str(int(modes['MODE_A'][2]))) else: self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') def clearParams(self): self.modepLineEdit.setText('60') self.moderLineEdit.setText('') self.moderLowerLimitPercentLineEdit.setText('') self.moderUpperLimitPercentLineEdit.setText('') self.modeaLineEdit.setText('') self.modeaLowerLimitLineEdit.setText('') self.modeaUpperLimitLineEdit.setText('') def onCancel(self): self._Form.close()
class IORUserPanel(TaurusWidget): """Widget to use the IOR""" def __init__(self, parent=None): TaurusWidget.__init__(self, parent) self._setup_ui() self.ior_model = None self.mot_model = None self.options = [] self.dict = {} def updateBoxes(self,arg): """ If receive signal to update the options, adjust the model""" if self.ior_model is not None and self.mot_model is not None : #only do it once initialised self.setModel(self.ior_model, self.mot_model,firstcall=False,updateIOR=True) def _setup_ui(self): self.gridLayout = QtGui.QGridLayout(self) self.taurusForm = TaurusForm(self) #form for the standard IOR widget self.taurusForm.setWithButtons(False) self.gridLayout.addWidget(self.taurusForm, 0, 0, 1, 2) #form for the standard motor widget self.taurusForm2 = TaurusForm(self) self.taurusForm2.setWithButtons(False) self.gridLayout.addWidget(self.taurusForm2, 1, 0, 1, 2) #form with a custom combo box - can replace the standard IOR widget #self.comboBox = TaurusValueComboBox(self) #self.comboBox.setAutoApply(True) #self.gridLayout.addWidget(self.comboBox, 2, 0, 1, 2) #self.label = TaurusLabel(self) #self.gridLayout.addWidget(self.label, 0, 1, 1, 1) def setModel(self, ior, mot, firstcall=False,updateIOR=False): self.ior_model = ior self.mot_model = mot self.updateIOR = updateIOR self.firstcall = firstcall #If we triggered a change, have the labels really changed, if so set model updated = False if self.firstcall or self.updateIOR: options = [(option.split(":")[0], option.split(":")[1]) for option in (taurus.Attribute(ior+"/Labels").read().value).split()] if options != self.options: updated = True self.options = options for opt in self.options: self.dict[opt[0]] = opt[1] #self.comboBox.setValueNames(self.options) #set the IOR widget try: self.taurusForm.setCustomWidgetMap(getattr(tauruscustomsettings,'T_FORM_CUSTOM_WIDGET_MAP',{})) except NameError: self.taurusForm.setCustomWidgetMap(getattr(TaurusCustomSettings,'T_FORM_CUSTOM_WIDGET_MAP',{})) self.taurusForm.setModel([self.ior_model]) #set the motor widget try: self.taurusForm2.setCustomWidgetMap(getattr(tauruscustomsettings,'T_FORM_CUSTOM_WIDGET_MAP',{})) except NameError: self.taurusForm2.setCustomWidgetMap(getattr(TaurusCustomSettings,'T_FORM_CUSTOM_WIDGET_MAP',{})) self.taurusForm2.setModel([self.mot_model]) if self.firstcall: #make ior widget auto apply settings for widget in self.taurusForm: widget.writeWidget().setAutoApply(True) #connect combo box changes to method below #self.connect(self.comboBox, QtCore.SIGNAL('currentIndexChanged(const int &)'), self.indexChanged) #fill label #self.label.setModel(taurus.Attribute(ior+"/Value")) #get taurus attribute which is value and also motor pos self.position_ior = taurus.Attribute(ior+"/Value")
def _updateTaurusValue(self): m = self.getModelName() self._TaurusValue.setModel("%s/value" % m) self._devButton.setModel(m) if __name__ == "__main__": import sys argv = sys.argv if len(argv) > 0: models = argv[1:] app = Qt.QApplication(sys.argv) form_tv = TaurusForm() form_tv.setModifiableByUser(True) tv_widget_class = "sardana.taurus.qt.qtgui.extra_pool.PoolChannelTV" tv_class_map = { "CTExpChannel": (tv_widget_class, (), {}), "OneDExpChannel": (tv_widget_class, (), {}), "TwoDExpChannel": (tv_widget_class, (), {}) } form_tv.setCustomWidgetMap(tv_class_map) form_tv.setModel(models) w = Qt.QWidget() w.setLayout(Qt.QVBoxLayout()) w.layout().addWidget(form_tv) w.show() sys.exit(app.exec_())
#toolbar=Qt.QToolBar(tmw) #tmw.addToolBar(toolbar) #toolbar.setIconSize(Qt.QSize(30,30)) #toolbar.addAction(Qt.QIcon(":/actions/media-record.svg"),"SnapApp",snap) #toolbar.setMovable(True) #toolbar.setFloatable(True) #toolbar.setToolTip("ToolBarrrrrrrr") #menubar=tmw.menuBar() #dupa=menubar.addMenu('&Dupa') #dupa.addAction(Qt.QIcon(":/actions/media-record.svg"),"SnapApp",snap) contextAttributes=[attr['full_name'] for attr in context.get_attributes().values()] taurusForm=TaurusForm(tmw) taurusForm.setModel(contextAttributes) tmw.setCentralWidget(taurusForm) tmw.statusBar().showMessage('Ready') s=tmw.splashScreen() s.finish(tmw) tmw.show() toolbar2=snapToolbar(tmw) toolbar2.setRefreshTime(5) tmw.addToolBar(toolbar2) #widgets=tmw.findChildren(taurus.qt.qtgui.base.TaurusBaseComponent) #att_table=[] #for w in widgets: #if type(w.getModelObj()).__name__ == 'TangoAttribute':
class Ui_Form(object): def setupUi(self, Form): Form.setObjectName("Form") self._Form = Form self.font = QtGui.QFont() self.font.setBold(True) self.gridLayout_2 = QtGui.QGridLayout(Form) self.gridLayout_2.setObjectName("gridLayout_2") self.gridLayout = QtGui.QGridLayout() self.gridLayout.setObjectName("gridLayout") self.chooseLabel = Qt.QLabel() self.chooseLabel.setObjectName("chooseLabel") self.chooseLabel.setFont(self.font) self.chooseLabel.setAlignment(QtCore.Qt.AlignCenter) self.gridLayout.addWidget(self.chooseLabel, 0, 0, 1, 1) self.tac = attributeChooser() self.tac.setObjectName("taurusAttributeChooser") self.gridLayout.addWidget(self.tac, 1, 0, 6, 1) self.selectedLabel = Qt.QLabel() self.selectedLabel.setObjectName("selectedLabel") self.selectedLabel.setFont(self.font) self.selectedLabel.setAlignment(QtCore.Qt.AlignCenter) self.selectedLabel.hide() self.gridLayout.addWidget(self.selectedLabel, 0, 1, 1, 6) self.tf = TaurusForm() self.tf.setWithButtons(False) self.tf.setObjectName("taurusForm") self.tf.hide() self.gridLayout.addWidget(self.tf, 1, 1, 1, 6) self.label = Qt.QLabel() self.label.setObjectName("label") self.label.setFont(self.font) self.label.setAlignment(QtCore.Qt.AlignCenter) self.gridLayout.addWidget(self.label, 1, 1, 1, 6) spacerItem = QtGui.QSpacerItem(1, 1, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout.addItem(spacerItem, 1, 1, 1, 1) self.modepLabel = QtGui.QLabel(Form) self.modepLabel.setObjectName("modepLabel") self.modepLabel.setText('Period [s]:') self.gridLayout.addWidget(self.modepLabel, 2, 1, 1, 1) self.modepLineEdit = QtGui.QLineEdit(Form) self.modepLineEdit.setObjectName("modepLineEdit") self.modepLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.modepLineEdit.setMaxLength(7) self.modepLineEdit.setMaximumWidth(60) self.modepLineEdit.setText('60.0') self.gridLayout.addWidget(self.modepLineEdit, 2, 2, 1, 1) self.modeaLabel = QtGui.QLabel(Form) self.modeaLabel.setObjectName("modeaLabel") self.modeaLabel.setText('Absolute Period [s]:') self.gridLayout.addWidget(self.modeaLabel, 3, 1, 1, 1) self.modeaLineEdit = QtGui.QLineEdit(Form) self.modeaLineEdit.setObjectName("modeaLineEdit") self.modeaLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.modeaLineEdit.setMaxLength(7) self.modeaLineEdit.setMaximumWidth(60) self.modeaLineEdit.setText('15.0') self.gridLayout.addWidget(self.modeaLineEdit, 3, 2, 1, 1) self.modeaLowerLimitLabel = QtGui.QLabel(Form) self.modeaLowerLimitLabel.setObjectName("modeaLowerLimitLabel") self.modeaLowerLimitLabel.setText('Lower Limit (decr.):') self.gridLayout.addWidget(self.modeaLowerLimitLabel, 3, 3, 1, 1) self.modeaLowerLimitLineEdit = QtGui.QLineEdit(Form) self.modeaLowerLimitLineEdit.setObjectName("modeaLowerLimitLineEdit") self.modeaLowerLimitLineEdit.setValidator( Qt.QDoubleValidator(1, 14400, 2, Form)) self.modeaLowerLimitLineEdit.setMaxLength(7) self.modeaLowerLimitLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.modeaLowerLimitLineEdit, 3, 4, 1, 1) self.modeaUpperLimitLabel = QtGui.QLabel(Form) self.modeaUpperLimitLabel.setObjectName("modeaUpperLimitLabel") self.modeaUpperLimitLabel.setText('Upper Limit (incr.):') self.gridLayout.addWidget(self.modeaUpperLimitLabel, 3, 5, 1, 1) self.modeaUpperLimitLineEdit = QtGui.QLineEdit(Form) self.modeaUpperLimitLineEdit.setObjectName("modeaUpperLimitLineEdit") self.modeaUpperLimitLineEdit.setValidator( Qt.QDoubleValidator(1, 14400, 2, Form)) self.modeaUpperLimitLineEdit.setMaxLength(7) self.modeaUpperLimitLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.modeaUpperLimitLineEdit, 3, 6, 1, 1) self.moderLabel = QtGui.QLabel(Form) self.moderLabel.setObjectName("moderLabel") self.moderLabel.setText('Relative Period [s]:') self.gridLayout.addWidget(self.moderLabel, 4, 1, 1, 1) self.moderLineEdit = QtGui.QLineEdit(Form) self.moderLineEdit.setObjectName("moderLineEdit") self.moderLineEdit.setValidator(Qt.QDoubleValidator(1, 14400, 1, Form)) self.moderLineEdit.setMaxLength(7) self.moderLineEdit.setMaximumWidth(60) self.moderLineEdit.setText('15.0') self.gridLayout.addWidget(self.moderLineEdit, 4, 2, 1, 1) self.moderLowerLimitPercentLabel = QtGui.QLabel(Form) self.moderLowerLimitPercentLabel.setObjectName( "moderLowerLimitPercentLabel") self.moderLowerLimitPercentLabel.setText('Lower % Limit (decr.):') self.gridLayout.addWidget(self.moderLowerLimitPercentLabel, 4, 3, 1, 1) self.moderLowerLimitPercentLineEdit = QtGui.QLineEdit(Form) self.moderLowerLimitPercentLineEdit.setObjectName( "moderLowerLimitPercentLineEdit") self.moderLowerLimitPercentLineEdit.setValidator( QtGui.QDoubleValidator(0, 1, 2, Form)) self.moderLowerLimitPercentLineEdit.setMaxLength(7) self.moderLowerLimitPercentLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.moderLowerLimitPercentLineEdit, 4, 4, 1, 1) self.moderUpperLimitPercentLabel = QtGui.QLabel(Form) self.moderUpperLimitPercentLabel.setObjectName( "moderUpperLimitPercentLabel") self.moderUpperLimitPercentLabel.setText('Upper % Limit (incr.):') self.gridLayout.addWidget(self.moderUpperLimitPercentLabel, 4, 5, 1, 1) self.moderUpperLimitPercentLineEdit = QtGui.QLineEdit(Form) self.moderUpperLimitPercentLineEdit.setObjectName( "moderUpperLimitPercentLineEdit") self.moderUpperLimitPercentLineEdit.setValidator( Qt.QDoubleValidator(0, 1, 2, Form)) self.moderUpperLimitPercentLineEdit.setMaxLength(7) self.moderUpperLimitPercentLineEdit.setMaximumWidth(60) self.gridLayout.addWidget(self.moderUpperLimitPercentLineEdit, 4, 6, 1, 1) self.gridButtonLayout = QtGui.QGridLayout() self.gridButtonLayout.setObjectName("gridButtonLayout") spacerItem = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridButtonLayout.addItem(spacerItem, 0, 1, 1, 1) self.pushButtonStart = QtGui.QPushButton(Form) self.pushButtonStart.setObjectName("pushButtonStart") self.pushButtonStart.setEnabled(False) self.gridButtonLayout.addWidget(self.pushButtonStart, 0, 2, 1, 1) self.pushButtonStop = QtGui.QPushButton(Form) self.pushButtonStop.setObjectName("pushButtonStop") self.pushButtonStop.setEnabled(False) self.gridButtonLayout.addWidget(self.pushButtonStop, 0, 3, 1, 1) self.pushButtonCancel = QtGui.QPushButton(Form) self.pushButtonCancel.setObjectName("pushButtonCancel") self.gridButtonLayout.addWidget(self.pushButtonCancel, 0, 4, 1, 1) self.gridLayout.addLayout(self.gridButtonLayout, 5, 1, 1, 6) self.gridLayout_2.addLayout(self.gridLayout, 1, 0, 1, 1) self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) def retranslateUi(self, Form): Form.setWindowTitle( QtGui.QApplication.translate("Form", "Archiving Widget", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonStart.setText( QtGui.QApplication.translate("Form", "Start Archiving", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonStop.setText( QtGui.QApplication.translate("Form", "Stop", None, QtGui.QApplication.UnicodeUTF8)) self.pushButtonCancel.setText( QtGui.QApplication.translate("Form", "Close", None, QtGui.QApplication.UnicodeUTF8)) self.label.setText( QtGui.QApplication.translate("Form", "Nothing to display", None, QtGui.QApplication.UnicodeUTF8)) self.selectedLabel.setText( QtGui.QApplication.translate( "Form", "Press start to start archiving selected attributes:", None, QtGui.QApplication.UnicodeUTF8)) self.chooseLabel.setText( QtGui.QApplication.translate( "Form", "Choose attributes to archive and hit apply to move attributes to selection", None, QtGui.QApplication.UnicodeUTF8)) self.tf.connect(self.tac, Qt.SIGNAL("UpdateAttrs"), self.onUpdate) QtCore.QObject.connect(self.pushButtonStart, Qt.SIGNAL("clicked()"), self.onStart) QtCore.QObject.connect(self.pushButtonStop, Qt.SIGNAL("clicked()"), self.onStop) QtCore.QObject.connect(self.pushButtonCancel, Qt.SIGNAL("clicked()"), self.onCancel) QtCore.QObject.connect(self.modepLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.modepTextChanged) QtCore.QObject.connect(self.modeaLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.modeaTextChanged) QtCore.QObject.connect(self.moderLineEdit, Qt.SIGNAL('textChanged(const QString &)'), self.moderTextChanged) #QtCore.QObject.connect(self.moderUpperLimitPercentLineEdit, Qt.SIGNAL('editingFinished()'), self.moderUpperLimitPercentTextChanged) #QtCore.QObject.connect(self.moderLowerLimitPercentLineEdit, Qt.SIGNAL('editingFinished()'), self.moderLowerLimitPercentTextChanged) #QtCore.QObject.connect(self.modeaUpperLimitLineEdit, Qt.SIGNAL('editingFinished()'), self.modeaUpperLimitTextChanged) #QtCore.QObject.connect(self.modeaLowerLimitLineEdit, Qt.SIGNAL('editingFinished()'), self.modeaLowerLimitTextChanged) def modepTextChanged(self): if self.modepLineEdit.text(): if (float(self.modepLineEdit.text()) < 1 or float(self.modepLineEdit.text()) > 14400): Qt.QMessageBox.critical(self._Form, 'Error', 'Value ranges between 1 and 14400', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) if float(self.modepLineEdit.text()) > 14400: self.modepLineEdit.setText('14400') else: self.modepLineEdit.setText('1') else: Qt.QMessageBox.critical(self._Form, 'Error', 'Value ranges between 1 and 14400', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modepLineEdit.setText('1') def modeaTextChanged(self): if self.modeaLineEdit.text(): if (float(self.modeaLineEdit.text()) > float( self.modepLineEdit.text())): Qt.QMessageBox.critical( self._Form, 'Error', 'Value cannot be higher than ' + self.modepLineEdit.text(), QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modeaLineEdit.setText('0') def moderTextChanged(self): if self.moderLineEdit.text(): if (float(self.moderLineEdit.text()) > float( self.modepLineEdit.text())): Qt.QMessageBox.critical( self._Form, 'Error', 'Value cannot be higher than ' + self.modepLineEdit.text(), QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.moderLineEdit.setText('0') def validate(self, modep, modea, moder): if (modep < modea or modep < moder): Qt.QMessageBox.critical( self._Form, 'Error', 'Period value has to be higher than the others', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) self.modepLineEdit.setText( str(10 * max(int(self.moderLineEdit.text()), int(self.modeaLineEdit.text())))) return False return True def floatValidation(self, line): val = line.text() try: float(val) return True except: Qt.QMessageBox.critical(self._Form, 'Error in ' + str(line.objectName()), 'Wrong value !\nSetting value to 0!', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) line.setText('0') return False def onStart(self): self.floatValidation(self.moderUpperLimitPercentLineEdit) self.floatValidation(self.moderLowerLimitPercentLineEdit) self.floatValidation(self.modeaUpperLimitLineEdit) self.floatValidation(self.modeaLowerLimitLineEdit) try: self.modep = int(1000 * self.modepLineEdit.text()) self.modea = (int(1000 * self.modeaLineEdit.text()) if self.modeaLineEdit.text() else None) self.modeaLowerLimit = (float(self.modeaLowerLimitLineEdit.text()) if self.modeaLowerLimitLineEdit.text() else None) self.modeaUpperLimit = (float(self.modeaUpperLimitLineEdit.text()) if self.modeaUpperLimitLineEdit.text() else None) self.moder = (int(1000 * self.moderLineEdit.text()) if self.moderLineEdit.text() else None) self.moderLowerLimit = ( float(self.moderLowerLimitPercentLineEdit.text()) if self.moderLowerLimitPercentLineEdit.text() else None) self.moderUpperLimit = ( float(self.moderUpperLimitPercentLineEdit.text()) if self.moderUpperLimitPercentLineEdit.text() else None) if self.validate(self.modep, self.modea, self.moder): reply = Qt.QMessageBox.question( self._Form, "Warning", "Do you want to start archiving selected attributes?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) if reply == QtGui.QMessageBox.Yes: command = {'MODE_P': [self.modep]} if (self.modea and self.modeaUpperLimit and self.modeaLowerLimit): command['MODE_A'] = [ self.modea, self.modeaUpperLimit, self.modeaLowerLimit ] if (self.moder and self.moderUpperLimit and self.moderLowerLimit): command['MODE_R'] = [ self.moder, self.moderUpperLimit, self.moderLowerLimit ] attrs = [a for a in self.tf.getModel()] cmd = self.tac.tdb.check_modes('tdb', command) toStop = [a for a in attrs if a in self.tac.beingArchived] try: if toStop: self.tac.tdb.api.start_archiving(attrs, cmd, kill=True) else: self.tac.tdb.api.start_archiving(attrs, cmd) except: Qt.QMessageBox.critical( self._Form, "Error", 'Cannot start archiving process.\nCheck the state of archiving managers.', QtGui.QMessageBox.AcceptRole, QtGui.QMessageBox.AcceptRole) print(traceback.format_exc()) self.tac.beingArchived = [ a.lower() for a in self.tac.tdb if self.tac.tdb.is_attribute_archived(a.lower()) ] #update archived list self.onUpdate(attrs) self.tac.setNewDevName() except: print(traceback.format_exc()) def onStop(self): toStop = [ att.lower() for att in self.tf.getModel() if att.lower() in self.tac.beingArchived ] reply = Qt.QMessageBox.question( self._Form, "Warning", "Do you want to stop archiving " + str(len(toStop)) + " attributes?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.Yes) if reply == QtGui.QMessageBox.Yes: self.tac.tdb.api.stop_archiving(toStop) self.tac.beingArchived = [ a.lower() for a in self.tac.tdb if self.tac.tdb.is_attribute_archived(a.lower()) ] #update archived list self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') self.tac.setNewDevName() self.clearParams() def onUpdate(self, attrs): self.clearParams() if not attrs: self.tf.hide() self.label.show() self.selectedLabel.hide() self.pushButtonStart.setEnabled(False) self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') else: self.label.hide() self.selectedLabel.show() self.tf.show() self.tf.setModel(attrs) for i in range(len(attrs)): item = self.tf.getItemByIndex(i) if item.getModel().lower() in self.tac.beingArchived: item.setExtraWidgetClass(historyButton) historyButton().setModel(item.getModel()) self.pushButtonStart.setEnabled(True) toStop = [ att.lower() for att in attrs if att.lower() in self.tac.beingArchived ] if toStop: self.pushButtonStop.setEnabled(True) self.pushButtonStop.setText('Stop (' + str(len(toStop)) + ')') modes = self.tac.tdb.get(toStop[0]).modes if 'MODE_P' in modes.keys(): self.modepLineEdit.setText( str(int(modes['MODE_P'][0] / 1000))) if 'MODE_R' in modes.keys(): if len(modes['MODE_R']) == 3: self.moderLineEdit.setText( str(int(modes['MODE_R'][0] / 1000))) self.moderLowerLimitPercentLineEdit.setText( str(float(modes['MODE_R'][1]))) self.moderUpperLimitPercentLineEdit.setText( str(float(modes['MODE_R'][2]))) if 'MODE_A' in modes.keys(): if len(modes['MODE_A']) == 3: self.modeaLineEdit.setText( str(int(modes['MODE_A'][0] / 1000))) self.modeaLowerLimitLineEdit.setText( str(int(modes['MODE_A'][1]))) self.modeaUpperLimitLineEdit.setText( str(int(modes['MODE_A'][2]))) else: self.pushButtonStop.setEnabled(False) self.pushButtonStop.setText('Stop') def clearParams(self): self.modepLineEdit.setText('60') self.moderLineEdit.setText('') self.moderLowerLimitPercentLineEdit.setText('') self.moderUpperLimitPercentLineEdit.setText('') self.modeaLineEdit.setText('') self.modeaLowerLimitLineEdit.setText('') self.modeaUpperLimitLineEdit.setText('') def onCancel(self): self._Form.close()
import sys from taurus.qt.qtgui.panel import TaurusForm from taurus.qt.qtgui.display import TaurusLabel from taurus.qt.qtgui.application import TaurusApplication app = TaurusApplication(sys.argv) panel = TaurusForm() props = ['state', 'status', 'position', 'velocity', 'acceleration'] model = ['sys/taurustest/1/%s' % p for p in props] panel.setModel(model) panel[0].readWidgetClass = TaurusLabel panel[2].writeWidgetClass = 'TaurusWheelEdit' panel.show() sys.exit(app.exec_())
import sys from taurus.qt.qtgui.panel import TaurusForm from taurus.qt.qtgui.application import TaurusApplication app = TaurusApplication(sys.argv) panel = TaurusForm() props = ['state', 'status', 'position', 'velocity', 'acceleration'] model = ['sys/taurustest/1/%s' % p for p in props] panel.setModel(model) panel.show() sys.exit(app.exec_())
def taurusFormMain(): """A launcher for TaurusForm.""" from taurus.qt.qtgui.panel import TaurusForm from taurus.external.qt import Qt from functools import partial parser = argparse.get_taurus_parser() parser.set_usage("%prog [options] [model1 [model2 ...]]") parser.set_description("the taurus form panel application") parser.add_option("--window-name", dest="window_name", default="TaurusForm", help="Name of the window") parser.add_option("--config", "--config-file", dest="config_file", default=None, help="use the given config file for initialization") app = TaurusApplication(cmd_line_parser=parser, app_name="taurusform", app_version=Release.version) args = app.get_command_line_args() options = app.get_command_line_options() dialog = TaurusForm() dialog.setModifiableByUser(True) dialog.setModelInConfig(True) dialog.setWindowTitle(options.window_name) # Make sure the window size and position are restored dialog.registerConfigProperty(dialog.saveGeometry, dialog.restoreGeometry, 'MainWindowGeometry') quitApplicationAction = Qt.QAction(Qt.QIcon.fromTheme("process-stop"), 'Close Form', dialog) quitApplicationAction.triggered.connect(dialog.close) saveConfigAction = Qt.QAction("Save current settings...", dialog) saveConfigAction.setShortcut(Qt.QKeySequence.Save) saveConfigAction.triggered.connect( partial(dialog.saveConfigFile, ofile=None)) loadConfigAction = Qt.QAction("&Retrieve saved settings...", dialog) loadConfigAction.setShortcut(Qt.QKeySequence.Open) loadConfigAction.triggered.connect( partial(dialog.loadConfigFile, ifile=None)) dialog.addActions( (saveConfigAction, loadConfigAction, quitApplicationAction)) # set the default map for this installation from taurus import tauruscustomsettings dialog.setCustomWidgetMap( getattr(tauruscustomsettings, 'T_FORM_CUSTOM_WIDGET_MAP', {})) # set a model list from the command line or launch the chooser if options.config_file is not None: dialog.loadConfigFile(options.config_file) elif len(args) > 0: models = args dialog.setModel(models) else: dialog.chooseModels() dialog.show() sys.exit(app.exec_())