Exemplo n.º 1
0
 def setEditorData(self, editor, index):
     model = index.model()
     dataSource = model.dataSource()
     taurus_role = model.role(index.column())
     if taurus_role == ChannelView.PlotType:
         editor.addItems(PlotType.keys())
         current = Qt.from_qvariant(model.data(index), str)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role == ChannelView.Normalization:
         editor.addItems(Normalization.keys())
         current = Qt.from_qvariant(model.data(index), str)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role in (ChannelView.Timer, ChannelView.Monitor):
         key = taurus_role == ChannelView.Timer and 'timer' or 'monitor'
         ch_name, ch_data = index.internalPointer().itemData()
         ctrl_filterlist = [ch_data['_controller_name']]
         ctrl_dict = getChannelConfigs(dataSource, ctrls=ctrl_filterlist)
         all_channels = model.getAvailableChannels()
         # if it is a timer capable type of element
         if all_channels[ch_name]['type'] in ('CTExpChannel',
                                              'OneDExpChannel',
                                              'TwoDExpChannel'):
             for full_name, channel_data in ctrl_dict:
                 editor.addItem(channel_data['name'],
                                Qt.QVariant(full_name))
             current = Qt.from_qvariant(model.data(index), str)
             editor.setCurrentIndex(editor.findText(current))
         else:
             for ctrl_data in dataSource['controllers'].values():
                 if key in ctrl_data:
                     channel = all_channels[ctrl_data[key]]
                     editor.addItem(channel['name'],
                                    Qt.QVariant(channel['full_name']))
             current = dataSource.get(key)  # current global timer/monitor
             editor.setCurrentIndex(editor.findData(Qt.QVariant(current)))
     elif taurus_role == ChannelView.Synchronization:
         editor.addItems(AcqSynchType.keys())
         current = Qt.from_qvariant(model.data(index), str)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role == ChannelView.PlotAxes:
         selectables = ['<idx>', '<mov>'] + \
             [n for n, d in getChannelConfigs(dataSource)]
         editor.setChoices(selectables)
         current = Qt.from_qvariant(model.data(index), str)
         editor.setCurrentChoices(current)
     elif taurus_role == ChannelView.Synchronizer:
         # add the triggergates to the editor
         all_triggers = model.getAvailableTriggers()
         for full_name, tg_data in all_triggers.items():
             editor.addItem(tg_data['name'], Qt.QVariant(full_name))
             current = Qt.from_qvariant(model.data(index), str)
             editor.setCurrentIndex(editor.findText(current))
     else:
         Qt.QStyledItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 2
0
 def setEditorData(self, editor, index):
     model = index.model()
     dataSource = model.dataSource()
     taurus_role = model.role(index.column())
     if taurus_role == ChannelView.PlotType:
         editor.addItems(PlotType.keys())
         current = model.data(index)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role == ChannelView.Normalization:
         editor.addItems(Normalization.keys())
         current = model.data(index)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role in (ChannelView.Timer, ChannelView.Monitor):
         key = taurus_role == ChannelView.Timer and 'timer' or 'monitor'
         ch_name, ch_data = index.internalPointer().itemData()
         ctrl_filterlist = [ch_data['_controller_name']]
         ctrl_dict = getChannelConfigs(dataSource, ctrls=ctrl_filterlist)
         all_channels = model.getAvailableChannels()
         # if it is a timer capable type of element
         if all_channels[ch_name]['type'] in ('CTExpChannel', 'OneDExpChannel', 'TwoDExpChannel'):
             for full_name, channel_data in ctrl_dict:
                 editor.addItem(
                     channel_data['name'], full_name)
             current = model.data(index)
             editor.setCurrentIndex(editor.findText(current))
         else:
             for ctrl_data in dataSource['controllers'].values():
                 if key in ctrl_data:
                     channel = all_channels[ctrl_data[key]]
                     editor.addItem(channel['name'], channel['full_name'])
             current = dataSource.get(key)  # current global timer/monitor
             editor.setCurrentIndex(editor.findData(current))
     elif taurus_role == ChannelView.Synchronization:
         editor.addItems(AcqSynchType.keys())
         current = model.data(index)
         editor.setCurrentIndex(editor.findText(current))
     elif taurus_role == ChannelView.PlotAxes:
         selectables = ['<idx>', '<mov>'] + \
             [n for n, d in getChannelConfigs(dataSource)]
         editor.setChoices(selectables)
         current = model.data(index)
         editor.setCurrentChoices(current)
     elif taurus_role == ChannelView.Synchronizer:
         # add the triggergates to the editor
         all_triggers = model.getAvailableTriggers()
         for full_name, tg_data in all_triggers.items():
             editor.addItem(tg_data['name'], full_name)
             current = model.data(index)
             editor.setCurrentIndex(editor.findText(current))
     else:
         Qt.QStyledItemDelegate.setEditorData(self, editor, index)
Exemplo n.º 3
0
 def addChannel(self, channel=None):
     qmodel = self.getQModel()
     dataSource = qmodel.dataSource()
     if channel is None:
         shown = [n for n, d in getChannelConfigs(dataSource)]
         avail_channels = qmodel.getAvailableChannels()
         clist = [
             ch_info['name'] for ch_name, ch_info in avail_channels.items()
             if ch_name not in shown
         ]
         clist = sorted(clist) + ['(Other...)']
         chname, ok = Qt.QInputDialog.getItem(self, "New Channel",
                                              "Choose channel:", clist, 0,
                                              False)
         if not ok:
             return
     chname = str(chname)
     if chname == '(Other...)':
         models, ok = TaurusModelChooser.modelChooserDlg(
             parent=self,
             singleModel=False,
             windowTitle='Choose source of data',
             selectables=[TaurusElementType.Attribute])
         if not ok:
             return
         for m in models:
             qmodel.addChannel(chname=m,
                               ctrlname='__tango__',
                               external=True)
     else:
         for ch_info in avail_channels.values():
             if ch_info['name'] == chname:
                 qmodel.addChannel(chinfo=ch_info)
Exemplo n.º 4
0
 def addChannel(self, channel=None):
     qmodel = self.getQModel()
     dataSource = qmodel.dataSource()
     if channel is None:
         shown = [n for n, d in getChannelConfigs(dataSource)]
         avail_channels = qmodel.getAvailableChannels()
         clist = [ch_info['name'] for ch_name, ch_info in avail_channels.items()
                  if ch_name not in shown]
         clist = sorted(clist) + ['(Other...)']
         chname, ok = Qt.QInputDialog.getItem(
             self, "New Channel", "Choose channel:", clist, 0, False)
         if not ok:
             return
     chname = str(chname)
     if chname == '(Other...)':
         models, ok = TaurusModelChooser.modelChooserDlg(parent=self, singleModel=False, windowTitle='Choose source of data',
                                                         selectables=[TaurusElementType.Attribute])
         if not ok:
             return
         for m in models:
             qmodel.addChannel(
                 chname=m, ctrlname='__tango__', external=True)
     else:
         for ch_info in avail_channels.values():
             if ch_info['name'] == chname:
                 qmodel.addChannel(chinfo=ch_info)
Exemplo n.º 5
0
 def setupModelData(self, mgconfig):
     if mgconfig is None:
         return
     root = self._rootItem  #@The root could eventually be changed for each unit or controller
     channelNodes = [MntGrpChannelItem(self, chcfg, root) for chcfg in getChannelConfigs(mgconfig)]
     for ch in channelNodes:
         root.appendChild(ch)
     self.updateMntGrpChannelIndex(root=root)
     #store the whole config object for accessing the info that is not at the channel level
     self._mgconfig = mgconfig
Exemplo n.º 6
0
 def setupModelData(self, mgconfig):
     if mgconfig is None:
         return
     root = self._rootItem  # @The root could eventually be changed for each unit or controller
     channelNodes = [MntGrpChannelItem(
         self, chcfg, root) for chcfg in getChannelConfigs(mgconfig)]
     for ch in channelNodes:
         root.appendChild(ch)
     self.updateMntGrpChannelIndex(root=root)
     # store the whole config object for accessing the info that is not at
     # the channel level
     self._mgconfig = mgconfig
Exemplo n.º 7
0
    def setModelData(self, editor, model, index):
        taurus_role = model.role(index.column())
        dataSource = model.dataSource()
        if taurus_role in (ChannelView.Channel, ChannelView.PlotType,
                           ChannelView.Normalization):
            data = Qt.QVariant(editor.currentText())
            model.setData(index, data)
        elif taurus_role == ChannelView.Synchronization:
            old_value = Qt.from_qvariant(model.data(index), str)
            new_value = str(editor.currentText())
            if new_value == old_value:
                return
            ch_name, ch_data = index.internalPointer().itemData()
            channels = getChannelConfigs(dataSource,
                                         ctrls=[ch_data['_controller_name']])
            affected = [d['name'] for n, d in channels]
            if len(affected) > 1:
                op = Qt.QMessageBox.question(
                    editor, "Caution: multiple channels affected",
                    "This change will also affect the following channels:\n- %s \nContinue?"
                    % "\n- ".join(affected),
                    Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                if op != Qt.QMessageBox.Yes:
                    return
            data = Qt.QVariant(new_value)
            model.setData(index, data)
        elif taurus_role in (ChannelView.Timer, ChannelView.Monitor):
            key = taurus_role == ChannelView.Timer and 'timer' or 'monitor'
            old_value = Qt.from_qvariant(model.data(index), str)
            new_value = str(editor.currentText())
            if new_value == old_value:
                return
            ch_name, ch_data = index.internalPointer().itemData()
            all_channels = model.getAvailableChannels()
            # if it is a timer capable type of element
            ch_info = all_channels[ch_name]
            selected_master = editor.itemData(editor.currentIndex())
            if ch_info['type'] in ('CTExpChannel', 'OneDExpChannel',
                                   'TwoDExpChannel'):
                affected = []
                ctrl_data = model.getPyData(
                    ctrlname=ch_data['_controller_name'])
                channels = getChannelConfigs(
                    dataSource, ctrls=[ch_data['_controller_name']])
                for n, d in channels:
                    affected.append(d['name'])
                # if old timer/monitor was also the global, then non
                # timerable/monitorable channels must be changed
                if ctrl_data[key] == dataSource.get(key):
                    for n, d in getChannelConfigs(dataSource):
                        if d['_controller_name'].startswith("__"):
                            continue
                        ch_info = all_channels[n]
                        if ch_info['type'] in ('CTExpChannel',
                                               'OneDExpChannel',
                                               'TwoDExpChannel'):
                            continue
                        affected.append(d['name'])

                if len(affected) > 1:
                    op = Qt.QMessageBox.question(
                        editor, "Caution: multiple channels affected",
                        "This change will also affect the following channels:\n- %s \nContinue?"
                        % "\n- ".join(affected),
                        Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                    if op != Qt.QMessageBox.Yes:
                        return
            else:
                affected = []
                channels = getChannelConfigs(dataSource)
                for n, d in channels:
                    if d['_controller_name'].startswith("__"):
                        continue
                    ch_info = all_channels[n]
                    if ch_info['type'] in ('CTExpChannel', 'OneDExpChannel',
                                           'TwoDExpChannel'):
                        continue
                    affected.append(d['name'])
                if len(affected) > 1:
                    op = Qt.QMessageBox.question(
                        editor, "Caution: multiple channels affected",
                        "This change will also affect the following channels:\n- %s \nContinue?"
                        % "\n- ".join(affected),
                        Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                    if op != Qt.QMessageBox.Yes:
                        return
            model.setData(index, selected_master)
        elif taurus_role == ChannelView.PlotAxes:
            data = Qt.QVariant(editor.text())
            model.setData(index, data)
        elif taurus_role == ChannelView.Synchronizer:
            old_value = Qt.from_qvariant(model.data(index), str)
            new_value = str(editor.currentText())
            if new_value == old_value:
                return

            ch_name, ch_data = index.internalPointer().itemData()
            ctrl_name = ch_data['_controller_name']
            ctrl_data = dataSource['controllers'][ctrl_name]
            # get the affected channels
            affected = []
            channels = ctrl_data.get('channels')
            for _, ch_data in channels.items():
                affected.append(ch_data['name'])

            if len(affected) > 1:
                op = Qt.QMessageBox.question(
                    editor, "Caution: multiple channels affected",
                    "This change will also affect the following channels:\n- %s \nContinue?"
                    % "\n- ".join(affected),
                    Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                if op != Qt.QMessageBox.Yes:
                    return

            selected_master = editor.itemData(editor.currentIndex())
            model.setData(index, selected_master)
        else:
            Qt.QStyledItemDelegate.setModelData(self, editor, model, index)
Exemplo n.º 8
0
    def onExpConfChanged(self, expconf):
        '''
        Slot to be called when experimental configuration changes. It should
        remove the temporary panels and create the new ones needed.

        :param expconf: (dict) An Experiment Description dictionary. See
                        :meth:`sardana.taurus.qt.qtcore.tango.sardana.
                        QDoor.getExperimentDescription`
                        for more details
        '''
        if expconf['ActiveMntGrp'] is None:
            return
        if expconf['ActiveMntGrp'] not in expconf['MntGrpConfigs'].keys():
            self.warning("ActiveMntGrp '%s' is not defined" %
                         expconf['ActiveMntGrp'])
            return
        mgconfig = expconf['MntGrpConfigs'][expconf['ActiveMntGrp']]
        channels = dict(getChannelConfigs(mgconfig, sort=False))

        # classify by type of plot:
        trends1d = {}
        trends2d = {}
        plots1d = {}
        images = {}

        for chname, chdata in channels.items():
            ptype = chdata['plot_type']
            if ptype == PlotType.No:
                continue
            elif ptype == PlotType.Spectrum:
                axes = tuple(chdata['plot_axes'])
                # TODO: get default value from the channel.
                ndim = chdata.get('ndim', 0)
                if ndim == 0:  # this is a trend
                    if axes in trends1d:
                        trends1d[axes].append(chname)
                    else:
                        trends1d[axes] = CaselessList([chname])
                elif ndim == 1:  # a 1D plot (e.g. a spectrum)
                    pass  # TODO: implement
                else:
                    self.warning('Cannot create plot for %s', chname)

            elif ptype == PlotType.Image:
                axes = tuple(chdata['plot_axes'])
                # TODO: get default value from the channel.
                ndim = chdata.get('ndim', 1)
                if ndim == 0:  # a mesh-like plot?
                    pass  # TODO implement
                elif ndim == 1:  # a 2D trend
                    if axes in trends2d:
                        trends2d[axes].append(chname)
                    else:
                        trends2d[axes] = CaselessList([chname])
                elif ndim == 2:  # a 2D plot (e.g. an image)
                    pass  # TODO: implement
                else:
                    self.warning('Cannot create plot for %s', chname)

        new1d, removed1d = self._updateTemporaryTrends1D(trends1d)
        self.newShortMessage.emit("Changed panels (%i new, %i removed)" %
                                  (len(new1d), len(removed1d)))
Exemplo n.º 9
0
    def onExpConfChanged(self, expconf):
        '''
        Slot to be called when experimental configuration changes. It should
        remove the temporary panels and create the new ones needed.

        :param expconf: (dict) An Experiment Description dictionary. See
                        :meth:`sardana.taurus.qt.qtcore.tango.sardana.
                        QDoor.getExperimentDescription`
                        for more details
        '''

        from sardana.taurus.core.tango.sardana import PlotType
        from sardana.taurus.core.tango.sardana.pool import getChannelConfigs
        activeMntGrp = expconf['ActiveMntGrp']
        if activeMntGrp is None:
            return
        if activeMntGrp not in expconf['MntGrpConfigs']:
            self.warning(
                "ActiveMntGrp '%s' is not defined" %
                activeMntGrp)
            return
        mgconfig = expconf['MntGrpConfigs'][activeMntGrp]
        channels = dict(getChannelConfigs(mgconfig, sort=False))

        # classify by type of plot:
        trends1d = {}
        trends2d = {}

        for chname, chdata in channels.items():
            ptype = chdata['plot_type']
            if ptype == PlotType.No:
                continue
            elif ptype == PlotType.Spectrum:
                axes = tuple(chdata['plot_axes'])
                # TODO: get default value from the channel.
                ndim = chdata.get('ndim', 0) or 0
                if ndim == 0:  # this is a trend
                    if axes in trends1d:
                        trends1d[axes].append(chname)
                    else:
                        trends1d[axes] = CaselessList([chname])
                elif ndim == 1:  # a 1D plot (e.g. a spectrum)
                    pass  # TODO: implement
                else:
                    self.warning('Cannot create plot for %s', chname)

            elif ptype == PlotType.Image:
                axes = tuple(chdata['plot_axes'])
                # TODO: get default value from the channel.
                ndim = chdata.get('ndim', 1)
                if ndim == 0:  # a mesh-like plot?
                    pass  # TODO implement
                elif ndim == 1:  # a 2D trend
                    if axes in trends2d:
                        trends2d[axes].append(chname)
                    else:
                        trends2d[axes] = CaselessList([chname])
                elif ndim == 2:  # a 2D plot (e.g. an image)
                    pass  # TODO: implement
                else:
                    self.warning('Cannot create plot for %s', chname)
        try:
            # TODO: adapt _updateTemporaryTrends1D to use tpg
            new1d, removed1d = self._updateTemporaryTrends1D(trends1d)
            self.newShortMessage.emit("Changed panels (%i new, %i removed)"
                                      % (len(new1d), len(removed1d)))
        except Exception:
            self.warning(
                'Plots cannot be updated. Only qwt5 is supported for now'
            )
Exemplo n.º 10
0
    def setModelData(self, editor, model, index):
        taurus_role = model.role(index.column())
        dataSource = model.dataSource()
        if taurus_role in (ChannelView.Channel, ChannelView.PlotType, ChannelView.Normalization):
            data = Qt.QVariant(editor.currentText())
            model.setData(index, data)
        elif taurus_role == ChannelView.Trigger:
            old_value = Qt.from_qvariant(model.data(index), str)
            new_value = str(editor.currentText())
            if new_value == old_value:
                return
            ch_name, ch_data = index.internalPointer().itemData()
            channels = getChannelConfigs(dataSource, ctrls=[ch_data['_controller_name']], units=[ch_data['_unit_id']])
            affected = [d['name'] for n, d in channels]
            if len(affected) > 1:
                op = Qt.QMessageBox.question(editor, "Caution: multiple channels affected",
                                            "This change will also affect the following channels:\n- %s \nContinue?" % "\n- ".join(affected),
                                            Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                if op != Qt.QMessageBox.Yes:
                    return
            data = Qt.QVariant(new_value)
            model.setData(index, data)
        elif taurus_role in (ChannelView.Timer, ChannelView.Monitor):
            key = taurus_role == ChannelView.Timer and 'timer' or 'monitor'
            old_value = Qt.from_qvariant(model.data(index), str)
            new_value = str(editor.currentText())
            if new_value == old_value:
                return
            ch_name, ch_data = index.internalPointer().itemData()
            all_channels = model.getAvailableChannels()
            # if it is a timer capable type of element
            ch_info = all_channels[ch_name]
            selected_master = editor.itemData(editor.currentIndex())
            if ch_info['type'] in ('CTExpChannel', 'OneDExpChannel', 'TwoDExpChannel'):
                affected = []
                unit_data = model.getPyData(ctrlname=ch_data['_controller_name'], unitid=ch_data['_unit_id'])
                channels = getChannelConfigs(dataSource, ctrls=[ch_data['_controller_name']], units=[ch_data['_unit_id']])
                for n, d in channels:
                    affected.append(d['name'])
                # if old timer/monitor was also the global, then non
                # timerable/monitorable channels must be changed
                if unit_data[key] == dataSource.get(key):
                    for n, d in getChannelConfigs(dataSource):
                        if d['_controller_name'].startswith("__"):
                            continue
                        ch_info = all_channels[n]
                        if ch_info['type'] in ('CTExpChannel', 'OneDExpChannel', 'TwoDExpChannel'):
                            continue
                        affected.append(d['name'])

                if len(affected) > 1:
                    op = Qt.QMessageBox.question(editor, "Caution: multiple channels affected",
                                                "This change will also affect the following channels:\n- %s \nContinue?" % "\n- ".join(affected),
                                                Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                    if op != Qt.QMessageBox.Yes:
                        return
            else:
                affected = []
                channels = getChannelConfigs(dataSource)
                for n, d in channels:
                    if d['_controller_name'].startswith("__"):
                        continue
                    ch_info = all_channels[n]
                    if ch_info['type'] in ('CTExpChannel', 'OneDExpChannel', 'TwoDExpChannel'):
                        continue
                    affected.append(d['name'])
                if len(affected) > 1:
                    op = Qt.QMessageBox.question(editor, "Caution: multiple channels affected",
                                                "This change will also affect the following channels:\n- %s \nContinue?" % "\n- ".join(affected),
                                                Qt.QMessageBox.Yes | Qt.QMessageBox.Cancel)
                    if op != Qt.QMessageBox.Yes:
                        return
            model.setData(index, selected_master)
        elif taurus_role == ChannelView.PlotAxes:
            data = Qt.QVariant(editor.text())
            model.setData(index, data)
        else:
            Qt.QStyledItemDelegate.setModelData(self, editor, model, index)