Beispiel #1
0
    def paintEvent(self, event):
        """ Paint the line numbers.
        """
        painter = QtGui.QPainter(self)
        painter.fillRect(event.rect(), self.background_color)

        cw = self.parent()

        pixels_per_block = self.height() / float(cw.blockCount())

        for line in self.info_lines:
            painter.fillRect(
                QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                QtCore.Qt.green,
            )

        for line in self.warn_lines:
            painter.fillRect(
                QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                QtCore.Qt.yellow,
            )

        for line in self.error_lines:
            painter.fillRect(
                QtCore.QRect(0, line * pixels_per_block, self.width(), 3),
                QtCore.Qt.red,
            )
Beispiel #2
0
    def resizeEvent(self, event):
        QtGui.QPlainTextEdit.resizeEvent(self, event)
        contents = self.contentsRect()
        self.line_number_widget.setGeometry(
            QtCore.QRect(
                contents.left(),
                contents.top(),
                self.line_number_widget.digits_width(),
                contents.height(),
            )
        )

        # use the viewport width to determine the right edge. This allows for
        # the propper placement w/ and w/o the scrollbar
        right_pos = (
            self.viewport().width()
            + self.line_number_widget.width()
            + 1
            - self.status_widget.sizeHint().width()
        )
        self.status_widget.setGeometry(
            QtCore.QRect(
                right_pos,
                contents.top(),
                self.status_widget.sizeHint().width(),
                contents.height(),
            )
        )
    def get_context_menu(self, pos):
        """ Returns a context menu containing split/collapse actions

        pos : position (in global coordinates) where the context menu was
        requested
        """
        menu = Menu()
        splitter = None

        splitter = None
        for tabwidget in self.tabwidgets():
            # obtain tabwidget's bounding rectangle in global coordinates
            global_rect = QtCore.QRect(tabwidget.mapToGlobal(QtCore.QPoint(0, 0)),
                                        tabwidget.size())
            if global_rect.contains(pos):
                splitter = tabwidget.parent()

        # no split/collapse context menu for positions outside any tabwidget
        # region
        if not splitter:
            return

        # add split actions (only show for non-empty tabwidgets)
        if not splitter.is_empty():
            actions = [Action(id='split_hor', name='Create new pane to the right',
                       on_perform=lambda : splitter.split(orientation=
                        QtCore.Qt.Horizontal)),
                       Action(id='split_ver', name='Create new pane to the bottom',
                       on_perform=lambda : splitter.split(orientation=
                        QtCore.Qt.Vertical))]

            splitgroup = Group(*actions, id='split')
            menu.append(splitgroup)

        # add collapse action (only show for collapsible splitters)
        if splitter.is_collapsible():
            if splitter is splitter.parent().leftchild:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with right pane'
                else:
                    text = 'Merge with bottom pane'
            else:
                if splitter.parent().orientation() is QtCore.Qt.Horizontal:
                    text = 'Merge with left pane'
                else:
                    text = 'Merge with top pane'
            actions = [Action(id='merge', name=text,
                        on_perform=lambda : splitter.collapse())]

            collapsegroup = Group(*actions, id='collapse')
            menu.append(collapsegroup)

        # return QMenu object
        return menu
Beispiel #4
0
    def _window_paint(self, event):
        if self.control is None:
            return

        # self._gc is an image context
        w = self._gc.width()
        h = self._gc.height()
        data = self._gc.pixel_map.convert_to_argb32string()
        image = QtGui.QImage(data, w, h, QtGui.QImage.Format_ARGB32)
        rect = QtCore.QRect(0, 0, w, h)
        painter = QtGui.QPainter(self.control)
        painter.drawImage(rect, image)
Beispiel #5
0
    def _window_paint(self, event):
        if self.control is None:
            return

        # Convert to Qt's pixel format
        self._shuffle_copy()

        # self._gc is an image context
        w = self._gc.width()
        h = self._gc.height()
        image = QtGui.QImage(self._shuffle_buffer, w, h,
                             QtGui.QImage.Format_RGB32)
        rect = QtCore.QRect(0, 0, w, h)
        painter = QtGui.QPainter(self.control)
        painter.drawImage(rect, image)
    def _create_canvas(self, parent):
        print(self.__class__.__name__, ": Creating canvas (_create_canvas)")
        frame_canvas = QtGui.QWidget()

        scrollarea = QtGui.QScrollArea()
        mpl_canvas = FigureCanvas(self.value)
        mpl_canvas.setParent(scrollarea)
        scrollarea.setWidget(mpl_canvas)

        mpl_toolbar = NavigationToolbar2QT(mpl_canvas, frame_canvas)
        # mpl_toolbar.setIconSize(QtCore.QSize(30, 30))  # activate for smaller icon sizes

        vbox = QtGui.QVBoxLayout()
        vbox.addWidget(scrollarea)
        vbox.addWidget(mpl_toolbar)
        vbox.setGeometry(QtCore.QRect(0, 0, 1000, 1000))
        frame_canvas.setLayout(vbox)
        return frame_canvas
Beispiel #7
0
    def paint(self, painter, option, index):
        """Overriden to draw images."""
        # First draw any text/background by delegating to our superclass
        QtGui.QStyledItemDelegate.paint(self, painter, option, index)

        # Now draw the image, if possible
        value = index.data(QtCore.Qt.ItemDataRole.UserRole)
        image = self.get_image_for_obj(value, index.row(), index.column())
        if image:
            image = image.create_bitmap()
            if self.scale_to_cell:
                w = min(image.width(), option.rect.width())
                h = min(image.height(), option.rect.height())
            else:
                w = image.width()
                h = image.height()

            x = option.rect.x()
            y = option.rect.y() + (option.rect.height() - h) / 2

            target = QtCore.QRect(x, y, w, h)
            painter.drawPixmap(target, image)
    def _hotspot(self, pos):
        """ Return a tuple of the tab widget, hotspot and hostspot geometry (as
        a tuple) at the given position.
        """
        global_pos = self.mapToGlobal(pos)
        miss = (None, self._HS_NONE, None)

        # Get the bounding rect of the cloned QTbarBar.
        top_widget = QtGui.QApplication.instance().topLevelAt(global_pos)
        if isinstance(top_widget, QtGui.QTabBar):
            cloned_rect = top_widget.frameGeometry()
        else:
            cloned_rect = None

        # Determine which visible SplitTabWidget, if any, is under the cursor
        # (compensating for the cloned QTabBar that may be rendered over it).
        split_widget = None
        for top_widget in QtGui.QApplication.instance().topLevelWidgets():
            for split_widget in top_widget.findChildren(SplitTabWidget, None):
                visible_region = split_widget.visibleRegion()
                widget_pos = split_widget.mapFromGlobal(global_pos)
                if cloned_rect and split_widget.geometry().contains(
                        widget_pos):
                    visible_rect = visible_region.boundingRect()
                    widget_rect = QtCore.QRect(
                        split_widget.mapFromGlobal(cloned_rect.topLeft()),
                        split_widget.mapFromGlobal(cloned_rect.bottomRight()))
                    if not visible_rect.intersected(widget_rect).isEmpty():
                        break
                elif visible_region.contains(widget_pos):
                    break
            else:
                split_widget = None
            if split_widget:
                break

        # Handle a drag outside of any split tab widget.
        if not split_widget:
            if self.window().frameGeometry().contains(global_pos):
                return miss
            else:
                return (None, self._HS_OUTSIDE, None)

        # Go through each tab widget.
        pos = split_widget.mapFromGlobal(global_pos)
        for tw in split_widget.findChildren(_TabWidget, None):
            if tw.geometry().contains(tw.parent().mapFrom(split_widget, pos)):
                break
        else:
            return miss

        # See if the hotspot is in the widget area.
        widg = tw.currentWidget()
        if widg is not None:

            # Get the widget's position relative to its parent.
            wpos = widg.parent().mapFrom(split_widget, pos)

            if widg.geometry().contains(wpos):
                # Get the position of the widget relative to itself (ie. the
                # top left corner is (0, 0)).
                p = widg.mapFromParent(wpos)
                x = p.x()
                y = p.y()
                h = widg.height()
                w = widg.width()

                # Get the global position of the widget.
                gpos = widg.mapToGlobal(widg.pos())
                gx = gpos.x()
                gy = gpos.y()

                # The corners of the widget belong to the north and south
                # sides.
                if y < h / 4:
                    return (tw, self._HS_NORTH, (gx, gy, w, h / 4))

                if y >= (3 * h) / 4:
                    return (tw, self._HS_SOUTH, (gx, gy + (3 * h) / 4, w,
                                                 h / 4))

                if x < w / 4:
                    return (tw, self._HS_WEST, (gx, gy, w / 4, h))

                if x >= (3 * w) / 4:
                    return (tw, self._HS_EAST, (gx + (3 * w) / 4, gy, w / 4,
                                                h))

                return miss

        # See if the hotspot is in the tab area.
        tpos = tw.mapFrom(split_widget, pos)
        tab_bar = tw.tabBar()
        top_bottom = tw.tabPosition() in (QtGui.QTabWidget.North,
                                          QtGui.QTabWidget.South)
        for i in range(tw.count()):
            rect = tab_bar.tabRect(i)

            if rect.contains(tpos):
                w = rect.width()
                h = rect.height()

                # Get the global position.
                gpos = tab_bar.mapToGlobal(rect.topLeft())
                gx = gpos.x()
                gy = gpos.y()

                if top_bottom:
                    off = pos.x() - rect.x()
                    ext = w
                    gx -= w / 2
                else:
                    off = pos.y() - rect.y()
                    ext = h
                    gy -= h / 2

                # See if it is in the left (or top) half or the right (or
                # bottom) half.
                if off < ext / 2:
                    return (tw, i, (gx, gy, w, h))

                if top_bottom:
                    gx += w
                else:
                    gy += h

                if i + 1 == tw.count():
                    return (tw, self._HS_AFTER_LAST_TAB, (gx, gy, w, h))

                return (tw, i + 1, (gx, gy, w, h))
        else:
            rect = tab_bar.rect()
            if rect.contains(tpos):
                gpos = tab_bar.mapToGlobal(rect.topLeft())
                gx = gpos.x()
                gy = gpos.y()
                w = rect.width()
                h = rect.height()
                if top_bottom:
                    tab_widths = sum(
                        tab_bar.tabRect(i).width()
                        for i in range(tab_bar.count()))
                    w -= tab_widths
                    gx += tab_widths
                else:
                    tab_heights = sum(
                        tab_bar.tabRect(i).height()
                        for i in range(tab_bar.count()))
                    h -= tab_heights
                    gy -= tab_heights
                return (tw, self._HS_AFTER_LAST_TAB, (gx, gy, w, h))

        return miss