def draw(self, comps, cluster): colors = QColor.colorNames() # for co in sample: # print(co) # x, _, z, _ = co['world'] # self.scene.addEllipse(x-50,z-50,100,100, pen=QPen(QColor('orange'), 5)) # x,_,z,_ = sample[-1]['world'] # self.scene.addRect(x,z,60,60, pen=QPen(QColor('red'), 100)) # x,_,z,_ = sample[0]['world'] # self.scene.addRect(x,z,60,60, pen=QPen(QColor('green'), 100)) # for co in comps: # if sample[co[-1]]['timestamp']-sample[co[0]]['timestamp'] > 200 and len(co)> 4: # color = colors[random.randint(0, len(colors)-1)] # for c in co: # x, _, z, _ = sample[c]['world'] # self.scene.addEllipse(x-15,z-15,30,30, pen=QPen(QColor(color), 100), brush=QBrush(color=QColor(color))) if cluster[-1]['timestamp'] - cluster[0]['timestamp'] > 200 and len( cluster) > 4: color = colors[random.randint(0, len(colors) - 1)] for sample in cluster: x, _, z, _ = sample['world'] self.scene.addEllipse(x - 15, z - 15, 30, 30, pen=QPen(QColor(color), 100), brush=QBrush(color=QColor(color)))
def drawTrack(self, clusters): colors = QColor.colorNames() # for line in self.lines: # self.scene.removeItem(line) self.scene.clear() for cluster in clusters: color = colors[random.randint(0, len(colors) - 1)] for t in cluster: self.scene.addLine(t[0][0], t[0][1], t[1][0], t[1][1], pen=QPen(QColor(color), 60))
def text_to_qcolor(text): """ Create a QColor from specified string Avoid warning from Qt when an invalid QColor is instantiated """ color = QColor() if not is_string(text): # testing for QString (PyQt API#1) text = str(text) if not is_text_string(text): return color if text.startswith('#') and len(text)==7: correct = '#0123456789abcdef' for char in text: if char.lower() not in correct: return color elif text not in list(QColor.colorNames()): return color color.setNamedColor(text) return color
def addPerson(self, pos, angle=0, color=-1, size=100): colors = QColor.colorNames() color = colors[random.randint(0, len(colors) - 1)] if color == -1 else color pos = [pos[0], pos[2]] if len(pos) > 2 else pos p = self.scene.addEllipse(pos[0] - size // 2, pos[1] - size // 2, size, size, pen=QPen(QColor(color), 20), brush=QBrush(color=QColor(color))) # pixmap pixmap = QPixmap("person.png").scaled(600, 300) self.pixmapSize = (pixmap.width() / 2, pixmap.height() / 2) pixItem = QGraphicsPixmapItem(pixmap) pixItem.setTransformOriginPoint(pixItem.boundingRect().center()) pixItem.setZValue(20) self.scene.addItem(pixItem) self.persons[p] = pixItem return p
from PySide2.QtWidgets import QApplication, QWidget, QPushButton, QHBoxLayout, QFormLayout, QGridLayout # from PySide2.QtCore import Qt from PySide2.QtGui import QPixmap, QPalette, QBrush, QColor import sys print("Begin") app = QApplication(sys.argv) window = QWidget() window.setWindowTitle('Цвета') # window.resize(300, 150) window.resize(1920, 1080) colors_list = QColor.colorNames() # Список имен цветов grid = QGridLayout() window.setLayout(grid) positions = [(i, j) for i in range(19) for j in range(8)] # zip(*iters) - Итератор, возвращающий кортежи, состоящие из соответствующих элементов аргументов-последовательностей. for position, name in zip(positions, colors_list): print("position", position, "name", name, "css", "background-color: {0}".format(name)) button = QPushButton(name) button.setStyleSheet("background-color: {0}".format(name)) # Если значения параметров, которые планируется передать в функцию, содержится в кортеже или списке, то перед # объектом следует указать символ * ( ПрохДрон стр 216 ) grid.addWidget(button, *position) print("End") window.show() sys.exit(app.exec_())
def setup(self): self.setAttribute(Qt.WA_DeleteOnClose) fixed = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) rightCenter = (Qt.AlignRight | Qt.AlignVCenter) # all the input boxes self.inputGrid = QGridLayout() self.inputGrid.setSpacing(5) h_spc = self.inputGrid.horizontalSpacing() v_spc = self.inputGrid.verticalSpacing() # RGB self.redInput = QSpinBox() self.grnInput = QSpinBox() self.bluInput = QSpinBox() self.rgbInputs = [self.redInput, self.grnInput, self.bluInput] self.redLabel = QLabel('&R:') self.redLabel.setToolTip('Red') self.grnLabel = QLabel('&G:') self.grnLabel.setToolTip('Green') self.bluLabel = QLabel('&B:') self.bluLabel.setToolTip('Blue') self.rgbLabels = [self.redLabel, self.grnLabel, self.bluLabel] self.redLabel.setBuddy(self.redInput) self.grnLabel.setBuddy(self.grnInput) self.bluLabel.setBuddy(self.bluInput) # HSV self.hueInput = QSpinBox() self.satInput = QSpinBox() self.valInput = QSpinBox() self.hsvInputs = [self.hueInput, self.satInput, self.valInput] self.hueInput.setWrapping(True) self.hueLabel = QLabel('&H:') self.hueLabel.setToolTip('Hue') self.satLabel = QLabel('&S:') self.satLabel.setToolTip('Saturation') self.valLabel = QLabel('&V:') self.valLabel.setToolTip('Value') self.hsvLabels = [self.hueLabel, self.satLabel, self.valLabel] self.hueLabel.setBuddy(self.hueInput) self.satLabel.setBuddy(self.satInput) self.valLabel.setBuddy(self.valInput) # CMYK self.cInput = QSpinBox() self.mInput = QSpinBox() self.yInput = QSpinBox() self.kInput = QSpinBox() self.cmykInputs = [self.cInput, self.mInput, self.yInput, self.kInput] self.cLabel = QLabel('&C:') self.cLabel.setToolTip('Cyan') self.mLabel = QLabel('&M:') self.mLabel.setToolTip('Magenta') self.yLabel = QLabel('&Y:') self.yLabel.setToolTip('Yellow') self.kLabel = QLabel('&K:') self.kLabel.setToolTip('Black') self.cmykLabels = [self.cLabel, self.mLabel, self.yLabel, self.kLabel] self.cLabel.setBuddy(self.cInput) self.mLabel.setBuddy(self.mInput) self.yLabel.setBuddy(self.yInput) self.kLabel.setBuddy(self.kInput) for i in self.rgbInputs + self.hsvInputs + self.cmykInputs: i.setRange(0, 255) i.setFixedSize(35, 22) i.setAlignment(Qt.AlignCenter) i.setButtonSymbols(QAbstractSpinBox.NoButtons) self.hueInput.setRange(0, 359) # HTML self.htmlInput = QLineEdit() self.htmlInput.setFixedSize(35 + 22 + h_spc, 22) # spans 2 cols self.htmlInput.setPlaceholderText('html') self.htmlInput.setAlignment(Qt.AlignCenter) regex = QRegExp('[0-9A-Fa-f]{1,6}') valid = QRegExpValidator(regex) self.htmlInput.setValidator(valid) self.htmlLabel = QLabel('&#') self.htmlLabel.setToolTip('Web color') self.htmlLabel.setBuddy(self.htmlInput) self.inputLabels = (self.rgbLabels + self.hsvLabels + self.cmykLabels + [ self.htmlLabel, ]) for i in self.inputLabels: i.setFixedSize(22, 22) i.setAlignment(rightCenter) #i.setFrameShape(QFrame.Box) self.inputs = self.rgbInputs + self.hsvInputs + self.cmykInputs for i in self.inputs: i.valueChanged.connect(self._colorEdited) self.htmlInput.editingFinished.connect(self._colorEdited) # picker button self.pickButton = QPushButton('&Pick') self.pickButton.setToolTip('Pick a color from the screen') self.pickButton.setFixedSize(35, 22) self.pickButton.clicked.connect(self.pickColor) # color display self.colorDisplay = QFrame() self.colorDisplay.setFixedSize(55, 4 * 22 + 3 * v_spc) # spans 4 rows self.colorDisplay.setFrameShape(QFrame.Panel) self.colorDisplay.setFrameShadow(QFrame.Sunken) self.colorDisplay.setAutoFillBackground(True) # show button / random button self.showButton = QPushButton('Sho&w') self.showButton.setToolTip('Show named colors on color wheel') self.showButton.setFixedSize(35, 22) self.showButton.setCheckable(True) self.showButton.clicked.connect(self.showColors) self.rndButton = QPushButton('R&and') self.rndButton.setToolTip('Select a random color') self.rndButton.setFixedSize(35, 22) self.rndButton.clicked.connect(self.randomColor) # color wheel self.colorWheel = wheel() self.colorWheel.setFixedSize(256, 256) #265, 265) self.colorWheel.currentColorChanged.connect(self.setColor) # named colors combo box self.colorNamesCB = QComboBox() self.colorNamesCB.setFixedSize(70 + 66 + 4 * h_spc, 22) # spans 5 cols #self.colorNamesCB.addItem('- Color Names -') self.cNameLabel = QLabel('&Named:') self.cNameLabel.setBuddy(self.colorNamesCB) self.cNameLabel.setAlignment(rightCenter) #self.cNameLabel.setFrameShape(QFrame.Box) self.cNameLabel.setFixedSize(55, 22) lst = [i for i in QColor.colorNames() if str(i) != 'transparent'] lst = [(i, QColor(i)) for i in lst] lst.append(('Cosmic latte', '#fff8e7')) lst.append(('rebeccapurple', '#663399')) self.addNamedColors(lst) self.colorNamesCB.currentIndexChanged.connect(self._colorEdited) self.inputs += [self.htmlInput, self.colorWheel, self.colorNamesCB] # ok/cancel buttons self.dialogButtons = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel) self.dialogButtons.accepted.connect(self.closeValid) self.dialogButtons.rejected.connect(self.closeInvalid) self.dialogButtons.setCenterButtons(True) # pass QColorDialog.NoButtons, False to setOption to remove # assemble grid! # 0 1 2 3 4 5 6 # # color wheeeeeeeeeeeeellll 0 # disp r: rrr h: hhh c: ccc 1 # disp g: ggg s: sss m: mmm 2 # disp b: bbb v: vvv y: yyy 3 # disp ## -html- pic k: kkk 4 # name coooommmboooobox rnd 5 #.addWidget(widget, row, col, rspan, cspan) self.inputGrid.addWidget(self.colorWheel, 0, 0, 1, 7) self.inputGrid.addWidget(self.colorDisplay, 1, 0, 4, 1) for i, lab in enumerate(self.rgbLabels, 1): self.inputGrid.addWidget(lab, i, 1, 1, 1) self.inputGrid.addWidget(self.htmlLabel, 4, 1, 1, 1) for i, wid in enumerate(self.rgbInputs, 1): self.inputGrid.addWidget(wid, i, 2) self.inputGrid.addWidget(self.htmlInput, 4, 2, 1, 2) for i, lab in enumerate(self.hsvLabels, 1): self.inputGrid.addWidget(lab, i, 3, 1, 1) for i, wid in enumerate(self.hsvInputs, 1): self.inputGrid.addWidget(wid, i, 4, 1, 1) self.inputGrid.addWidget(self.pickButton, 4, 4, 1, 1) for i, lab in enumerate(self.cmykLabels, 1): self.inputGrid.addWidget(lab, i, 5, 1, 1) for i, wid in enumerate(self.cmykInputs, 1): self.inputGrid.addWidget(wid, i, 6, 1, 1) self.inputGrid.addWidget(self.colorNamesCB, 5, 1, 1, 5) self.inputGrid.addWidget(self.cNameLabel, 5, 0, 1, 1) self.inputGrid.addWidget(self.showButton, 5, 6, 1, 1) self.inputGrid.addWidget(self.rndButton, 5, 6, 1, 1) self.inputGrid.addWidget(self.dialogButtons, 6, 0, 1, 7) self.setWindowTitle('Select color') ico = self.style().standardIcon(QStyle.SP_DialogResetButton) self.setWindowIcon(ico) self.setLayout(self.inputGrid) self.setFixedSize(self.sizeHint()) self.useRandom() #False)