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 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 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_())