Ejemplo n.º 1
0
    def _create_item(self, nid, node, obj, index=None):
        """Create  a new TreeWidgetItem as per word_wrap policy.

        Index is the index of the new node in the parent:
        None implies append the child to the end.

        """
        if index is None:
            cnid = QtWidgets.QTreeWidgetItem(nid)
        else:
            cnid = QtWidgets.QTreeWidgetItem()
            nid.insertChild(index, cnid)

        cnid.setText(0, node.get_label(obj))
        cnid.setIcon(0, self._get_icon(node, obj))
        cnid.setToolTip(0, node.get_tooltip(obj))

        color = node.get_background(obj)
        if color:
            cnid.setBackground(0, self._get_brush(color))
        color = node.get_foreground(obj)
        if color:
            cnid.setForeground(0, self._get_brush(color))

        return cnid
Ejemplo n.º 2
0
    def create_widget(self, parent):
        """Create the QListView widget."""
        # Create the list widget.
        widget = QtWidgets.QListWidget(parent)

        # Populate the widget.
        self._set_widget_items(widget)

        # Set the selection mode.
        if self.multiselect:
            mode = QtWidgets.QAbstractItemView.ExtendedSelection
            selected = self.selected_items
        else:
            mode = QtWidgets.QAbstractItemView.SingleSelection
            selected = [self.selected_item]
        widget.setSelectionMode(mode)

        self.proxy.widget = widget  # Anticipated so that selection works

        # Make sure the widget selection reflects the members.
        if self.items:
            self._select_on_widget(selected, widget)

        widget.itemSelectionChanged.connect(self.on_selection)
        return widget
Ejemplo n.º 3
0
    def _insert_node(self, nid, index, node, obj):
        """Inserts a new node before a specified index into the children of
        the specified node.

        """

        cnid = self._create_item(nid, node, obj, index)

        has_children = self._has_children(node, obj)
        self._set_node_data(cnid, (False, node, obj))
        self._map.setdefault(id(obj), []).append((node.get_children_id(obj), cnid))
        self._add_listeners(node, obj)

        # Automatically expand the new node (if requested):
        if node.allows_children(obj):
            if has_children and node.can_auto_open(obj):
                cnid.setExpanded(True)
            else:
                # Qt only draws the control that expands the tree if there is a
                # child.  As the tree is being populated lazily we create a
                # dummy that will be removed when the node is expanded for the
                # first time.
                cnid._dummy = QtWidgets.QTreeWidgetItem(cnid)

        # Return the newly created node:
        return cnid
Ejemplo n.º 4
0
    def create_widget(self, parent):
        """Finishes initializing the editor by creating the underlying toolkit
        widget.

        """
        widget = QtWidgets.QTextEdit(parent)
        widget.setReadOnly(True)
        widget.setHtml(self.text)
        return widget
Ejemplo n.º 5
0
    def create_widget(self, parent):
        """Finishes initializing by creating the underlying toolkit widget.

        """
        widget = QtWidgets.QLineEdit(parent)
        self._completer = QDelimitedCompleter(widget, self.delimiters,
                                              self.entries,
                                              self.entries_updater)
        widget.setText(self.text)
        self.proxy.widget = widget  # Anticipated so that selection works
        widget.textEdited.connect(self.update_object)
        return widget
Ejemplo n.º 6
0
 def __init__(self, proxy, parent=None):
     super().__init__(parent)
     self.proxy = proxy
     self.title_item = QtWidgets.QGraphicsTextItem(self)