예제 #1
0
    def __init__(self, parent=None, selectables=None, buttonsPos=None, designMode=None):
        TaurusWidget.__init__(self, parent)
        if selectables is None:
            selectables = [taurus.core.taurusbasetypes.TaurusElementType.Attribute, taurus.core.taurusbasetypes.TaurusElementType.Member,
                           taurus.core.taurusbasetypes.TaurusElementType.Device]
        self._selectables = selectables

        # tree
        self._deviceTree = TaurusDbTreeWidget(
            perspective=taurus.core.taurusbasetypes.TaurusElementType.Device)
        self._deviceTree.getQModel().setSelectables(self._selectables)
        self._deviceTree.setUseParentModel(True)

        # toolbar
        self._toolbar = Qt.QToolBar("TangoSelector toolbar")
        self._toolbar.setIconSize(Qt.QSize(16, 16))
        self._toolbar.setFloatable(False)
        self._addSelectedAction = self._toolbar.addAction(
            Qt.QIcon.fromTheme("list-add"), "Add selected", self.onAddSelected)

        # defines the layout
        self.setButtonsPos(buttonsPos)

        self._deviceTree.recheckTaurusParent()  # NOT WORKING????
        # @todo: This is Workaround because UseSetParentModel is giving trouble again!
        self.modelChanged.connect(self._deviceTree.setModel)
예제 #2
0
    def __init__(self,
                 parent=None,
                 selectables=None,
                 buttonsPos=None,
                 designMode=None):
        TaurusModelSelectorItem.__init__(self, parent)
        if selectables is None:
            selectables = [
                taurus.core.taurusbasetypes.TaurusElementType.Attribute,
                taurus.core.taurusbasetypes.TaurusElementType.Member,
                taurus.core.taurusbasetypes.TaurusElementType.Device
            ]
        self._selectables = selectables

        # tree
        self._deviceTree = TaurusDbTreeWidget(
            perspective=taurus.core.taurusbasetypes.TaurusElementType.Device)
        self._deviceTree.getQModel().setSelectables(self._selectables)

        # toolbar
        self._toolbar = Qt.QToolBar("TangoSelector toolbar")
        self._toolbar.setIconSize(Qt.QSize(16, 16))
        self._toolbar.setFloatable(False)
        self._addSelectedAction = self._toolbar.addAction(
            Qt.QIcon.fromTheme("list-add"), "Add selected", self.onAddSelected)

        # defines the layout
        self.setButtonsPos(buttonsPos)

        self.modelChanged.connect(self._deviceTree.setModel)
예제 #3
0
파일: senv.py 프로젝트: tacaswell/sardana
 def createEditor(self, parent, option, index):
     if index.column() == 1:
         self.combo_attr_tree_widget = TaurusDbTreeWidget(
             perspective=TaurusElementType.Device)
         self.combo_attr_tree_widget.setModel(self.host)
         treeView = self.combo_attr_tree_widget.treeView()
         qmodel = self.combo_attr_tree_widget.getQModel()
         editor = Qt.QComboBox(parent)
         editor.setModel(qmodel)
         editor.setMaxVisibleItems(20)
         editor.setView(treeView)
     elif index.column() == 2:
         editor = MSAttrListComboBox(parent)
         editor.setUseParentModel(True)
         editor.setModel("/InstrumentList")
     else:
         editor = Qt.QItemDelegate.createEditor(self, parent, option, index)
     return editor
예제 #4
0
파일: senv.py 프로젝트: cmft/sardana
 def createEditor(self, parent, option, index):
     if index.column() == 1:
         self.combo_attr_tree_widget = TaurusDbTreeWidget(perspective=TaurusElementType.Device)
         self.combo_attr_tree_widget.setModel(self.host)
         treeView = self.combo_attr_tree_widget.treeView()
         qmodel = self.combo_attr_tree_widget.getQModel()
         editor = Qt.QComboBox(parent)
         editor.setModel(qmodel)
         editor.setMaxVisibleItems(20)
         editor.setView(treeView)
     elif index.column() == 2:
         editor = MSAttrListComboBox(parent)
         editor.setUseParentModel(True)
         editor.setModel("/InstrumentList")
     else:
         editor = Qt.QItemDelegate.createEditor(self, parent, option, index)
     return editor
예제 #5
0
파일: senv.py 프로젝트: tacaswell/sardana
class ExtraColumnsDelegate(Qt.QItemDelegate):
    def __init__(self, parent=None):
        Qt.QItemDelegate.__init__(self, parent)
        db = Database()
        self.host = db.getNormalName()

    def createEditor(self, parent, option, index):
        if index.column() == 1:
            self.combo_attr_tree_widget = TaurusDbTreeWidget(
                perspective=TaurusElementType.Device)
            self.combo_attr_tree_widget.setModel(self.host)
            treeView = self.combo_attr_tree_widget.treeView()
            qmodel = self.combo_attr_tree_widget.getQModel()
            editor = Qt.QComboBox(parent)
            editor.setModel(qmodel)
            editor.setMaxVisibleItems(20)
            editor.setView(treeView)
        elif index.column() == 2:
            editor = MSAttrListComboBox(parent)
            editor.setUseParentModel(True)
            editor.setModel("/InstrumentList")
        else:
            editor = Qt.QItemDelegate.createEditor(self, parent, option, index)
        return editor

    def setEditorData(self, editor, index):
        if index.column() == 2:
            text = index.model().data(index, Qt.Qt.DisplayRole)
            editor.setCurrentText(text)
        else:
            Qt.QItemDelegate.setEditorData(self, editor, index)

    def setModelData(self, editor, model, index):
        column = index.column()
        if column == 1:
            selectedItems = self.combo_attr_tree_widget.selectedItems()
            if not len(selectedItems) == 1:
                return
            taurusTreeAttributeItem = selectedItems[0]
            itemData = taurusTreeAttributeItem.itemData()
            if isinstance(itemData, TaurusAttrInfo):
                model.setData(index, itemData.fullName())
        elif column == 2:
            model.setData(index, editor.currentText())
        else:
            Qt.QItemDelegate.setModelData(self, editor, model, index)

    def sizeHint(self, option, index):
        if index.column() == 0:
            fm = option.fontMetrics
            text = index.model().data(index, Qt.Qt.DisplayRole)
            document = Qt.QTextDocument()
            document.setDefaultFont(option.font)
            document.setHtml(text)
            size = Qt.QSize(document.idealWidth() + 5, fm.height())
        elif index.column() == 1:
            editor = self.createEditor(self.parent(), option, index)
            if editor is None:
                size = Qt.QItemDelegate.sizeHint(self, option, index)
            else:
                size = editor.sizeHint()
                editor.hide()
                editor.setParent(None)


#                editor.destroy()
        else:
            size = Qt.QItemDelegate.sizeHint(self, option, index)
        return size
예제 #6
0
class TaurusModelSelectorTree(TaurusModelSelectorItem):

    addModels = Qt.pyqtSignal('QStringList')

    def __init__(self,
                 parent=None,
                 selectables=None,
                 buttonsPos=None,
                 designMode=None):
        TaurusModelSelectorItem.__init__(self, parent)
        if selectables is None:
            selectables = [
                taurus.core.taurusbasetypes.TaurusElementType.Attribute,
                taurus.core.taurusbasetypes.TaurusElementType.Member,
                taurus.core.taurusbasetypes.TaurusElementType.Device
            ]
        self._selectables = selectables

        # tree
        self._deviceTree = TaurusDbTreeWidget(
            perspective=taurus.core.taurusbasetypes.TaurusElementType.Device)
        self._deviceTree.getQModel().setSelectables(self._selectables)

        # toolbar
        self._toolbar = Qt.QToolBar("TangoSelector toolbar")
        self._toolbar.setIconSize(Qt.QSize(16, 16))
        self._toolbar.setFloatable(False)
        self._addSelectedAction = self._toolbar.addAction(
            Qt.QIcon.fromTheme("list-add"), "Add selected", self.onAddSelected)

        # defines the layout
        self.setButtonsPos(buttonsPos)

        self.modelChanged.connect(self._deviceTree.setModel)

    def setButtonsPos(self, buttonsPos):
        # we must delete the previous layout before we can set a new one
        currlayout = self.layout()
        if currlayout is not None:
            currlayout.deleteLater()
            Qt.QCoreApplication.sendPostedEvents(currlayout,
                                                 Qt.QEvent.DeferredDelete)
        # add to layout
        if buttonsPos is None:
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.BottomToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        elif buttonsPos == Qt.Qt.TopToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.LeftToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.RightToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        else:
            raise ValueError("Invalid buttons position")

    def getSelectedModels(self):
        selected = []
        try:
            from taurus.core.tango.tangodatabase import (TangoDevInfo,
                                                         TangoAttrInfo)
        except:
            return selected
        # TODO: Tango-centric
        for item in self._deviceTree.selectedItems():
            nfo = item.itemData()
            if isinstance(nfo, TangoDevInfo):
                selected.append(nfo.fullName())
            elif isinstance(nfo, TangoAttrInfo):
                selected.append("%s/%s" %
                                (nfo.device().fullName(), nfo.name()))
            else:
                self.info("Unknown item '%s' in selection" % repr(nfo))
        return selected

    def onAddSelected(self):
        self.addModels.emit(self.getSelectedModels())

    def treeView(self):
        return self._deviceTree.treeView()

    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusWidget.getQtDesignerPluginInfo()
        ret['module'] = 'taurus.qt.qtgui.panel'
        ret['icon'] = "designer:listview.png"
        ret['container'] = False
        ret['group'] = 'Taurus Views'
        return ret
예제 #7
0
class TaurusModelSelectorTree(TaurusWidget):

    addModels = Qt.pyqtSignal('QStringList')

    def __init__(self, parent=None, selectables=None, buttonsPos=None, designMode=None):
        TaurusWidget.__init__(self, parent)
        if selectables is None:
            selectables = [taurus.core.taurusbasetypes.TaurusElementType.Attribute, taurus.core.taurusbasetypes.TaurusElementType.Member,
                           taurus.core.taurusbasetypes.TaurusElementType.Device]
        self._selectables = selectables

        # tree
        self._deviceTree = TaurusDbTreeWidget(
            perspective=taurus.core.taurusbasetypes.TaurusElementType.Device)
        self._deviceTree.getQModel().setSelectables(self._selectables)
        self._deviceTree.setUseParentModel(True)

        # toolbar
        self._toolbar = Qt.QToolBar("TangoSelector toolbar")
        self._toolbar.setIconSize(Qt.QSize(16, 16))
        self._toolbar.setFloatable(False)
        self._addSelectedAction = self._toolbar.addAction(
            Qt.QIcon.fromTheme("list-add"), "Add selected", self.onAddSelected)

        # defines the layout
        self.setButtonsPos(buttonsPos)

        self._deviceTree.recheckTaurusParent()  # NOT WORKING????
        # @todo: This is Workaround because UseSetParentModel is giving trouble again!
        self.modelChanged.connect(self._deviceTree.setModel)

    def setButtonsPos(self, buttonsPos):
        # we must delete the previous layout before we can set a new one
        currlayout = self.layout()
        if currlayout is not None:
            currlayout.deleteLater()
            Qt.QCoreApplication.sendPostedEvents(
                currlayout, Qt.QEvent.DeferredDelete)
        # add to layout
        if buttonsPos is None:
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.BottomToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        elif buttonsPos == Qt.Qt.TopToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.LeftToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.RightToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        else:
            raise ValueError("Invalid buttons position")

    def getSelectedModels(self):
        # todo: this method is tango-centric, but it could be fixed...
        selected = []
        for item in self._deviceTree.selectedItems():
            nfo = item.itemData()
            if isinstance(nfo, TangoDevInfo):
                selected.append(nfo.fullName())
            elif isinstance(nfo, TangoAttrInfo):
                selected.append("%s/%s" %
                                (nfo.device().fullName(), nfo.name()))
            else:
                self.info("Unknown item '%s' in selection" % repr(nfo))
        return selected

    def onAddSelected(self):
        self.addModels.emit(self.getSelectedModels())

    def treeView(self):
        return self._deviceTree.treeView()

    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusWidget.getQtDesignerPluginInfo()
        ret['module'] = 'taurus.qt.qtgui.panel'
        ret['icon'] = "designer:listview.png"
        ret['container'] = False
        ret['group'] = 'Taurus Views'
        return ret
예제 #8
0
파일: senv.py 프로젝트: cmft/sardana
class ExtraColumnsDelegate(Qt.QItemDelegate):

    def __init__(self, parent=None):
        Qt.QItemDelegate.__init__(self, parent)
        db = Database()
        self.host = db.getNormalName()

    def createEditor(self, parent, option, index):
        if index.column() == 1:
            self.combo_attr_tree_widget = TaurusDbTreeWidget(perspective=TaurusElementType.Device)
            self.combo_attr_tree_widget.setModel(self.host)
            treeView = self.combo_attr_tree_widget.treeView()
            qmodel = self.combo_attr_tree_widget.getQModel()
            editor = Qt.QComboBox(parent)
            editor.setModel(qmodel)
            editor.setMaxVisibleItems(20)
            editor.setView(treeView)
        elif index.column() == 2:
            editor = MSAttrListComboBox(parent)
            editor.setUseParentModel(True)
            editor.setModel("/InstrumentList")
        else:
            editor = Qt.QItemDelegate.createEditor(self, parent, option, index)
        return editor

    def setEditorData(self, editor, index):
        if index.column() == 2:
            text = Qt.from_qvariant(index.model().data(index, Qt.Qt.DisplayRole), str)
            editor.setCurrentText(text)
        else:
            Qt.QItemDelegate.setEditorData(self, editor, index)

    def setModelData(self, editor, model, index):
        column = index.column()
        if column == 1:
            selectedItems = self.combo_attr_tree_widget.selectedItems()
            if not len(selectedItems) == 1: return
            taurusTreeAttributeItem = selectedItems[0]
            itemData = taurusTreeAttributeItem.itemData()
            if isinstance(itemData, TaurusAttrInfo):
                model.setData(index, Qt.QVariant(itemData.fullName()))
        elif column == 2:
            model.setData(index, Qt.QVariant(editor.currentText()))
        else:
            Qt.QItemDelegate.setModelData(self, editor, model, index)

    def sizeHint(self, option, index):
        if index.column() == 0:
            fm = option.fontMetrics
            text = Qt.from_qvariant(index.model().data(index, Qt.Qt.DisplayRole), str)
            document = Qt.QTextDocument()
            document.setDefaultFont(option.font)
            document.setHtml(text)
            size = Qt.QSize(document.idealWidth() + 5, fm.height())
        elif index.column() == 1:
            editor = self.createEditor(self.parent(), option, index)
            if editor is None:
                size = Qt.QItemDelegate.sizeHint(self, option, index)
            else:
                size = editor.sizeHint()
                editor.hide()
                editor.setParent(None)
#                editor.destroy()
        else:
            size = Qt.QItemDelegate.sizeHint(self, option, index)
        return size
class TaurusModelSelectorTree(TaurusWidget):

    def __init__(self, parent=None, selectables=None, buttonsPos=None, designMode=None):
        TaurusWidget.__init__(self, parent)
        if selectables is None:
            selectables = [taurus.core.taurusbasetypes.TaurusElementType.Attribute, taurus.core.taurusbasetypes.TaurusElementType.Member,
                           taurus.core.taurusbasetypes.TaurusElementType.Device]
        self._selectables = selectables

        # tree
        self._deviceTree = TaurusDbTreeWidget(
            perspective=taurus.core.taurusbasetypes.TaurusElementType.Device)
        self._deviceTree.getQModel().setSelectables(self._selectables)
        self._deviceTree.setUseParentModel(True)

        # toolbar
        self._toolbar = Qt.QToolBar("TangoSelector toolbar")
        self._toolbar.setIconSize(Qt.QSize(16, 16))
        self._toolbar.setFloatable(False)
        self._addSelectedAction = self._toolbar.addAction(
            taurus.qt.qtgui.resource.getThemeIcon("list-add"), "Add selected", self.onAddSelected)

        # defines the layout
        self.setButtonsPos(buttonsPos)

        self._deviceTree.recheckTaurusParent()  # NOT WORKING????
        # @todo: This is Workaround because UseSetParentModel is giving trouble again!
        self.connect(self, Qt.SIGNAL(self.ModelChangedSignal),
                     self._deviceTree.setModel)

    def setButtonsPos(self, buttonsPos):
        # we must delete the previous layout before we can set a new one
        currlayout = self.layout()
        if currlayout is not None:
            currlayout.deleteLater()
            Qt.QCoreApplication.sendPostedEvents(
                currlayout, Qt.QEvent.DeferredDelete)
        # add to layout
        if buttonsPos is None:
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.BottomToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        elif buttonsPos == Qt.Qt.TopToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Horizontal)
            self.setLayout(Qt.QVBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.LeftToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._toolbar)
            self.layout().addWidget(self._deviceTree)
        elif buttonsPos == Qt.Qt.RightToolBarArea:
            self._toolbar.setOrientation(Qt.Qt.Vertical)
            self.setLayout(Qt.QHBoxLayout())
            self.layout().addWidget(self._deviceTree)
            self.layout().addWidget(self._toolbar)
        else:
            raise ValueError("Invalid buttons position")

    def getSelectedModels(self):
        # todo: this method is tango-centric, but it could be fixed...
        selected = []
        for item in self._deviceTree.selectedItems():
            nfo = item.itemData()
            if isinstance(nfo, TangoDevInfo):
                selected.append(nfo.fullName())
            elif isinstance(nfo, TangoAttrInfo):
                selected.append("%s/%s" %
                                (nfo.device().fullName(), nfo.name()))
            else:
                self.info("Unknown item '%s' in selection" % repr(nfo))
        return selected

    def onAddSelected(self):
        self.emit(Qt.SIGNAL("addModels"), self.getSelectedModels())

    def treeView(self):
        return self._deviceTree.treeView()

    @classmethod
    def getQtDesignerPluginInfo(cls):
        ret = TaurusWidget.getQtDesignerPluginInfo()
        ret['module'] = 'taurus.qt.qtgui.panel'
        ret['icon'] = ":/designer/listview.png"
        ret['container'] = False
        ret['group'] = 'Taurus Views'
        return ret