def setTextColor(self): if self.lastNodeItem not in self.node: return node = self.node[self.lastNodeItem] item = self.nodeItem[node] if 'tcolor' in node.u['_bklnk']: color = node.u['_bklnk']['tcolor'] newcolor = QtWidgets.QColorDialog.getColor(QtGui.QColor(color)) else: newcolor = QtWidgets.QColorDialog.getColor() if QtGui.QColor.isValid(newcolor): newcolor = str(newcolor.name()) # store strings not objects item.set_text_color(newcolor) node.u['_bklnk']['tcolor'] = newcolor self.releaseNode(item) # reselect self.c.redraw() # update color of node in the tree too
def showColorNames(event=None): """Put up a dialog showing color names.""" c = event.get('c') template = ''' QComboBox { background-color: %s; selection-background-color: %s; selection-color: black; }''' ivar = 'leo_settings_color_picker' if getattr(c, ivar, None): g.es('The color picker already exists in the icon bar.') else: color_list: List[str] = [] box = QtWidgets.QComboBox() def onActivated(n, *args, **keys): color = color_list[n] sheet = template % (color, color) box.setStyleSheet(sheet) g.es("copied to clipboard:", color) QtWidgets.QApplication.clipboard().setText(color) box.activated.connect(onActivated) color_db = leoColor.leo_color_database for key in sorted(color_db): if not key.startswith('grey'): # Use gray, not grey. val = color_db.get(key) color = QtGui.QColor(val) color_list.append(val) pixmap = QtGui.QPixmap(40, 40) pixmap.fill(color) icon = QtGui.QIcon(pixmap) box.addItem(icon, key) c.frame.iconBar.addWidget(box) setattr(c, ivar, True) # Do this last, so errors don't prevent re-execution. g.es('created color picker in icon area')
def showColorWheel(self, event=None): """Show a Qt color dialog.""" c = self.c; p = c.p picker = QtWidgets.QColorDialog() in_color_setting = p.h.startswith('@color ') try: text = QtWidgets.QApplication.clipboard().text() if in_color_setting: text = p.h.split('=', 1)[1].strip() color = QtGui.QColor(text) picker.setCurrentColor(color) except(ValueError, IndexError) as e: g.trace('error caught', e) if not picker.exec_(): g.es("No color selected") elif in_color_setting: udata = c.undoer.beforeChangeNodeContents(p) p.h = f"{p.h.split('=', 1)[0].strip()} = {picker.selectedColor().name()}" c.undoer.afterChangeNodeContents(p, 'change-color', udata) else: text = picker.selectedColor().name() g.es("copied to clipboard:", text) QtWidgets.QApplication.clipboard().setText(text)
def set_text_color(self, color): self.text.setDefaultTextColor(QtGui.QColor(color))
def set_bg_color(self, color): self.bg.setBrush(QtGui.QBrush(QtGui.QColor(color)))
def focusOutEvent(self, event): QtWidgets.QGraphicsItemGroup.focusOutEvent(self, event) self.bg.setBrush(QtGui.QBrush(QtGui.QColor(200, 240, 200))) g.es("focusOutEvent")