コード例 #1
0
ファイル: taurusdevicepanel.py プロジェクト: cmft/taurus
class TaurusDevicePanel(TaurusWidget):
    '''
    TaurusDevPanel is a Taurus Application inspired in Jive and Atk Panel.

    It Provides a Device selector and a panel for displaying information from
    the selected device.
    '''
    # TODO: Tango-centric (This whole class should be called TangoDevicePanel)
    # TODO: a scheme-agnostic base class should be implemented

    READ_ONLY = False
    # A dictionary like {device_regexp:[attribute_regexps]}
    _attribute_filter = {}
    # A dictionary like {device_regexp:[(command_regexp,default_args)]}
    _command_filter = {}
    _icon_map = {}  # A dictionary like {device_regexp:pixmap_url}

    @classmethod
    def setIconMap(klass, filters):
        """A dictionary like {device_regexp:pixmap_url}"""
        klass._icon_map = filters

    @classmethod
    def getIconMap(klass):
        return klass._icon_map

    @classmethod
    def setAttributeFilters(klass, filters):
        """
        It will set the attribute filters
        filters will be like: {device_regexp:[attribute_regexps]}
        example: {'.*/VGCT-.*': ['ChannelState','p[0-9]']}
        """
        klass._attribute_filter.update(filters)

    @classmethod
    def getAttributeFilters(klass):
        return klass._attribute_filter

    @classmethod
    def setCommandFilters(klass, filters):
        """
        It will set the command filters
        filters will be like: {device_regexp:[command_regexps]}
        example::

          {'.*/IPCT-.*': (
                           ('setmode',('SERIAL','LOCAL','STEP','FIXED','START','PROTECT')),
                           ('onhv1',()), ('offhv1',()), ('onhv2',()), ('offhv2',()),
                           ('sendcommand',())
                         ),}

        """
        klass._command_filter.update(filters)

    @classmethod
    def getCommandFilters(klass):
        return klass._command_filter

    ###########################################################################

    def __init__(self, parent=None, model=None, palette=None, bound=True):
        TaurusWidget.__init__(self, parent)
        if palette:
            self.setPalette(palette)
        self.setLayout(Qt.QGridLayout())
        self.bound = bound
        self._dups = []

        self.setWindowTitle('TaurusDevicePanel')
        self._label = Qt.QLabel()
        self._label.font().setBold(True)

        self._stateframe = TaurusWidget(self)
        self._stateframe.setLayout(Qt.QGridLayout())
        self._stateframe.layout().addWidget(Qt.QLabel('State'), 0, 0, Qt.Qt.AlignCenter)
        self._statelabel = TaurusLabel(self._stateframe)
        self._statelabel.setMinimumWidth(100)
        self._statelabel.setBgRole('state')
        self._stateframe.layout().addWidget(self._statelabel, 0, 1, Qt.Qt.AlignCenter)
        self._state = TaurusLed(self._stateframe)
        self._state.setShowQuality(False)
        self._stateframe.layout().addWidget(self._state, 0, 2, Qt.Qt.AlignCenter)

        self._statusframe = Qt.QScrollArea(self)
        self._status = TaurusLabel(self._statusframe)
        self._status.setBgRole('none')
        self._status.setAlignment(Qt.Qt.AlignLeft)
        self._status.setFixedHeight(2000)
        self._status.setFixedWidth(5000)
        # self._statusframe.setFixedHeight(STATUS_HEIGHT)
        self._statusframe.setHorizontalScrollBarPolicy(Qt.Qt.ScrollBarAlwaysOn)
        self._statusframe.setVerticalScrollBarPolicy(Qt.Qt.ScrollBarAlwaysOn)
        self._statusframe.setWidget(self._status)
        self._statusframe.setPalette(get_White_palette())

        self._attrsframe = Qt.QTabWidget(self)

        # Horizontal will not allow to show labels of attributes!
        self._splitter = Qt.QSplitter(Qt.Qt.Vertical, self)

        self._attrs, self._comms = None, None

        self.layout().addWidget(self._splitter, 0, 0)
        self._header = Qt.QFrame()
        self._header.setFixedHeight(1.1 * IMAGE_SIZE[1])
        self._header.setLayout(Qt.QGridLayout())

        self._dup = Qt.QPushButton()
        qpixmap = Qt.QIcon("actions:window-new.svg")
        self._dup.setIcon(Qt.QIcon(qpixmap))
        self._dup.setIconSize(Qt.QSize(15, 15))
        self._dup.pressed.connect(self.duplicate)

        self._image = Qt.QLabel()

        self._header.layout().addWidget(self._image, 0, 0, 2, 1, Qt.Qt.AlignCenter)
        self._header.layout().addWidget(self._label, 0, 1, Qt.Qt.AlignLeft)
        self._header.layout().addWidget(self._stateframe, 1, 1, 1, 2, Qt.Qt.AlignLeft)
        self._header.layout().addWidget(self._dup, 0, 2, Qt.Qt.AlignRight)

        self._splitter.insertWidget(0, self._header)
        self._splitter.insertWidget(1, self._attrsframe)
        self._splitter.insertWidget(2, self._statusframe)
        self._splitter.setSizes(SPLIT_SIZES)
        [self._splitter.setStretchFactor(i, v)
         for i, v in enumerate(SPLIT_SIZES)]
        self._splitter.setCollapsible(0, False)
        self._splitter.setCollapsible(1, False)

        if model:
            self.setModel(model)

    def loadConfigFile(self, ifile=None):
        self.info('In TaurusDevicePanel.loadConfigFile(%s)' % ifile)
        if isinstance(ifile, file) or isinstance(ifile, str) and not ifile.endswith('.py'):
            TaurusWidget.loadConfigFile(self, ifile)
        else:
            from imp import load_source
            config_file = load_source('config_file', ifile)
            af, cf, im = [getattr(config_file, x, None) for x in (
                'AttributeFilters', 'CommandFilters', 'IconMap')]
            if af is not None:
                self.setAttributeFilters(af)
            if cf is not None:
                self.setCommandFilters(cf)
            if im is not None:
                self.setIconMap(im)
        self.debug('AttributeFilters are:\n%s' % self.getAttributeFilters())

    def duplicate(self):
        self._dups.append(TaurusDevicePanel(bound=False))
        self._dups[-1].setModel(self.getModel())
        self._dups[-1].show()

    @Qt.pyqtSlot('QString')
    def setModel(self, model, pixmap=None):
        model, modelclass, raw = str(model).strip(), '', model
        if model:
            model = model and model.split()[0] or ''
            modelclass = taurus.Factory().findObjectClass(model)
        self.trace('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]  # TODO: Tango-centric
        elif not issubclass(modelclass, TaurusDevice):
            self.warning('TaurusDevicePanel accepts only Device models')
            return
        try:
            taurus.Device(model).ping()  # TODO: Tango-centric
            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():
                for k, v in self.getIconMap().items():
                    if searchCl(k, model):
                        pixmap = v
            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:
                logo = getattr(tauruscustomsettings, 'ORGANIZATION_LOGO',
                               "logos:taurus.png")
                qpixmap = getCachedPixmap(logo)

            self._image.setPixmap(qpixmap)
            self._state.setModel(model + '/state')  # TODO: Tango-centric
            if hasattr(self, '_statelabel'):
                self._statelabel.setModel(
                    model + '/state')  # TODO: Tango-centric
            self._status.setModel(model + '/status')  # TODO: Tango-centric
            try:
                self._attrsframe.clear()
                filters = get_regexp_dict(
                    TaurusDevicePanel._attribute_filter, model, ['.*'])
                if hasattr(filters, 'keys'):
                    filters = filters.items()  # Dictionary!
                if filters and isinstance(filters[0], (list, tuple)):  # Mapping
                    self._attrs = []
                    for tab, attrs in filters:
                        self._attrs.append(self.get_attrs_form(
                            device=model, filters=attrs, parent=self))
                        self._attrsframe.addTab(self._attrs[-1], tab)
                else:
                    if self._attrs and isinstance(self._attrs, list):
                        self._attrs = self._attrs[0]
                    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 SPLIT_SIZES:
                    self._splitter.setSizes(SPLIT_SIZES)
            except:
                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()
        except:
            self.warning(traceback.format_exc())
            qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' %
                                  model, '%s not available' % model, Qt.QMessageBox.Ok, self)
            qmsg.show()
        self.setWindowTitle(self.getModel())
        return

    def detach(self):
        self.trace('In TaurusDevicePanel(%s).detach()' % self.getModel())
        _detached = []
        # long imports to avoid comparison problems in the isinstance below
        import taurus.qt.qtgui.container
        import taurus.qt.qtgui.base

        def detach_recursive(obj):
            if obj in _detached:
                return
            if isinstance(obj, taurus.qt.qtgui.container.TaurusBaseContainer):
                for t in obj.taurusChildren():
                    detach_recursive(t)
            if obj is not self and isinstance(obj, taurus.qt.qtgui.base.TaurusBaseWidget):
                try:
                    if getattr(obj, 'model', None):
                        #self.debug('detaching %s from %s'%(obj,obj.model))
                        obj.setModel([] if isinstance(obj, TaurusForm) else '')
                except:
                    self.warning('detach of %s failed!' % obj)
                    self.warning(traceback.format_exc())
            _detached.append(obj)
        detach_recursive(self)
        try:
            self._label.setText('')
            self._state.setModel('')
            if hasattr(self, '_statelabel'):
                self._statelabel.setModel('')
            self._status.setModel('')
            self._image.setPixmap(Qt.QPixmap())
        except:
            self.warning(traceback.format_exc())

    def get_attrs_form(self, device, form=None, filters=None, parent=None):
        filters = filters or get_regexp_dict(
            TaurusDevicePanel._attribute_filter, device, ['.*'])
        self.trace('In TaurusDevicePanel.get_attrs_form(%s,%s)' %
                   (device, filters))
        allattrs = sorted(str(a) for a in taurus.Device(
            device).get_attribute_list() if str(a).lower() not in ('state', 'status'))
        attrs = []
        for a in filters:
            for t in allattrs:
                if a and searchCl(a.strip(), t.strip()):
                    aname = '%s/%s' % (device, t)
                    if aname not in attrs:
                        attrs.append(aname)
        if attrs:
            #self.trace( 'Matching attributes are: %s' % str(attrs)[:100])
            if form is None:
                form = TaurusForm(parent)
            elif hasattr(form, 'setModel'):
                form.setModel([])
            # Configuring the TauForm:
            form.setWithButtons(False)
            form.setWindowTitle(device)
            try:
                form.setModel(attrs)
            except Exception:
                self.warning(
                    'TaurusDevicePanel.ERROR: Unable to setModel for TaurusDevicePanel.attrs_form!!: %s' % traceback.format_exc())
            return form
        else:
            return None

    def get_comms_form(self, device, form=None, parent=None):
        self.trace('In TaurusDevicePanel.get_comms_form(%s)' % device)
        params = get_regexp_dict(TaurusDevicePanel._command_filter, device, [])
        # If filters are defined only listed devices will show commands
        if TaurusDevicePanel._command_filter and not params:
            self.debug(
                'TaurusDevicePanel.get_comms_form(%s): By default an unknown device type will display no commands' % device)
            return None
        if not form:
            form = TaurusCommandsForm(parent)
        elif hasattr(form, 'setModel'):
            form.setModel('')
        try:
            form.setModel(device)
            if params:
                form.setSortKey(lambda x, vals=[s[0].lower() for s in params]: vals.index(
                    x.cmd_name.lower()) if str(x.cmd_name).lower() in vals else 100)
                form.setViewFilters([lambda c: str(c.cmd_name).lower() not in (
                    'state', 'status') and any(searchCl(s[0], str(c.cmd_name)) for s in params)])
                form.setDefaultParameters(dict((k, v) for k, v in (
                    params if not hasattr(params, 'items') else params.items()) if v))
            for wid in form._cmdWidgets:
                if not hasattr(wid, 'getCommand') or not hasattr(wid, 'setDangerMessage'):
                    continue
                if re.match('.*(on|off|init|open|close).*', str(wid.getCommand().lower())):
                    wid.setDangerMessage(
                        'This action may affect other systems!')
            # form._splitter.setStretchFactor(1,70)
            # form._splitter.setStretchFactor(0,30)
            form._splitter.setSizes([80, 20])
        except Exception:
            self.warning(
                'Unable to setModel for TaurusDevicePanel.comms_form!!: %s' % traceback.format_exc())
        return form
コード例 #2
0
ファイル: taurusdevicepanel.py プロジェクト: tcsgmrt/taurus
class TaurusDevicePanel(TaurusWidget):
    '''
    TaurusDevPanel is a Taurus Application inspired in Jive and Atk Panel.

    It Provides a Device selector and a panel for displaying information from
    the selected device.
    '''
    # TODO: Tango-centric (This whole class should be called TangoDevicePanel)
    # TODO: a scheme-agnostic base class should be implemented

    READ_ONLY = False
    # A dictionary like {device_regexp:[attribute_regexps]}
    _attribute_filter = {}
    # A dictionary like {device_regexp:[(command_regexp,default_args)]}
    _command_filter = {}
    _icon_map = {}  # A dictionary like {device_regexp:pixmap_url}

    @classmethod
    def setIconMap(klass, filters):
        """A dictionary like {device_regexp:pixmap_url}"""
        klass._icon_map = filters

    @classmethod
    def getIconMap(klass):
        return klass._icon_map

    @classmethod
    def setAttributeFilters(klass, filters):
        """
        It will set the attribute filters
        filters will be like: {device_regexp:[attribute_regexps]}
        example: {'.*/VGCT-.*': ['ChannelState','p[0-9]']}
        """
        klass._attribute_filter.update(filters)

    @classmethod
    def getAttributeFilters(klass):
        return klass._attribute_filter

    @classmethod
    def setCommandFilters(klass, filters):
        """
        It will set the command filters
        filters will be like: {device_regexp:[command_regexps]}
        example::

          {'.*/IPCT-.*': (
                           ('setmode',('SERIAL','LOCAL','STEP','FIXED','START','PROTECT')),
                           ('onhv1',()), ('offhv1',()), ('onhv2',()), ('offhv2',()),
                           ('sendcommand',())
                         ),}

        """
        klass._command_filter.update(filters)

    @classmethod
    def getCommandFilters(klass):
        return klass._command_filter

    ###########################################################################

    def __init__(self, parent=None, model=None, palette=None, bound=True):
        TaurusWidget.__init__(self, parent)
        if palette:
            self.setPalette(palette)
        self.setLayout(Qt.QGridLayout())
        self.bound = bound
        self._dups = []

        self.setWindowTitle('TaurusDevicePanel')
        self._label = Qt.QLabel()
        self._label.font().setBold(True)

        self._stateframe = TaurusWidget(self)
        self._stateframe.setLayout(Qt.QGridLayout())
        self._stateframe.layout().addWidget(Qt.QLabel('State'), 0, 0,
                                            Qt.Qt.AlignCenter)
        self._statelabel = TaurusLabel(self._stateframe)
        self._statelabel.setMinimumWidth(100)
        self._statelabel.setBgRole('value')
        self._stateframe.layout().addWidget(self._statelabel, 0, 1,
                                            Qt.Qt.AlignCenter)

        self._statusframe = Qt.QScrollArea(self)
        self._status = TaurusLabel(self._statusframe)
        self._status.setBgRole('none')
        self._status.setAlignment(Qt.Qt.AlignLeft)
        self._status.setFixedHeight(2000)
        self._status.setFixedWidth(5000)
        # self._statusframe.setFixedHeight(STATUS_HEIGHT)
        self._statusframe.setHorizontalScrollBarPolicy(Qt.Qt.ScrollBarAlwaysOn)
        self._statusframe.setVerticalScrollBarPolicy(Qt.Qt.ScrollBarAlwaysOn)
        self._statusframe.setWidget(self._status)
        self._statusframe.setPalette(get_White_palette())

        self._attrsframe = Qt.QTabWidget(self)

        # Horizontal will not allow to show labels of attributes!
        self._splitter = Qt.QSplitter(Qt.Qt.Vertical, self)

        self._attrs, self._comms = None, None

        self.layout().addWidget(self._splitter, 0, 0)
        self._header = Qt.QFrame()
        self._header.setFixedHeight(1.1 * IMAGE_SIZE[1])
        self._header.setLayout(Qt.QGridLayout())

        self._dup = Qt.QPushButton()
        qpixmap = Qt.QIcon("actions:window-new.svg")
        self._dup.setIcon(Qt.QIcon(qpixmap))
        self._dup.setIconSize(Qt.QSize(15, 15))
        self._dup.pressed.connect(self.duplicate)

        self._image = Qt.QLabel()

        self._header.layout().addWidget(self._image, 0, 0, 2, 1,
                                        Qt.Qt.AlignCenter)
        self._header.layout().addWidget(self._label, 0, 1, Qt.Qt.AlignLeft)
        self._header.layout().addWidget(self._stateframe, 1, 1, 1, 2,
                                        Qt.Qt.AlignLeft)
        self._header.layout().addWidget(self._dup, 0, 2, Qt.Qt.AlignRight)

        self._splitter.insertWidget(0, self._header)
        self._splitter.insertWidget(1, self._attrsframe)
        self._splitter.insertWidget(2, self._statusframe)
        self._splitter.setSizes(SPLIT_SIZES)
        [
            self._splitter.setStretchFactor(i, v)
            for i, v in enumerate(SPLIT_SIZES)
        ]
        self._splitter.setCollapsible(0, False)
        self._splitter.setCollapsible(1, False)

        if model:
            self.setModel(model)

    def loadConfigFile(self, ifile=None):
        self.info('In TaurusDevicePanel.loadConfigFile(%s)' % ifile)
        if isinstance(
                ifile,
                file) or isinstance(ifile, str) and not ifile.endswith('.py'):
            TaurusWidget.loadConfigFile(self, ifile)
        else:
            from imp import load_source
            config_file = load_source('config_file', ifile)
            af, cf, im = [
                getattr(config_file, x, None)
                for x in ('AttributeFilters', 'CommandFilters', 'IconMap')
            ]
            if af is not None:
                self.setAttributeFilters(af)
            if cf is not None:
                self.setCommandFilters(cf)
            if im is not None:
                self.setIconMap(im)
        self.debug('AttributeFilters are:\n%s' % self.getAttributeFilters())

    def duplicate(self):
        self._dups.append(TaurusDevicePanel(bound=False))
        self._dups[-1].setModel(self.getModel())
        self._dups[-1].show()

    @Qt.pyqtSlot('QString')
    def setModel(self, model, pixmap=None):
        model, modelclass, raw = str(model).strip(), '', model
        if model:
            model = model and model.split()[0] or ''
            modelclass = taurus.Factory().findObjectClass(model)
        self.trace('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]  # TODO: Tango-centric
        elif not issubclass(modelclass, TaurusDevice):
            self.warning('TaurusDevicePanel accepts only Device models')
            return
        try:
            taurus.Device(model).ping()  # TODO: Tango-centric
            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():
                for k, v in self.getIconMap().items():
                    if searchCl(k, model):
                        pixmap = v
            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:
                logo = getattr(tauruscustomsettings, 'ORGANIZATION_LOGO',
                               "logos:taurus.png")
                qpixmap = getCachedPixmap(logo)

            self._image.setPixmap(qpixmap)
            if hasattr(self, '_statelabel'):
                self._statelabel.setModel(model +
                                          '/state')  # TODO: Tango-centric
            self._status.setModel(model + '/status')  # TODO: Tango-centric
            try:
                self._attrsframe.clear()
                filters = get_regexp_dict(TaurusDevicePanel._attribute_filter,
                                          model, ['.*'])
                if hasattr(filters, 'keys'):
                    filters = filters.items()  # Dictionary!
                if filters and isinstance(filters[0],
                                          (list, tuple)):  # Mapping
                    self._attrs = []
                    for tab, attrs in filters:
                        self._attrs.append(
                            self.get_attrs_form(device=model,
                                                filters=attrs,
                                                parent=self))
                        self._attrsframe.addTab(self._attrs[-1], tab)
                else:
                    if self._attrs and isinstance(self._attrs, list):
                        self._attrs = self._attrs[0]
                    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 SPLIT_SIZES:
                    self._splitter.setSizes(SPLIT_SIZES)
            except:
                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()
        except:
            self.warning(traceback.format_exc())
            qmsg = Qt.QMessageBox(Qt.QMessageBox.Critical, '%s Error' % model,
                                  '%s not available' % model,
                                  Qt.QMessageBox.Ok, self)
            qmsg.show()
        self.setWindowTitle(self.getModel())
        return

    def detach(self):
        self.trace('In TaurusDevicePanel(%s).detach()' % self.getModel())
        _detached = []
        # long imports to avoid comparison problems in the isinstance below
        import taurus.qt.qtgui.container
        import taurus.qt.qtgui.base

        def detach_recursive(obj):
            if obj in _detached:
                return
            if isinstance(obj, taurus.qt.qtgui.container.TaurusBaseContainer):
                for t in obj.taurusChildren():
                    detach_recursive(t)
            if obj is not self and isinstance(
                    obj, taurus.qt.qtgui.base.TaurusBaseWidget):
                try:
                    if getattr(obj, 'model', None):
                        #self.debug('detaching %s from %s'%(obj,obj.model))
                        obj.setModel([] if isinstance(obj, TaurusForm) else '')
                except:
                    self.warning('detach of %s failed!' % obj)
                    self.warning(traceback.format_exc())
            _detached.append(obj)

        detach_recursive(self)
        try:
            self._label.setText('')
            if hasattr(self, '_statelabel'):
                self._statelabel.setModel('')
            self._status.setModel('')
            self._image.setPixmap(Qt.QPixmap())
        except:
            self.warning(traceback.format_exc())

    def get_attrs_form(self, device, form=None, filters=None, parent=None):
        filters = filters or get_regexp_dict(
            TaurusDevicePanel._attribute_filter, device, ['.*'])
        self.trace('In TaurusDevicePanel.get_attrs_form(%s,%s)' %
                   (device, filters))
        allattrs = sorted(
            str(a) for a in taurus.Device(device).get_attribute_list()
            if str(a).lower() not in ('state', 'status'))
        attrs = []
        for a in filters:
            for t in allattrs:
                if a and searchCl(a.strip(), t.strip()):
                    aname = '%s/%s' % (device, t)
                    if aname not in attrs:
                        attrs.append(aname)
        if attrs:
            #self.trace( 'Matching attributes are: %s' % str(attrs)[:100])
            if form is None:
                form = TaurusForm(parent)
            elif hasattr(form, 'setModel'):
                form.setModel([])
            # Configuring the TauForm:
            form.setWithButtons(False)
            form.setWindowTitle(device)
            try:
                form.setModel(attrs)
            except Exception:
                self.warning(
                    'TaurusDevicePanel.ERROR: Unable to setModel for TaurusDevicePanel.attrs_form!!: %s'
                    % traceback.format_exc())
            return form
        else:
            return None

    def get_comms_form(self, device, form=None, parent=None):
        self.trace('In TaurusDevicePanel.get_comms_form(%s)' % device)
        params = get_regexp_dict(TaurusDevicePanel._command_filter, device, [])
        # If filters are defined only listed devices will show commands
        if TaurusDevicePanel._command_filter and not params:
            self.debug(
                'TaurusDevicePanel.get_comms_form(%s): By default an unknown device type will display no commands'
                % device)
            return None
        if not form:
            form = TaurusCommandsForm(parent)
        elif hasattr(form, 'setModel'):
            form.setModel('')
        try:
            form.setModel(device)
            if params:
                form.setSortKey(lambda x, vals=[s[0].lower() for s in params]:
                                vals.index(x.cmd_name.lower())
                                if str(x.cmd_name).lower() in vals else 100)
                form.setViewFilters([
                    lambda c: str(c.cmd_name).lower() not in
                    ('state', 'status') and any(
                        searchCl(s[0], str(c.cmd_name)) for s in params)
                ])
                form.setDefaultParameters(
                    dict((k, v)
                         for k, v in (params if not hasattr(params, 'items')
                                      else params.items()) if v))
            for wid in form._cmdWidgets:
                if not hasattr(wid, 'getCommand') or not hasattr(
                        wid, 'setDangerMessage'):
                    continue
                if re.match('.*(on|off|init|open|close).*',
                            str(wid.getCommand().lower())):
                    wid.setDangerMessage(
                        'This action may affect other systems!')
            # form._splitter.setStretchFactor(1,70)
            # form._splitter.setStretchFactor(0,30)
            form._splitter.setSizes([80, 20])
        except Exception:
            self.warning(
                'Unable to setModel for TaurusDevicePanel.comms_form!!: %s' %
                traceback.format_exc())
        return form
コード例 #3
0
ファイル: panels.py プロジェクト: hayg25/PyQTDev
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)
コード例 #4
0
ファイル: panels.py プロジェクト: hayg25/PyQTDev
class MagnetCircuitPanel(TaurusWidget):
    "Displays the important attributes of the circuit device"

    attrs = [
        "energy", "MainFieldComponent", "PowerSupplyReadValue",
        "PowerSupplySetPoint", "fixNormFieldOnEnergyChange"
    ]

    def __init__(self, parent=None):
        TaurusWidget.__init__(self, parent)
        self._setup_ui()
        print('Magnet Circuit juste avant setmodel')
        self.setModel('sys/tg_test/1')

    def _setup_ui(self):

        hbox = QtGui.QHBoxLayout(self)
        self.setLayout(hbox)

        form_vbox = self.vbox = QtGui.QVBoxLayout(self)

        hbox2 = QtGui.QVBoxLayout(self)
        self.device_and_state = DevnameAndState(self)
        hbox2.addWidget(self.device_and_state)
        self.magnet_type_label = QtGui.QLabel("Magnet type:")
        hbox2.addWidget(self.magnet_type_label)
        form_vbox.addLayout(hbox2)

        # attributes
        self.form = MAXForm(withButtons=False)
        form_vbox.addWidget(self.form, stretch=1)
        self.status_area = StatusArea(self)
        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)
        if device:
            self.form.setModel(
                ["%s/%s" % (device, attribute) for attribute in self.attrs])

            #---- Partie qui correspond a l'appel de la bdd de Tango
            # avec types d'aimant etc ... on peut le faire a la main pour tester
            # pour le moment nous sommes obliges de sauter cette partie
            db_ok = False
            if db_ok:
                db = PyTango.Database()
                magnet = db.get_device_property(
                    device, "MagnetProxies")["MagnetProxies"][0]
                magnet_type = PyTango.Database().get_device_property(
                    magnet, "Type")["Type"][0]
            else:
                magnet_type = 'Dipole'

            self.magnet_type_label.setText("Magnet type: <b>%s</b>" %
                                           magnet_type)
            attrname = "%s/%s" % (device, "MainFieldComponent")
            self.valuebar.setModel(attrname)
            attr = Attribute(attrname)
            self.current_label.setText("%s [%s]" % (attr.label, attr.unit))
            self.status_area.setModel(device)
        else:
            self.form.setModel(None)
            self.valuebar.setModel(None)
            self.status_area.setModel(None)
コード例 #5
0
ファイル: panels.py プロジェクト: hayg25/PyQTDev
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)
コード例 #6
0
class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(1006, 686)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            MainWindow.sizePolicy().hasHeightForWidth())
        MainWindow.setSizePolicy(sizePolicy)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
        self.gridLayout = QtGui.QGridLayout(self.centralwidget)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
        self.groupBox_2 = QtGui.QGroupBox(self.centralwidget)
        self.groupBox_2.setObjectName(_fromUtf8("groupBox_2"))
        self.gridLayout_9 = QtGui.QGridLayout(self.groupBox_2)
        self.gridLayout_9.setObjectName(_fromUtf8("gridLayout_9"))
        self.btn_prepCollect = QtGui.QPushButton(self.groupBox_2)
        self.btn_prepCollect.setObjectName(_fromUtf8("btn_prepCollect"))
        self.gridLayout_9.addWidget(self.btn_prepCollect, 1, 0, 1, 1)
        self.btn_prepObserv = QtGui.QPushButton(self.groupBox_2)
        self.btn_prepObserv.setObjectName(_fromUtf8("btn_prepObserv"))
        self.gridLayout_9.addWidget(self.btn_prepObserv, 0, 0, 1, 1)
        self.btn_prepAlign = QtGui.QPushButton(self.groupBox_2)
        self.btn_prepAlign.setObjectName(_fromUtf8("btn_prepAlign"))
        self.gridLayout_9.addWidget(self.btn_prepAlign, 2, 0, 1, 1)
        self.gridLayout.addWidget(self.groupBox_2, 1, 1, 1, 1)
        self.groupBox = QtGui.QGroupBox(self.centralwidget)
        self.groupBox.setObjectName(_fromUtf8("groupBox"))
        self.gridLayout_8 = QtGui.QGridLayout(self.groupBox)
        self.gridLayout_8.setObjectName(_fromUtf8("gridLayout_8"))
        self.btn_lightOff = QtGui.QPushButton(self.groupBox)
        self.btn_lightOff.setObjectName(_fromUtf8("btn_lightOff"))
        self.gridLayout_8.addWidget(self.btn_lightOff, 1, 1, 1, 1)
        self.btn_lightOn = QtGui.QPushButton(self.groupBox)
        self.btn_lightOn.setObjectName(_fromUtf8("btn_lightOn"))
        self.gridLayout_8.addWidget(self.btn_lightOn, 1, 0, 1, 1)
        self.sld_lightSet = QtGui.QSlider(self.groupBox)
        self.sld_lightSet.setOrientation(QtCore.Qt.Horizontal)
        self.sld_lightSet.setObjectName(_fromUtf8("sld_lightSet"))
        self.gridLayout_8.addWidget(self.sld_lightSet, 2, 0, 1, 2)
        self.lb_lightstate = QtGui.QLabel(self.groupBox)
        font = QtGui.QFont()
        font.setPointSize(12)
        self.lb_lightstate.setFont(font)
        self.lb_lightstate.setText(_fromUtf8(""))
        self.lb_lightstate.setAlignment(QtCore.Qt.AlignCenter)
        self.lb_lightstate.setObjectName(_fromUtf8("lb_lightstate"))
        self.gridLayout_8.addWidget(self.lb_lightstate, 0, 0, 1, 2)
        self.gridLayout.addWidget(self.groupBox, 2, 1, 1, 1)
        spacerItem = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                       QtGui.QSizePolicy.Expanding)
        self.gridLayout.addItem(spacerItem, 4, 1, 1, 1)
        self.tabWidget = QtGui.QTabWidget(self.centralwidget)
        self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
        self.tab_motors = QtGui.QWidget()
        self.tab_motors.setObjectName(_fromUtf8("tab_motors"))
        self.gridLayout_2 = QtGui.QGridLayout(self.tab_motors)
        self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
        self.wdgt_zoom = QtGui.QWidget(self.tab_motors)
        self.wdgt_zoom.setMinimumSize(QtCore.QSize(100, 50))
        self.wdgt_zoom.setObjectName(_fromUtf8("wdgt_zoom"))
        self.gridLayout_6 = QtGui.QGridLayout(self.wdgt_zoom)
        self.gridLayout_6.setMargin(0)
        self.gridLayout_6.setObjectName(_fromUtf8("gridLayout_6"))
        self.gridLayout_2.addWidget(self.wdgt_zoom, 0, 4, 1, 1)
        self.wdgt_diacorr = QtGui.QWidget(self.tab_motors)
        self.wdgt_diacorr.setMinimumSize(QtCore.QSize(100, 50))
        self.wdgt_diacorr.setObjectName(_fromUtf8("wdgt_diacorr"))
        self.gridLayout_5 = QtGui.QGridLayout(self.wdgt_diacorr)
        self.gridLayout_5.setMargin(0)
        self.gridLayout_5.setObjectName(_fromUtf8("gridLayout_5"))
        self.gridLayout_2.addWidget(self.wdgt_diacorr, 0, 0, 1, 1)
        self.wdgt_motors = QtGui.QWidget(self.tab_motors)
        self.wdgt_motors.setMinimumSize(QtCore.QSize(0, 50))
        self.wdgt_motors.setObjectName(_fromUtf8("wdgt_motors"))
        self.gridLayout_7 = QtGui.QGridLayout(self.wdgt_motors)
        self.gridLayout_7.setMargin(0)
        self.gridLayout_7.setObjectName(_fromUtf8("gridLayout_7"))
        self.gridLayout_2.addWidget(self.wdgt_motors, 1, 0, 1, 5)
        spacerItem1 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                        QtGui.QSizePolicy.Minimum)
        self.gridLayout_2.addItem(spacerItem1, 0, 2, 1, 1)
        spacerItem2 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        self.gridLayout_2.addItem(spacerItem2, 2, 0, 1, 1)
        self.tabWidget.addTab(self.tab_motors, _fromUtf8(""))
        self.tab_festo = QtGui.QWidget()
        self.tab_festo.setObjectName(_fromUtf8("tab_festo"))
        self.gridLayout_10 = QtGui.QGridLayout(self.tab_festo)
        self.gridLayout_10.setObjectName(_fromUtf8("gridLayout_10"))
        spacerItem3 = QtGui.QSpacerItem(20, 40, QtGui.QSizePolicy.Minimum,
                                        QtGui.QSizePolicy.Expanding)
        self.gridLayout_10.addItem(spacerItem3, 6, 1, 1, 1)
        self.label_2 = QtGui.QLabel(self.tab_festo)
        self.label_2.setObjectName(_fromUtf8("label_2"))
        self.gridLayout_10.addWidget(self.label_2, 1, 0, 1, 1)
        self.taurusLabel = TaurusLabel(self.tab_festo)
        self.taurusLabel.setMinimumSize(QtCore.QSize(100, 40))
        self.taurusLabel.setAlignment(QtCore.Qt.AlignCenter)
        self.taurusLabel.setObjectName(_fromUtf8("taurusLabel"))
        self.gridLayout_10.addWidget(self.taurusLabel, 0, 1, 1, 1)
        self.btn_NF_on = QtGui.QToolButton(self.tab_festo)
        self.btn_NF_on.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_NF_on.setObjectName(_fromUtf8("btn_NF_on"))
        self.gridLayout_10.addWidget(self.btn_NF_on, 2, 3, 1, 1)
        self.taurusLabel_3 = TaurusLabel(self.tab_festo)
        self.taurusLabel_3.setMinimumSize(QtCore.QSize(100, 40))
        self.taurusLabel_3.setAlignment(QtCore.Qt.AlignCenter)
        self.taurusLabel_3.setObjectName(_fromUtf8("taurusLabel_3"))
        self.gridLayout_10.addWidget(self.taurusLabel_3, 2, 1, 1, 1)
        self.taurusLabel_2 = TaurusLabel(self.tab_festo)
        self.taurusLabel_2.setMinimumSize(QtCore.QSize(100, 40))
        self.taurusLabel_2.setAlignment(QtCore.Qt.AlignCenter)
        self.taurusLabel_2.setObjectName(_fromUtf8("taurusLabel_2"))
        self.gridLayout_10.addWidget(self.taurusLabel_2, 1, 1, 1, 1)
        self.label = QtGui.QLabel(self.tab_festo)
        self.label.setObjectName(_fromUtf8("label"))
        self.gridLayout_10.addWidget(self.label, 0, 0, 1, 1)
        self.label_3 = QtGui.QLabel(self.tab_festo)
        self.label_3.setObjectName(_fromUtf8("label_3"))
        self.gridLayout_10.addWidget(self.label_3, 2, 0, 1, 1)
        self.btn_CC_on = QtGui.QToolButton(self.tab_festo)
        self.btn_CC_on.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_CC_on.setObjectName(_fromUtf8("btn_CC_on"))
        self.gridLayout_10.addWidget(self.btn_CC_on, 0, 3, 1, 1)
        self.btn_LC_on = QtGui.QToolButton(self.tab_festo)
        self.btn_LC_on.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_LC_on.setObjectName(_fromUtf8("btn_LC_on"))
        self.gridLayout_10.addWidget(self.btn_LC_on, 1, 3, 1, 1)
        self.btn_LC_off = QtGui.QToolButton(self.tab_festo)
        self.btn_LC_off.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_LC_off.setObjectName(_fromUtf8("btn_LC_off"))
        self.gridLayout_10.addWidget(self.btn_LC_off, 1, 4, 1, 1)
        self.btn_CC_off = QtGui.QToolButton(self.tab_festo)
        self.btn_CC_off.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_CC_off.setObjectName(_fromUtf8("btn_CC_off"))
        self.gridLayout_10.addWidget(self.btn_CC_off, 0, 4, 1, 1)
        self.btn_NF_off = QtGui.QToolButton(self.tab_festo)
        self.btn_NF_off.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_NF_off.setObjectName(_fromUtf8("btn_NF_off"))
        self.gridLayout_10.addWidget(self.btn_NF_off, 2, 4, 1, 1)
        self.taurusLabel_4 = TaurusLabel(self.tab_festo)
        self.taurusLabel_4.setMinimumSize(QtCore.QSize(100, 40))
        self.taurusLabel_4.setAlignment(QtCore.Qt.AlignCenter)
        self.taurusLabel_4.setObjectName(_fromUtf8("taurusLabel_4"))
        self.gridLayout_10.addWidget(self.taurusLabel_4, 3, 1, 1, 1)
        self.label_4 = QtGui.QLabel(self.tab_festo)
        self.label_4.setObjectName(_fromUtf8("label_4"))
        self.gridLayout_10.addWidget(self.label_4, 3, 0, 1, 1)
        self.btn_SH_on = QtGui.QToolButton(self.tab_festo)
        self.btn_SH_on.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_SH_on.setObjectName(_fromUtf8("btn_SH_on"))
        self.gridLayout_10.addWidget(self.btn_SH_on, 3, 3, 1, 1)
        self.btn_SH_off = QtGui.QToolButton(self.tab_festo)
        self.btn_SH_off.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_SH_off.setObjectName(_fromUtf8("btn_SH_off"))
        self.gridLayout_10.addWidget(self.btn_SH_off, 3, 4, 1, 1)
        self.label_5 = QtGui.QLabel(self.tab_festo)
        self.label_5.setObjectName(_fromUtf8("label_5"))
        self.gridLayout_10.addWidget(self.label_5, 4, 0, 1, 1)
        self.taurusLabel_5 = TaurusLabel(self.tab_festo)
        self.taurusLabel_5.setMinimumSize(QtCore.QSize(100, 40))
        self.taurusLabel_5.setAlignment(QtCore.Qt.AlignCenter)
        self.taurusLabel_5.setObjectName(_fromUtf8("taurusLabel_5"))
        self.gridLayout_10.addWidget(self.taurusLabel_5, 4, 1, 1, 1)
        self.btn_532 = QtGui.QPushButton(self.tab_festo)
        self.btn_532.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_532.setMaximumSize(QtCore.QSize(40, 16777215))
        self.btn_532.setObjectName(_fromUtf8("btn_532"))
        self.gridLayout_10.addWidget(self.btn_532, 4, 3, 1, 1)
        self.btn_650 = QtGui.QPushButton(self.tab_festo)
        self.btn_650.setMinimumSize(QtCore.QSize(40, 40))
        self.btn_650.setMaximumSize(QtCore.QSize(40, 16777215))
        self.btn_650.setObjectName(_fromUtf8("btn_650"))
        self.gridLayout_10.addWidget(self.btn_650, 4, 4, 1, 1)
        spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding,
                                        QtGui.QSizePolicy.Minimum)
        self.gridLayout_10.addItem(spacerItem4, 4, 5, 1, 1)
        self.tabWidget.addTab(self.tab_festo, _fromUtf8(""))
        self.tab_calc = QtGui.QWidget()
        self.tab_calc.setObjectName(_fromUtf8("tab_calc"))
        self.gridLayout_3 = QtGui.QGridLayout(self.tab_calc)
        self.gridLayout_3.setMargin(0)
        self.gridLayout_3.setObjectName(_fromUtf8("gridLayout_3"))
        self.wv_calc = QtWebKit.QWebView(self.tab_calc)
        self.wv_calc.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
        self.wv_calc.setObjectName(_fromUtf8("wv_calc"))
        self.gridLayout_3.addWidget(self.wv_calc, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_calc, _fromUtf8(""))
        self.tab_save = QtGui.QWidget()
        self.tab_save.setObjectName(_fromUtf8("tab_save"))
        self.gridLayout_4 = QtGui.QGridLayout(self.tab_save)
        self.gridLayout_4.setMargin(0)
        self.gridLayout_4.setObjectName(_fromUtf8("gridLayout_4"))
        self.wv_save = QtWebKit.QWebView(self.tab_save)
        self.wv_save.setUrl(QtCore.QUrl(_fromUtf8("about:blank")))
        self.wv_save.setObjectName(_fromUtf8("wv_save"))
        self.gridLayout_4.addWidget(self.wv_save, 0, 0, 1, 1)
        self.tabWidget.addTab(self.tab_save, _fromUtf8(""))
        self.gridLayout.addWidget(self.tabWidget, 1, 0, 4, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 1006, 21))
        self.menubar.setObjectName(_fromUtf8("menubar"))
        self.menuCalibration = QtGui.QMenu(self.menubar)
        self.menuCalibration.setObjectName(_fromUtf8("menuCalibration"))
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        self.actionCalibrate_Motors = QtGui.QAction(MainWindow)
        self.actionCalibrate_Motors.setObjectName(
            _fromUtf8("actionCalibrate_Motors"))
        self.menuCalibration.addAction(self.actionCalibrate_Motors)
        self.menubar.addAction(self.menuCalibration.menuAction())

        self.retranslateUi(MainWindow)
        self.tabWidget.setCurrentIndex(0)
        QtCore.QObject.connect(self.menubar,
                               QtCore.SIGNAL(_fromUtf8("triggered(QAction*)")),
                               MainWindow.processMenuAction)
        QtCore.QObject.connect(self.btn_lightOn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionLightOn)
        QtCore.QObject.connect(self.btn_lightOff,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionLightOff)
        QtCore.QObject.connect(self.sld_lightSet,
                               QtCore.SIGNAL(_fromUtf8("sliderReleased()")),
                               MainWindow.actionLightSet)
        QtCore.QObject.connect(self.btn_prepObserv,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionPrepObservation)
        QtCore.QObject.connect(self.btn_prepCollect,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionPrepCollection)
        QtCore.QObject.connect(self.btn_LC_on,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionLCon)
        QtCore.QObject.connect(self.btn_LC_off,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionLCoff)
        QtCore.QObject.connect(self.btn_CC_on,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionCCon)
        QtCore.QObject.connect(self.btn_CC_off,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionCCoff)
        QtCore.QObject.connect(self.btn_NF_on,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionNFon)
        QtCore.QObject.connect(self.btn_NF_off,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionNFoff)
        QtCore.QObject.connect(self.btn_SH_on,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionSHon)
        QtCore.QObject.connect(self.btn_SH_off,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionSHoff)
        QtCore.QObject.connect(self.btn_prepAlign,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.actionPrepAlignment)
        QtCore.QObject.connect(self.btn_532,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.action532On)
        QtCore.QObject.connect(self.btn_650,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.action660On)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.btn_prepObserv, self.btn_prepCollect)
        MainWindow.setTabOrder(self.btn_prepCollect, self.btn_prepAlign)
        MainWindow.setTabOrder(self.btn_prepAlign, self.btn_lightOn)
        MainWindow.setTabOrder(self.btn_lightOn, self.btn_lightOff)
        MainWindow.setTabOrder(self.btn_lightOff, self.sld_lightSet)
        MainWindow.setTabOrder(self.sld_lightSet, self.tabWidget)
        MainWindow.setTabOrder(self.tabWidget, self.btn_CC_on)
        MainWindow.setTabOrder(self.btn_CC_on, self.btn_CC_off)
        MainWindow.setTabOrder(self.btn_CC_off, self.btn_LC_on)
        MainWindow.setTabOrder(self.btn_LC_on, self.btn_LC_off)
        MainWindow.setTabOrder(self.btn_LC_off, self.btn_NF_on)
        MainWindow.setTabOrder(self.btn_NF_on, self.btn_NF_off)
        MainWindow.setTabOrder(self.btn_NF_off, self.btn_SH_on)
        MainWindow.setTabOrder(self.btn_SH_on, self.btn_SH_off)
        MainWindow.setTabOrder(self.btn_SH_off, self.btn_532)
        MainWindow.setTabOrder(self.btn_532, self.btn_650)
        MainWindow.setTabOrder(self.btn_650, self.wv_calc)
        MainWindow.setTabOrder(self.wv_calc, self.wv_save)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow", None))
        self.groupBox_2.setTitle(
            _translate("MainWindow", "Fast Controls", None))
        self.btn_prepCollect.setText(
            _translate("MainWindow", "Prep. &Collection", None))
        self.btn_prepObserv.setText(
            _translate("MainWindow", "Prep. &Observation", None))
        self.btn_prepAlign.setText(
            _translate("MainWindow", "Prep. &Alignment", None))
        self.groupBox.setTitle(_translate("MainWindow", "Light Control", None))
        self.btn_lightOff.setText(_translate("MainWindow", "OFF", None))
        self.btn_lightOn.setText(_translate("MainWindow", "ON", None))
        self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_motors),
                                  _translate("MainWindow", "Motors", None))
        self.label_2.setText(_translate("MainWindow", "Camera Cube", None))
        self.taurusLabel.setProperty(
            "model",
            _translate(
                "MainWindow",
                "tango://haspllabcl1:10000/llab/ramanoptics/llabcl1.01/Valve2",
                None))
        self.btn_NF_on.setText(_translate("MainWindow", "532", None))
        self.taurusLabel_3.setProperty(
            "model",
            _translate(
                "MainWindow",
                "tango://haspllabcl1:10000/llab/ramanoptics/llabcl1.01/Valve3",
                None))
        self.taurusLabel_2.setProperty(
            "model",
            _translate(
                "MainWindow",
                "tango://haspllabcl1:10000/llab/ramanoptics/llabcl1.01/Valve1",
                None))
        self.label.setText(_translate("MainWindow", "Light Cube", None))
        self.label_3.setText(_translate("MainWindow", "NF 532 | 660nm", None))
        self.btn_CC_on.setText(_translate("MainWindow", "ON", None))
        self.btn_LC_on.setText(_translate("MainWindow", "ON", None))
        self.btn_LC_off.setText(_translate("MainWindow", "OFF", None))
        self.btn_CC_off.setText(_translate("MainWindow", "OFF", None))
        self.btn_NF_off.setText(_translate("MainWindow", "660", None))
        self.taurusLabel_4.setProperty(
            "model",
            _translate(
                "MainWindow",
                "tango://haspllabcl1:10000/llab/ramanoptics/llabcl1.01/Valve4",
                None))
        self.label_4.setText(_translate("MainWindow", "Shutter", None))
        self.btn_SH_on.setText(_translate("MainWindow", "ON", None))
        self.btn_SH_off.setText(_translate("MainWindow", "OFF", None))
        self.label_5.setText(_translate("MainWindow", "532nm | 660nm", None))
        self.taurusLabel_5.setProperty(
            "model",
            _translate(
                "MainWindow",
                "tango://haspllabcl1:10000/llab/ramanoptics/llabcl1.01/Valve5",
                None))
        self.btn_532.setText(_translate("MainWindow", "532", None))
        self.btn_650.setText(_translate("MainWindow", "660", None))
        self.tabWidget.setTabText(
            self.tabWidget.indexOf(self.tab_festo),
            _translate("MainWindow", "Optical Elements", None))
        self.tabWidget.setTabText(
            self.tabWidget.indexOf(self.tab_calc),
            _translate("MainWindow", "Calculations Ruby", None))
        self.tabWidget.setTabText(
            self.tabWidget.indexOf(self.tab_save),
            _translate("MainWindow", "Saving Positions", None))
        self.menuCalibration.setTitle(_translate("MainWindow", "Expert", None))
        self.actionCalibrate_Motors.setText(
            _translate("MainWindow", "Calibrate Motors", None))
コード例 #7
0
class MagnetCircuitPanel(TaurusWidget):
    "Displays the important attributes of the circuit device"

    attrs = ["energy", "MainFieldComponent", "PowerSupplyReadValue", "PowerSupplySetPoint",
             "fixNormFieldOnEnergyChange"]

    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 = self.vbox = QtGui.QVBoxLayout(self)

        hbox2 = QtGui.QVBoxLayout(self)
        self.device_and_state = DevnameAndState(self)
        hbox2.addWidget(self.device_and_state)
        self.magnet_type_label = QtGui.QLabel("Magnet type:")
        hbox2.addWidget(self.magnet_type_label)
        form_vbox.addLayout(hbox2)

        # attributes
        self.form = MAXForm(withButtons=False)
        form_vbox.addWidget(self.form, stretch=1)
        self.status_area = StatusArea(self)
        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)
        if device:
            self.form.setModel(["%s/%s" % (device, attribute)
                                for attribute in self.attrs])
            db = PyTango.Database()
            magnet = db.get_device_property(device, "MagnetProxies")["MagnetProxies"][0]
            magnet_type = PyTango.Database().get_device_property(magnet, "Type")["Type"][0]
            self.magnet_type_label.setText("Magnet type: <b>%s</b>" % magnet_type)
            attrname = "%s/%s" % (device, "MainFieldComponent")
            self.valuebar.setModel(attrname)
            attr = Attribute(attrname)
            self.current_label.setText("%s [%s]" % (attr.label, attr.unit))
            self.status_area.setModel(device)
        else:
            self.form.setModel(None)
            self.valuebar.setModel(None)
            self.status_area.setModel(None)