def __init__(self, timeout=10000): self._pixmap = Qt.QPixmap(wdir('image/icons/alba-entry.JPG')) Qt.QSplashScreen.__init__(self, self._pixmap) self.showMessage('initializing application...') self._timer = Qt.QTimer.singleShot(timeout, self.close) self.show()
class VaccaPanel(fandango.qt.Dropable(taurus.qt.qtgui.panel.TaurusDevicePanel) ): """ :param parent: :param model: a device name or an state attribute :param palette: :param bound: :param filters: :return: It is a class that inherits from TaurusDevicePanel and Dropable module from fandango. If connect=True at init, it checks if it exists any shareDataManager to subscribe in it. It can be done later using getPanelDescription or connectSharedSignals This Widget shows the device Commands and Attributes, it is listening the shareDataManager to show the device selected information. The title of this Widget can be draggable. VaccaPanel has the follow functionalities: * Title is draggable. * Is connected to shareDataManager to share information in the GUI. """ def __init__(self, parent=None, model=None, filters=[], connect=False): #,palette=None, bound=True,filters=[]): """ In Init, the class VaccaPanel check if exist any shareDataManager to subscribe in it. :param parent: :param model: Model to start the Panel. :param filters: dictionary with 'attrs' and 'comms' filters as regexp or tuples lists :return: """ self.call__init__(taurus.qt.qtgui.panel.TaurusDevicePanel, parent, model) #self.setLogLevel(self.Info) self.info('init(%s,%s): connecting ...' % (model, filters)) self._connected = [] if connect: self.connectSharedSignals() if self.checkDropSupport(): self.setSupportedMimeTypes([ self.TAURUS_DEV_MIME_TYPE, self.TEXT_MIME_TYPE, self.TAURUS_MODEL_MIME_TYPE ]) self.setDropEventCallback(self.setModelHook) self.info('init(...): layout ...') self._header.layout().removeWidget(self._label) #self._label = vacca.utils.DraggableLabel() self._label = fandango.qt.Draggable(Qt.QLabel)() self._label.font().setBold(True) self._label.setText('SELECT A DEVICE FROM THE TREE') self._header.layout().addWidget(self._label, 0, 1, Qt.Qt.AlignLeft) self._label.setDragEventCallback(self._label.text) #self.setToolTip(getattr(self,'__help__',self.__doc__)) if filters: self.info('VaccaPanel(filters=%s)' % filters) if 'attrs' in filters: type(self)._attribute_filter = {'.*': filters['attrs']} if 'comms' in filters: type(self)._command_filter = { '.*': [ c if fun.isSequence(c) else (c, ()) for c in filters['comms'] ] } def connectSharedSignals(self, read='SelectedInstrument', write=''): self.info('connectSharedSignals(%s,%s)' % (read, write)) sdm = vacca.utils.get_shared_data_manager() if sdm and read and read not in self._connected: sdm.connectReader(read, self.setModelHook, readOnConnect=True) self._connected.append(read) return def setModelHook(self, model): #self.info('%s,%s'%(repr(args),repr(kwargs))) #l = [(str(type(a)),) for l in (args,kwargs.values()) for a in args] self.info('In setModelHook(%s)' % str(model)) try: fandango.tango.parse_tango_model(str(model).strip())['device'] self.setModel(model) except: self.warning('Invalid model: %s\n%s' % (repr(model), traceback.format_exc())) @classmethod def getAttributeFilters(klass, dev_class=None): """ TaurusDevicePanel filters are fixed to work by device name. But, if AttributeFilters is declared as class property, it will override them. get{Property}(klass,dev_class) will update it from Tango DB and return the matching values. set{Property}(dict) will update the parent TaurusDevicePanel dictionary, not the DB """ if dev_class is not None and dev_class not in klass._attribute_filter: filters = get_class_property(dev_class, 'AttributeFilters', extract=False) if filters: filters = [(l.split(':')[0], l.split(':')[-1].split(',')) for l in filters] klass._attribute_filter[dev_class] = filters #return {'.*':filters} print('getAttributeFilters(%s,%s): ...' % (klass, dev_class) ) #,klass._attribute_filter)) return klass._attribute_filter @classmethod def getCommandFilters(klass, dev_class=None): """ get{Property}(klass,dev_class) will update it from Tango DB and return the matching values. set{Property}(dict) will update the parent TaurusDevicePanel dictionary, not the DB """ if dev_class is not None and dev_class not in klass._command_filter: filters = get_class_property(dev_class, 'CommandFilters', extract=False) if filters: #filters = dict((k,eval(v)) for k,v in (l.split(':',1) for l in filters)) filters = [(c, ()) for c in filters] klass._command_filter[dev_class] = filters print('getCommandFilters(%s,%s): ...' % (klass, dev_class) ) #,klass._command_filter)) return klass._command_filter @classmethod def getIconMap(klass, dev_class=None): if dev_class is not None and dev_class not in klass._icon_map: p = get_class_property(dev_class, 'Icon', extract=True) if p: klass._icon_map[dev_class] = p #Not trivial! print('getIconMap(%s): ...' % (klass)) #print('getIconMap(%s): ...%s'%(klass,klass._icon_map)) return klass._icon_map def setModel(self, model, pixmap=None): """ Set Model is the callback used in shareDataManager to manage device selections. :param model: Model to VaccaPanel :param pixmap: :return: """ try: #self.setLogLevel(self.Debug) self.info('VaccaPanel(%s).setModel(%s,%s)' % (id(self), model, pixmap)) model, modelclass, raw = str(model).strip(), '', model model = fandango.tango.parse_tango_model(model) if model is None: self.warning( 'VaccaPanel(%s).setModel(%s,%s): MODEL NOT PARSABLE!' % (id(self), model, pixmap)) return else: model = model['device'] if model: model = model and model.split()[0] or '' modelclass = taurus.Factory().findObjectClass(model) self.debug('In TaurusDevicePanel.setModel(%s(%s),%s)' % (raw, modelclass, pixmap)) if model == self.getModel(): return elif raw is None or not model or not modelclass: if self.getModel(): self.detach() return elif issubclass(modelclass, TaurusAttribute): #if model.lower().endswith('/state'): model = model.rsplit('/', 1)[0] elif not issubclass(modelclass, TaurusDevice): self.warning('TaurusDevicePanel accepts only Device models') return except Exception, e: traceback.print_exc() raise e try: taurus.Device(model).ping() dev_class = fandango.get_device_info(model).dev_class if self.getModel(): self.detach( ) #Do not dettach previous model before pinging the new one (fail message will be shown at except: clause) TaurusWidget.setModel(self, model) self.setWindowTitle(str(model).upper()) model = self.getModel() self._label.setText(model.upper()) font = self._label.font() font.setPointSize(15) self._label.setFont(font) if pixmap is None and self.getIconMap(dev_class=dev_class): for k, v in self.getIconMap().items(): if searchCl(k, model) or searchCl(k, dev_class): pixmap = v break if pixmap is not None: #print 'Pixmap is %s'%pixmap qpixmap = Qt.QPixmap(pixmap) if qpixmap.height() > .9 * IMAGE_SIZE[1]: qpixmap = qpixmap.scaledToHeight(.9 * IMAGE_SIZE[1]) if qpixmap.width() > .9 * IMAGE_SIZE[0]: qpixmap = qpixmap.scaledToWidth(.9 * IMAGE_SIZE[0]) else: qpixmap = getPixmap(':/logo.png') self._image.setPixmap(qpixmap) self._state.setModel(model + '/state') if hasattr(self, '_statelabel'): self._statelabel.setModel(model + '/state') self._status.setModel(model + '/status') try: self._attrsframe.clear() class_filters = type(self).getAttributeFilters( dev_class=dev_class) filters = get_regexp_dict(self._attribute_filter, model, []) if not filters: filters = get_regexp_dict(self._attribute_filter, dev_class, ['.*']) search_tab = None if filters == [ '.*' ] and len(taurus.Device(model).get_attribute_list()) > 32: filters = [('Attributes', ['.*'])] if hasattr(filters, 'keys'): filters = filters.items() #Dictionary! print('\tfilters = %s' % filters) #Showing multiple Tabs if filters and isinstance(filters[0], (list, tuple)): self._attrs = [] for tab, attrs in filters: if attrs[1:] or attrs[0] not in ('*', '.*'): self.debug( 'VaccaPanel.setModel.get_attrs_form(%s,%s)' % (model, attrs)) self._attrs.append( self.get_attrs_form(device=model, filters=attrs, parent=self)) self._attrsframe.addTab(self._attrs[-1], tab) else: self.info('Embedding a Search panel') search_tab = tab, VaccaSearchForm(preffix=model + '/*', suffix='*', labels=True) #Mapping into a single form else: if self._attrs and isinstance(self._attrs, list): self._attrs = self._attrs[0] if not isinstance(self._attrs, Qt.QWidget): self._attrs = None self._attrs = self.get_attrs_form(device=model, form=self._attrs, filters=filters, parent=self) if self._attrs: self._attrsframe.addTab(self._attrs, 'Attributes') if not TaurusDevicePanel.READ_ONLY: self._comms = self.get_comms_form(model, self._comms, self) if self._comms: self._attrsframe.addTab(self._comms, 'Commands') if search_tab: self._attrsframe.addTab(search_tab[1], search_tab[0]) if SPLIT_SIZES: self._splitter.setSizes(SPLIT_SIZES) except Exception, e: self.warning('setModel(%s) failed!' % model) self.warning(traceback.format_exc()) qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' % model, '%s not available' % model, Qt.QMessageBox.Ok, self) qmsg.setDetailedText(traceback.format_exc()) qmsg.show() raise e except Exception, e: self.warning('setModel(%s) failed!' % model) self.warning(traceback.format_exc()) qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' % model, '%s not available' % model, Qt.QMessageBox.Ok, self) qmsg.setDetailedText(traceback.format_exc()) qmsg.show() raise e