def __init__(self, parent=None): super(XOverlayWizardPage, self).__init__(parent) self.setFrameShape(QtGui.QFrame.Box) # define custom properties self._commitPage = False self._finalPage = False self._retryEnabled = False self._nextId = None # create the title information font = self.font() font.setBold(True) base_size = font.pointSize() font.setPointSize(base_size + 4) # set the palette coloring pal = self.palette() pal.setColor(pal.WindowText, QtGui.QColor('white')) self.setPalette(pal) # create the title labels self._titleLabel = QtGui.QLabel('', self) self._titleLabel.setFont(font) self._titleLabel.setPalette(pal) font.setPointSize(base_size + 2) self._subTitleLabel = QtGui.QLabel('', self) self._subTitleLabel.setPalette(pal) self.adjustMargins()
def createMenu(self, parent): """ Creates a new menu for the inputed parent item. :param parent | <QMenu> """ menu = QtGui.QMenu(parent) menu.setTitle('&View') act = menu.addAction('&Lock/Unlock Layout') act.setIcon(QtGui.QIcon(projexui.resources.find('img/view/lock.png'))) act.triggered.connect(self.toggleLocked) menu.addSeparator() act = menu.addAction('&Export Layout as...') act.setIcon(QtGui.QIcon( projexui.resources.find('img/view/export.png'))) act.triggered.connect(self.exportProfile) act = menu.addAction('&Import Layout from...') act.setIcon(QtGui.QIcon( projexui.resources.find('img/view/import.png'))) act.triggered.connect(self.importProfile) menu.addSeparator() act = menu.addAction('&Clear Layout') act.setIcon(QtGui.QIcon( projexui.resources.find('img/view/remove.png'))) act.triggered.connect(self.resetForced) return menu
def paintEvent(self, event): with XPainter(self) as painter: painter.fillRect(event.rect(), QtGui.QColor('lightGray')) edit = self.codeEditor() block = edit.firstVisibleBlock() blockNumber = block.blockNumber() top = edit.blockBoundingGeometry(block).translated( edit.contentOffset()).top() bottom = top + edit.blockBoundingRect(block).height() textHeight = edit.fontMetrics().height() painter.setFont(self.font()) painter.setPen(QtGui.QColor('black')) while block.isValid() and top <= event.rect().bottom(): if block.isVisible() and bottom >= event.rect().top(): painter.drawText(0, top, self.width() - 6, textHeight, QtCore.Qt.AlignRight, str(blockNumber + 1)) block = block.next() top = bottom bottom = top + edit.blockBoundingRect(block).height() blockNumber += 1
def drawDisplay(self, painter, option, rect, text): """ Overloads the drawDisplay method to render HTML if the rich text \ information is set to true. :param painter | <QtGui.QPainter> option | <QtGui.QStyleOptionItem> rect | <QtCore.QRect> text | <str> """ if self.showRichText(): # create the document doc = QtGui.QTextDocument() doc.setTextWidth(float(rect.width())) doc.setHtml(text) # draw the contents painter.translate(rect.x(), rect.y()) doc.drawContents( painter, QtCore.QRectF(0, 0, float(rect.width()), float(rect.height()))) painter.translate(-rect.x(), -rect.y()) else: if type(text).__name__ not in ('str', 'unicode', 'QString'): text = nativestring(text) metrics = QtGui.QFontMetrics(option.font) text = metrics.elidedText( text, QtCore.Qt.TextElideMode(option.textElideMode), rect.width()) painter.setFont(option.font) painter.drawText(rect, int(option.displayAlignment), text)
def __init__(self, parent): super(XListGroupItem, self).__init__(parent) # define the text property self._text = '' self._expanded = True self._children = set() # define the widget for this item lwidget = self.listWidget() btn = QtGui.QToolButton(lwidget) btn.setAutoRaise(True) btn.setToolButtonStyle(QtCore.Qt.ToolButtonTextBesideIcon) btn.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Preferred) ico = 'img/treeview/triangle_down.png' btn.setIcon(QtGui.QIcon(resources.find(ico))) font = btn.font() font.setBold(True) btn.setFont(font) lwidget.setItemWidget(self, btn) # create connections btn.clicked.connect(self.toggle)
def __init__(self, parent=None): super(XOverlayWidget, self).__init__(parent) # define custom properties self._centralWidget = None self._result = None self._closable = True self._closeAlignment = QtCore.Qt.AlignTop | QtCore.Qt.AlignRight self._closeButton = XToolButton(self) self._closeButton.setShadowed(True) self._closeButton.setIcon( QtGui.QIcon(resources.find('img/overlay/close.png'))) self._closeButton.setIconSize(QtCore.QSize(24, 24)) self._closeButton.setToolTip('Close') # create the coloring for the overlay palette = self.palette() clr = QtGui.QColor('#222222') clr.setAlpha(210) palette.setColor(palette.Window, clr) self.setPalette(palette) self.setAutoFillBackground(True) # listen to the parents event filter parent.installEventFilter(self) # initialize the widget self.hide() self.move(0, 0) self.resize(parent.size()) self._closeButton.clicked.connect(self.reject)
def updateUi(self): if self.uiRecordBTN.isChecked(): ico = resources.find('img/debug/break.png') clr = QtGui.QColor('red') self.uiRecordBTN.blink(True) else: ico = resources.find('img/debug/continue.png') clr = QtGui.QColor('blue') self.uiRecordBTN.blink(False) self.uiRecordBTN.setIcon(QtGui.QIcon(ico)) palette = self.uiRecordBTN.palette() palette.setColor(palette.Shadow, clr) self.uiRecordBTN.setPalette(palette)
def initGroupStyle(self, useIcons=True, columnCount=None): """ Initialzes this item with a grouping style option. """ flags = self.flags() if flags & QtCore.Qt.ItemIsSelectable: flags ^= QtCore.Qt.ItemIsSelectable self.setFlags(flags) if useIcons: ico = QtGui.QIcon(resources.find('img/treeview/triangle_right.png')) expand_ico = QtGui.QIcon(resources.find('img/treeview/triangle_down.png')) self.setIcon(0, ico) self.setExpandedIcon(0, expand_ico) palette = QtGui.QApplication.palette() line_clr = palette.color(palette.Mid) base_clr = palette.color(palette.Button) text_clr = palette.color(palette.ButtonText) gradient = QtGui.QLinearGradient() gradient.setColorAt(0.00, line_clr) gradient.setColorAt(0.03, line_clr) gradient.setColorAt(0.04, base_clr.lighter(105)) gradient.setColorAt(0.25, base_clr) gradient.setColorAt(0.96, base_clr.darker(105)) gradient.setColorAt(0.97, line_clr) gradient.setColorAt(1.00, line_clr) h = self._fixedHeight if not h: h = self.sizeHint(0).height() if not h: h = 18 gradient.setStart(0.0, 0.0) gradient.setFinalStop(0.0, h) brush = QtGui.QBrush(gradient) tree = self.treeWidget() columnCount = columnCount or (tree.columnCount() if tree else self.columnCount()) for i in range(columnCount): self.setForeground(i, text_clr) self.setBackground(i, brush)
def startLoading(self): """ Updates this item to mark the item as loading. This will create a QLabel with the loading ajax spinner to indicate that progress is occurring. """ if self._loading: return False tree = self.treeWidget() if not tree: return self._loading = True self.setText(0, '') # create the label for this item lbl = QtGui.QLabel(self.treeWidget()) lbl.setMovie(XLoaderWidget.getMovie()) lbl.setAlignment(QtCore.Qt.AlignCenter) tree.setItemWidget(self, 0, lbl) try: tree.loadStarted.emit(self) except AttributeError: pass return True
def drawCheck(self, painter, option, rect, state): """ Renders a check indicator within the rectangle based on the inputed \ check state. :param painter | <QtGui.QPainter> option | <QtGui.QStyleOptionViewItem> rect | <QtGui.QRect> state | <QtCore.Qt.CheckState> """ if not self.useCheckMaps(): return super(XTreeWidgetDelegate, self).drawCheck(painter, option, rect, state) pixmap = None if state == QtCore.Qt.Checked: pixmap = self.checkOnMap() elif state == QtCore.Qt.PartiallyChecked: pixmap = self.checkPartialMap() elif state == QtCore.Qt.Unchecked: pixmap = self.checkOffMap() if type(pixmap) in (str, unicode): pixmap = QtGui.QPixmap(pixmap) if not pixmap: return x = rect.x() + (rect.width() - 16) / 2.0 y = rect.y() + (rect.height() - 16) / 2.0 painter.drawPixmap(int(x), int(y), pixmap)
def setUnlockIcon(self, icon): """ Sets the unlock icon for this button. :param icon | <str> || <QtGui.QIcon> """ self._unlockIcon = QtGui.QIcon(icon)
def setHtml(self, column, html): """ Creates a label with the given HTML for this item and column. This method requires the item to be a part of the tree. :param column | <int> html | <unicode> :return <bool> | success """ tree = self.treeWidget() if not tree: return False lbl = tree.itemWidget(self, column) if not html and lbl: lbl.deleteLater() return True elif not lbl: lbl = QtGui.QLabel(tree) lbl.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction) lbl.setOpenExternalLinks(True) tree.setItemWidget(self, column, lbl) lbl.setText(html) return True
def __init__(self, parent, record): super(XLogRecordItem, self).__init__(parent) # set default properties self.setFixedHeight(22) created = datetime.datetime.fromtimestamp(record.created) self.setData(0, QtCore.Qt.DisplayRole, wrapVariant(record.levelname)) self.setData(1, QtCore.Qt.DisplayRole, wrapVariant(record.levelno)) self.setData(2, QtCore.Qt.DisplayRole, wrapVariant(record.name)) self.setData(3, QtCore.Qt.DisplayRole, wrapVariant(str(created))) self.setData(4, QtCore.Qt.DisplayRole, wrapVariant(record.message)) self.setData( 5, QtCore.Qt.DisplayRole, wrapVariant('% 10.4f' % (record.relativeCreated / 1000.0))) self.setData(6, QtCore.Qt.DisplayRole, wrapVariant(record.filename)) self.setData(7, QtCore.Qt.DisplayRole, wrapVariant(record.module)) self.setData(8, QtCore.Qt.DisplayRole, wrapVariant(record.funcName)) self.setData(9, QtCore.Qt.DisplayRole, wrapVariant(record.lineno)) self.setData(10, QtCore.Qt.DisplayRole, wrapVariant(record.pathname)) self.setData(11, QtCore.Qt.DisplayRole, wrapVariant(record.process)) self.setData(12, QtCore.Qt.DisplayRole, wrapVariant(record.processName)) self.setData(13, QtCore.Qt.DisplayRole, wrapVariant(record.thread)) self.setData(14, QtCore.Qt.DisplayRole, wrapVariant(record.threadName)) clr = XLogRecordItem.Colors.get(record.levelno) if clr: for i in range(self.columnCount()): self.setForeground(i, QtGui.QColor(clr)) # create custom properties self._record = record
def setMovie(self, column, movie): """ Sets the movie that will play for the given column. :param column | <int> movie | <QtGui.QMovie> || None """ curr = self._movies.get(column) if curr == movie: return True else: try: curr.frameChanged.disconnect(self._updateFrame) except StandardError: pass if movie is not None: self.requireCleanup() self._movies[column] = movie self.setIcon(column, QtGui.QIcon(movie.currentPixmap())) try: movie.frameChanged.connect(self._updateFrame, QtCore.Qt.UniqueConnection) except StandardError: pass else: self._movies.pop(column, None)
def setGridPen(self, gridPen): """ Sets the pen that will be used when drawing the grid lines. :param gridPen | <QtGui.QPen> || <QtGui.QColor> """ self._gridPen = QtGui.QPen(gridPen)
def _updateFrame(self): """ Updates the frame for the given sender. """ mov = self.movie() if mov: self.setIcon(QtGui.QIcon(mov.currentPixmap()))
def setExpandedIcon( self, column, icon ): """ Sets the icon to be used when the item is expanded. :param column | <int> icon | <QtGui.QIcon> || None """ self._expandedIcon[column] = QtGui.QIcon(icon)
def setCheckPartialMap(self, pixmap): """ Sets the pixmap to be used when rendering a check state in the \ partial state. :param pixmap | <QtGui.QPixmap> || <str> || None """ self._checkPartialMap = QtGui.QPixmap(pixmap)
def __init__(self, parent): super(XLogRecordView, self).__init__(parent) # define custom properties self._logger = XLogRecordWidget(self) layout = QtGui.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._logger) self.setLayout(layout)
def setHoverIcon( self, column, icon ): """ Returns the icon to use when coloring when the user hovers over the item for the given column. :param column | <int> icon | <QtGui.QIcon) """ self._hoverIcon[column] = QtGui.QIcon(icon)
def setHoverForeground( self, column, brush ): """ Returns the brush to use when coloring when the user hovers over the item for the given column. :param column | <int> brush | <QtGui.QBrush> """ self._hoverForeground[column] = QtGui.QBrush(brush)
def setIconOverlay(self, column, icon): """ Sets the icon overlay for this item at the inputed column to the given icon. :param column | <int> icon | <str> || <QtGui.QIcon> """ self._iconOverlays[column] = QtGui.QIcon(icon)
def setCentralWidget(self, widget): """ Sets the central widget for this overlay to the inputed widget. :param widget | <QtGui.QWidget> """ self._centralWidget = widget if widget is not None: widget.setParent(self) widget.installEventFilter(self) # create the drop shadow effect effect = QtGui.QGraphicsDropShadowEffect(self) effect.setColor(QtGui.QColor('black')) effect.setBlurRadius(80) effect.setOffset(0, 0) widget.setGraphicsEffect(effect)
def setForeground(self, column, brush): """ Sets the default item foreground brush. :param brush | <QtGui.QBrush> || None """ if brush: self._foreground[column] = QtGui.QBrush(brush) elif column in self._background: self._foreground.pop(column)
def __init__(self, editor): super(XNumberArea, self).__init__(editor) self._codeEditor = editor # set default properties font = QtGui.QFont() font.setPointSize(8) font.setFamily('Courier New') self.setFont(font)
def updateUi(self): if self.logger() == 'root': log = logging.getLogger() else: log = logging.getLogger(self.logger()) level = log.level if self.treeWidget().loggerWidget().hasLogger(self.logger()): checked = QtCore.Qt.Checked fg = QtGui.QColor('black') else: checked = QtCore.Qt.Unchecked fg = QtGui.QColor('gray') self.setCheckState(0, checked) self.setForeground(0, fg) self.setForeground(1, fg) text = XLoggerTreeWidget.LoggingMap.get(level, ('', ''))[0] self.setText(1, projex.text.pretty(text))
def __init__(self, parent=None): super(XSearchEdit, self).__init__(parent) # setup default properties self.setHint('enter search') self.setIcon(QtGui.QIcon(resources.find('img/search.png'))) self.setCornerRadius(8) # setup custom properties self._cancelButton = XToolButton(self) self._cancelButton.setIcon( QtGui.QIcon(resources.find('img/remove_dark.png'))) self._cancelButton.setToolTip('Clear Search Text') self._cancelButton.setShadowed(True) self._cancelButton.hide() self.addButton(self._cancelButton, QtCore.Qt.AlignRight) # create connections self._cancelButton.clicked.connect(self.clear) self.textChanged.connect(self.toggleCancelButton)
def __init__(self, parent): super(XScriptView, self).__init__(parent) # define custom properties self._edit = XCodeEdit(self) self._edit.setLanguage('Python') layout = QtGui.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._edit) self.setLayout(layout)
def setPage(self, pageId, page): """ Sets the page and id for the given page vs. auto-constructing it. This will allow the developer to create a custom order for IDs. :param pageId | <int> page | <projexui.widgets.xoverlaywizard.XOverlayWizardPage> """ page.setParent(self) # create the drop shadow effect effect = QtGui.QGraphicsDropShadowEffect(page) effect.setColor(QtGui.QColor('black')) effect.setBlurRadius(50) effect.setOffset(0, 0) page.setGraphicsEffect(effect) self._pages[pageId] = page if self._startId == -1: self._startId = pageId
def __init__(self, parent): super(XConsoleView, self).__init__(parent) # define custom properties self._console = XConsoleEdit(self) layout = QtGui.QHBoxLayout() layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(self._console) self.setLayout(layout) self.initialized.connect(self.setupConsole)