def main(): from taurus.core.util.log import Logger from taurus.qt.qtgui.util import TaurusWidgetFactory Logger.setLogLevel(Logger.Debug) _log = Logger(__name__) try: wf = TaurusWidgetFactory() klasses = wf.getWidgetClasses() ok_nb, skipped_nb, e1_nb, e2_nb, e3_nb, e4_nb = 0, 0, 0, 0, 0, 0 for widget_klass in klasses: name = widget_klass.__name__ #_log.debug("Processing %s" % name) if name in _SKIP: #_log.debug("Skipped %s" % name) skipped_nb += 1 continue # if getQtDesignerPluginInfo does not exist, returns None or raises # an exception: forget the widget cont = False try: qt_info = widget_klass.getQtDesignerPluginInfo() if qt_info is None: #_log.debug("E1: Canceled %s (getQtDesignerPluginInfo)" % name) e1_nb += 1 cont = True except AttributeError: #_log.debug("E2: Canceled %s (widget doesn't have getQtDesignerPluginInfo())" % name) e2_nb += 1 cont = True except Exception, e: #_log.debug("E3: Canceled %s (%s)" % (name, str(e))) e3_nb += 1 cont = True if cont: continue for k in ('module', ): if not qt_info.has_key(k): #_log.debug("E4: Canceled %s (getQtDesignerPluginInfo doesn't have key %s)" % (name, k)) e4_nb += 1 cont = True if cont: continue plugin_klass = build_qtdesigner_widget_plugin(widget_klass) plugin_klass_name = plugin_klass.__name__ globals()[plugin_klass_name] = plugin_klass _plugins[plugin_klass_name] = plugin_klass ok_nb += 1 #_log.debug("DONE processing %s" % name) _log.info("Inpected %d widgets. %d (OK), %d (Skipped), %d (E1), %d (E2), %d (E3), %d(E4)" % ( len(klasses), ok_nb, skipped_nb, e1_nb, e2_nb, e3_nb, e4_nb)) _log.info("E1: getQtDesignerPluginInfo() returns None") _log.info("E2: widget doesn't implement getQtDesignerPluginInfo()") _log.info("E3: getQtDesignerPluginInfo() throws exception") _log.info( "E4: getQtDesignerPluginInfo() returns dictionary with missing key (probably 'module' key)")
def fromPanel(panel): name = str(panel.objectName()) classname = panel.getWidgetClassName() modulename = panel.getWidgetModuleName() # in the case of classes known to the TaurusWidgetFactory, # do not store the modulename if modulename.startswith('taurus.') and \ classname in TaurusWidgetFactory().getWidgetClassNames(): modulename = None widgetname = None floating = panel.isFloating() sharedDataWrite = None sharedDataRead = None model = getattr(panel.widget(), 'model', None) if model is None or isinstance(model, basestring): pass elif hasattr(model, '__iter__'): # if model is a sequence, convert to space-separated string try: model = " ".join(model) except Exception, e: msg = ('Cannot convert %s to a space-separated string: %s' % (model, e)) Logger().debug(msg) model = None
def getWidget(self, sdm=None, setModel=True): ''' Returns the widget to be inserted in the panel :param sdm: (SharedDataManager) if given, the widget will be registered as reader and/or writer in this manager as defined by the sharedDataRead and sharedDataWrite properties :param setModel: (bool) if True (default) the widget will be given the model deined in the model property :return: (QWidget) a new widget instance matching the description ''' # instantiate the widget if self.modulename is None: klass = TaurusWidgetFactory().getWidgetClass(self.classname) w = klass() else: module = __import__(self.modulename, fromlist=['']) if self.classname is None: w = getattr(module, self.widgetname) else: klass = getattr(module, self.classname) w = klass() # set the model if setModel is True if self.model is not None and setModel: w.setModel(self.model) # connect (if an sdm is given) if sdm is not None: for dataUID, signalname in self.sharedDataWrite.iteritems(): sdm.connectWriter(dataUID, w, signalname) for dataUID, slotname in self.sharedDataRead.iteritems(): sdm.connectReader(dataUID, getattr(w, slotname)) # set the name w.name = self.name return w
def createWidget(self): from taurus.qt.qtgui.util import TaurusWidgetFactory klass = TaurusWidgetFactory().getWidgetClass(self._widgetClassName) widget = klass(*self._args, **self._kwargs) self.setWidget(widget) if self._dialog.previousWidgetConfig is not None: try: widget.applyConfig(self._dialog.previousWidgetConfig) except Exception as e: self.warning( 'Cannot apply previous configuration to widget. Reason: %s', repr(e))
def fromPanel(panel): name = str(panel.objectName()) classname = panel.getWidgetClassName() modulename = panel.getWidgetModuleName() # in the case of classes known to the TaurusWidgetFactory, # do not store the modulename if modulename.startswith('taurus.') and \ classname in TaurusWidgetFactory().getWidgetClassNames(): modulename = None widgetname = None floating = panel.isFloating() sharedDataWrite = None sharedDataRead = None model = getattr(panel.widget(), 'model', None) if model is None or isinstance(model, string_types): pass elif hasattr(model, '__iter__'): # if model is a sequence, convert to space-separated string try: model = " ".join(model) except Exception as e: msg = ('Cannot convert %s to a space-separated string: %s' % (model, e)) Logger().debug(msg) model = None else: # ignore other "model" attributes (they are not from Taurus) model = None return PanelDescription(name, classname=classname, modulename=modulename, widgetname=widgetname, floating=floating, sharedDataWrite=sharedDataWrite, sharedDataRead=sharedDataRead, model=model, icon=panel.icon, model_in_config=panel.model_in_config, modifiable_by_user=panel.modifiable_by_user, widget_formatter=panel.widget_formatter, widget_properties=panel.widget_properties)
def __init__(self, parent=None, designMode=False, extraWidgets=None): Qt.QWizardPage.__init__(self, parent) TaurusBaseWidget.__init__(self, 'WidgetPage') if extraWidgets: customWidgets, customWidgetScreenshots = list(zip(*extraWidgets)) pixmaps = {} for k, s in extraWidgets: if s is None: pixmaps[k] = None else: try: pixmaps[k] = getCachedPixmap(s) if pixmaps[k].isNull(): raise Exception('Invalid Pixmap') except: self.warning('Could not create pixmap from %s' % s) pixmaps[k] = None else: customWidgets, customWidgetScreenshots = [], [] pixmaps = {} self.setFinalPage(True) self.setTitle('Panel type') self.setSubTitle('Choose a name and type for the new panel') self.setButtonText(Qt.QWizard.NextButton, 'Advanced settings...') self.widgetDescription = { 'widgetname': None, 'modulename': None, 'classname': None } # name part self.nameLE = Qt.QLineEdit() self.registerField("panelname*", self.nameLE) self.diagnosticLabel = Qt.QLabel('') nameLayout = Qt.QHBoxLayout() nameLayout.addWidget(Qt.QLabel("Panel Name")) nameLayout.addWidget(self.nameLE) nameLayout.addWidget(self.diagnosticLabel) # contents available = TaurusWidgetFactory().getWidgetClassNames() choices = [] row = [] for cname in self.defaultCandidates + list(customWidgets): if cname in available or '.' in cname: row.append(cname) if cname not in pixmaps: pixmaps[cname] = getCachedPixmap('snapshot:%s.png' % cname) if len(row) == 3: choices.append(row) row = [] row.append(self.OTHER_TXT) choices.append(row) # defaultPixmap=getPixmap('logos:taurus.png') self.choiceWidget = GraphicalChoiceWidget(choices=choices, pixmaps=pixmaps) self.widgetTypeLB = Qt.QLabel("<b>Widget Type:</b>") self.choiceWidget.choiceMade.connect(self.onChoiceMade) layout = Qt.QVBoxLayout() layout.addLayout(nameLayout) layout.addWidget(self.choiceWidget) layout.addWidget(self.widgetTypeLB) self.setLayout(layout)