def colorPairs(maximum): # capitalize the first letter colors = QColor.colorNames() colors.removeAll("transparent") num = len(colors) for c in range(num): colors[c] = colors[c][0].toUpper() + colors[c].mid(1) # combine two colors, e.g. "lime skyblue" combinedColors = [] for i in range(num): for j in range(num): combinedColors.append( QString("%1 %2").arg(colors[i]).arg(colors[j])) # randomize it colors = [] while combinedColors: i = random.randint(0, len(combinedColors)) colors.append(combinedColors[i]) del combinedColors[i] if len(colors) == maximum: break return colors
def colorPairs(maximum): # capitalize the first letter colors = QColor.colorNames() colors.removeAll("transparent") num = len(colors) for c in range(num): colors[c] = colors[c][0].toUpper() + colors[c].mid(1) # combine two colors, e.g. "lime skyblue" combinedColors = [] for i in range(num): for j in range(num): combinedColors.append(QString("%1 %2").arg(colors[i]).arg(colors[j])) # randomize it colors = [] while combinedColors: i = random.randint(0, len(combinedColors)) colors.append(combinedColors[i]) del combinedColors[i] if len(colors) == maximum: break return colors
def __set_colors(self): '''Sets colors to plot.''' self.colors = ['#000000', '#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff', '#ff8800', '#ff0088', '#ff8888', '#88ff00', '#8800ff', '#8888ff', '#88ff88', '#00ff88', '#0088ff', '#880000', '#008800', '#000088', '#888888'] self.colors += [str(s) for s in QColor.colorNames()]
def populateList( self ): colorNames = QColor.colorNames() for i, name in enumerate( colorNames ): self.insertItem( i, str( name ).capitalize() ) self.setItemData( i, QColor( name ), Qt.DecorationRole ) self.insertItem( len( colorNames ), "" ) self.updateCustomColor()
def populateList(self): colorNames = QColor.colorNames() for i, name in enumerate(colorNames): self.insertItem(i, str(name).capitalize()) self.setItemData(i, QColor(name), Qt.DecorationRole) self.insertItem(len(colorNames), "") self.updateCustomColor()
def __set_colors(self): '''Sets colors to plot.''' self.colors = [ '#000000', '#ff0000', '#00ff00', '#0000ff', '#ffff00', '#ff00ff', '#00ffff', '#ff8800', '#ff0088', '#ff8888', '#88ff00', '#8800ff', '#8888ff', '#88ff88', '#00ff88', '#0088ff', '#880000', '#008800', '#000088', '#888888' ] self.colors += [str(s) for s in QColor.colorNames()]
def color(self, layer=None, f=None): global colorNames #TODO: add function to material manager vals = self.properties["colorWidget"] if vals[0] == ColorWidgetFunc.RGB: return vals[2] elif vals[0] == ColorWidgetFunc.RANDOM or layer is None or f is None: if len(colorNames) == 0: colorNames = QColor.colorNames() colorName = random.choice(colorNames) colorNames.remove(colorName) return QColor(colorName).name().replace("#", "0x") symbol = layer.rendererV2().symbolForFeature(f) if symbol is None: QgsMessageLog.logMessage(u'Symbol for feature is not found. Once try to show layer: {0}'.format(layer.name()), "Qgis2threejs") symbol = layer.rendererV2().symbols()[0] return symbol.color().name().replace("#", "0x")
def text_to_qcolor(text): """ Create a QColor from specified string Avoid warning from Qt when an invalid QColor is instantiated """ color = QColor() text = str(text) if not isinstance(text, (unicode, str)): 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 text_to_qcolor(text): """ Create a QColor from specified string Avoid warning from Qt when an invalid QColor is instantiated """ color = QColor() text = str(text) if not isinstance(text, (unicode, str)): 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 text_to_qcolor(text): """ Create a QColor from specified string Avoid warning from Qt when an invalid QColor is instantiated """ color = QColor() if isinstance(text, QObject): # actually a QString, which is not provided by the new PyQt4 API: text = str(text) if not isinstance(text, (unicode, str)): 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 _readColor(self, widgetValues, f=None, isBorder=False): global colorNames mode = widgetValues["comboData"] if mode == OptionalColorWidgetFunc.NONE: return None if mode == ColorWidgetFunc.RGB: return widgetValues["editText"] if mode == ColorWidgetFunc.RANDOM or f is None: if len(colorNames) == 0: colorNames = QColor.colorNames() colorName = random.choice(colorNames) colorNames.remove(colorName) return QColor(colorName).name().replace("#", "0x") # feature color symbol = self.layer.rendererV2().symbolForFeature(f) if symbol is None: logMessage(u'Symbol for feature cannot be found: {0}'.format( self.layer.name())) symbol = self.layer.rendererV2().symbols()[0] else: sl = symbol.symbolLayer(0) if sl and isBorder: return sl.outlineColor().name().replace("#", "0x") if sl: # and sl.hasDataDefinedProperties(): # needs >= 2.2 expr = sl.dataDefinedProperty("color") if expr: # data defined color cs_rgb = expr.evaluate(f, f.fields()) # "rrr,ggg,bbb" (dec) to "0xRRGGBB" (hex) rgb = map(int, cs_rgb.split(",")[0:3]) return "0x" + "".join(map(chr, rgb)).encode("hex") return symbol.color().name().replace("#", "0x")
def _readColor(self, widgetValues, f=None, isBorder=False): global colorNames mode = widgetValues["comboData"] if mode == OptionalColorWidgetFunc.NONE: return None if mode == ColorWidgetFunc.RGB: return widgetValues["editText"] if mode == ColorWidgetFunc.RANDOM or f is None: if len(colorNames) == 0: colorNames = QColor.colorNames() colorName = random.choice(colorNames) colorNames.remove(colorName) return QColor(colorName).name().replace("#", "0x") # feature color symbol = self.layer.rendererV2().symbolForFeature(f) if symbol is None: QgsMessageLog.logMessage(u'Symbol for feature cannot be found: {0}'.format(self.layer.name()), "Qgis2threejs") symbol = self.layer.rendererV2().symbols()[0] else: sl = symbol.symbolLayer(0) if sl and isBorder: return sl.outlineColor().name().replace("#", "0x") if sl: # and sl.hasDataDefinedProperties(): # needs >= 2.2 expr = sl.dataDefinedProperty("color") if expr: # data defined color cs_rgb = expr.evaluate(f, f.fields()) # "rrr,ggg,bbb" (dec) to "0xRRGGBB" (hex) rgb = map(int, cs_rgb.split(",")[0:3]) return "0x" + "".join(map(chr, rgb)).encode("hex") return symbol.color().name().replace("#", "0x")
def color(cls, mscolor, opacity=100): n = len(mscolor) a = int(round(opacity * 2.55)) color_ = QColor("red") #color de error if isinstance(mscolor, list): if n == 3: color_ = QColor(mscolor[0], mscolor[1], mscolor[2], a) elif isinstance(mscolor, (str, unicode)): match = cls.REGEX_ATTR.search(mscolor) if mscolor[:1] == "#": print("#", n) r = int(mscolor[1:3], 16) g = int(mscolor[3:5], 16) b = int(mscolor[5:7], 16) if n == 7: color_ = QColor(r, g, b, a) elif n == 9: a2 = int(mscolor[7:9], 16) #unificar "a" con opacity y alpha del string #es el promedio, o % de la que ya tiene a = int(round((a + a2) / 2)) #a = int(a2 * opacity * 1.0 / 100) color_ = QColor(r, g, b, a) elif match: #Color es definido por atributo return (match.group(1), True) else: if mscolor in QColor.colorNames(): color_ = QColor(mscolor) color_.setAlpha(a) r = color_.red() g = color_.green() b = color_.blue() a = color_.alpha() qcolor_ = "{},{},{},{}".format(r, g, b, a) return (qcolor_, False, r, g, b, a)
def __init__(self, iface, geometry, mntButton=False, zerosButton=False): """ Constructor :param iface: interface :param width: dock widget geometry """ QDockWidget.__init__(self) self.setWindowTitle(QCoreApplication.translate("VDLTools", "Profile Tool")) self.__iface = iface self.__geom = geometry self.__canvas = self.__iface.mapCanvas() self.__types = ['PDF', 'PNG'] # ], 'SVG', 'PS'] self.__libs = [] if Qwt5_loaded: self.__lib = 'Qwt5' self.__libs.append('Qwt5') if matplotlib_loaded: self.__libs.append('Matplotlib') elif matplotlib_loaded: self.__lib = 'Matplotlib' self.__libs.append('Matplotlib') else: self.__lib = None self.__iface.messageBar().pushMessage( QCoreApplication.translate("VDLTools", "No graph lib available (qwt5 or matplotlib)"), level=QgsMessageBar.CRITICAL, duration=0) self.__doTracking = False self.__vline = None self.__profiles = None self.__numLines = None self.__mntPoints = None self.__marker = None self.__tabmouseevent = None if self.__geom is not None: self.setGeometry(self.__geom) self.__contentWidget = QWidget() self.setWidget(self.__contentWidget) self.__boxLayout = QHBoxLayout() self.__contentWidget.setLayout(self.__boxLayout) self.__plotFrame = QFrame() self.__frameLayout = QHBoxLayout() self.__plotFrame.setLayout(self.__frameLayout) self.__printLayout = QHBoxLayout() self.__printLayout.addWidget(self.__plotFrame) self.__legendLayout = QVBoxLayout() self.__printLayout.addLayout(self.__legendLayout) self.__printWdg = QWidget() self.__printWdg.setLayout(self.__printLayout) self.__plotWdg = None self.__changePlotWidget() size = QSize(150, 20) self.__boxLayout.addWidget(self.__printWdg) self.__vertLayout = QVBoxLayout() self.__libCombo = QComboBox() self.__libCombo.setFixedSize(size) self.__libCombo.addItems(self.__libs) self.__vertLayout.addWidget(self.__libCombo) self.__libCombo.currentIndexChanged.connect(self.__setLib) if mntButton: self.__displayMnt = False self.__mntButton = QPushButton(QCoreApplication.translate("VDLTools", "Display MNT")) self.__mntButton.setFixedSize(size) self.__mntButton.clicked.connect(self.__mnt) self.__vertLayout.addWidget(self.__mntButton) if zerosButton: self.__displayZeros = False self.__zerosButton = QPushButton(QCoreApplication.translate("VDLTools", "Display Zeros")) self.__zerosButton.setFixedSize(size) self.__zerosButton.clicked.connect(self.__zeros) self.__vertLayout.addWidget(self.__zerosButton) else: self.__displayZeros = True self.__maxLabel = QLabel("y max") self.__maxLabel.setFixedSize(size) self.__vertLayout.addWidget(self.__maxLabel) self.__maxSpin = QSpinBox() self.__maxSpin.setFixedSize(size) self.__maxSpin.setRange(-10000, 10000) self.__maxSpin.valueChanged.connect(self.__reScalePlot) self.__vertLayout.addWidget(self.__maxSpin) self.__vertLayout.insertSpacing(10, 20) self.__minLabel = QLabel("y min") self.__minLabel.setFixedSize(size) self.__vertLayout.addWidget(self.__minLabel) self.__minSpin = QSpinBox() self.__minSpin.setFixedSize(size) self.__minSpin.setRange(-10000, 10000) self.__minSpin.valueChanged.connect(self.__reScalePlot) self.__vertLayout.addWidget(self.__minSpin) self.__vertLayout.insertSpacing(10, 40) self.__typeCombo = QComboBox() self.__typeCombo.setFixedSize(size) self.__typeCombo.addItems(self.__types) self.__vertLayout.addWidget(self.__typeCombo) self.__saveButton = QPushButton(QCoreApplication.translate("VDLTools", "Save")) self.__saveButton.setFixedSize(size) self.__saveButton.clicked.connect(self.__save) self.__vertLayout.addWidget(self.__saveButton) self.__boxLayout.addLayout(self.__vertLayout) self.__maxSpin.setEnabled(False) self.__minSpin.setEnabled(False) self.__colors = [] for cn in QColor.colorNames(): qc = QColor(cn) val = qc.red() + qc.green() + qc.blue() if 0 < val < 450: self.__colors.append(cn)
convert_to_color.info = ('a string of the form (r,g,b) or (r,g,b,a) where r, ' 'g, b, and a are integers from 0 to 255, a QColor ' 'instance, a Qt.GlobalColor, an integer which in hex ' 'is of the form 0xRRGGBB, a string of the form #RGB, ' '#RRGGBB, #RRRGGGBBB or #RRRRGGGGBBBB') #------------------------------------------------------------------------------- # Standard colors: #------------------------------------------------------------------------------- # Note that this is slightly different from the wx implementation in that the # names do not include spaces and the full set of SVG color keywords is # supported. standard_colors = {} for name in QColor.colorNames(): standard_colors[ str( name ) ] = QColor( name ) #------------------------------------------------------------------------------- # Define PyQt specific color facets: #------------------------------------------------------------------------------- ColorFacets = ( Facet( 'white', standard_colors, convert_to_color, editor = ColorEditor ), Facet( 'white', None, standard_colors, convert_to_color, editor = ColorEditor ) ) def PyQtColor ( default = 'white', allow_none = False, **metadata ): """ Defines PyQt-specific color facets. """ return ColorFacets[ allow_none is True ]( default, **metadata )
def __init__(self, iface): """ Constructor :param iface: interface """ QDockWidget.__init__(self) self.setWindowTitle(QCoreApplication.translate("VDLTools", "Profile Tool")) self.resize(1024, 400) self.__iface = iface self.__canvas = self.__iface.mapCanvas() self.__types = ['PDF', 'PNG'] # ], 'SVG', 'PS'] self.__libs = [] if Qwt5_loaded: self.__lib = 'Qwt5' self.__libs.append('Qwt5') if matplotlib_loaded: self.__libs.append('Matplotlib') elif matplotlib_loaded: self.__lib = 'Matplotlib' self.__libs.append('Matplotlib') else: self.__lib = None self.__iface.messageBar().pushMessage( QCoreApplication.translate("VDLTools", "No graph lib available (qwt5 or matplotlib)"), level=QgsMessageBar.CRITICAL, duration=0) self.__doTracking = False self.__vline = None self.__profiles = None self.__numLines = None self.__mntPoints = None self.__marker = None self.__tabmouseevent = None self.__contentWidget = QWidget() self.setWidget(self.__contentWidget) self.__boxLayout = QHBoxLayout() self.__contentWidget.setLayout(self.__boxLayout) self.__plotFrame = QFrame() self.__frameLayout = QHBoxLayout() self.__plotFrame.setLayout(self.__frameLayout) self.__printLayout = QHBoxLayout() self.__printLayout.addWidget(self.__plotFrame) self.__legendLayout = QVBoxLayout() self.__printLayout.addLayout(self.__legendLayout) self.__printWdg = QWidget() self.__printWdg.setLayout(self.__printLayout) self.__plotWdg = None self.__changePlotWidget() size = QSize(150, 20) self.__boxLayout.addWidget(self.__printWdg) self.__vertLayout = QVBoxLayout() self.__libCombo = QComboBox() self.__libCombo.setFixedSize(size) self.__libCombo.addItems(self.__libs) self.__vertLayout.addWidget(self.__libCombo) self.__libCombo.currentIndexChanged.connect(self.__setLib) self.__maxLabel = QLabel("y max") self.__maxLabel.setFixedSize(size) self.__vertLayout.addWidget(self.__maxLabel) self.__maxSpin = QSpinBox() self.__maxSpin.setFixedSize(size) self.__maxSpin.setRange(-10000, 10000) self.__maxSpin.valueChanged.connect(self.__reScalePlot) self.__vertLayout.addWidget(self.__maxSpin) self.__vertLayout.insertSpacing(10, 20) self.__minLabel = QLabel("y min") self.__minLabel.setFixedSize(size) self.__vertLayout.addWidget(self.__minLabel) self.__minSpin = QSpinBox() self.__minSpin.setFixedSize(size) self.__minSpin.setRange(-10000, 10000) self.__minSpin.valueChanged.connect(self.__reScalePlot) self.__vertLayout.addWidget(self.__minSpin) self.__vertLayout.insertSpacing(10, 40) self.__typeCombo = QComboBox() self.__typeCombo.setFixedSize(size) self.__typeCombo.addItems(self.__types) self.__vertLayout.addWidget(self.__typeCombo) self.__saveButton = QPushButton(QCoreApplication.translate("VDLTools", "Save")) self.__saveButton.setFixedSize(size) self.__saveButton.clicked.connect(self.__save) self.__vertLayout.addWidget(self.__saveButton) self.__boxLayout.addLayout(self.__vertLayout) self.__maxSpin.setEnabled(False) self.__minSpin.setEnabled(False) self.__colors = [] for cn in QColor.colorNames(): qc = QColor(cn) val = qc.red() + qc.green() + qc.blue() if 0 < val < 450: self.__colors.append(cn)