def __init__(self, parent): super(XWalkthroughWidget, self).__init__(parent) # setup the properties self.setAutoFillBackground(True) self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) self.setFocusPolicy(QtCore.Qt.StrongFocus) self.setMouseTracking(True) # install the event filter parent.installEventFilter(self) # define child widgets self._direction = QtGui.QBoxLayout.TopToBottom self._slideshow = XStackedWidget(self) self._previousButton = XWalkthroughButton('Previous', self) self._nextButton = XWalkthroughButton('Finish', self) self._previousButton.hide() self.resize(parent.size()) # setup look for the widget clr = QtGui.QColor('black') clr.setAlpha(120) palette = self.palette() palette.setColor(palette.Window, clr) palette.setColor(palette.WindowText, QtGui.QColor('white')) self.setPalette(palette) # create connections self._slideshow.currentChanged.connect(self.updateUi) self._previousButton.clicked.connect(self.goBack) self._nextButton.clicked.connect(self.goForward)
def paintEvent(self, event): super(XMdiSubWindow, self).paintEvent(event) palette = self.palette() # draw the title with XPainter(self) as painter: painter.setRenderHint(QtGui.QPainter.Antialiasing) painter.setPen(self.titleBarBorder()) painter.setBrush(self.titleBarBackground()) painter.drawRect(0, 0, self.width(), 29) grad = QtGui.QLinearGradient() grad.setColorAt(0, QtGui.QColor(255, 255, 255, 30)) grad.setColorAt(1, QtGui.QColor(0, 0, 0, 28)) grad.setStart(0, 0) grad.setFinalStop(0, 30) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(grad) painter.drawRect(0, 0, self.width(), 30) # draw the text painter.setFont(self.titleBarFont()) bg = self.titleBarBackground() painter.setPen(bg.lighter(110)) painter.drawText(45, 1, self.width(), 30, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, self.windowTitle()) painter.setPen(self.titleBarForeground()) painter.drawText(45, 0, self.width(), 30, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, self.windowTitle())
def __init__(self, text, parent=None): super(XWalkthroughButton, self).__init__(text, parent) font = self.font() font.setBold(True) self.setFont(font) palette = self.palette() palette.setColor(palette.Highlight, QtGui.QColor('#3EBDFF')) palette.setColor(palette.HighlightedText, QtGui.QColor('white')) palette.setColor(palette.Button, QtGui.QColor('#4070FF')) palette.setColor(palette.ButtonText, QtGui.QColor('white')) self.setPalette(palette) self.setFont(font) self.setFixedSize(150, 30)
def setupSplash(self, pixmap, align=None, color='white', cls=None): """ Sets up a splash screen for the application for the given pixmap. :param pixmap | <QtGui.QPixmap> align | <QtCore.Qt.Alignment> color | <QtGui.QColor> cls | <subclass of QtGui.QSplashScreen> :return <QtGui.QSplashScreen> """ if cls is None: cls = XLoggerSplashScreen if align is None: align = QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom color = QtGui.QColor('white') pixmap = QtGui.QPixmap(pixmap) screen = cls(splash) screen.setTextColor(color) screen.setTextAlignment(align) screen.show() self.processEvents() self._splash = screen return screen
def addToGroup(self, item): """ Adds the inputed item to this group. :param item | <QtGui.QGraphicsItem> """ effect = QtGui.QGraphicsDropShadowEffect(self.scene()) effect.setColor(QtGui.QColor('black')) effect.setOffset(0, 0) effect.setBlurRadius(40) item.setGraphicsEffect(effect) item.setParentItem(self) super(XWalkthroughGraphic, self).addToGroup(item)
def updateUi(self): if not self.isClickable(): return effect = self.graphicsEffect() if isinstance(effect, QtGui.QGraphicsDropShadowEffect): palette = self.palette() transparent = QtGui.QColor(0, 0, 0, 0) clr = palette.color(palette.Shadow) show = self.isChecked() and self.isEnabled() effect.setColor(transparent if not show else clr) elif isinstance(effect, QtGui.QGraphicsColorizeEffect): effect.setStrength(1 if self.isChecked() else 0)
def timerEvent(self, event): effect = self.graphicsEffect() if not (effect and self.isBlinking()): self.killTimer(event.timerId()) elif isinstance(effect, QtGui.QGraphicsDropShadowEffect): palette = self.palette() transparent = QtGui.QColor(0, 0, 0, 0) clr = palette.color(palette.Shadow) if effect.color() == transparent: effect.setColor(clr) else: effect.setColor(transparent) elif isinstance(effect, QtGui.QGraphicsColorizeEffect): effect.setStrength(int(not effect.strength()))
def update(self, enabled=None): """ Updates this item based on the interface. """ if enabled is None: enabled = self.checkState(0) == QtCore.Qt.Checked elif not enabled or self._element.get('enabled', 'True') != 'True': self.setCheckState(0, QtCore.Qt.Unchecked) else: self.setCheckState(0, QtCore.Qt.Checked) if enabled: self.setForeground(0, QtGui.QBrush()) else: self.setForeground(0, QtGui.QBrush(QtGui.QColor('lightGray'))) for child in self.children(): child.update(enabled)
def restoreValue(self, xelem): """ Stores the value for the inptued instance to the given xml element. :param xelem | <xml.etree.Element> :return <variant> """ typ = xelem.get('type') if typ == 'color': return QtGui.QColor(xelem.text) elif typ == 'point': return QtCore.QPoint(*map(int, xelem.text.split(','))) elif typ == 'pointf': return QtCore.QPointF(*map(float, xelem.text.split(','))) elif typ == 'rect': return QtCore.QRectF(*map(int, xelem.text.split(','))) elif typ == 'rectf': return QtCore.QRectF(*map(float, xelem.text.split(','))) elif typ == 'bytea': return QtCore.QByteArray(cPickle.loads(xelem.text)) elif typ == 'pickle': return cPickle.loads(xelem.text) elif typ == 'xml': return xelem[0] elif typ in ('str', 'unicode'): return xelem.text else: try: return eval('{0}({1})'.format(typ, xelem.text)) except: return None
def setShadowed(self, state): self._shadowed = state if state: self._colored = False effect = QtGui.QGraphicsDropShadowEffect(self) effect.setColor(QtGui.QColor(0, 0, 0, 0)) effect.setOffset(0, 0) effect.setBlurRadius(self.shadowRadius()) self.setGraphicsEffect(effect) if self.isClickable(): self.setStyleSheet(CLICKABLE_SHEET) else: self.setStyleSheet(UNCLICKABLE_SHEET) self.updateUi() else: self.setStyleSheet('') self.setGraphicsEffect(None) self.blink(False)
def paintEvent(self, event): with XPainter(self) as painter: if self.isHovered(): alpha = 120 else: alpha = 30 x = 0 y = 0 w = self.width() - 1 h = self.height() - 1 clr = QtGui.QColor(self.background()) clr.setAlpha(alpha) brush = QtGui.QBrush(clr) painter.setPen(self.foreground()) painter.setBrush(brush) painter.drawRect(x, y, w, h) painter.drawText(x, y, w, h, QtCore.Qt.AlignCenter | QtCore.Qt.TextWordWrap, self.text())
def setTheme(self, theme): if theme == XCodeHighlighter.Theme.Default: # create the default keyword format form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor('blue')) self._formats[XCodeHighlighter.Style.Keyword] = form # create the default comment format form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor('green')) self._formats[XCodeHighlighter.Style.Comment] = form # create the default string format form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor('brown')) self._formats[XCodeHighlighter.Style.String] = form # create the class format form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor('darkMagenta')) form.setFontWeight(QtGui.QFont.Bold) self._formats[XCodeHighlighter.Style.Class] = form # create the function format form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor('darkMagenta')) form.setFontWeight(QtGui.QFont.Bold) self._formats[XCodeHighlighter.Style.Function] = form elif theme == XCodeHighlighter.Theme.Dark: opts = [] opts.append((self.Style.Keyword, '#2da4ff', False)) opts.append((self.Style.String, 'orange', False)) opts.append((self.Style.Comment, '#10ff00', False)) opts.append((self.Style.Class, '#f7ffc1', True)) opts.append((self.Style.Function, '#f7ffc1', True)) for style, clr, bold in opts: form = QtGui.QTextCharFormat() form.setForeground(QtGui.QColor(clr)) if bold: form.setFontWeight(QtGui.QFont.Bold) self._formats[style] = form
def addText(self, text, width=None): """ Adds a simple text item to this group. :param text | <str> maximumWidth | <float> || None maximumHeight | <float> || None """ item = QtGui.QGraphicsTextItem() font = item.font() font.setFamily('Arial') font.setPointSize(12) item.setFont(font) item.setHtml(text) item.setDefaultTextColor(QtGui.QColor('white')) self.addToGroup(item) item.graphicsEffect().setBlurRadius(8) if width: item.setTextWidth(width) return item
def setup(applicationName, applicationType=None, style='plastique', splash='', splashType=None, splashTextColor='white', splashTextAlign=None, theme=''): """ Wrapper system for the QApplication creation process to handle all proper pre-application setup. This method will verify that there is no application running, creating one if necessary. If no application is created, a None value is returned - signaling that there is already an app running. If you need to specify your own QApplication subclass, you can do so through the applicationType parameter. :note This method should always be used with the exec_ method to handle the post setup process. :param applicationName | <str> applicationType | <subclass of QApplication> || None style | <str> || <QStyle> | style to use for the new app splash | <str> | filepath to use for a splash screen splashType | <subclass of QSplashScreen> || None splashTextColor | <str> || <QColor> splashTextAlign | <Qt.Alignment> :usage |import projexui | |def main(argv): | # initialize the application | data = projexui.setup() | | # do some initialization code | window = MyWindow() | window.show() | | # execute the application | projexui.exec_(window, data) :return { <str> key: <variant> value, .. } """ import_qt(globals()) output = {} # check to see if there is a qapplication running if not QtGui.QApplication.instance(): # make sure we have a valid QApplication type if applicationType is None: applicationType = QtGui.QApplication app = applicationType([applicationName]) app.setApplicationName(applicationName) app.setQuitOnLastWindowClosed(True) stylize(app, style=style, theme=theme) # utilized with the projexui.config.xschemeconfig app.setProperty('useScheme', wrapVariant(True)) output['app'] = app # create a new splash screen if desired if splash: if not splashType: splashType = XLoggerSplashScreen pixmap = QtGui.QPixmap(splash) screen = splashType(pixmap) if splashTextAlign is None: splashTextAlign = QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom screen.setTextColor(QtGui.QColor(splashTextColor)) screen.setTextAlignment(splashTextAlign) screen.show() QtGui.QApplication.instance().processEvents() output['splash'] = screen return output
def __init__(self, parent, windowFlags=0): windowFlags = QtCore.Qt.WindowFlags(windowFlags) super(XMdiSubWindow, self).__init__(parent, windowFlags) # define custom properties palette = self.palette() font = self.font() font.setBold(True) font.setPointSize(font.pointSize() + 2) self._titleBarFont = font self._titleBarBackground = palette.color(palette.Button) self._titleBarForeground = palette.color(palette.ButtonText) self._titleBarBorder = QtGui.QColor('black') # create the drop shadow effect eff = QtGui.QGraphicsDropShadowEffect(self) eff.setOffset(0, 0) eff.setBlurRadius(40) eff.setColor(palette.color(palette.Shadow)) self.setGraphicsEffect(eff) # create the control buttons self._sysmenuBtn = XToolButton(self) self._sysmenuBtn.setIcon(self.windowIcon()) self._sysmenuBtn.setPalette(palette) self._sysmenuBtn.setAutoRaise(True) self._sysmenuBtn.setFixedSize(QtCore.QSize(22, 22)) self._sysmenuBtn.move(4, 4) self._sysmenuBtn.show() palette.setColor(palette.Shadow, QtGui.QColor('yellow')) self._minimizeBtn = XToolButton(self) self._minimizeBtn.setIcon( QtGui.QIcon(resources.find('img/mdiarea/minimize.png'))) self._minimizeBtn.setPalette(palette) self._minimizeBtn.setShadowed(True) self._minimizeBtn.setShadowRadius(10) self._minimizeBtn.setFixedSize(QtCore.QSize(22, 22)) self._minimizeBtn.show() palette.setColor(palette.Shadow, QtGui.QColor('orange')) self._maximizeBtn = XToolButton(self) self._maximizeBtn.setIcon( QtGui.QIcon(resources.find('img/mdiarea/maximize.png'))) self._maximizeBtn.setPalette(palette) self._maximizeBtn.setShadowed(True) self._maximizeBtn.setShadowRadius(10) self._maximizeBtn.setFixedSize(QtCore.QSize(22, 22)) self._maximizeBtn.show() palette.setColor(palette.Shadow, QtGui.QColor('red')) self._closeBtn = XToolButton(self) self._closeBtn.setIcon( QtGui.QIcon(resources.find('img/mdiarea/close.png'))) self._closeBtn.setPalette(palette) self._closeBtn.setShadowed(True) self._closeBtn.setShadowRadius(10) self._closeBtn.setFixedSize(QtCore.QSize(22, 22)) self._closeBtn.show() # create connections self._sysmenuBtn.clicked.connect(self.showSystemMenu) self._minimizeBtn.clicked.connect(self.toggleMinimized) self._maximizeBtn.clicked.connect(self.toggleMaximized) self._closeBtn.clicked.connect(self.close)
registerWidgetValue(QtGui.QRadioButton, lambda w: w.isChecked(), lambda w, v: w.setChecked(bool(v))) registerWidgetValue(QtGui.QFontComboBox, lambda w: w.currentFont(), lambda w, v: w.setCurrentFont(v)) registerWidgetValue(XColorTreeWidget, lambda w: w.savedColorSet(), lambda w, v: w.setColorSet(v)) registerWidgetValue(XColorButton, lambda w: w.color(), lambda w, v: w.setColor(QtGui.QColor(v))) registerWidgetValue(XEnumBox, lambda w: w.currentValue(), lambda w, v: w.setCurrentValue(v)) registerWidgetValue(XLineEdit, lambda w: nativestring(w.currentText()), lambda w, v: w.setText(v)) registerWidgetValue(XLocationWidget, lambda w: w.location(), lambda w, v: w.setLocation(nativestring(v))) registerWidgetValue(XUrlWidget, lambda w: w.url(),