Пример #1
0
    def __init__(self, orientation, parent):
        super(XSplitterHandle, self).__init__(orientation, parent)

        # create a layout for the different buttons
        self._collapsed = False
        self._storedSizes = None

        self._collapseBefore = QToolButton(self)
        self._resizeGrip = QLabel(self)
        self._collapseAfter = QToolButton(self)

        self._collapseBefore.setAutoRaise(True)
        self._collapseAfter.setAutoRaise(True)

        self._collapseBefore.setCursor(Qt.ArrowCursor)
        self._collapseAfter.setCursor(Qt.ArrowCursor)

        # define the layout
        layout = QBoxLayout(QBoxLayout.LeftToRight, self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addStretch(1)
        layout.addWidget(self._collapseBefore)
        layout.addWidget(self._resizeGrip)
        layout.addWidget(self._collapseAfter)
        layout.addStretch(1)
        self.setLayout(layout)

        # set the orientation to start with
        self.setOrientation(orientation)

        # create connections
        self._collapseAfter.clicked.connect(self.toggleCollapseAfter)
        self._collapseBefore.clicked.connect(self.toggleCollapseBefore)
Пример #2
0
    def __init__(self, parent=None):
        super(XPagesWidget, self).__init__(parent)

        # define custom properties
        self._currentPage = 1
        self._pageCount = 10
        self._itemCount = 0
        self._pageSize = 50
        self._itemsTitle = 'items'

        self._pagesSpinner = QSpinBox()
        self._pagesSpinner.setMinimum(1)
        self._pagesSpinner.setMaximum(10)

        self._pageSizeCombo = XComboBox(self)
        self._pageSizeCombo.setHint('all')
        self._pageSizeCombo.addItems(['', '25', '50', '75', '100'])
        self._pageSizeCombo.setCurrentIndex(2)

        self._nextButton = QToolButton(self)
        self._nextButton.setAutoRaise(True)
        self._nextButton.setArrowType(Qt.RightArrow)
        self._nextButton.setFixedWidth(16)

        self._prevButton = QToolButton(self)
        self._prevButton.setAutoRaise(True)
        self._prevButton.setArrowType(Qt.LeftArrow)
        self._prevButton.setFixedWidth(16)
        self._prevButton.setEnabled(False)

        self._pagesLabel = QLabel('of 10 for ', self)
        self._itemsLabel = QLabel(' items per page', self)

        # define the interface
        layout = QHBoxLayout()
        layout.addWidget(QLabel('Page', self))
        layout.addWidget(self._prevButton)
        layout.addWidget(self._pagesSpinner)
        layout.addWidget(self._nextButton)
        layout.addWidget(self._pagesLabel)
        layout.addWidget(self._pageSizeCombo)
        layout.addWidget(self._itemsLabel)
        layout.addStretch(1)

        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)

        self.setLayout(layout)
        self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        # create connections
        self._pageSizeCombo.currentIndexChanged.connect(self.pageSizePicked)
        self._nextButton.clicked.connect(self.gotoNext)
        self._prevButton.clicked.connect(self.gotoPrevious)
        self._pagesSpinner.editingFinished.connect(self.assignCurrentPage)
Пример #3
0
    def __init__(self, parent):
        super(XUrlWidget, self).__init__(parent)

        # define the interface
        self._urlEdit = XLineEdit(self)
        self._urlButton = QToolButton(self)

        self._urlButton.setAutoRaise(True)
        self._urlButton.setIcon(QIcon(resources.find('img/web.png')))
        self._urlButton.setToolTip('Browse Link')
        self._urlButton.setFocusPolicy(Qt.NoFocus)

        self._urlEdit.setHint('http://')

        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self._urlEdit)
        layout.addWidget(self._urlButton)

        self.setLayout(layout)
        self.setFocusPolicy(Qt.StrongFocus)

        # create connections
        self._urlEdit.textChanged.connect(self.urlChanged)
        self._urlEdit.textEdited.connect(self.urlEdited)
        self._urlButton.clicked.connect(self.browse)
Пример #4
0
    def __init__(self, parent):
        super(XLocationWidget, self).__init__(parent)

        # define the interface
        self._locationEdit = XLineEdit(self)
        self._locationButton = QToolButton(self)
        self._urlTemplate = 'http://maps.google.com/maps?%(params)s'
        self._urlQueryKey = 'q'

        self._locationButton.setAutoRaise(True)
        self._locationButton.setIcon(QIcon(resources.find('img/map.png')))

        self._locationEdit.setHint('no location set')

        layout = QHBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(self._locationEdit)
        layout.addWidget(self._locationButton)

        self.setLayout(layout)

        # create connections
        self._locationEdit.textChanged.connect(self.locationChanged)
        self._locationEdit.textEdited.connect(self.locationEdited)
        self._locationButton.clicked.connect(self.browseMaps)
Пример #5
0
    def __init__(self, parent=None):
        super(XViewProfileManager, self).__init__(parent)

        # define custom properties
        self._profiles = []
        self._optionsMenuPolicy = Qt.DefaultContextMenu
        self._viewWidget = None

        # define the interface
        self._profileCombo = QComboBox(self)
        self._optionsButton = QToolButton(self)
        self._optionsButton.setAutoRaise(True)
        self._optionsButton.setToolTip('Advanced Options')
        self._optionsButton.setIcon(QIcon(resources.find('img/advanced.png')))

        layout = QHBoxLayout()
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)

        layout.addWidget(self._profileCombo)
        layout.addWidget(self._optionsButton)

        self.setLayout(layout)

        # create connections
        self._profileCombo.currentIndexChanged.connect(
            self.handleProfileChange)
        self._optionsButton.clicked.connect(self.showOptionsMenu)
Пример #6
0
    def __init__(self, parent=None):
        super(XCommentEdit, self).__init__(parent)

        # define custom properties
        self._attachments = {}
        self._showAttachments = True

        # create toolbar
        self._toolbar = QToolBar(self)
        self._toolbar.setMovable(False)
        self._toolbar.setFixedHeight(30)
        self._toolbar.setAutoFillBackground(True)
        self._toolbar.setFocusProxy(self)
        self._toolbar.hide()

        # create toolbar buttons
        self._attachButton = QToolButton(self)
        self._attachButton.setIcon(QIcon(resources.find('img/attach.png')))
        self._attachButton.setToolTip('Add Attachment')
        self._attachButton.setAutoRaise(True)
        self._attachButton.setIconSize(QSize(24, 24))
        self._attachButton.setFixedSize(26, 26)

        self._submitButton = QPushButton(self)
        self._submitButton.setText('Submit')
        self._submitButton.setFocusProxy(self)

        # create attachments widget
        self._attachmentsEdit = XMultiTagEdit(self)
        self._attachmentsEdit.setAutoResizeToContents(True)
        self._attachmentsEdit.setFrameShape(XMultiTagEdit.NoFrame)
        self._attachmentsEdit.setViewMode(XMultiTagEdit.ListMode)
        self._attachmentsEdit.setEditable(False)
        self._attachmentsEdit.setFocusProxy(self)
        self._attachmentsEdit.hide()

        # define toolbar layout
        spacer = QWidget(self)
        spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)

        self._attachAction = self._toolbar.addWidget(self._attachButton)
        self._toolbar.addWidget(spacer)
        self._toolbar.addWidget(self._submitButton)

        # set standard properties
        self.setAutoResizeToContents(True)
        self.setHint('add comment')
        self.setFocusPolicy(Qt.StrongFocus)
        self.setRequireShiftForNewLine(True)

        # create connections
        self._attachButton.clicked.connect(self.attachmentRequested)
        self._submitButton.clicked.connect(self.acceptText)
        self._attachmentsEdit.tagRemoved.connect(self.removeAttachment)
        self.focusChanged.connect(self.setToolbarVisible)
Пример #7
0
 def __init__( self, parent = None ):
     super(XFilepathEdit, self).__init__( parent )
     
     # define custom properties
     self._validated         = False
     self._validForeground   = QColor(0, 120, 0)
     self._validBackground   = QColor(0, 120, 0, 100)
     self._invalidForeground = QColor(255, 0, 0)
     self._invalidBackground = QColor(255, 0, 0, 100)
     self._normalizePath     = False
     
     self._filepathMode      = XFilepathEdit.Mode.OpenFile
     self._filepathEdit      = XLineEdit(self)
     self._filepathButton    = QToolButton(self)
     self._filepathTypes     = 'All Files (*.*)'
     
     # set default properties
     ico = projexui.resources.find('img/folder.png')
     self._filepathEdit.setReadOnly(False)
     self._filepathEdit.setSizePolicy(QSizePolicy.Expanding,
                                      QSizePolicy.Expanding)
     self._filepathButton.setText('...')
     self._filepathButton.setFixedSize(25, 23)
     self._filepathButton.setAutoRaise(True)
     self._filepathButton.setIcon(QIcon(ico))
     self._filepathEdit.setContextMenuPolicy(Qt.CustomContextMenu)
     
     self.setWindowTitle('Load File')
     self.setAcceptDrops(True)
     
     # define the layout
     layout = QHBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     layout.setSpacing(0)
     layout.addWidget(self._filepathEdit)
     layout.addWidget(self._filepathButton)
     self.setLayout(layout)
     
     # create connections
     self._filepathEdit.installEventFilter(self)
     
     self._filepathButton.clicked.connect(   self.pickFilepath )
     self._filepathEdit.textChanged.connect( self.emitFilepathChanged )
     self._filepathEdit.textChanged.connect( self.validateFilepath )
     self._filepathEdit.customContextMenuRequested.connect( self.showMenu )
Пример #8
0
    def clear(self):
        """
        Clears out this toolbar from the system.
        """
        # preserve the collapse button
        super(XToolBar, self).clear()

        # clears out the toolbar
        if self.isCollapsable():
            self._collapseButton = QToolButton(self)
            self._collapseButton.setAutoRaise(True)
            self._collapseButton.setSizePolicy(QSizePolicy.Expanding,
                                               QSizePolicy.Expanding)

            self.addWidget(self._collapseButton)
            self.refreshButton()

            # create connection
            self._collapseButton.clicked.connect(self.toggleCollapsed)

        elif self._collapseButton:
            self._collapseButton.setParent(None)
            self._collapseButton.deleteLater()
            self._collapseButton = None
Пример #9
0
 def reset( self ):
     """
     Resets the user interface buttons for this widget.
     """
     # clear previous widgets
     for btn in self.findChildren(QToolButton):
         btn.close()
         btn.setParent(None)
         btn.deleteLater()
     
     # determine coloring options
     palette             = self.palette()
     unchecked           = palette.color(palette.Button)
     
     # determine if this is a dark or light scheme
     avg = (unchecked.red() + unchecked.green() + unchecked.blue()) / 3.0
     if ( avg < 140 ):
         checked             = unchecked.lighter(115)
         
         checked_clr         = self.colorString(unchecked.lighter(120))
         border_clr          = self.colorString(unchecked.darker(140))
         unchecked_clr       = self.colorString(checked.lighter(140))
         unchecked_clr_alt   = self.colorString(checked.lighter(120))
         checked_clr_alt     = self.colorString(unchecked)
     else:
         checked             = unchecked.lighter(120)
         
         checked_clr         = self.colorString(unchecked)
         border_clr          = self.colorString(unchecked.darker(160))
         unchecked_clr       = self.colorString(checked)
         unchecked_clr_alt   = self.colorString(checked.darker(130))
         checked_clr_alt     = self.colorString(unchecked.darker(120))
     
     # define the stylesheet options
     options = {}
     options['top_left_radius']      = 0
     options['top_right_radius']     = 0
     options['bot_left_radius']      = 0
     options['bot_right_radius']     = 0
     options['border_color']         = border_clr
     options['checked_clr']          = checked_clr
     options['checked_clr_alt']      = checked_clr_alt
     options['unchecked_clr']        = unchecked_clr
     options['unchecked_clr_alt']    = unchecked_clr_alt
     options['padding_top']          = 1
     options['padding_bottom']       = 1
     options['padding_left']         = 1
     options['padding_right']        = 1
     
     horiz = self.direction() in (QBoxLayout.LeftToRight, 
                                  QBoxLayout.RightToLeft)
     
     if ( horiz ):
         options['x1'] = 0
         options['y1'] = 0
         options['x2'] = 0
         options['y2'] = 1
     else:
         options['x1'] = 0
         options['y1'] = 0
         options['x2'] = 1
         options['y2'] = 1
     
     actions = self.actionGroup().actions()
     count = len(actions)
     for i, action in enumerate(actions):
         btn = QToolButton(self)
         btn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
         btn.setDefaultAction(action)
         self.layout().insertWidget(i, btn)
         
         options['top_left_radius']  = 1
         options['bot_left_radius']  = 1
         options['top_right_radius'] = 1
         options['bot_right_radius'] = 1
         
         if ( horiz ):
             options['padding_left']     = self._padding
             options['padding_right']    = self._padding
         else:
             options['padding_top']      = self._padding
             options['padding_bottom']   = self._padding
         
         if ( not i ):
             if ( horiz ):
                 options['top_left_radius'] = self.cornerRadius()
                 options['bot_left_radius'] = self.cornerRadius()
                 options['padding_left']    += self.cornerRadius() / 3.0
             else:
                 options['top_left_radius'] = self.cornerRadius()
                 options['top_right_radius'] = self.cornerRadius()
                 options['padding_top']     += self.cornerRadius() / 3.0
                 
         elif ( i == count - 1 ):
             if ( horiz ):
                 options['top_right_radius'] = self.cornerRadius()
                 options['bot_right_radius'] = self.cornerRadius()
                 options['padding_right']    += self.cornerRadius() / 3.0
             else:
                 options['bot_left_radius']  = self.cornerRadius()
                 options['bot_right_radius'] = self.cornerRadius()
                 options['padding_bottom']   += self.cornerRadius() / 3.0
         
         btn.setStyleSheet(TOOLBUTTON_STYLE % options)
         btn.setAutoFillBackground(True)
Пример #10
0
 def __init__( self, parent = None ):
     super(XFindWidget, self).__init__( parent )
     
     # define custom properties
     self._textEdit   = None
     self._webView    = None
     self._lastCursor = QTextCursor()
     self._lastText = ''
     
     self._closeButton = QToolButton(self)
     self._closeButton.setIcon(QIcon(resources.find('img/close.png')))
     self._closeButton.setAutoRaise(True)
     self._closeButton.setToolTip('Hide the Find Field.')
     
     self._searchEdit = XLineEdit(self)
     self._searchEdit.setHint('search for...')
     
     self._previousButton = QToolButton(self)
     self._previousButton.setIcon(QIcon(resources.find('img/back.png')))
     self._previousButton.setAutoRaise(True)
     self._previousButton.setToolTip('Find Previous')
     
     self._nextButton = QToolButton(self)
     self._nextButton.setIcon(QIcon(resources.find('img/forward.png')))
     self._nextButton.setAutoRaise(True)
     self._nextButton.setToolTip('Find Next')
     
     self._caseSensitiveCheckbox = QCheckBox(self)
     self._caseSensitiveCheckbox.setText('Case Sensitive')
     
     self._wholeWordsCheckbox = QCheckBox(self)
     self._wholeWordsCheckbox.setText('Whole Words Only')
     
     self._regexCheckbox = QCheckBox(self)
     self._regexCheckbox.setText('Use Regex')
     
     self._findAction = QAction(self)
     self._findAction.setText('Find...')
     self._findAction.setIcon(QIcon(resources.find('img/search.png')))
     self._findAction.setToolTip('Find in Text')
     self._findAction.setShortcut(QKeySequence('Ctrl+F'))
     self._findAction.setShortcutContext(Qt.WidgetWithChildrenShortcut)
     
     # layout the widgets
     layout = QHBoxLayout()
     layout.setContentsMargins(0, 0, 0, 0)
     layout.addWidget( self._closeButton )
     layout.addWidget( self._searchEdit )
     layout.addWidget( self._previousButton )
     layout.addWidget( self._nextButton )
     layout.addWidget( self._caseSensitiveCheckbox )
     layout.addWidget( self._wholeWordsCheckbox )
     layout.addWidget( self._regexCheckbox )
     
     self.setLayout(layout)
     
     # create connections
     self._findAction.triggered.connect(          self.show )
     self._searchEdit.textChanged.connect(        self.findNext )
     self._closeButton.clicked.connect(           self.hide )
     self._previousButton.clicked.connect(        self.findPrev )
     self._nextButton.clicked.connect(            self.findNext )
     self._caseSensitiveCheckbox.clicked.connect( self.findNext )
     self._wholeWordsCheckbox.clicked.connect(    self.findNext )
     self._searchEdit.returnPressed.connect(      self.findNext )
     self._regexCheckbox.clicked.connect(         self.findNext )
Пример #11
0
    def __init__(self, parent=None, buttons=None):
        super(XPopupWidget, self).__init__(parent)

        # define custom properties
        self._anchor = XPopupWidget.Anchor.TopCenter
        self._autoCalculateAnchor = False
        self._autoCloseOnAccept = True
        self._autoCloseOnReject = True
        self._autoCloseOnFocusOut = False
        self._autoDefault = True
        self._first = True
        self._animated = False
        self._currentMode = None
        self._positionLinkedTo = []
        self._possibleAnchors = XPopupWidget.Anchor.all()

        # define controls
        self._result = 0
        self._resizable = True
        self._popupPadding = 10
        self._titleBarVisible = True
        self._buttonBoxVisible = True
        self._dialogButton = QToolButton(self)
        self._closeButton = QToolButton(self)
        self._scrollArea = QScrollArea(self)
        self._sizeGrip = QSizeGrip(self)
        self._sizeGrip.setFixedWidth(12)
        self._sizeGrip.setFixedHeight(12)

        self._leftSizeGrip = QSizeGrip(self)
        self._leftSizeGrip.setFixedWidth(12)
        self._leftSizeGrip.setFixedHeight(12)

        if buttons is None:
            buttons = QDialogButtonBox.NoButton

        self._buttonBox = QDialogButtonBox(buttons, Qt.Horizontal, self)
        self._buttonBox.setContentsMargins(3, 0, 3, 9)

        self._scrollArea.setWidgetResizable(True)
        self._scrollArea.setFrameShape(QScrollArea.NoFrame)
        self._scrollArea.setSizePolicy(QSizePolicy.Expanding,
                                       QSizePolicy.Expanding)

        palette = self.palette()
        self._scrollArea.setPalette(palette)

        self._dialogButton.setToolTip('Popout to Dialog')
        self._closeButton.setToolTip('Close Popup')

        for btn in (self._dialogButton, self._closeButton):
            btn.setAutoRaise(True)
            btn.setIconSize(QSize(14, 14))
            btn.setMaximumSize(16, 16)

        # setup the icons
        icon = QIcon(projexui.resources.find('img/dialog.png'))
        self._dialogButton.setIcon(icon)

        icon = QIcon(projexui.resources.find('img/close.png'))
        self._closeButton.setIcon(icon)

        # define the ui
        hlayout = QHBoxLayout()
        hlayout.setSpacing(0)
        hlayout.addStretch(1)
        hlayout.addWidget(self._dialogButton)
        hlayout.addWidget(self._closeButton)
        hlayout.setContentsMargins(0, 0, 0, 0)

        hlayout2 = QHBoxLayout()
        hlayout2.addWidget(self._buttonBox)
        hlayout2.setContentsMargins(0, 0, 3, 0)

        vlayout = QVBoxLayout()
        vlayout.addLayout(hlayout)
        vlayout.addWidget(self._scrollArea)
        vlayout.addLayout(hlayout2)
        vlayout.setContentsMargins(3, 2, 3, 2)
        vlayout.setSpacing(0)

        self.setLayout(vlayout)
        self.setPositionLinkedTo(parent)

        # set default properties
        self.setAutoFillBackground(True)
        self.setBackgroundRole(QPalette.Window)
        self.setWindowTitle('Popup')
        self.setFocusPolicy(Qt.StrongFocus)
        self.setCurrentMode(XPopupWidget.Mode.Popup)

        # create connections
        self._dialogButton.clicked.connect(self.setDialogMode)
        self._closeButton.clicked.connect(self.reject)
        self._buttonBox.accepted.connect(self.accept)
        self._buttonBox.rejected.connect(self.reject)
        self._buttonBox.clicked.connect(self.handleButtonClick)
Пример #12
0
    def rebuild(self):
        """
        Rebuilds the user interface buttons for this widget.
        """
        self.setUpdatesEnabled(False)

        # sync up the toolbuttons with our actions
        actions = self._actionGroup.actions()
        btns = self.findChildren(QToolButton)
        horiz = self.direction() in (QBoxLayout.LeftToRight,
                                     QBoxLayout.RightToLeft)

        # remove unnecessary buttons
        if len(actions) < len(btns):
            rem_btns = btns[len(actions) - 1:]
            btns = btns[:len(actions)]

            for btn in rem_btns:
                btn.close()
                btn.setParent(None)
                btn.deleteLater()

        # create new buttons
        elif len(btns) < len(actions):
            for i in range(len(btns), len(actions)):
                btn = QToolButton(self)
                btn.setAutoFillBackground(True)
                btns.append(btn)
                self.layout().addWidget(btn)

                btn.clicked.connect(self.emitClicked)

        # determine coloring options
        palette = self.palette()
        checked = palette.color(palette.Highlight)
        checked_fg = palette.color(palette.HighlightedText)
        unchecked = palette.color(palette.Button)
        unchecked_fg = palette.color(palette.ButtonText)
        border = palette.color(palette.Mid)

        # define the stylesheet options
        options = {}
        options['top_left_radius'] = 0
        options['top_right_radius'] = 0
        options['bot_left_radius'] = 0
        options['bot_right_radius'] = 0
        options['border_color'] = border.name()
        options['checked_fg'] = checked_fg.name()
        options['checked_bg'] = checked.name()
        options['checked_bg_alt'] = checked.darker(120).name()
        options['unchecked_fg'] = unchecked_fg.name()
        options['unchecked_bg'] = unchecked.name()
        options['unchecked_bg_alt'] = unchecked.darker(120).name()
        options['padding_top'] = 1
        options['padding_bottom'] = 1
        options['padding_left'] = 1
        options['padding_right'] = 1

        if horiz:
            options['x1'] = 0
            options['y1'] = 0
            options['x2'] = 0
            options['y2'] = 1
        else:
            options['x1'] = 0
            options['y1'] = 0
            options['x2'] = 1
            options['y2'] = 1

        # sync up the actions and buttons
        count = len(actions)
        palette = self.palette()
        font = self.font()
        for i, action in enumerate(actions):
            btn = btns[i]

            # assign the action for this button
            if btn.defaultAction() != action:
                # clear out any existing actions
                for act in btn.actions():
                    btn.removeAction(act)

                # assign the given action
                btn.setDefaultAction(action)

            options['top_left_radius'] = 1
            options['bot_left_radius'] = 1
            options['top_right_radius'] = 1
            options['bot_right_radius'] = 1

            if horiz:
                options['padding_left'] = self._padding
                options['padding_right'] = self._padding
            else:
                options['padding_top'] = self._padding
                options['padding_bottom'] = self._padding

            if not i:
                if horiz:
                    options['top_left_radius'] = self.cornerRadius()
                    options['bot_left_radius'] = self.cornerRadius()
                    options['padding_left'] += self.cornerRadius() / 3.0
                else:
                    options['top_left_radius'] = self.cornerRadius()
                    options['top_right_radius'] = self.cornerRadius()
                    options['padding_top'] += self.cornerRadius() / 3.0

            if i == count - 1:
                if horiz:
                    options['top_right_radius'] = self.cornerRadius()
                    options['bot_right_radius'] = self.cornerRadius()
                    options['padding_right'] += self.cornerRadius() / 3.0
                else:
                    options['bot_left_radius'] = self.cornerRadius()
                    options['bot_right_radius'] = self.cornerRadius()
                    options['padding_bottom'] += self.cornerRadius() / 3.0

            btn.setFont(font)
            btn.setPalette(palette)
            btn.setStyleSheet(TOOLBUTTON_STYLE % options)
            if horiz:
                btn.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
            else:
                btn.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)

        self.setUpdatesEnabled(True)
Пример #13
0
    def rebuild(self):
        """
        Rebuilds the parts widget with the latest text.
        """
        navitem = self.currentItem()
        if (navitem):
            navitem.initialize()

        self.setUpdatesEnabled(False)
        self.scrollWidget().show()
        self._originalText = ''

        partsw = self.partsWidget()
        for button in self._buttonGroup.buttons():
            self._buttonGroup.removeButton(button)
            button.close()
            button.setParent(None)
            button.deleteLater()

        # create the root button
        layout = partsw.layout()
        parts = self.parts()

        button = QToolButton(partsw)
        button.setAutoRaise(True)
        button.setMaximumWidth(12)
        button.setArrowType(Qt.RightArrow)

        button.setProperty('path', wrapVariant(''))
        button.setProperty('is_completer', wrapVariant(True))
        last_button = button

        self._buttonGroup.addButton(button)
        layout.insertWidget(0, button)

        # check to see if we have a navigation model setup
        if (self._navigationModel):
            last_item = self._navigationModel.itemByPath(self.text())
            show_last = last_item and last_item.rowCount() > 0
        else:
            show_last = False

        # load the navigation system
        count = len(parts)
        for i, part in enumerate(parts):
            path = self.separator().join(parts[:i + 1])

            button = QToolButton(partsw)
            button.setAutoRaise(True)
            button.setText(part)

            if (self._navigationModel):
                item = self._navigationModel.itemByPath(path)
                if (item):
                    button.setIcon(item.icon())
                    button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)

            button.setProperty('path', wrapVariant(path))
            button.setProperty('is_completer', wrapVariant(False))

            self._buttonGroup.addButton(button)
            layout.insertWidget((i * 2) + 1, button)

            # determine if we should show the final button
            if (show_last or i < (count - 1)):
                button = QToolButton(partsw)
                button.setAutoRaise(True)
                button.setMaximumWidth(12)
                button.setArrowType(Qt.RightArrow)

                button.setProperty('path', wrapVariant(path))
                button.setProperty('is_completer', wrapVariant(True))

                self._buttonGroup.addButton(button)
                layout.insertWidget((i * 2) + 2, button)

                last_button = button

        if (self.scrollWidget().width() < partsw.width()):
            self.scrollParts(partsw.width() - self.scrollWidget().width())

        self.setUpdatesEnabled(True)
        self.navigationChanged.emit()