示例#1
0
    def _prepare_toplevel_for_item(self, layout):
        """ Returns a sized toplevel QDockWidget for a LayoutItem.
        """
        if isinstance(layout, PaneItem):
            dock_widget = self._get_dock_widget(layout)
            if dock_widget is None:
                logger.warning(
                    "Cannot retrieve dock widget for pane %r" % layout.id
                )
            else:
                if is_qt4:
                    if layout.width > 0:
                        dock_widget.widget().setFixedWidth(layout.width)
                    if layout.height > 0:
                        dock_widget.widget().setFixedHeight(layout.height)
                else:
                    sizeHint = lambda : QtCore.QSize(layout.width, layout.height)
                    dock_widget.widget().sizeHint = sizeHint
            return dock_widget

        elif isinstance(layout, LayoutContainer):
            return self._prepare_toplevel_for_item(layout.items[0])

        else:
            raise MainWindowLayoutError("Leaves of layout must be PaneItems")
示例#2
0
 def sizeHint(self, option, index):
     """ Reimplemented to provide size hint based on a checkbox
     """
     box = QtGui.QStyleOptionButton()
     style = QtGui.QApplication.instance().style()
     return style.sizeFromContents(QtGui.QStyle.CT_CheckBox, box,
                                   QtCore.QSize(), None)
示例#3
0
    def sizeHint(self):
        """ Reimplemented to return the initial size or the view's current
        size.
        """
        central_widget = self.centralWidget()
        if central_widget is not None:
            sh = central_widget.sizeHint()

            if self._width > 0:
                if self._width > 1:
                    w = self._width
                else:
                    w = self._main_window.width() * self._width

                sh.setWidth(int(w))

            if self._height > 0:
                if self._height > 1:
                    h = self._height
                else:
                    h = self._main_window.height() * self._height

                sh.setHeight(int(h))
        else:
            sh = QtCore.QSize()

        return sh
    def create_tool_bar(self, parent, controller=None):
        """ Creates a tool bar. """

        # If a controller is required it can either be set as a trait on the
        # tool bar manager (the trait is part of the 'ActionManager' API), or
        # passed in here (if one is passed in here it takes precedence over the
        # trait).
        if controller is None:
            controller = self.controller

        # Create the control.
        tool_bar = _ToolBar(self, parent)
        self._toolbars.append(tool_bar)
        tool_bar.setObjectName(self.id)
        tool_bar.setWindowTitle(self.name)

        if self.show_tool_names:
            tool_bar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)

        if self.orientation == "horizontal":
            tool_bar.setOrientation(QtCore.Qt.Horizontal)
        else:
            tool_bar.setOrientation(QtCore.Qt.Vertical)

        # We would normally leave it to the current style to determine the icon
        # size.
        w, h = self.image_size
        tool_bar.setIconSize(QtCore.QSize(w, h))

        # Add all of items in the manager's groups to the tool bar.
        self._qt4_add_tools(parent, tool_bar, controller)

        return tool_bar
示例#5
0
 def sizeHint(self, option, mi):
     """Reimplemented to define a size hint based on the size of the pixmap."""
     name = mi.data(QtCore.Qt.ItemDataRole.DisplayRole)
     pixmap = self._get_pixmap(name)
     if pixmap is None:
         return QtCore.QSize()
     return pixmap.size()
示例#6
0
    def _create_control(self, parent):
        control = _Wizard(parent, self)
        control.setOptions(QtGui.QWizard.NoDefaultButton
                           | QtGui.QWizard.NoBackButtonOnStartPage)
        control.setModal(self.style == "modal")
        control.setWindowTitle(self.title)

        # Necessary for 'nonmodal'. See Dialog for more info.
        if self.style == "nonmodal":
            control.finished.connect(self._finished_fired)

        if self.size != (-1, -1):
            size = QtCore.QSize(*self.size)
            control.setMinimumSize(size)
            control.resize(size)

        if not self.show_cancel:
            control.setOption(QtGui.QWizard.NoCancelButton)

        if self.help_id:
            control.setOption(QtGui.QWizard.HaveHelpButton)
            control.helpRequested.connect(self._help_requested)

        # Add the initial pages.
        for page in self.pages:
            page.pyface_wizard = self
            control.addWizardPage(page)

        # Set the start page.
        control.setStartWizardPage()

        return control
示例#7
0
    def paint(self, painter, option, index):
        """Reimplemented to paint the checkbox."""
        # Determine whether the checkbox is check or unchecked
        column = index.model()._editor.columns[index.column()]
        obj = index.data(QtCore.Qt.ItemDataRole.UserRole)
        checked = column.get_raw_value(obj)

        # First draw the background
        painter.save()
        row_brushes = [option.palette.base(), option.palette.alternateBase()]
        if option.state & QtGui.QStyle.StateFlag.State_Selected:
            if option.state & QtGui.QStyle.StateFlag.State_Active:
                color_group = QtGui.QPalette.ColorGroup.Active
            else:
                color_group = QtGui.QPalette.ColorGroup.Inactive
            bg_brush = option.palette.brush(color_group,
                                            QtGui.QPalette.ColorRole.Highlight)
        else:
            bg_brush = index.data(QtCore.Qt.ItemDataRole.BackgroundRole)
            if bg_brush == NotImplemented or bg_brush is None:
                if index.model()._editor.factory.alternate_bg_color:
                    bg_brush = row_brushes[index.row() % 2]
                else:
                    bg_brush = row_brushes[0]
        painter.fillRect(option.rect, bg_brush)

        # Then draw the checkbox
        style = QtGui.QApplication.instance().style()
        box = QtGui.QStyleOptionButton()
        box.palette = option.palette

        # Align the checkbox appropriately.
        box.rect = option.rect
        size = style.sizeFromContents(QtGui.QStyle.ContentsType.CT_CheckBox,
                                      box, QtCore.QSize(), None)
        box.rect.setWidth(size.width())
        margin = style.pixelMetric(QtGui.QStyle.PixelMetric.PM_ButtonMargin,
                                   box)
        alignment = column.horizontal_alignment
        if alignment == "left":
            box.rect.setLeft(option.rect.left() + margin)
        elif alignment == "right":
            box.rect.setLeft(option.rect.right() - size.width() - margin)
        else:
            # FIXME: I don't know why I need the 2 pixels, but I do.
            box.rect.setLeft(option.rect.left() + option.rect.width() // 2 -
                             size.width() // 2 + margin - 2)

        # We mark the checkbox always active even when not selected, so
        # it's clear if it's ticked or not on OSX. See bug #439
        if option.state & QtGui.QStyle.StateFlag.State_Enabled:
            box.state = QtGui.QStyle.StateFlag.State_Enabled | QtGui.QStyle.StateFlag.State_Active

        if checked:
            box.state |= QtGui.QStyle.StateFlag.State_On
        else:
            box.state |= QtGui.QStyle.StateFlag.State_Off
        style.drawControl(QtGui.QStyle.ControlElement.CE_CheckBox, box,
                          painter)
        painter.restore()
 def show_button(self, index):
     lbl = QtGui.QLabel(self)
     movie = QtGui.QMovie(_TabWidget._spinner_data.absolute_path,
                          parent=lbl)
     movie.setCacheMode(QtGui.QMovie.CacheAll)
     movie.setScaledSize(QtCore.QSize(16, 16))
     lbl.setMovie(movie)
     movie.start()
     self.tabBar().setTabButton(index, QtGui.QTabBar.LeftSide, lbl)
示例#9
0
        def __init__(self,
                     is_image=False,
                     bgcolor="white",
                     image_default_origin="top left",
                     *args,
                     **kw):

            size = kw.pop("size", None)
            if isinstance(size, tuple):
                size = QtCore.QSize(*size)

            super(PlotWindow, self).__init__(None, *args, **kw)

            if size is not None:
                self.resize(size)

            # Some defaults which should be overridden by preferences.
            self.bgcolor = bgcolor
            self.image_default_origin = image_default_origin

            # Create an empty top-level container
            if is_image:
                top_container = self._create_top_img_container()
            else:
                top_container = self._create_top_container()

            # The PlotSession of which we are a part.  We need to know this in order
            # to notify it of our being closed, etc.
            self.session = None

            # Create the Enable Window object, and store a reference to it.
            # (This will be handy later.)  The Window requires a parent object
            # as its first argument, so we just pass 'self'.
            self.plot_window = Window(self, component=top_container)

            layout = QtGui.QVBoxLayout()
            layout.setContentsMargins(0, 0, 0, 0)
            layout.addWidget(self.plot_window.control)
            self.setLayout(layout)

            size = kw.get("size", QtCore.QSize(600, 600))
            self.set_size(size.width(), size.height())

            self.show()
示例#10
0
    def _create_dialog_area(self, parent):
        panel = QtGui.QWidget(parent)
        panel.setMinimumSize(QtCore.QSize(100, 200))

        palette = panel.palette()
        palette.setColor(QtGui.QPalette.ColorRole.Window, QtGui.QColor("red"))
        panel.setPalette(palette)
        panel.setAutoFillBackground(True)

        return panel
示例#11
0
 def sizeHint(self):
     # Suggest a size that is 80 characters wide and 40 lines tall.
     style = self.style()
     opt = QtGui.QStyleOptionHeader()
     font_metrics = QtGui.QFontMetrics(self.document().defaultFont())
     width = font_metrics.width(' ') * 80
     width += self.line_number_widget.sizeHint().width()
     width += self.status_widget.sizeHint().width()
     width += style.pixelMetric(QtGui.QStyle.PM_ScrollBarExtent, opt, self)
     height = font_metrics.height() * 40
     return QtCore.QSize(width, height)
示例#12
0
    def sizeHint(self):
        """ Reimplemented to set a size hint based on the size of the larget
            image.
        """
        size = QtCore.QSize()
        for name in self._editor.names:
            size = size.expandedTo(self._editor.get_pixmap(name).size())

        option = QtGui.QStyleOptionComboBox()
        self.initStyleOption(option)
        size = self.style().sizeFromContents(QtGui.QStyle.CT_ComboBox, option,
                                             size, self)
        return size
示例#13
0
    def paint(self, painter, option, index):
        """ Reimplemented to paint the checkbox.
        """
        # Determine whether the checkbox is check or unchecked
        column = index.model()._editor.columns[index.column()]
        obj = index.data(QtCore.Qt.UserRole)
        checked = column.get_raw_value(obj)

        # First draw the background
        painter.save()
        row_brushes = [option.palette.base(), option.palette.alternateBase()]
        if option.state & QtGui.QStyle.State_Selected:
            bg_brush = option.palette.highlight()
        else:
            bg_brush = index.data(QtCore.Qt.BackgroundRole)
            if bg_brush == NotImplemented or bg_brush is None:
                if index.model()._editor.factory.alternate_bg_color:
                    bg_brush = row_brushes[index.row() % 2]
                else:
                    bg_brush = row_brushes[0]
        painter.fillRect(option.rect, bg_brush)

        # Then draw the checkbox
        style = QtGui.QApplication.instance().style()
        box = QtGui.QStyleOptionButton()
        box.palette = option.palette

        # Align the checkbox appropriately.
        box.rect = option.rect
        size = style.sizeFromContents(QtGui.QStyle.CT_CheckBox, box,
                                      QtCore.QSize())
        box.rect.setWidth(size.width())
        margin = style.pixelMetric(QtGui.QStyle.PM_ButtonMargin, box)
        alignment = column.horizontal_alignment
        if alignment == 'left':
            box.rect.setLeft(option.rect.left() + margin)
        elif alignment == 'right':
            box.rect.setLeft(option.rect.right() - size.width() - margin)
        else:
            # FIXME: I don't know why I need the 2 pixels, but I do.
            box.rect.setLeft(option.rect.left() + option.rect.width() // 2 -
                             size.width() // 2 + margin - 2)

        box.state = QtGui.QStyle.State_Enabled
        if checked:
            box.state |= QtGui.QStyle.State_On
        else:
            box.state |= QtGui.QStyle.State_Off
        style.drawControl(QtGui.QStyle.CE_CheckBox, box, painter)
        painter.restore()
示例#14
0
 def sizeHint(self):
     # Suggest a size that is 80 characters wide and 40 lines tall.
     style = self.style()
     opt = QtGui.QStyleOptionHeader()
     font_metrics = QtGui.QFontMetrics(self.document().defaultFont())
     # QFontMetrics.width() is deprecated and Qt docs suggest using
     # horizontalAdvance() instead, but is only available since Qt 5.11
     if QtCore.__version_info__ >= (5, 11):
         width = font_metrics.horizontalAdvance(" ") * 80
     else:
         width = font_metrics.width(" ") * 80
     width += self.line_number_widget.sizeHint().width()
     width += self.status_widget.sizeHint().width()
     width += style.pixelMetric(QtGui.QStyle.PM_ScrollBarExtent, opt, self)
     height = font_metrics.height() * 40
     return QtCore.QSize(width, height)
示例#15
0
    def init(self, parent):
        """ Finishes initializing the editor by creating the underlying toolkit
            widget.
        """
        self.icon = QtGui.QIcon(self.factory.filename)
        if self.factory.toggle_filename:
            self.toggled_icon = QtGui.QIcon(self.factory.toggle_filename)

        if self.factory.toggle_label != "":
            self.toggle_label = self.factory.toggle_label
        else:
            self.toggle_label = self.factory.label

        if self.factory.toggle_tooltip != "":
            self.toggle_tooltip = self.factory.toggle_tooltip
        else:
            self.toggle_tooltip = self.factory.tooltip

        control = self.control = QtGui.QToolButton()
        control.setAutoRaise(True)
        control.setIcon(self.icon)
        control.setText(self.factory.label)
        control.setIconSize(
            QtCore.QSize(self.factory.width, self.factory.height))

        if self.factory.label:
            if self.factory.orientation == "horizontal":
                control.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon)
            else:
                control.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
        else:
            control.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly)
        if self.factory.toggle:
            control.setCheckable(True)
            control.toggled.connect(self._toggle_button)

        control.clicked.connect(self.update_object)

        if self.factory.tooltip:
            control.setToolTip(self.factory.tooltip)
        else:
            self.set_tooltip()
示例#16
0
 def sizeHint(self):
     return QtCore.QSize(self.digits_width(), 0)
示例#17
0
    def position(self, ui):
        """ Positions the associated dialog window on the display.
        """
        view = ui.view
        window = ui.control

        # Set up the default position of the window:
        parent = window.parent()
        if parent is None:
            px = 0
            py = 0
            pdx = screen_dx
            pdy = screen_dy
        else:
            pos = parent.pos()
            if int(parent.windowFlags()) & QtCore.Qt.Window == 0:
                pos = parent.mapToGlobal(pos)
            px = pos.x()
            py = pos.y()
            pdx = parent.width()
            pdy = parent.height()

        # Get the window's prefered size.
        size_hint = window.sizeHint()

        # Calculate the correct width and height for the window:
        cur_width = size_hint.width()
        cur_height = size_hint.height()
        width = view.width
        height = view.height

        if width < 0.0:
            width = cur_width
        elif width <= 1.0:
            width = int(width * screen_dx)
        else:
            width = int(width)

        if height < 0.0:
            height = cur_height
        elif height <= 1.0:
            height = int(height * screen_dy)
        else:
            height = int(height)

        # Calculate the correct position for the window:
        x = view.x
        y = view.y

        if x < -99999.0:
            x = px + ((pdx - width) / 2)
        elif x <= -1.0:
            x = px + pdx - width + int(x) + 1
        elif x < 0.0:
            x = px + pdx - width + int(x * pdx)
        elif x <= 1.0:
            x = px + int(x * pdx)
        else:
            x = int(x)

        if y < -99999.0:
            y = py + ((pdy - height) / 2)
        elif y <= -1.0:
            y = py + pdy - height + int(y) + 1
        elif x < 0.0:
            y = py + pdy - height + int(y * pdy)
        elif y <= 1.0:
            y = py + int(y * pdy)
        else:
            y = int(y)

        # Position and size the window as requested:
        layout = window.layout()
        if layout.sizeConstraint() == QtGui.QLayout.SetFixedSize:
            layout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
            window.move(max(0, x), max(0, y))
            window.setFixedSize(QtCore.QSize(width, height))
        else:
            window.setGeometry(max(0, x), max(0, y), width, height)
示例#18
0
 def __init__(self, tree, show_icons, *args, **kwargs):
     self._tree = tree
     self._show_icons = show_icons
     # self._size_map = {}
     self._size_map = collections.defaultdict(lambda: QtCore.QSize(1, 21))
     super(PipelineDelegate, self).__init__(*args, **kwargs)
示例#19
0
 def sizeHint(self, option, index):
     """ returns area taken by the text. """
     # return self._size_map[self._tree.itemFromIndex(index)]
     return QtCore.QSize(1, 20)
示例#20
0
 def sizeHint(self):
     return QtCore.QSize(self.min_width, 0)
示例#21
0
 def sizeHint(self):
     return QtCore.QSize(10, 0)
示例#22
0
    def __init__(self):
        super(Select, self).__init__()
        vlayout = QtGui.QVBoxLayout(self)
        vlayout.setContentsMargins(5, 10, 10, 5)
        vlayout.setSpacing(20)

        self.label = QLabel(self)
        self.label.setFixedSize(64, 64)
        picture = QtGui.QPixmap("../resource/3d.png").scaled(self.label.width(),
                                                             self.label.height())
        self.label.setPixmap(picture)

        self.texbox = QLineEdit(self)
        self.texbox.resize(250, 40)
        self.texbox.setPlaceholderText('文件路径(.nii;图片序列)')

        self.nii_button = QPushButton(self)
        self.nii_button.setText("选择nii文件")
        self.nii_button.setStyleSheet("QPushButton{color:black}"
                                      "QPushButton:hover{color:red}"
                                      "QPushButton{background-color:gray}"
                                      "QPushButton{border:2px}"
                                      "QPushButton{border-radius:10px}"
                                      "QPushButton{padding:2px 4px}"
                                      "QPushButton{font-size:20px}")
        self.nii_button.setIcon(QIcon("../resource/open_nii.png"))
        self.nii_button.setIconSize(QtCore.QSize(20, 20))
        self.nii_button.clicked.connect(self.open_nii)

        self.pic_button = QPushButton(self)
        self.pic_button.setText("图片序列目录")
        self.pic_button.setStyleSheet("QPushButton{color:black}"
                                      "QPushButton:hover{color:red}"
                                      "QPushButton{background-color:gray}"
                                      "QPushButton{border:2px}"
                                      "QPushButton{border-radius:10px}"
                                      "QPushButton{padding:2px 4px}"
                                      "QPushButton{font-size:20px}")
        self.pic_button.setIcon(QIcon("../resource/pic_file.png"))
        self.pic_button.setIconSize(QtCore.QSize(20, 20))
        self.pic_button.clicked.connect(self.open_pic_file)

        self.start_button = QPushButton(self)
        self.start_button.setMaximumSize(70, 70)
        self.start_button.setMinimumSize(64, 64)
        self.start_button.setStyleSheet(
            "QPushButton{background-image:url('../resource/start.png')}"
            "QPushButton{border:none;border-width:0;border-style:outset}")
        self.start_button.setFocusPolicy(QtCore.Qt.NoFocus)
        self.start_button.clicked.connect(self.start)

        self.stop_button = QPushButton(self)
        self.stop_button.setMaximumSize(70, 70)
        self.stop_button.setMinimumSize(64, 64)
        self.stop_button.setStyleSheet(
            "QPushButton{background-image:url('../resource/stop.png')}"
            "QPushButton{border:none;border-width:0;border-style:outset}")
        self.stop_button.setFocusPolicy(QtCore.Qt.NoFocus)
        self.stop_button.clicked.connect(self.stop)
        sslayout = QHBoxLayout(self)
        sslayout.setSpacing(20)
        sslayout.addWidget(self.start_button, stretch=1)
        sslayout.addWidget(self.stop_button, stretch=1)
        ssweight = QWidget()
        ssweight.setLayout(sslayout)
        vlayout.addStretch(1)
        vlayout.addWidget(self.label, 0, QtCore.Qt.AlignHCenter)
        vlayout.addWidget(self.texbox)
        vlayout.addWidget(self.nii_button)
        vlayout.addWidget(self.pic_button)
        vlayout.addWidget(ssweight, 0, QtCore.Qt.AlignHCenter)
        vlayout.addStretch(1)