예제 #1
0
class ChoosePluginToolbarsDialog(QDialog):

    def __init__(self, parent, plugin, locations):
        QDialog.__init__(self, parent)
        self.locations = locations

        self.setWindowTitle(
            _('Add "%s" to toolbars or menus')%plugin.name)

        self._layout = QVBoxLayout(self)
        self.setLayout(self._layout)

        self._header_label = QLabel(
                _('Select the toolbars and/or menus to add <b>%s</b> to:') %
                plugin.name)
        self._layout.addWidget(self._header_label)

        self._locations_list = QListWidget(self)
        self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        self._locations_list.setSizePolicy(sizePolicy)
        for key, text in locations:
            self._locations_list.addItem(text)
            if key in {'toolbar', 'toolbar-device'}:
                self._locations_list.item(self._locations_list.count()-1
                        ).setSelected(True)
        self._layout.addWidget(self._locations_list)

        self._footer_label = QLabel(
            _('You can also customise the plugin locations '
              'using <b>Preferences -> Customise the toolbar</b>'))
        self._layout.addWidget(self._footer_label)

        button_box = QDialogButtonBox(QDialogButtonBox.Ok |
                QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box)
        self.resize(self.sizeHint())

    def selected_locations(self):
        selected = []
        for row in self._locations_list.selectionModel().selectedRows():
            selected.append(self.locations[row.row()])
        return selected
예제 #2
0
class ChoosePluginToolbarsDialog(QDialog):
    def __init__(self, parent, plugin, locations):
        QDialog.__init__(self, parent)
        self.locations = locations

        self.setWindowTitle(_('Add "%s" to toolbars or menus') % plugin.name)

        self._layout = QVBoxLayout(self)
        self.setLayout(self._layout)

        self._header_label = QLabel(
            _('Select the toolbars and/or menus to add <b>%s</b> to:') %
            plugin.name)
        self._layout.addWidget(self._header_label)

        self._locations_list = QListWidget(self)
        self._locations_list.setSelectionMode(QAbstractItemView.MultiSelection)
        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred,
                                       QtGui.QSizePolicy.Minimum)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        self._locations_list.setSizePolicy(sizePolicy)
        for key, text in locations:
            self._locations_list.addItem(text)
            if key in {'toolbar', 'toolbar-device'}:
                self._locations_list.item(self._locations_list.count() -
                                          1).setSelected(True)
        self._layout.addWidget(self._locations_list)

        self._footer_label = QLabel(
            _('You can also customise the plugin locations '
              'using <b>Preferences -> Customise the toolbar</b>'))
        self._layout.addWidget(self._footer_label)

        button_box = QDialogButtonBox(QDialogButtonBox.Ok
                                      | QDialogButtonBox.Cancel)
        button_box.accepted.connect(self.accept)
        button_box.rejected.connect(self.reject)
        self._layout.addWidget(button_box)
        self.resize(self.sizeHint())

    def selected_locations(self):
        selected = []
        for row in self._locations_list.selectionModel().selectedRows():
            selected.append(self.locations[row.row()])
        return selected
예제 #3
0
class PM_Clipboard(PM_GroupBox):
    """
    The PM_Clipboard class provides a groupbox containing a list of clipboard
    items that can be pasted in the 3D Workspace. The selected item in this
    list is shown by its elementViewer (an instance of L{PM_PreviewGroupBox})
    The object being previewed can then be deposited into the 3D workspace.
    """
    def __init__(self,
                 parentWidget,
                 title='Clipboard',
                 win=None,
                 elementViewer=None):
        """
        Appends a PM_Clipboard groupbox widget to I{parentWidget},a L{PM_Dialog}

        @param parentWidget: The parent dialog (Property manager) containing
                             this  widget.
        @type  parentWidget: L{PM_Dialog}

        @param title: The title (button) text.
        @type  title: str

        @param win: MainWindow object
        @type  win: L{MWsemantics} or None

        @param elementViewer: The associated preview pane groupbox. If provided,
                              The selected item in L{self.clipboardListWidget}
                              is shown (previewed) by L{elementViewer}.
                              The object being previewed can then be deposited
                              into the 3D workspace.
        @type  elementViewer: L{PM_PreviewGroupBox} or None

        """

        self.w = win
        self.elementViewer = elementViewer
        self.elementViewer.setDisplay(diTUBES)
        self.pastableItems = None

        PM_GroupBox.__init__(self, parentWidget, title)

        self._loadClipboardGroupbox()

    def _loadClipboardGroupbox(self):
        """
        Load the L{self.clipboardListWidget} widget used to display a list of
        clipboard items inside this  clipboard  groupbox.
        """
        self.clipboardListWidget = QListWidget(self)

        self.gridLayout.addWidget(self.clipboardListWidget)
        #Append to the widget list. This is important for expand -collapse
        #functions (of the groupbox) to work properly.
        self._widgetList.append(self.clipboardListWidget)

    def _updateElementViewer(self, newModel=None):
        """
        Update the view of L{self.elementViewer}
        @param newModel: The model correseponding to the item selected
                         in L{self.clipboardListWidget}.
        @type  newModel: L{molecule} or L{Group}
        """
        if not self.elementViewer:
            return

        assert isinstance(self.elementViewer, MMKitView)
        self.elementViewer.resetView()
        if newModel:
            self.elementViewer.updateModel(newModel)

    def update(self):
        """
        Updates the clipboard items in the L{PM_Clipboard} groupbox. Also
        updates its element viewer.
        """
        PM_GroupBox.update(self)
        self.pastableItems = self.w.assy.shelf.getPastables()
        i = self.clipboardListWidget.currentRow()
        self.clipboardListWidget.clear()
        newModel = None

        if len(self.pastableItems):
            for item in self.pastableItems:
                self.clipboardListWidget.addItem(item.name)

            if i >= self.clipboardListWidget.count():
                i = self.clipboardListWidget.count() - 1

            if i < 0:
                i = 0

            self.clipboardListWidget.setCurrentItem(
                self.clipboardListWidget.item(i))

            newModel = self.pastableItems[i]

        self._updateElementViewer(newModel)

    def clipboardListItemChanged(self, currentItem=None, previousItem=None):
        """
        Slot method. Called when user clicks on a different pastable item
        displayed in this groupbox
        @param currentItem: Current item in the L{self.clipboardListWidget}
                            that is selected
        @type  currentItem: U{B{QListWidgetItem}
                            <http://doc.trolltech.com/4.2/qlistwidgetitem.html>}
        @param previousItem: Previously selected item in the
                            L{self.clipboardListWidget}
        @type  previousItem: U{B{QListWidgetItem}
                            <http://doc.trolltech.com/4.2/qlistwidgetitem.html>}
        """

        if not (currentItem or previousItem):
            return

        itemId = self.clipboardListWidget.row(currentItem)

        if itemId != -1:

            newChunk = self.pastableItems[itemId]
            self.clipboardListWidget.setCurrentRow(itemId)
            self._updateElementViewer(newChunk)

    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        if isConnect:
            change_connect = self.w.connect
        else:
            change_connect = self.w.disconnect

        change_connect(
            self.clipboardListWidget,
            SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"),
            self.clipboardListItemChanged)

    def currentRow(self):
        """
        Return the current row of the selected item in this groupbox's
        listwidget ( L{self.clipboardListWidget} )
        @return: Current Row of the selected pastable item in the
                 clipboard groupbox.
        @rtype: int
        """
        currentRow = self.clipboardListWidget.currentRow()
        return currentRow
예제 #4
0
class PM_Clipboard(PM_GroupBox):
    """
    The PM_Clipboard class provides a groupbox containing a list of clipboard
    items that can be pasted in the 3D Workspace. The selected item in this
    list is shown by its elementViewer (an instance of L{PM_PreviewGroupBox})
    The object being previewed can then be deposited into the 3D workspace.
    """
    def __init__(self,
                parentWidget,
                title = 'Clipboard',
                win   = None,
                elementViewer = None
                ):

        """
        Appends a PM_Clipboard groupbox widget to I{parentWidget},a L{PM_Dialog}

        @param parentWidget: The parent dialog (Property manager) containing
                             this  widget.
        @type  parentWidget: L{PM_Dialog}

        @param title: The title (button) text.
        @type  title: str

        @param win: MainWindow object
        @type  win: L{MWsemantics} or None

        @param elementViewer: The associated preview pane groupbox. If provided,
                              The selected item in L{self.clipboardListWidget}
                              is shown (previewed) by L{elementViewer}.
                              The object being previewed can then be deposited
                              into the 3D workspace.
        @type  elementViewer: L{PM_PreviewGroupBox} or None

        """

        self.w = win
        self.elementViewer = elementViewer
        self.elementViewer.setDisplay(diTUBES)
        self.pastableItems = None

        PM_GroupBox.__init__(self, parentWidget, title)

        self._loadClipboardGroupbox()


    def _loadClipboardGroupbox(self):
        """
        Load the L{self.clipboardListWidget} widget used to display a list of
        clipboard items inside this  clipboard  groupbox.
        """
        self.clipboardListWidget = QListWidget(self)

        self.gridLayout.addWidget(self.clipboardListWidget)
        #Append to the widget list. This is important for expand -collapse
        #functions (of the groupbox) to work properly.
        self._widgetList.append(self.clipboardListWidget)

    def _updateElementViewer(self, newModel = None):
        """
        Update the view of L{self.elementViewer}
        @param newModel: The model correseponding to the item selected
                         in L{self.clipboardListWidget}.
        @type  newModel: L{molecule} or L{Group}
        """
        if not self.elementViewer:
            return

        assert isinstance(self.elementViewer, MMKitView)
        self.elementViewer.resetView()
        if newModel:
            self.elementViewer.updateModel(newModel)

    def update(self):
        """
        Updates the clipboard items in the L{PM_Clipboard} groupbox. Also
        updates its element viewer.
        """
        PM_GroupBox.update(self)
        self.pastableItems = self.w.assy.shelf.getPastables()
        i = self.clipboardListWidget.currentRow()
        self.clipboardListWidget.clear()
        newModel = None

        if len(self.pastableItems):
            for item in self.pastableItems:
                self.clipboardListWidget.addItem(item.name)

            if i >= self.clipboardListWidget.count():
                i = self.clipboardListWidget.count() - 1

            if i < 0:
                i = 0

            self.clipboardListWidget.setCurrentItem(
                    self.clipboardListWidget.item(i))


            newModel = self.pastableItems[i]

        self._updateElementViewer(newModel)

    def clipboardListItemChanged(self, currentItem = None, previousItem = None):
        """
        Slot method. Called when user clicks on a different pastable item
        displayed in this groupbox
        @param currentItem: Current item in the L{self.clipboardListWidget}
                            that is selected
        @type  currentItem: U{B{QListWidgetItem}
                            <http://doc.trolltech.com/4.2/qlistwidgetitem.html>}
        @param previousItem: Previously selected item in the
                            L{self.clipboardListWidget}
        @type  previousItem: U{B{QListWidgetItem}
                            <http://doc.trolltech.com/4.2/qlistwidgetitem.html>}
        """

        if not (currentItem or previousItem):
            return

        itemId = self.clipboardListWidget.row(currentItem)

        if itemId != -1:

            newChunk = self.pastableItems[itemId]
            self.clipboardListWidget.setCurrentRow(itemId)
            self._updateElementViewer(newChunk)


    def connect_or_disconnect_signals(self, isConnect):
        """
        Connect or disconnect widget signals sent to their slot methods.
        @param isConnect: If True the widget will send the signals to the slot
                          method.
        @type  isConnect: boolean
        """
        if isConnect:
            change_connect = self.w.connect
        else:
            change_connect = self.w.disconnect

        change_connect(
            self.clipboardListWidget,
            SIGNAL("currentItemChanged(QListWidgetItem*,QListWidgetItem*)"),
            self.clipboardListItemChanged )

    def currentRow(self):
        """
        Return the current row of the selected item in this groupbox's
        listwidget ( L{self.clipboardListWidget} )
        @return: Current Row of the selected pastable item in the
                 clipboard groupbox.
        @rtype: int
        """
        currentRow = self.clipboardListWidget.currentRow()
        return currentRow
class LayersFilterDialog(QtGui.QDialog):

    filterTextChanged = QtCore.pyqtSignal()
    filterLayersChanged = QtCore.pyqtSignal()

    def __init__(self, layers, widget, parent):
        super(LayersFilterDialog, self).__init__(parent)
        self.checkBox = []
        self.layers = layers
        self.widget = widget
        self.filterLayers = None
        self.filterText = ""
        self.initGui()
        self.setLayers(layers)

    def initGui(self):
        layout = QtGui.QVBoxLayout()
        self.label = QtGui.QLabel("<b>Filter by layer</b>")
        layout.addWidget(self.label)
        self.layersList = QListWidget()
        layout.addWidget(self.layersList)
        self.label = QtGui.QLabel("<b>Filter by text</b>")
        layout.addWidget(self.label)
        self.text = QtGui.QLineEdit()
        layout.addWidget(self.text)
        self.button = QtGui.QPushButton("Apply")
        self.button.clicked.connect(self.apply)
        layout.addWidget(self.button)
        self.setLayout(layout)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Popup)
        self.resize(200, 150)

    def show(self):
        self.computeLocation()
        QtGui.QDialog.show(self)

    def computeLocation(self):
        point = self.widget.rect().bottomRight()
        global_point = self.widget.mapToGlobal(point)
        self.move(global_point)


    def setLayers(self, layers):
        for layer in layers:
            item = QtGui.QListWidgetItem(layer)
            item.setCheckState(QtCore.Qt.Checked)
            self.layersList.addItem(item)
        self.filterLayers = None

    def setFilterLayers(self, layers):
        for i in xrange(self.layersList.count()):
            item = self.layersList.item(i)
            item.setCheckState(QtCore.Qt.Checked if layers is None or item.text() in layers
                                else QtCore.Qt.Unchecked)

    def setFilterText(self, text):
        self.text.setText(text)

    def apply(self):
        filterLayers = []
        for i in xrange(self.layersList.count()):
            item = self.layersList.item(i)
            if item.checkState() == QtCore.Qt.Checked:
                filterLayers.append(item.text())
        if len(filterLayers) == self.layersList.count():
            filterLayers = None
        if filterLayers != self.filterLayers:
            self.filterLayers = filterLayers
            self.filterLayersChanged.emit()
        filterText = self.text.text()
        if filterText != self.filterText:
            self.filterText = filterText
            self.filterTextChanged.emit()
        self.hide()
예제 #6
0
class LayersFilterDialog(QtGui.QDialog):

    filterTextChanged = QtCore.pyqtSignal()
    filterLayersChanged = QtCore.pyqtSignal()

    def __init__(self, layers, widget, parent):
        super(LayersFilterDialog, self).__init__(parent)
        self.checkBox = []
        self.layers = layers
        self.widget = widget
        self.filterLayers = None
        self.filterText = ""
        self.initGui()
        self.setLayers(layers)

    def initGui(self):
        layout = QtGui.QVBoxLayout()
        self.label = QtGui.QLabel("<b>Filter by layer</b>")
        layout.addWidget(self.label)
        self.layersList = QListWidget()
        layout.addWidget(self.layersList)
        self.label = QtGui.QLabel("<b>Filter by text</b>")
        layout.addWidget(self.label)
        self.text = QtGui.QLineEdit()
        layout.addWidget(self.text)
        self.button = QtGui.QPushButton("Apply")
        self.button.clicked.connect(self.apply)
        layout.addWidget(self.button)
        self.setLayout(layout)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Popup)
        self.resize(200, 150)

    def show(self):
        self.computeLocation()
        QtGui.QDialog.show(self)

    def computeLocation(self):
        point = self.widget.rect().bottomRight()
        global_point = self.widget.mapToGlobal(point)
        self.move(global_point)

    def setLayers(self, layers):
        for layer in layers:
            item = QtGui.QListWidgetItem(layer)
            item.setCheckState(QtCore.Qt.Checked)
            self.layersList.addItem(item)
        self.filterLayers = None

    def setFilterLayers(self, layers):
        for i in xrange(self.layersList.count()):
            item = self.layersList.item(i)
            item.setCheckState(QtCore.Qt.Checked if layers is None or item.
                               text() in layers else QtCore.Qt.Unchecked)

    def setFilterText(self, text):
        self.text.setText(text)

    def apply(self):
        filterLayers = []
        for i in xrange(self.layersList.count()):
            item = self.layersList.item(i)
            if item.checkState() == QtCore.Qt.Checked:
                filterLayers.append(item.text())
        if len(filterLayers) == self.layersList.count():
            filterLayers = None
        if filterLayers != self.filterLayers:
            self.filterLayers = filterLayers
            self.filterLayersChanged.emit()
        filterText = self.text.text()
        if filterText != self.filterText:
            self.filterText = filterText
            self.filterTextChanged.emit()
        self.hide()