def __extract_complete(self, result, success): ''' triggered when the extraction thread completes. ''' if self.__executor is not None: if success: logger.info( f"Extraction complete for {self.outputFilename.text()}") self.ffmpegProgress.setValue(100) self.__extracted = True if not self.__is_remux: self.signalName.setEnabled(True) self.signalNameLabel.setEnabled(True) self.signalName.setText( Path(self.outputFilename.text()).resolve().stem) self.buttonBox.button( QDialogButtonBox.Ok).setText('Create Signals') else: logger.error( f"Extraction failed for {self.outputFilename.text()}") palette = QPalette(self.ffmpegProgress.palette()) palette.setColor(QPalette.Highlight, QColor(Qt.red)) self.ffmpegProgress.setPalette(palette) self.statusBar.showMessage('Extraction failed', 5000) self.ffmpegOutput.setPlainText(result) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(True) audio = self.__preferences.get(EXTRACTION_NOTIFICATION_SOUND) if audio is not None: logger.debug(f"Playing {audio}") self.__sound = QSound(audio) self.__sound.play()
def __extract_started(self): ''' Changes the UI to signal that extraction has started ''' self.inputFilePicker.setEnabled(False) self.audioStreams.setEnabled(False) self.videoStreams.setEnabled(False) self.channelCount.setEnabled(False) self.lfeChannelIndex.setEnabled(False) self.monoMix.setEnabled(False) self.bassManage.setEnabled(False) self.decimateAudio.setEnabled(False) self.audioFormat.setEnabled(False) self.eacBitRate.setEnabled(False) self.includeOriginalAudio.setEnabled(False) self.includeSubtitles.setEnabled(False) self.targetDirPicker.setEnabled(False) self.outputFilename.setEnabled(False) self.filterMapping.setEnabled(False) self.gainOffset.setEnabled(False) self.ffmpegOutput.setEnabled(True) self.ffmpegProgress.setEnabled(True) self.ffmpegProgressLabel.setEnabled(True) self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) palette = QPalette(self.ffmpegProgress.palette()) palette.setColor(QPalette.Highlight, QColor(Qt.green)) self.ffmpegProgress.setPalette(palette)
def __init__(self, *args): QFrame.__init__(self, *args) self.setFrameStyle(QFrame.Box | QFrame.Raised) self.setLineWidth(2) self.setMidLineWidth(3) p = QPalette() p.setColor(self.backgroundRole(), QColor(30, 30, 50)) self.setPalette(p) # make curves and maps self.tuples = [] # curve 1 curve = QwtPlotCurve() curve.setPen(QPen(QColor(150, 150, 200), 2)) curve.setStyle(QwtPlotCurve.Lines) curve.setSymbol( QwtSymbol(QwtSymbol.XCross, QBrush(), QPen(Qt.yellow, 2), QSize(7, 7))) self.tuples.append( (curve, QwtScaleMap(0, 100, -1.5, 1.5), QwtScaleMap(0, 100, 0.0, 2 * np.pi))) # curve 2 curve = QwtPlotCurve() curve.setPen(QPen(QColor(200, 150, 50), 1, Qt.DashDotDotLine)) curve.setStyle(QwtPlotCurve.Sticks) curve.setSymbol( QwtSymbol(QwtSymbol.Ellipse, QBrush(Qt.blue), QPen(Qt.yellow), QSize(5, 5))) self.tuples.append( (curve, QwtScaleMap(0, 100, 0.0, 2 * np.pi), QwtScaleMap(0, 100, -3.0, 1.1))) # curve 3 curve = QwtPlotCurve() curve.setPen(QPen(QColor(100, 200, 150))) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append( (curve, QwtScaleMap(0, 100, -1.1, 3.0), QwtScaleMap(0, 100, -1.1, 3.0))) # curve 4 curve = QwtPlotCurve() curve.setPen(QPen(Qt.red)) curve.setStyle(QwtPlotCurve.Lines) self.tuples.append( (curve, QwtScaleMap(0, 100, -5.0, 1.1), QwtScaleMap(0, 100, -1.1, 5.0))) # data self.phase = 0.0 self.base = np.arange(0.0, 2.01 * np.pi, 2 * np.pi / (USize - 1)) self.uval = np.cos(self.base) self.vval = np.sin(self.base) self.uval[1::2] *= 0.5 self.vval[1::2] *= 0.5 self.newValues() # start timer self.tid = self.startTimer(250)
def calc_error_palette(self) -> QPalette: """Palette with red background, used for widgets with invalid input.""" error_palette = QPalette(self.palette()) bg = error_palette.color(QPalette.Base) red = QColor(qc.Qt.red) red_bg = blend_colors(bg, red, 0.5) error_palette.setColor(QPalette.Base, red_bg) return error_palette
def load(self): """Load palette and stylesheet from the plugin't settings""" self.editor.setPlainText( self.plugin.settings['_style'] or '', 'text/plain', 'utf8' ) palette = self.plugin.settings['_palette'] if palette is not None: self._palette = QPalette(palette) self.update_palette_controls()
def _on_color_pick(self, key, color): """Callback when a palette color has been picked""" if self.cbo_mode.currentText() == 'basic': # Other values should be auto-generated self._palette = QPalette(self.pickers['basic']['Window'].color) self._palette.setColor( getattr(self._palette, key), color )
def _handle_mouse_moved(self, pos): """Show tooltip at mouse move.""" if not self._show_tooltip: return # create label tooltip, if needed if not hasattr(self, 'label_tooltip'): self.label_tooltip = QLabel(self, Qt.ToolTip) self.timer_tooltip = QTimer(self) self.timer_tooltip.timeout.connect(self.label_tooltip.hide) self.timer_tooltip.setInterval(1000) # find nearest curve point nearest = (self._curves[0], _np.inf, None, None) for idx, curve in enumerate(self._curves): if not curve.isVisible(): continue mappos = curve.mapFromScene(pos) posx, posy = mappos.x(), mappos.y() xData, yData = curve.curve.xData, curve.curve.yData if not xData.size: continue diffx = xData - posx idx = _np.argmin(_np.abs(diffx)) if diffx[idx] < 0.5: valx, valy = xData[idx], yData[idx] diffy = abs(valy - posy) if diffy < nearest[1]: nearest = (curve, diffy, valx, valy) # show tooltip curve, diffy, valx, valy = nearest ylimts = self.getViewBox().state['viewRange'][1] ydelta = ylimts[1] - ylimts[0] if diffy < 1e-2 * ydelta: txt = Time(timestamp=valx).get_iso8601() + '\n' txt += f'{curve.name()}: {valy:.3f}' font = QApplication.instance().font() font.setPointSize(font.pointSize() - 10) palette = QPalette() palette.setColor(QPalette.WindowText, curve.color) self.label_tooltip.setText(txt) self.label_tooltip.setFont(font) self.label_tooltip.setPalette(palette) self.label_tooltip.move(self.mapToGlobal(pos.toPoint())) self.label_tooltip.show() self.timer_tooltip.start() curve.scatter.setData(pos=[ (valx, valy), ], symbol='o', size=15, brush=mkBrush(curve.color)) curve.scatter.show()
def set_palette(self, background, foreground): """ Set text editor palette colors: background color and caret (text cursor) color """ palette = QPalette() palette.setColor(QPalette.Base, background) palette.setColor(QPalette.Text, foreground) self.setPalette(palette) # Set the right background color when changing color schemes # or creating new Editor windows. This seems to be a Qt bug. # Fixes Issue 2028 and 8069 if self.objectName(): style = "QPlainTextEdit#%s {background: %s; color: %s;}" % \ (self.objectName(), background.name(), foreground.name()) self.setStyleSheet(style)
def updateDepth(self, depth): ## Change item's appearance based on its depth in the tree ## This allows highest-level groups to be displayed more prominently. if depth == 0: for c in [0, 1]: self.setBackground(c, QBrush(QPalette().color(QPalette.Light))) # self.setForeground(c, QBrush(QPalette().color(QPalette.Dark))) font = self.font(c) font.setBold(True) font.setPointSize(font.pointSize() + 1) self.setFont(c, font) self.setSizeHint(0, QSize(0, 25)) else: for c in [0, 1]: self.setBackground(c, QBrush(QPalette().color(QPalette.Light))) font = self.font(c) font.setBold(True) # font.setPointSize(font.pointSize()+1) self.setFont(c, font) self.setSizeHint(0, QSize(0, 20))
def setColour(self, colour): """ Set the colour of the ColourButton. `colour` can be either a QColor instance or any valid arg to QColor. See `QColor docs <https://doc.qt.io/qt-5/qcolor.html>_` for more details. """ if isinstance(colour, str): colour = QColor(colour) if not isinstance(colour, QColor): raise TypeError() self._colour = colour self.setPalette(QPalette(self._colour)) self.setAutoFillBackground(True)
def __init__(self, parent, packages, data): super(CondaPackagesModel, self).__init__(parent) self._parent = parent self._packages = packages self._rows = data self._name_to_index = {r[C.COL_NAME]: i for i, r in enumerate(data)} palette = QPalette() self._palette = { 'icon.upgrade.active': get_icon('conda_upgrade_active.png'), 'icon.upgrade.inactive': get_icon('conda_upgrade_inactive.png'), 'icon.upgrade.pressed': get_icon('conda_upgrade_pressed.png'), 'icon.downgrade.active': get_icon('conda_downgrade_active.png'), 'icon.downgrade.inactive': get_icon('conda_downgrade_inactive.png'), 'icon.downgrade.pressed': get_icon('conda_downgrade_pressed.png'), 'icon.add.active': get_icon('conda_add_active.png'), 'icon.add.inactive': get_icon('conda_add_inactive.png'), 'icon.add.pressed': get_icon('conda_add_pressed.png'), 'icon.remove.active': get_icon('conda_remove_active.png'), 'icon.remove.inactive': get_icon('conda_remove_inactive.png'), 'icon.remove.pressed': get_icon('conda_remove_pressed.png'), 'icon.action.not_installed': get_icon('conda_action_not_installed.png'), 'icon.action.installed': get_icon('conda_action_installed.png'), 'icon.action.installed_upgradable': get_icon('conda_action_installed_upgradable.png'), 'icon.action.remove': get_icon('conda_action_remove.png'), 'icon.action.add': get_icon('conda_action_add.png'), 'icon.action.upgrade': get_icon('conda_action_upgrade.png'), 'icon.action.downgrade': get_icon('conda_action_downgrade.png'), 'icon.upgrade.arrow': get_icon('conda_upgrade_arrow.png'), 'spacer': get_icon('spacer.png'), 'icon.python': get_icon('python.png').pixmap(QSize(16, 16)), 'icon.anaconda': get_icon('anaconda.png').pixmap(QSize(16, 16)), 'background.remove': QColor(128, 0, 0, 50), 'background.install': QColor(0, 128, 0, 50), 'background.upgrade': QColor(0, 0, 128, 50), 'background.downgrade': QColor(128, 0, 128, 50), 'foreground.not.installed': palette.color(QPalette.Mid), 'foreground.upgrade': QColor(0, 0, 128, 255), }
def __init__(self, parent=None): super(SvgView, self).__init__(parent) self.signal = NodeSignal() self.renderer = SvgView.Native self.__svg_items = [] self.__wrapper_item = None self.__svg_renderer = QSvgRenderer() self.setScene(QGraphicsScene(self)) self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse) self.setDragMode(QGraphicsView.ScrollHandDrag) self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate) self.setViewport(QWidget()) self.setBackgroundBrush( QBrush(QColor(QPalette().color(QPalette.Active, QPalette.Window))))
def __init__(self, plugin, ui, parent): super(StyleDialog, self).__init__(parent) self.ui = ui self.setWindowTitle(tr("Edit application styles")) self.plugin = plugin self._palette = QPalette() self._rows = {} i = 0 for entries in self.palette_entries.values(): for key in entries: self._rows[key] = i for pair in self.pairs: if key == pair[0]: break else: i += 1 self.create_controls() self.save_action = QtWidgets.QAction(self) self.save_action.setShortcut(QtGui.QKeySequence.Save) self.save_action.triggered.connect(self.save) self.addAction(self.save_action) self.load()
def set_palette(self, app): """Set the widget color palette on a QApplication.""" palette = QPalette() for style in self.styles: element = getattr(QPalette, style[0], None) if element: palette.setColor(element, style[1]) if len(style) == 3: palette.setColor(QPalette.Disabled, element, style[2]) app.setPalette(palette)
def validateString(self): string_to_validate = str(self.text()) if self._validator is not None: status = self._validator.validate(string_to_validate) palette = QPalette() if not status: palette.setColor(self.backgroundRole(), ValidationSupport.ERROR_COLOR) self.setPalette(palette) self._validation.setValidationMessage( str(status), ValidationSupport.EXCLAMATION) else: palette.setColor(self.backgroundRole(), self._valid_color) self.setPalette(palette) self._validation.setValidationMessage("")
def dark(app): """ Apply Dark Theme to the Qt application instance. Args: app (QApplication): QApplication instance. """ darkPalette = QPalette() # base darkPalette.setColor(QPalette.WindowText, QColor(180, 180, 180)) darkPalette.setColor(QPalette.Button, QColor(53, 53, 53)) darkPalette.setColor(QPalette.Light, QColor(180, 180, 180)) darkPalette.setColor(QPalette.Midlight, QColor(90, 90, 90)) darkPalette.setColor(QPalette.Dark, QColor(35, 35, 35)) darkPalette.setColor(QPalette.Text, QColor(180, 180, 180)) darkPalette.setColor(QPalette.BrightText, QColor(180, 180, 180)) darkPalette.setColor(QPalette.ButtonText, QColor(180, 180, 180)) darkPalette.setColor(QPalette.Base, QColor(42, 42, 42)) darkPalette.setColor(QPalette.Window, QColor(53, 53, 53)) darkPalette.setColor(QPalette.Shadow, QColor(20, 20, 20)) darkPalette.setColor(QPalette.Highlight, QColor(42, 130, 218)) darkPalette.setColor(QPalette.HighlightedText, QColor(180, 180, 180)) darkPalette.setColor(QPalette.Link, QColor(56, 252, 196)) darkPalette.setColor(QPalette.AlternateBase, QColor(66, 66, 66)) darkPalette.setColor(QPalette.ToolTipBase, QColor(53, 53, 53)) darkPalette.setColor(QPalette.ToolTipText, QColor(180, 180, 180)) # disabled darkPalette.setColor(QPalette.Disabled, QPalette.WindowText, QColor(127, 127, 127)) darkPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(127, 127, 127)) darkPalette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(127, 127, 127)) darkPalette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(80, 80, 80)) darkPalette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(127, 127, 127)) app.setPalette(darkPalette) _apply_base_theme(app)
def getPalette(): if config.theme in ("dark", "night"): palette = QPalette() palette.setColor(QPalette.Window, QColor(50, 50, 50)) palette.setColor(QPalette.WindowText, QColor(200, 200, 200)) palette.setColor(QPalette.Background, QColor(50, 50, 50)) palette.setColor(QPalette.Base, QColor(50, 50, 50)) palette.setColor(QPalette.AlternateBase, QColor(50, 50, 50)) palette.setColor(QPalette.ToolTipBase, QColor(50, 50, 50)) palette.setColor(QPalette.ToolTipText, QColor(200,200,200)) palette.setColor(QPalette.Text, QColor(200, 200, 200)) palette.setColor(QPalette.Button, QColor(50, 50, 50)) palette.setColor(QPalette.ButtonText, QColor(200, 200, 200)) palette.setColor(QPalette.BrightText, QColor(255,255,255)) palette.setColor(QPalette.Link, QColor(42, 130, 218)) palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) palette.setColor(QPalette.HighlightedText, QColor(50, 50, 50)) return palette else: palette = QPalette() # palette.setColor(QPalette.Background, QColor("white")) return palette
def data(self, index, role=Qt.DisplayRole): """Override Qt method""" if not index.isValid() or not 0 <= index.row() < len(self._rows): return to_qvariant() row = index.row() column = index.column() P = self._palette if self._rows[row] == row: action = C.ACTION_NONE type_ = u'' name = u'' description = u'' version = u'-' status = -1 # url = u'' # license_ = u'' i = False r = False u = False d = False # action_version = None else: action = self._rows[row][C.COL_ACTION] type_ = self._rows[row][C.COL_PACKAGE_TYPE] name = self._rows[row][C.COL_NAME] description = self._rows[row][C.COL_DESCRIPTION] version = self._rows[row][C.COL_VERSION] status = self._rows[row][C.COL_STATUS] # url = self._rows[row][C.COL_URL] # license_ = self._rows[row][C.COL_LICENSE] i = self._rows[row][C.COL_INSTALL] r = self._rows[row][C.COL_REMOVE] u = self._rows[row][C.COL_UPGRADE] d = self._rows[row][C.COL_DOWNGRADE] # action_version = self._rows[row][C.COL_ACTION_VERSION] is_upgradable = self.is_upgradable(self.index(row, C.COL_VERSION)) # if is_upgradable: # version += C.UPGRADE_SYMBOL if role == Qt.DisplayRole: if column == C.COL_PACKAGE_TYPE: return to_qvariant(type_) if column == C.COL_NAME: return to_qvariant(name) elif column == C.COL_VERSION: return to_qvariant(version) elif column == C.COL_STATUS: return to_qvariant(status) elif column == C.COL_DESCRIPTION: return to_qvariant(description) elif column == C.COL_ACTION: return to_qvariant(action) elif role == Qt.BackgroundRole: if action == C.ACTION_REMOVE: return to_qvariant(P['background.remove']) elif action == C.ACTION_INSTALL: return to_qvariant(P['background.install']) elif action == C.ACTION_UPGRADE: return to_qvariant(P['background.upgrade']) elif action == C.ACTION_DOWNGRADE: return to_qvariant(P['background.downgrade']) elif role == Qt.TextAlignmentRole: if column in [C.COL_NAME, C.COL_DESCRIPTION]: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) elif column in [C.COL_VERSION] and is_upgradable: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) # else: # return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) elif role == Qt.DecorationRole: if column == C.COL_ACTION: if action == C.ACTION_NONE: if status == C.NOT_INSTALLED: return to_qvariant(P['icon.action.not_installed']) elif status in [C.UPGRADABLE, C.MIXGRADABLE]: return to_qvariant(P['icon.action.installed']) elif status in [C.INSTALLED, C.DOWNGRADABLE, C.MIXGRADABLE]: return to_qvariant(P['icon.action.installed']) elif action == C.ACTION_INSTALL: return to_qvariant(P['icon.action.add']) elif action == C.ACTION_REMOVE: return to_qvariant(P['icon.action.remove']) elif action == C.ACTION_UPGRADE: return to_qvariant(P['icon.action.upgrade']) elif action == C.ACTION_DOWNGRADE: return to_qvariant(P['icon.action.downgrade']) else: return to_qvariant() elif column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return to_qvariant(P['icon.anaconda']) elif type_ == C.PIP_PACKAGE: return to_qvariant(P['icon.python']) else: return to_qvariant() elif column == C.COL_INSTALL: if status == C.NOT_INSTALLED: if i: return to_qvariant(P['icon.add.pressed']) else: return to_qvariant(P['icon.add.active']) elif (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): if r: return to_qvariant(P['icon.remove.pressed']) else: return to_qvariant(P['icon.remove.active']) else: return to_qvariant(P['icon.add.inactive']) elif column == C.COL_REMOVE: if (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): if r: return to_qvariant(P['icon.remove.pressed']) else: return to_qvariant(P['icon.remove.active']) else: return to_qvariant(P['icon.remove.inactive']) elif column == C.COL_UPGRADE: if status == C.UPGRADABLE or \ status == C.MIXGRADABLE: if u: return to_qvariant(P['icon.upgrade.pressed']) else: return to_qvariant(P['icon.upgrade.active']) else: return to_qvariant(P['icon.upgrade.inactive']) elif column == C.COL_DOWNGRADE: if status == C.DOWNGRADABLE or \ status == C.MIXGRADABLE: if d: return to_qvariant(P['icon.downgrade.pressed']) else: return to_qvariant(P['icon.downgrade.active']) else: return to_qvariant(P['icon.downgrade.inactive']) elif column == C.COL_VERSION: if is_upgradable: return to_qvariant(P['icon.upgrade.arrow']) else: return to_qvariant(P['spacer']) elif role == Qt.ToolTipRole: if column == C.COL_INSTALL and status == C.NOT_INSTALLED: return to_qvariant(_('Install package')) elif column == C.COL_INSTALL and (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Remove package')) elif column == C.COL_UPGRADE and (status == C.INSTALLED or status == C.UPGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Upgrade package')) elif column == C.COL_DOWNGRADE and (status == C.INSTALLED or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Downgrade package')) elif column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return to_qvariant(_('Conda package')) elif type_ == C.PIP_PACKAGE: return to_qvariant(_('Python package')) elif column == C.COL_VERSION: if is_upgradable: return to_qvariant(_('Update available')) elif role == Qt.ForegroundRole: palette = QPalette() if column in [C.COL_NAME, C.COL_DESCRIPTION]: if status in [C.INSTALLED, C.UPGRADABLE, C.DOWNGRADABLE, C.MIXGRADABLE]: color = palette.color(QPalette.WindowText) return to_qvariant(color) elif status in [C.NOT_INSTALLED]: color = palette.color(QPalette.Mid) color = P['foreground.not.installed'] return to_qvariant(color) elif column in [C.COL_VERSION]: if is_upgradable: return to_qvariant(P['foreground.upgrade']) elif role == Qt.SizeHintRole: if column in [C.ACTION_COLUMNS] + [C.COL_PACKAGE_TYPE]: return to_qvariant(QSize(24, 24)) return to_qvariant()
def data(self, index, role=Qt.DisplayRole): """Override Qt method""" if not index.isValid() or not 0 <= index.row() < len(self._rows): return to_qvariant() row = index.row() column = index.column() P = self._palette if self._rows[row] == row: action = C.ACTION_NONE type_ = u'' name = u'' description = u'' version = u'-' status = -1 # url = u'' # license_ = u'' i = False r = False u = False d = False # action_version = None else: action = self._rows[row][C.COL_ACTION] type_ = self._rows[row][C.COL_PACKAGE_TYPE] name = self._rows[row][C.COL_NAME] description = self._rows[row][C.COL_DESCRIPTION] version = self._rows[row][C.COL_VERSION] status = self._rows[row][C.COL_STATUS] # url = self._rows[row][C.COL_URL] # license_ = self._rows[row][C.COL_LICENSE] i = self._rows[row][C.COL_INSTALL] r = self._rows[row][C.COL_REMOVE] u = self._rows[row][C.COL_UPGRADE] d = self._rows[row][C.COL_DOWNGRADE] # action_version = self._rows[row][C.COL_ACTION_VERSION] is_upgradable = self.is_upgradable(self.index(row, C.COL_VERSION)) # if is_upgradable: # version += C.UPGRADE_SYMBOL if role == Qt.DisplayRole: if column == C.COL_PACKAGE_TYPE: return to_qvariant(type_) if column == C.COL_NAME: return to_qvariant(name) elif column == C.COL_VERSION: return to_qvariant(version) elif column == C.COL_STATUS: return to_qvariant(status) elif column == C.COL_DESCRIPTION: return to_qvariant(description) elif column == C.COL_ACTION: return to_qvariant(action) elif role == Qt.BackgroundRole: if action == C.ACTION_REMOVE: return to_qvariant(P['background.remove']) elif action == C.ACTION_INSTALL: return to_qvariant(P['background.install']) elif action == C.ACTION_UPGRADE: return to_qvariant(P['background.upgrade']) elif action == C.ACTION_DOWNGRADE: return to_qvariant(P['background.downgrade']) elif role == Qt.TextAlignmentRole: if column in [C.COL_NAME, C.COL_DESCRIPTION]: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) elif column in [C.COL_VERSION] and is_upgradable: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) else: return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) elif role == Qt.DecorationRole: if column == C.COL_ACTION: if action == C.ACTION_NONE: if status == C.NOT_INSTALLED: return to_qvariant(P['icon.action.not_installed']) elif status in [C.UPGRADABLE, C.MIXGRADABLE]: return to_qvariant(P['icon.action.installed']) elif status in [ C.INSTALLED, C.DOWNGRADABLE, C.MIXGRADABLE ]: return to_qvariant(P['icon.action.installed']) elif action == C.ACTION_INSTALL: return to_qvariant(P['icon.action.add']) elif action == C.ACTION_REMOVE: return to_qvariant(P['icon.action.remove']) elif action == C.ACTION_UPGRADE: return to_qvariant(P['icon.action.upgrade']) elif action == C.ACTION_DOWNGRADE: return to_qvariant(P['icon.action.downgrade']) else: return to_qvariant() elif column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return to_qvariant(P['icon.anaconda']) elif type_ == C.PIP_PACKAGE: return to_qvariant(P['icon.python']) else: return to_qvariant() elif column == C.COL_INSTALL: if status == C.NOT_INSTALLED: if i: return to_qvariant(P['icon.add.pressed']) else: return to_qvariant(P['icon.add.active']) elif (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): if r: return to_qvariant(P['icon.remove.pressed']) else: return to_qvariant(P['icon.remove.active']) else: return to_qvariant(P['icon.add.inactive']) elif column == C.COL_REMOVE: if (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): if r: return to_qvariant(P['icon.remove.pressed']) else: return to_qvariant(P['icon.remove.active']) else: return to_qvariant(P['icon.remove.inactive']) elif column == C.COL_UPGRADE: if status == C.UPGRADABLE or \ status == C.MIXGRADABLE: if u: return to_qvariant(P['icon.upgrade.pressed']) else: return to_qvariant(P['icon.upgrade.active']) else: return to_qvariant(P['icon.upgrade.inactive']) elif column == C.COL_DOWNGRADE: if status == C.DOWNGRADABLE or \ status == C.MIXGRADABLE: if d: return to_qvariant(P['icon.downgrade.pressed']) else: return to_qvariant(P['icon.downgrade.active']) else: return to_qvariant(P['icon.downgrade.inactive']) elif column == C.COL_VERSION and is_upgradable: return to_qvariant(P['icon.upgrade.arrow']) elif role == Qt.ToolTipRole: if column == C.COL_INSTALL and status == C.NOT_INSTALLED: return to_qvariant(_('Install package')) elif column == C.COL_INSTALL and (status == C.INSTALLED or status == C.UPGRADABLE or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Remove package')) elif column == C.COL_UPGRADE and (status == C.INSTALLED or status == C.UPGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Upgrade package')) elif column == C.COL_DOWNGRADE and (status == C.INSTALLED or status == C.DOWNGRADABLE or status == C.MIXGRADABLE): return to_qvariant(_('Downgrade package')) elif column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return to_qvariant(_('Conda package')) elif type_ == C.PIP_PACKAGE: return to_qvariant(_('Python package')) elif column == C.COL_VERSION: if is_upgradable: return to_qvariant(_('Update available')) elif role == Qt.ForegroundRole: palette = QPalette() if column in [C.COL_NAME, C.COL_DESCRIPTION]: if status in [ C.INSTALLED, C.UPGRADABLE, C.DOWNGRADABLE, C.MIXGRADABLE ]: color = palette.color(QPalette.WindowText) return to_qvariant(color) elif status in [C.NOT_INSTALLED]: color = palette.color(QPalette.Mid) color = P['foreground.not.installed'] return to_qvariant(color) elif column in [C.COL_VERSION]: if is_upgradable: return to_qvariant(P['foreground.upgrade']) elif role == Qt.SizeHintRole: if column in [C.ACTION_COLUMNS] + [C.COL_PACKAGE_TYPE]: return to_qvariant(QSize(24, 24)) return to_qvariant()
def __init__(self, data, win_parent=None): """ +-----------------+ | Edit Node Props | +-----------------+------+ | LEwingTip | | Node2 | | Node3 | | Node4 | | | | All Nodes: | | Color red | | PointSize 3 | | Opacity 0.3 | | Show/Hide | | | | Name LEwingTip | | Location X Y Z | | Coord 0 | | CoordType R, C, S | | | | Previous Next | | | | Close | +------------------------+ """ QDialog.__init__(self, win_parent) self.setWindowTitle('Edit Node Properties') #default self.win_parent = win_parent self.out_data = data point_properties = data['point_properties'] print(point_properties) #name = point_properties.name point_size = point_properties.point_size opacity = point_properties.opacity color = point_properties.color show = point_properties.is_visible self.points = data['points'] self.keys = sorted(self.points.keys()) keys = self.keys #nrows = len(keys) active_point = data['active_point'] #self.active_key = keys[0] self.active_key = active_point name = self.active_key description = self.points[self.active_key][0] self._use_old_table = False items = ['Node %i' % val for val in keys] header_labels = ['Nodes'] table_model = Model(items, header_labels, self) view = SingleChoiceQTableView(self) #Call your custom QTableView here view.setModel(table_model) view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table = view #self.representation = actor_obj.representation #print('rep =', self.representation) table = self.table #headers = [QtCore.QString('Groups')] header = table.horizontalHeader() header.setStretchLastSection(True) #---------------------------------------------- #self._default_is_apply = False self.color = QLabel("Color:") self.color_edit = QPushButton() #self.color_edit.setFlat(True) color = self.out_data['point_properties'].color opacity = self.out_data['point_properties'].opacity show = self.out_data['point_properties'].is_visible #color = self.out_data[self.active_key].color qcolor = QColor() qcolor.setRgb(*color) #print('color =%s' % str(color)) palette = QPalette( self.color_edit.palette()) # make a copy of the palette #palette.setColor(QPalette.Active, QPalette.Base, \ #qcolor) palette.setColor(QPalette.Background, QColor('blue')) # ButtonText self.color_edit.setPalette(palette) self.color_edit.setStyleSheet("QPushButton {" "background-color: rgb(%s, %s, %s);" % tuple(color) + #"border:1px solid rgb(255, 170, 255); " "}") self.all_nodes_header = QLabel("All Nodes:") self.point_size = QLabel("Point Size:") self.point_size_edit = QSpinBox(self) self.point_size_edit.setRange(1, 10) self.point_size_edit.setSingleStep(1) self.point_size_edit.setValue(point_size) self.opacity = QLabel("Opacity:") self.opacity_edit = QDoubleSpinBox(self) self.opacity_edit.setRange(0.1, 1.0) self.opacity_edit.setDecimals(1) self.opacity_edit.setSingleStep(0.1) self.opacity_edit.setValue(opacity) # show/hide self.checkbox_show = QCheckBox("Show") self.checkbox_hide = QCheckBox("Hide") self.checkbox_show.setChecked(show) self.checkbox_hide.setChecked(not show) #---------------------------------------------- self.nodes_header = QLabel("Single Node:") self.name = QLabel("ID:") self.name_edit = QLineEdit('Node %i' % name) self.name_edit.setDisabled(True) self.description = QLabel("Description:") self.description_edit = QLineEdit(str(description)) #self.description_edit.setDisabled(True) location_x = 0.1 location_y = 0.1 location_z = 0.1 self.location = QLabel("Location:") self.location_x_edit = QDoubleSpinBox(self) self.location_y_edit = QDoubleSpinBox(self) self.location_z_edit = QDoubleSpinBox(self) #self.location_x_edit.setDecimals(1) delta_x = abs(location_x) / 100. if location_x != 0.0 else 0.1 delta_y = abs(location_y) / 100. if location_y != 0.0 else 0.1 delta_z = abs(location_z) / 100. if location_z != 0.0 else 0.1 self.location_x_edit.setSingleStep(delta_x) self.location_y_edit.setSingleStep(delta_y) self.location_z_edit.setSingleStep(delta_z) self.location_x_edit.setValue(location_x) self.location_y_edit.setValue(location_y) self.location_z_edit.setValue(location_z) self.coord = QLabel("Coord:") self.coord_edit = QSpinBox(self) self.coord_edit.setRange(0, 99999999) #self.coord_edit.setSingleStep(1) self.coord_edit.setValue(0) self.coord_type = QLabel("Coord Type:") #---------------------------------------------- # closing #if self._default_is_apply: #self.apply_button.setDisabled(True) self.close_button = QPushButton("Close") self.create_layout() self.set_connections()
def data(self, index, role=Qt.DisplayRole): """Override Qt method.""" if not index.isValid() or not 0 <= index.row() < len(self._rows): return row = index.row() column = index.column() P = self._palette # Include the palete directly here. if self._rows[row] == row: action = C.ACTION_NONE type_ = u'' name = u'' description = u'' version = u'-' status = -1 else: action = self._rows[row][C.COL_ACTION] type_ = self._rows[row][C.COL_PACKAGE_TYPE] name = self._rows[row][C.COL_NAME] description = self._rows[row][C.COL_DESCRIPTION] version = self._rows[row][C.COL_VERSION] status = self._rows[row][C.COL_STATUS] is_upgradable = self.is_upgradable(self.index(row, C.COL_VERSION)) if role == Qt.DisplayRole: if column == C.COL_PACKAGE_TYPE: return type_ if column == C.COL_NAME: return name elif column == C.COL_VERSION: return version elif column == C.COL_STATUS: return status elif column == C.COL_DESCRIPTION: return description elif column == C.COL_ACTION: return action elif role == Qt.TextAlignmentRole: if column in [C.COL_NAME, C.COL_DESCRIPTION]: return int(Qt.AlignLeft | Qt.AlignVCenter) elif column in [C.COL_VERSION]: return int(Qt.AlignLeft | Qt.AlignVCenter) else: return int(Qt.AlignCenter) elif role == Qt.DecorationRole: if column == C.COL_ACTION: if action == C.ACTION_NONE: if status == C.NOT_INSTALLED: return P['icon.action.not_installed'] elif status in [C.UPGRADABLE, C.MIXGRADABLE]: return P['icon.action.installed'] elif status in [ C.INSTALLED, C.DOWNGRADABLE, C.MIXGRADABLE ]: return P['icon.action.installed'] elif action == C.ACTION_INSTALL: return P['icon.action.add'] elif action == C.ACTION_REMOVE: return P['icon.action.remove'] elif action == C.ACTION_UPGRADE: return P['icon.action.upgrade'] elif action == C.ACTION_UPDATE: return P['icon.action.upgrade'] elif action == C.ACTION_DOWNGRADE: return P['icon.action.downgrade'] else: return elif column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return P['icon.anaconda'] elif type_ == C.PIP_PACKAGE: return P['icon.python'] else: return elif column == C.COL_VERSION: if is_upgradable: return P['icon.upgrade.arrow'] else: return P['icon.spacer'] elif role == Qt.ToolTipRole: if column == C.COL_PACKAGE_TYPE: if type_ == C.CONDA_PACKAGE: return 'Conda package' elif type_ == C.PIP_PACKAGE: return 'Python package' elif column == C.COL_VERSION and is_upgradable: return 'Update available' elif role == Qt.ForegroundRole: palette = QPalette() if column in [C.COL_NAME, C.COL_DESCRIPTION]: if status in [ C.INSTALLED, C.UPGRADABLE, C.DOWNGRADABLE, C.MIXGRADABLE ]: color = palette.color(QPalette.WindowText) color = QColor('#000') return color elif status in [C.NOT_INSTALLED]: color = palette.color(QPalette.Mid) color = P['color.foreground.not.installed'] return color elif column in [C.COL_VERSION] and is_upgradable: return P['color.foreground.upgrade'] elif (role == Qt.SizeHintRole and column in [C.ACTION_COLUMNS, C.COL_PACKAGE_TYPE]): return P['size.icons'] return
def update_color_button(self): palette = QPalette(self.button.palette()) qcolor = QColor(self.get_color()) palette.setColor(QPalette.Button, qcolor) self.button.setPalette(palette) self.button.update()
def data(self, index, role=Qt.DisplayRole): """Override Qt method""" if not index.isValid() or not 0 <= index.row() < len(self._rows): return to_qvariant() row = index.row() column = index.column() # Carefull here with the order, this has to be adjusted manually if self._rows[row] == row: [name, description, version, status, url, license_, i, r, u, d] =\ [u'', u'', '-', -1, u'', u'', False, False, False, False] else: [name, description, version, status, url, license_, i, r, u, d] = self._rows[row] if role == Qt.DisplayRole: if column == const.NAME: return to_qvariant(name) elif column == const.VERSION: return to_qvariant(version) elif column == const.STATUS: return to_qvariant(status) elif column == const.DESCRIPTION: return to_qvariant(description) elif role == Qt.TextAlignmentRole: if column in [const.NAME, const.DESCRIPTION]: return to_qvariant(int(Qt.AlignLeft | Qt.AlignVCenter)) else: return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) elif role == Qt.DecorationRole: if column == const.INSTALL: if status == const.NOT_INSTALLED: if i: return to_qvariant(self._icons['add.pressed']) else: return to_qvariant(self._icons['add.active']) elif (status == const.INSTALLED or status == const.UPGRADABLE or status == const.DOWNGRADABLE or status == const.MIXGRADABLE): if r: return to_qvariant(self._icons['remove.pressed']) else: return to_qvariant(self._icons['remove.active']) else: return to_qvariant(self._icons['add.inactive']) elif column == const.REMOVE: if (status == const.INSTALLED or status == const.UPGRADABLE or status == const.DOWNGRADABLE or status == const.MIXGRADABLE): if r: return to_qvariant(self._icons['remove.pressed']) else: return to_qvariant(self._icons['remove.active']) else: return to_qvariant(self._icons['remove.inactive']) elif column == const.UPGRADE: if status == const.UPGRADABLE or \ status == const.MIXGRADABLE: if u: return to_qvariant(self._icons['upgrade.pressed']) else: return to_qvariant(self._icons['upgrade.active']) else: return to_qvariant(self._icons['upgrade.inactive']) elif column == const.DOWNGRADE: if status == const.DOWNGRADABLE or \ status == const.MIXGRADABLE: if d: return to_qvariant(self._icons['downgrade.pressed']) else: return to_qvariant(self._icons['downgrade.active']) else: return to_qvariant(self._icons['downgrade.inactive']) elif role == Qt.ToolTipRole: if column == const.INSTALL and status == const.NOT_INSTALLED: return to_qvariant(_('Install package')) elif column == const.INSTALL and (status == const.INSTALLED or status == const.UPGRADABLE or status == const.DOWNGRADABLE or status == const.MIXGRADABLE): return to_qvariant(_('Remove package')) elif column == const.UPGRADE and (status == const.INSTALLED or status == const.UPGRADABLE or status == const.MIXGRADABLE): return to_qvariant(_('Upgrade package')) elif column == const.DOWNGRADE and (status == const.INSTALLED or status == const.DOWNGRADABLE or status == const.MIXGRADABLE): return to_qvariant(_('Downgrade package')) elif role == Qt.ForegroundRole: palette = QPalette() if column in [const.NAME, const.DESCRIPTION, const.VERSION]: if status in [const.INSTALLED, const.UPGRADABLE, const.DOWNGRADABLE, const.MIXGRADABLE]: color = palette.color(QPalette.WindowText) return to_qvariant(color) elif status in [const.NOT_INSTALLED, const.NOT_INSTALLABLE]: color = palette.color(QPalette.Mid) return to_qvariant(color) return to_qvariant()
def _clear_styles(self): """Reset style inputs to default values""" self._palette = QPalette(self.style().standardPalette()) self.editor.clear() self.update_palette_controls()
def __init__(self, parent=None): QWidget.__init__(self, parent) palette = QPalette(self.palette()) palette.setColor(palette.Background, QtCore.Qt.transparent) self.setPalette(palette) self.timer = None
def apply_dark_theme(self): dark_palette = QPalette() # base dark_palette.setColor(QPalette.WindowText, QColor(180, 180, 180)) dark_palette.setColor(QPalette.Button, QColor(53, 53, 53)) dark_palette.setColor(QPalette.Light, QColor(180, 180, 180)) dark_palette.setColor(QPalette.Midlight, QColor(90, 90, 90)) dark_palette.setColor(QPalette.Dark, QColor(35, 35, 35)) dark_palette.setColor(QPalette.Text, QColor(180, 180, 180)) dark_palette.setColor(QPalette.BrightText, QColor(180, 180, 180)) dark_palette.setColor(QPalette.ButtonText, QColor(180, 180, 180)) dark_palette.setColor(QPalette.Base, QColor(42, 42, 42)) dark_palette.setColor(QPalette.Window, QColor(53, 53, 53)) dark_palette.setColor(QPalette.Shadow, QColor(20, 20, 20)) dark_palette.setColor(QPalette.Highlight, QColor(42, 130, 218)) dark_palette.setColor(QPalette.HighlightedText, QColor(180, 180, 180)) dark_palette.setColor(QPalette.Link, QColor(56, 252, 196)) dark_palette.setColor(QPalette.AlternateBase, QColor(66, 66, 66)) dark_palette.setColor(QPalette.ToolTipBase, QColor(53, 53, 53)) dark_palette.setColor(QPalette.ToolTipText, QColor(180, 180, 180)) # disabled dark_palette.setColor(QPalette.Disabled, QPalette.WindowText, QColor(127, 127, 127)) dark_palette.setColor(QPalette.Disabled, QPalette.Text, QColor(127, 127, 127)) dark_palette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(127, 127, 127)) dark_palette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(80, 80, 80)) dark_palette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(127, 127, 127)) self.app.ctx.app.setPalette(dark_palette) self._apply_base_theme()
def light(app): """ Apply Light Theme to the Qt application instance. Args: app (QApplication): QApplication instance. """ lightPalette = QPalette() # base lightPalette.setColor(QPalette.WindowText, QColor(0, 0, 0)) lightPalette.setColor(QPalette.Button, QColor(240, 240, 240)) lightPalette.setColor(QPalette.Light, QColor(180, 180, 180)) lightPalette.setColor(QPalette.Midlight, QColor(200, 200, 200)) lightPalette.setColor(QPalette.Dark, QColor(225, 225, 225)) lightPalette.setColor(QPalette.Text, QColor(0, 0, 0)) lightPalette.setColor(QPalette.BrightText, QColor(0, 0, 0)) lightPalette.setColor(QPalette.ButtonText, QColor(0, 0, 0)) lightPalette.setColor(QPalette.Base, QColor(237, 237, 237)) lightPalette.setColor(QPalette.Window, QColor(240, 240, 240)) lightPalette.setColor(QPalette.Shadow, QColor(20, 20, 20)) lightPalette.setColor(QPalette.Highlight, QColor(76, 163, 224)) lightPalette.setColor(QPalette.HighlightedText, QColor(0, 0, 0)) lightPalette.setColor(QPalette.Link, QColor(0, 162, 232)) lightPalette.setColor(QPalette.AlternateBase, QColor(225, 225, 225)) lightPalette.setColor(QPalette.ToolTipBase, QColor(240, 240, 240)) lightPalette.setColor(QPalette.ToolTipText, QColor(0, 0, 0)) # disabled lightPalette.setColor(QPalette.Disabled, QPalette.WindowText, QColor(115, 115, 115)) lightPalette.setColor(QPalette.Disabled, QPalette.Text, QColor(115, 115, 115)) lightPalette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(115, 115, 115)) lightPalette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(190, 190, 190)) lightPalette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(115, 115, 115)) app.setPalette(lightPalette) _apply_base_theme(app)
def apply_styles(self): palette = self.settings['_palette'] if palette is not None: QApplication.setPalette(QPalette(palette)) QApplication.instance().setStyleSheet(self.settings['_style'] or '')
def __init__(self): self.style = QwtColumnSymbol.Box self.frameStyle = QwtColumnSymbol.Raised self.lineWidth = 2 self.palette = QPalette(Qt.gray)
class StyleDialog(ExToolWindow): """A dialog for editing Qt palette and stylesheet. Edits and sets Qt's application wide palette and stylesheet. See http://doc.qt.io/qt-4.8/stylesheet.html, and http://doc.qt.io/qt-4.8/qpalette.html for documentation of the effects of various settings, and the style sheet syntax. """ palette_entries = OrderedDict(( ('basic', ( 'Window', 'WindowText', )), ('extended', ( 'Base', 'Text', 'ToolTipBase', 'ToolTipText', 'Button', 'ButtonText', )), ('full', ( 'Highlight', 'HighlightedText', 'BrightText', 'Light', 'Midlight', 'Mid', 'Dark', 'Shadow', 'Link', 'LinkVisited', 'NoRole', )), )) pairs = [ ('Window', 'WindowText'), ('Base', 'Text'), ('Button', 'ButtonText'), ('ToolTipBase', 'ToolTipText'), ('Highlight', 'HighlightedText'), ('Light', 'Midlight'), ('Mid', 'Dark'), ('Link', 'LinkVisited'), ] def __init__(self, plugin, ui, parent): super(StyleDialog, self).__init__(parent) self.ui = ui self.setWindowTitle(tr("Edit application styles")) self.plugin = plugin self._palette = QPalette() self._rows = {} i = 0 for entries in self.palette_entries.values(): for key in entries: self._rows[key] = i for pair in self.pairs: if key == pair[0]: break else: i += 1 self.create_controls() self.save_action = QtWidgets.QAction(self) self.save_action.setShortcut(QtGui.QKeySequence.Save) self.save_action.triggered.connect(self.save) self.addAction(self.save_action) self.load() def save(self): """Store the palette and stylesheet to the plugin's settings""" self.plugin.settings['_style'] = self.editor.toPlainText() self.plugin.settings['_palette'] = self._palette def apply(self): """Apply current palette and stylesheet application wide""" QApplication.setPalette(self._palette) QApplication.instance().setStyleSheet(self.editor.toPlainText()) def load(self): """Load palette and stylesheet from the plugin't settings""" self.editor.setPlainText( self.plugin.settings['_style'] or '', 'text/plain', 'utf8' ) palette = self.plugin.settings['_palette'] if palette is not None: self._palette = QPalette(palette) self.update_palette_controls() def _clear_styles(self): """Reset style inputs to default values""" self._palette = QPalette(self.style().standardPalette()) self.editor.clear() self.update_palette_controls() def create_controls(self): """Build the editor's controls""" # First set up the stylesheet editor: editor = api.CodeEdit() editor.backend.start(server.__file__) editor.panels.append(panels.LineNumberPanel()) editor.panels.append(panels.CheckerPanel()) editor.modes.append(AutoIndentMode()) editor.modes.append(modes.CaretLineHighlighterMode()) editor.modes.append(modes.CodeCompletionMode()) editor.modes.append(modes.ExtendedSelectionMode()) editor.modes.append(modes.SmartBackSpaceMode()) editor.modes.append(modes.OccurrencesHighlighterMode()) editor.modes.append(modes.SymbolMatcherMode()) editor.modes.append(modes.ZoomMode()) self.editor = editor # Create the pushbuttons for the button bar: self.btn_apply = QPushButton(tr("Apply")) self.btn_apply.clicked.connect(self.apply) self.btn_save = QPushButton(tr("Save")) self.btn_save.clicked.connect(self.save) self.btn_revert = QPushButton(tr("Revert")) self.btn_revert.clicked.connect(self.load) self.btn_clear = QPushButton(tr("Clear")) self.btn_clear.clicked.connect(self._clear_styles) self.hbox = QHBoxLayout() for w in [self.btn_apply, self.btn_save, self.btn_revert, self.btn_clear]: self.hbox.addWidget(w) # Create the group-box with the palette editor self.palette_box = self.create_palette_colors() # Lay out the various components: vbox = QVBoxLayout(self) vbox.addWidget(self.palette_box) vbox.addWidget(editor) vbox.addLayout(self.hbox) self.setLayout(vbox) def create_palette_colors(self): """Create the controls for editing the palette""" layout = QtWidgets.QGridLayout() # Create combobox simple/extended/full cbo = QComboBox() cbo.addItems(list(self.palette_entries.keys())) cbo.currentIndexChanged[str].connect(self._on_cbo_change) layout.addWidget(cbo, 0, 0) self.cbo_mode = cbo # Create pickers for all self.pickers = {} for key, entries in self.palette_entries.items(): self.pickers[key] = {} for subkey in entries: btn = ColorButton() self.pickers[key][subkey] = btn btn.colorChanged.connect( partial(self._on_color_pick, subkey)) label = QLabel(subkey) if key != 'basic': btn.hide() label.hide() row = 1 + self._rows[subkey] for pair in self.pairs: if subkey == pair[1]: layout.addWidget(label, row, 2) layout.addWidget(btn, row, 3) break else: layout.addWidget(label, row, 0) layout.addWidget(btn, row, 1) # Initialize colors: self.update_palette_controls() box = QGroupBox('Palette') box.setLayout(layout) return box def update_palette_controls(self): """Update palette controls from internal QPalette""" for key, entries in self.palette_entries.items(): for subkey in entries: color = self._palette.color( getattr(self._palette, subkey)) btn = self.pickers[key][subkey] with block_signals(btn): btn.color = color def _setvis_palette_entry(self, key, show): """Show/hide specific palette entries""" row = 1 + self._rows[key] layout = self.palette_box.layout() # Always show/hide pairs together: for i in range(4): item = layout.itemAtPosition(row, i) if item is not None: item.widget().setVisible(show) def _on_color_pick(self, key, color): """Callback when a palette color has been picked""" if self.cbo_mode.currentText() == 'basic': # Other values should be auto-generated self._palette = QPalette(self.pickers['basic']['Window'].color) self._palette.setColor( getattr(self._palette, key), color ) def _on_cbo_change(self, selection): """Callback for when palette-mode selection changes""" # Use all up-until selection (keys are ordered) included = list(self.palette_entries.keys()) included = included[:1 + included.index(selection)] for key, entries in self.palette_entries.items(): visible = key in included for subkey in entries: self._setvis_palette_entry(subkey, show=visible)
def apply_light_theme(self): light_palette = QPalette() # base light_palette.setColor(QPalette.WindowText, QColor(0, 0, 0)) light_palette.setColor(QPalette.Button, QColor(240, 240, 240)) light_palette.setColor(QPalette.Light, QColor(180, 180, 180)) light_palette.setColor(QPalette.Midlight, QColor(200, 200, 200)) light_palette.setColor(QPalette.Dark, QColor(225, 225, 225)) light_palette.setColor(QPalette.Text, QColor(0, 0, 0)) light_palette.setColor(QPalette.BrightText, QColor(0, 0, 0)) light_palette.setColor(QPalette.ButtonText, QColor(0, 0, 0)) light_palette.setColor(QPalette.Base, QColor(237, 237, 237)) light_palette.setColor(QPalette.Window, QColor(240, 240, 240)) light_palette.setColor(QPalette.Shadow, QColor(20, 20, 20)) light_palette.setColor(QPalette.Highlight, QColor(76, 163, 224)) light_palette.setColor(QPalette.HighlightedText, QColor(0, 0, 0)) light_palette.setColor(QPalette.Link, QColor(0, 162, 232)) light_palette.setColor(QPalette.AlternateBase, QColor(225, 225, 225)) light_palette.setColor(QPalette.ToolTipBase, QColor(240, 240, 240)) light_palette.setColor(QPalette.ToolTipText, QColor(0, 0, 0)) # disabled light_palette.setColor(QPalette.Disabled, QPalette.WindowText, QColor(115, 115, 115)) light_palette.setColor(QPalette.Disabled, QPalette.Text, QColor(115, 115, 115)) light_palette.setColor(QPalette.Disabled, QPalette.ButtonText, QColor(115, 115, 115)) light_palette.setColor(QPalette.Disabled, QPalette.Highlight, QColor(190, 190, 190)) light_palette.setColor(QPalette.Disabled, QPalette.HighlightedText, QColor(115, 115, 115)) self.app.ctx.app.setPalette(light_palette) self._apply_base_theme()
def __init__(self, parent, packages, data): super(CondaPackagesModel, self).__init__(parent) self._parent = parent self._packages = packages self._rows = data self._name_to_index = {r[C.COL_NAME]: i for i, r in enumerate(data)} palette = QPalette() self._palette = { 'icon.upgrade.active': get_icon('conda_upgrade_active.png'), 'icon.upgrade.inactive': get_icon('conda_upgrade_inactive.png'), 'icon.upgrade.pressed': get_icon('conda_upgrade_pressed.png'), 'icon.downgrade.active': get_icon('conda_downgrade_active.png'), 'icon.downgrade.inactive': get_icon('conda_downgrade_inactive.png'), 'icon.downgrade.pressed': get_icon('conda_downgrade_pressed.png'), 'icon.add.active': get_icon('conda_add_active.png'), 'icon.add.inactive': get_icon('conda_add_inactive.png'), 'icon.add.pressed': get_icon('conda_add_pressed.png'), 'icon.remove.active': get_icon('conda_remove_active.png'), 'icon.remove.inactive': get_icon('conda_remove_inactive.png'), 'icon.remove.pressed': get_icon('conda_remove_pressed.png'), 'icon.action.not_installed': get_icon('conda_action_not_installed.png'), 'icon.action.installed': get_icon('conda_action_installed.png'), 'icon.action.installed_upgradable': get_icon('conda_action_installed_upgradable.png'), 'icon.action.remove': get_icon('conda_action_remove.png'), 'icon.action.add': get_icon('conda_action_add.png'), 'icon.action.upgrade': get_icon('conda_action_upgrade.png'), 'icon.action.downgrade': get_icon('conda_action_downgrade.png'), 'icon.upgrade.arrow': get_icon('conda_upgrade_arrow.png'), 'icon.python': get_icon('python.png').pixmap(QSize(16, 16)), 'icon.anaconda': get_icon('anaconda.png').pixmap(QSize(16, 16)), 'background.remove': QColor(128, 0, 0, 50), 'background.install': QColor(0, 128, 0, 50), 'background.upgrade': QColor(0, 0, 128, 50), 'background.downgrade': QColor(128, 0, 128, 50), 'foreground.not.installed': palette.color(QPalette.Mid), 'foreground.upgrade': QColor(0, 0, 128, 255), }