def __init__(self, *args): super(XTabWidget, self).__init__(*args) # create the tab bar self.setTabBar(XTabBar(self)) # create custom properties self._showAddButton = True self._showOptionsButton = True # create the add button self._addButton = XTabButton(self) self._addButton.setIcon(QIcon(resources.find('img/tab/add.png'))) self._addButton.setFixedSize(18, 18) self._addButton.setIconSize(QSize(10, 10)) # create the option button self._optionsButton = XTabButton(self) self._optionsButton.setFixedSize(22, 18) self._optionsButton.setIcon(QIcon(resources.find('img/tab/gear.png'))) self._optionsButton.setIconSize(QSize(10, 10)) # create connection self.connect(self.tabBar(), SIGNAL('currentChanged(int)'), self.adjustButtons) self.connect(self.tabBar(), SIGNAL('resized()'), self.adjustButtons) self.connect(self._optionsButton, SIGNAL('clicked()'), self.emitOptionsRequested) self.connect(self._addButton, SIGNAL('clicked()'), self.emitAddRequested)
def __init__(self, parent=None): super(XDockToolbar, self).__init__(parent) # defines the position for this widget self._currentAction = -1 self._selectedAction = None self._padding = 8 self._position = XDockToolbar.Position.South self._minimumPixmapSize = QSize(16, 16) self._maximumPixmapSize = QSize(48, 48) self._hoverTimer = QTimer(self) self._hoverTimer.setSingleShot(True) self._hoverTimer.setInterval(1000) self._actionHeld = False self._easingCurve = QEasingCurve(QEasingCurve.InOutQuad) self._duration = 200 self._animating = False # install an event filter to update the location for this toolbar layout = QBoxLayout(QBoxLayout.LeftToRight) layout.setContentsMargins(2, 2, 2, 2) layout.setSpacing(0) layout.addStretch(1) layout.addStretch(1) self.setLayout(layout) self.setContentsMargins(2, 2, 2, 2) self.setMouseTracking(True) parent.window().installEventFilter(self) parent.window().statusBar().installEventFilter(self) self._hoverTimer.timeout.connect(self.emitActionHovered)
def __init__(self, parent=None): super(XRatingSlider, self).__init__(parent) # define custom properties self._emptyPixmap = QPixmap(resources.find('img/star_gray.png')) self._fullPixmap = QPixmap(resources.find('img/star.png')) self._alignment = Qt.AlignCenter self._pixmapSize = QSize(16, 16) # set default properties self.setOrientation(Qt.Horizontal) self.setMinimum(0) self.setMaximum(10) self.setPixmapSize(QSize(16, 16))
def setThumbnailSize( self, size ): """ Sets the size that will be used for the thumbnails in this widget. :param size | <QSize> """ self._thumbnailSize = QSize(size)
def createActionItem(self, key): """ Creates a new action item for the inputed key. :param key | <str> :return <QTreeWidgetItem> """ action = self._actions.get(key) if (not action): text = 'Missing Action: %s' % key item = QTreeWidgetItem([text]) ico = projexui.resources.find('img/log/warning.png') item.setIcon(0, QIcon(ico)) else: item = QTreeWidgetItem( [nativestring(action.text()).replace('&', '')]) item.setIcon(0, action.icon()) item.setSizeHint(0, QSize(120, 20)) item.setData(0, Qt.UserRole, wrapVariant(key)) flags = item.flags() flags ^= Qt.ItemIsDropEnabled item.setFlags(flags) return item
def sizeHint(self): """ Returns the base size hint for this widget. :return <QSize> """ return QSize(35, 22)
def addButton(self, button, alignment=None): """ Adds a button the edit. All the buttons will be layed out at the \ end of the widget. :param button | <QToolButton> alignment | <Qt.Alignment> :return <bool> | success """ if alignment == None: if button.pos().x() < self.pos().x(): alignment = Qt.AlignLeft else: alignment = Qt.AlignRight all_buttons = self.buttons() if button in all_buttons: return False # move the button to this edit button.setParent(self) button.setAutoRaise(True) button.setIconSize(self.iconSize()) button.setCursor(Qt.ArrowCursor) button.setFixedSize(QSize(self.height() - 2, self.height() - 2)) self._buttons.setdefault(alignment, []) self._buttons[alignment].append(button) self.adjustButtons() return True
def update(self, recursive=False): if (not self.childCount()): return # update the look for the group font = self.font(0) font.setBold(True) self.setFont(0, font) for i in range(self.columnCount()): self.setText(i, '') # make sure we size properly self.setSizeHint(0, QSize(150, 20)) self.setFirstColumnSpanned(True) palette = QApplication.instance().palette() if (not self.isExpanded()): self.setForeground(0, palette.color(palette.Mid)) else: self.setForeground(0, palette.color(palette.AlternateBase)) self.setText(0, '(%s)' % self.summary()) if (recursive): for c in range(self.childCount()): self.child(c).update(True)
def _loadCardGroup( self, groupName, records, parent = None ): if ( not groupName ): groupName = 'None' cards = self.cardWidget() factory = self.factory() # create the group item group_item = QTreeWidgetItem(parent, [groupName]) font = group_item.font(0) font.setBold(True) font.setPointSize(font.pointSize() + 2) group_item.setFont(0, font) group_item.setFlags(Qt.ItemIsEnabled) # load sub-groups if ( type(records) == dict ): for subgroup, records in sorted(records.items()): self._loadCardGroup(subgroup, records, group_item) else: for record in records: widget = factory.createCard(cards, record) if ( not widget ): continue widget.adjustSize() # create the card item item = QTreeWidgetItem(group_item) item.setSizeHint(0, QSize(0, widget.height())) cards.setItemWidget(item, 0, widget) group_item.setExpanded(True)
def adjustButtons(self): """ Adjusts the placement of the buttons for this line edit. """ y = 1 for btn in self.buttons(): btn.setIconSize(self.iconSize()) btn.setFixedSize(QSize(self.height() - 2, self.height() - 2)) # adjust the location for the left buttons left_buttons = self._buttons.get(Qt.AlignLeft, []) x = (self.cornerRadius() / 2.0) + 2 for btn in left_buttons: btn.move(x, y) x += btn.width() # adjust the location for the right buttons right_buttons = self._buttons.get(Qt.AlignRight, []) w = self.width() bwidth = sum([btn.width() for btn in right_buttons]) bwidth += (self.cornerRadius() / 2.0) + 1 for btn in right_buttons: btn.move(w - bwidth, y) bwidth -= btn.width() self._buttonWidth = sum([btn.width() for btn in self.buttons()]) self.adjustTextMargins()
def __init__(self, *args): super(XLineEdit, self).__init__(*args) palette = self.palette() hint_clr = palette.color(palette.Disabled, palette.Text) # set the hint property self._hint = '' self._hintPrefix = '' self._hintSuffix = '' self._spacer = '_' self._encoding = 'utf-8' self._hintColor = hint_clr self._buttonWidth = 0 self._cornerRadius = 0 self._currentState = XLineEdit.State.Normal self._inputFormat = XLineEdit.InputFormat.Normal self._selectAllOnFocus = False self._focusedIn = False self._useHintValue = True self._icon = QIcon() self._iconSize = QSize(14, 14) self._buttons = {} self.textChanged.connect(self.adjustText) self.returnPressed.connect(self.emitTextEntered)
def __init__( self, parent = None ): super(XOrbGridEdit, self).__init__( parent ) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._queryWidget = XOrbQueryWidget(self) self.uiSaveBTN.hide() self.uiSearchTXT.setIconSize(QSize(28, 28)) self.uiSearchTXT.addButton(self.uiQueryBTN) self.uiQueryBTN.setCentralWidget(self._queryWidget) self.uiQueryBTN.setDefaultAnchor(XPopupWidget.Anchor.TopRight) popup = self.uiQueryBTN.popupWidget() popup.setShowTitleBar(False) # set default properties self.uiRecordTREE.setUserGroupingEnabled(False) self.uiRecordTREE.setGroupingActive(False) self.uiRecordTREE.setEditable(False) self.uiRecordTREE.setPageSize(50) self.uiRecordTREE.setTabKeyNavigation(True) # create connections self.uiRefreshBTN.clicked.connect(self.refresh) self.uiSaveBTN.clicked.connect(self.commit) self.uiQueryBTN.popupAboutToShow.connect(self.loadQuery) self.uiQueryBTN.popupAccepted.connect(self.assignQuery) popup.resetRequested.connect(self._queryWidget.reset)
def __init__(self, parent, filepath, title=None, folder=False): super(XdkEntryItem, self).__init__(parent) # set custom properties filepath = nativestring(filepath).replace('\\', '/') self._isFolder = folder self._filepath = filepath self._url = 'file:///' + filepath self._loaded = False self.setFixedHeight(22) # define custom properties if folder: self.setIcon(0, QIcon(projexui.resources.find('img/folder.png'))) self.setExpandedIcon( 0, QIcon(projexui.resources.find('img/folder_open.png'))) self.setChildIndicatorPolicy(self.ShowIndicator) else: self.setIcon(0, QIcon(projexui.resources.find('img/file.png'))) self._loaded = True if filepath: if title is not None: self.TITLE_MAP[self._url] = title self.setText(0, title) else: self.setText(0, self.titleForFilepath(self._url)) # set default properties self.setSizeHint(0, QSize(20, 18)) self.setText(1, os.path.basename(os.path.splitext(filepath)[0]))
def __init__(self, text='Root'): super(XNavigationItem, self).__init__(text) # set custom properties self._initialized = False # set default parameters self.setSizeHint(QSize(80, 20))
def __init__( self, parent = None ): super(XOrbBrowserWidget, self).__init__( parent ) # load the user interface projexui.loadUi(__file__, self) # define custom properties self._hint = '' self._query = Q() self._advancedGrouping = [] self._records = RecordSet() self._groupBy = XOrbBrowserWidget.GroupByAdvancedKey self._factory = XOrbBrowserFactory() self._queryWidget = XOrbQueryWidget(self, self._factory) self._thumbnailSize = QSize(128, 128) # set default properties self.uiSearchTXT.addButton(self.uiQueryBTN) self.uiQueryBTN.setCentralWidget(self._queryWidget) self.uiThumbLIST.installEventFilter(self) self.uiQueryACT.setShortcutContext(Qt.WidgetWithChildrenShortcut) self.uiQueryBTN.setDefaultAction(self.uiQueryACT) self.uiViewModeWGT.addAction(self.uiDetailsACT) self.uiViewModeWGT.addAction(self.uiCardACT) self.uiViewModeWGT.addAction(self.uiThumbnailACT) # create connections self.uiGroupOptionsBTN.clicked.connect(self.showGroupMenu) self.uiSearchTXT.returnPressed.connect(self.refresh) self.queryChanged.connect(self.refresh) self.uiGroupBTN.toggled.connect(self.refreshResults) self.uiDetailsACT.triggered.connect(self.setDetailMode) self.uiCardACT.triggered.connect(self.setCardMode) self.uiThumbnailACT.triggered.connect(self.setThumbnailMode) self.uiQueryBTN.popupAboutToShow.connect(self.prepareQuery) self.uiQueryBTN.popupAccepted.connect(self.acceptQuery) self.uiQueryBTN.popupReset.connect(self.resetQuery) self.uiRefreshBTN.clicked.connect(self.refresh) self.uiRecordsTREE.itemDoubleClicked.connect(self.handleDetailDblClick) self.uiRecordsTREE.currentItemChanged.connect( self.emitCurrentRecordChanged) self.uiThumbLIST.itemDoubleClicked.connect(self.handleThumbDblClick) self.uiThumbLIST.currentItemChanged.connect( self.emitCurrentRecordChanged) self.uiCardTREE.itemDoubleClicked.connect(self.handleCardDblClick) self.uiCardTREE.currentItemChanged.connect( self.emitCurrentRecordChanged)
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)
def getDialog(cls, name, parent=None): """ Generates a dialog for this class widget and returns it. :param parent | <QtGui.QWidget> || None :return <QtGui.QDialog> """ key = '_{0}__{1}_dialog'.format(cls.__name__, name) dlgref = getattr(cls, key, None) if dlgref is not None: dlg = dlgref() if dlg: return dlg if parent is None: parent = QApplication.activeWindow() dlg = QDialog(parent) # create widget widget = cls(dlg) dlg.__dict__['_mainwidget'] = widget widget.layout().setContentsMargins(0, 0, 0, 0) # create buttons opts = QDialogButtonBox.Save | QDialogButtonBox.Cancel buttons = QDialogButtonBox(opts, Qt.Horizontal, dlg) # create layout layout = QVBoxLayout() layout.addWidget(widget) layout.addWidget(buttons) dlg.setLayout(layout) dlg.resize(widget.minimumSize() + QSize(15, 15)) widget.resizeRequested.connect(dlg.adjustSize) # create connections buttons.accepted.connect(widget.save) buttons.rejected.connect(dlg.reject) widget.saved.connect(dlg.accept) widget.setFocus() dlg.adjustSize() if parent and parent.window(): center = parent.window().geometry().center() dlg.move(center.x() - dlg.width() / 2.0, center.y() - dlg.height() / 2.0) setattr(cls, key, weakref.ref(dlg)) return dlg
def __init__( self, name, colors ): super(XColorTreeWidgetItem, self).__init__() # set custom properties self._name = name # set standard properties self.setSizeHint(0, QSize(0, 22)) self.setName(name) # define colors for i, color in enumerate(colors): self.setBackground( i+1, color )
def setText(self, text): """ Sets the text for this item and resizes it to fit the text and the remove button. :param text | <str> """ super(XMultiTagItem, self).setText(text) metrics = QFontMetrics(self.font()) hint = QSize(metrics.width(text) + 24, 18) self.setSizeHint(hint)
def __init__(self, parent): super(XBasicCardWidget, self).__init__(parent) # define the interface self._thumbnailButton = XIconButton(self) self._thumbnailButton.setIconSize(QSize(64, 64)) self._titleLabel = QLabel(self) layout = QHBoxLayout() layout.addWidget(self._thumbnailButton) layout.addWidget(self._titleLabel) self.setLayout(layout)
def __init__(self, parent, operator, preceeding=None): if (preceeding): super(XJoinItem, self).__init__(parent, preceeding) else: super(XJoinItem, self).__init__(parent) # setup the sizing options self.setSizeHint(0, QSize(150, 20)) self.setFirstColumnSpanned(True) self.setText(0, operator) # update the flags for this item flags = self.flags() flags |= Qt.ItemIsEditable self.setFlags(flags)
def createMenuItem(self, title): """ Creates a new menu item with the given title. :param title | <str> :return <QTreeWidgetItem> """ item = QTreeWidgetItem([title]) ico = projexui.resources.find('img/folder.png') item.setIcon(0, QIcon(ico)) item.setSizeHint(0, QSize(120, 20)) item.setData(0, Qt.UserRole, wrapVariant('menu')) return item
def __init__( self, text, widget ): super(GroupListWidgetItem, self).__init__(text, widget) # set the text alignment self.setTextAlignment(Qt.AlignLeft | Qt.AlignVCenter) self.setFlags(Qt.ItemFlags(0)) # update the font font = self.font() font.setBold(True) font.setPointSize(font.pointSize() + 2) self.setFont(font) # update the size hint hint = QSize(widget.width() - 20, 22) self.setSizeHint(hint)
def generatePixmap(color, style=Style.Plain, size=None): """ Generates a new pixmap for the inputed color and style. If no size is provided, then the default 32x32 will be used. :return <QPixmap> """ if size is None: size = QSize(32, 32) pixmap = QPixmap(size) # create a plain pixmap if style == XColorIcon.Style.Plain: pixmap.fill(color) return pixmap
def __init__(self, parent): super(XViewProfileToolBar, self).__init__(parent) # create custom properties self._editingEnabled = True self._viewWidget = None self._profileText = 'Profile' self._profileGroup = QActionGroup(self) self._currentProfile = None # set the default options self.setIconSize(QSize(48, 48)) self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) self.setContextMenuPolicy(Qt.CustomContextMenu) # create connections self.actionTriggered.connect(self.handleActionTrigger) self.customContextMenuRequested.connect(self.showProfileMenu)
def eventFilter( self, object, event ): """ Processes resize events on the thumbnail widget to update the group items to force a proper sizing. :param object | <QObject> event | <QEvent> :return <bool> | consumed """ if ( event.type() == event.Resize and \ self.currentMode() == XOrbBrowserWidget.Mode.Thumbnail and \ self.isGroupingActive() ): size = QSize(event.size().width() - 20, 22) for row in range(object.count()): item = object.item(row) if ( isinstance(item, GroupListWidgetItem) ): item.setSizeHint(size) return False
def __init__(self, parent, query, preceeding=None): if (preceeding): super(XQueryItem, self).__init__(parent, preceeding) else: super(XQueryItem, self).__init__(parent) self.setSizeHint(2, QSize(150, 20)) # create custom properties self._value = None # add a simple query item if (Q.typecheck(query)): self.setTextAlignment(1, Qt.AlignCenter) # set the data for this item if (not query.isNull()): self.setColumnName(query.columnName()) self.setOperatorType(query.operatorType()) self.setValue(query.value()) else: self.setColumnName('') self.setOperatorType(Q.Op.Is) self.setValue('') # set the flags for this item self.setFlags( Qt.ItemIsEnabled | \ Qt.ItemIsEditable | \ Qt.ItemIsSelectable ) else: operator = QueryCompound.Op[query.operatorType()].lower() for i, sub_query in enumerate(query.queries()): if (i): XJoinItem(self, operator) XQueryItem(self, sub_query) self.update()
def refreshCards( self ): """ Refreshes the results for the cards view of the browser. """ cards = self.cardWidget() factory = self.factory() self.setUpdatesEnabled(False) self.blockSignals(True) cards.setUpdatesEnabled(False) cards.blockSignals(True) cards.clear() QApplication.instance().processEvents() if ( self.isGroupingActive() ): grouping = self.records().grouped() for groupName, records in sorted(grouping.items()): self._loadCardGroup(groupName, records, cards) else: for record in self.records(): widget = factory.createCard(cards, record) if ( not widget ): continue widget.adjustSize() # create the card item item = QTreeWidgetItem(cards) item.setSizeHint(0, QSize(0, widget.height())) cards.setItemWidget(item, 0, widget) cards.setUpdatesEnabled(True) cards.blockSignals(False) self.setUpdatesEnabled(True) self.blockSignals(False)
def __init__(self, query, joiner=''): super(XQueryItem, self).__init__() # set the joiner self._joiner = joiner # update the hint self.setText(0, joiner) self.setSizeHint(1, QSize(80, 20)) if (Q.typecheck(query)): op_name = Q.Op[query.operatorType()] op_name = projex.text.joinWords(op_name, ' ').lower() palette = QApplication.palette() for i in range(4): self.setBackground(i, palette.color(palette.Base)) self.setTextAlignment(0, Qt.AlignRight | Qt.AlignVCenter) self.setText(1, query.columnName()) self.setText(2, op_name) self.setText(3, query.valueString()) flags = self.flags() flags |= Qt.ItemIsEditable self.setFlags(flags) else: sub_joiner = QueryCompound.Op[query.operatorType()].lower() for i, sub_query in enumerate(query.queries()): if (i): item = XQueryItem(sub_query, sub_joiner) else: item = XQueryItem(sub_query) self.addChild(item)
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)