def set_background_color(self, color): self.SendScintilla(QsciScintilla.SCI_STYLESETBACK, QsciScintilla.STYLE_DEFAULT, QColor(color)) self.lexer.setPaperBackground(QColor(color))
def set_painter(self, painter, light_color): """Set scroll flag area painter pen and brush colors""" painter.setPen(QColor(light_color).darker(120)) painter.setBrush(QBrush(QColor(light_color)))
def cmd_line(): """the setup.py entry point for ``pyNastranGUI``""" # this fixes the icon shown in the windows taskbar to be the custom one (not the python one) if sys.platform == 'win32': myappid = 'pynastran.pynastrangui.%s' % (pyNastran.__version__) # arbitrary string ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(myappid) from qtpy.QtWidgets import QApplication app = QApplication(sys.argv) if 0: # pragma: no cover try: import qtmodern.styles except ImportError: pass else: qtmodern.styles.dark(app) #app.setStyle('Fusion') #app.setStyle('WindowsXP') #if 0: #import qtpy.QtGui as QtGui #import qtpy.QtCore as QtCore #palette = QtGui.QPalette() #palette.setColor(QtGui.QPalette.Window, QtGui.QColor(53,53,53)) #palette.setColor(QtGui.QPalette.WindowText, QtCore.Qt.white) #palette.setColor(QtGui.QPalette.Base, QtGui.QColor(15,15,15)) #palette.setColor(QtGui.QPalette.AlternateBase, QtGui.QColor(53,53,53)) #palette.setColor(QtGui.QPalette.ToolTipBase, QtCore.Qt.white) #palette.setColor(QtGui.QPalette.ToolTipText, QtCore.Qt.white) #palette.setColor(QtGui.QPalette.Text, QtCore.Qt.white) #palette.setColor(QtGui.QPalette.Button, QtGui.QColor(53,53,53)) #palette.setColor(QtGui.QPalette.ButtonText, QtCore.Qt.white) #palette.setColor(QtGui.QPalette.BrightText, QtCore.Qt.red) #palette.setColor(QtGui.QPalette.Highlight, QtGui.QColor(142,45,197).lighter()) #palette.setColor(QtGui.QPalette.HighlightedText, QtCore.Qt.black) #app.setPalette(palette) #if 1: stylesheet = get_stylesheet() if stylesheet: app.setStyleSheet(stylesheet) if 0: # pragma: no cover import qtpy.QtGui as QtGui #import qtpy.QtCore as QtCore from qtpy.QtGui import QPalette, QColor dark_palette = QtGui.QPalette() 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)) app.setPalette(dark_palette) QApplication.setOrganizationName("pyNastran") QApplication.setOrganizationDomain(pyNastran.__website__) QApplication.setApplicationName("pyNastran") QApplication.setApplicationVersion(pyNastran.__version__) inputs = get_inputs(print_inputs=False) #inputs['app'] = app MainWindow(inputs) app.exec_()
def __init__( self, initial_values=None, data_range=None, step_size=None, collapsible=True, collapsed=False, parent=None, ): """A range slider with two handles for min/max values. Values should be provided in the range of the underlying data. (normalization to 0-1 happens internally in the slider.sliderValues()) Parameters ---------- initial_values : 2-tuple, optional Initial min & max values of the slider, defaults to (0.2, 0.8) data_range : 2-tuple, optional Min and max of the slider range, defaults to (0, 1) step_size : float, optional Single step size for the slider, defaults to 1 collapsible : bool Whether the slider is collapsible, defaults to True. collapsed : bool Whether the slider begins collapsed, defaults to False. parent : qtpy.QtWidgets.QWidget Parent widget. """ super().__init__(parent) self.handle_radius = 8 self.slider_width = 6 self.moving = "none" self.collapsible = collapsible self.collapsed = collapsed self.prev_moving = None self.bc_min = None self.bc_max = None # Variables initialized in methods self.value_min = 0 self.value_max = 1 self.start_display_min = None self.start_display_max = None self.start_pos = None self.display_min = None self.display_max = None self.setBarColor(QColor(200, 200, 200)) self.setBackgroundColor(QColor(100, 100, 100)) self.setHandleColor(QColor(200, 200, 200)) self.setHandleBorderColor(QColor(200, 200, 200)) self.setRange((0, 100) if data_range is None else data_range) self.setValues((20, 80) if initial_values is None else initial_values) if step_size is None: # pick an appropriate slider step size based on the data range if data_range is not None: step_size = (data_range[1] - data_range[0]) / 1000 else: step_size = 0.001 self.setStep(step_size) if not parent: if 'HRange' in self.__class__.__name__: self.setGeometry(200, 200, 200, 20) else: self.setGeometry(200, 200, 20, 200)
def invalidBrush(self): return QBrush(QColor("#910404"))
def paint(self, p, opt, widget): # Enforce constraints on handles r2 = Point(np.cos(np.radians(self.thetacenter)), np.sin(np.radians( self.thetacenter))) # chi center direction vector # constrain innerhandle to be parallel to outerhandle, and shorter than outerhandle self.innerhandle.setPos(r2 * self.innerradius) # constrain widthhandle to be counter-clockwise from innerhandle widthangle = np.radians(self.thetawidth / 2 + self.thetacenter) widthv = Point(np.cos(widthangle), np.sin(widthangle)) if self.thetawidth > 0 else r2 # constrain widthhandle to half way between inner and outerhandles self.widthhandle.setPos(widthv * (self.innerradius + self.outerradius) / 2) # constrain handles to base values self.outerhandle.setPos(r2 * self.outerradius) pen = self.currentPen pen.setColor(QColor(0, 255, 255)) p.setPen(pen) r = self.boundingRect() # p.drawRect(r) p.setRenderHint(QPainter.Antialiasing) p.scale(r.width(), r.height()) # workaround for GL bug centerangle = self.innerhandle.pos().angle(Point(1, 0)) startangle = centerangle - self.thetawidth / 2 endangle = centerangle + self.thetawidth / 2 r = QCircRectF(radius=0.5) if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) radius = self.innerradius / self.outerradius / 2 r = QCircRectF() r.radius = radius if self.innerradius < self.outerradius and self.thetawidth > 0: p.drawArc(r, -startangle * 16, -self.thetawidth * 16) pen.setStyle(Qt.DashLine) p.setPen(pen) p.drawLine(QPointF(0.0, 0.0), self.widthhandle.pos().norm() / 2) r1v = self.innerhandle.pos().norm() p.drawLine(QPointF(0.0, 0.0), (-1.0 * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) pen.setStyle(Qt.SolidLine) if self.innerradius < self.outerradius and self.thetawidth > 0: path = QPainterPath() path.moveTo((-1.0 * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) path.arcTo(r, -startangle, -self.thetawidth) # inside path.lineTo(self.widthhandle.pos().norm() / 2) # ? side path.arcTo(QCircRectF(radius=0.5), -endangle, self.thetawidth) # outside path.lineTo((-1.0 * self.widthhandle.pos() + 2 * self.widthhandle.pos().dot(r1v) * r1v).norm() / 2) self.path = path p.fillPath(path, QBrush(QColor(0, 255, 255, 20)))
def __init__(self, *args, pen=pg.mkPen(QColor(0, 255, 255)), **kwargs): super(LineROI, self).__init__(*args, pen=pen, **kwargs) self._update_state()
def _paint_icon(self, iconic, painter, rect, mode, state, options): """Paint a single icon.""" painter.save() color = options['color'] char = options['char'] color_options = { QIcon.On: { QIcon.Normal: (options['color_on'], options['on']), QIcon.Disabled: (options['color_on_disabled'], options['on_disabled']), QIcon.Active: (options['color_on_active'], options['on_active']), QIcon.Selected: (options['color_on_selected'], options['on_selected']) }, QIcon.Off: { QIcon.Normal: (options['color_off'], options['off']), QIcon.Disabled: (options['color_off_disabled'], options['off_disabled']), QIcon.Active: (options['color_off_active'], options['off_active']), QIcon.Selected: (options['color_off_selected'], options['off_selected']) } } color, char = color_options[state][mode] painter.setPen(QColor(color)) # A 16 pixel-high icon yields a font size of 14, which is pixel perfect # for font-awesome. 16 * 0.875 = 14 # The reason why the glyph size is smaller than the icon size is to # account for font bearing. draw_size = 0.875 * round(rect.height() * options['scale_factor']) prefix = options['prefix'] # Animation setup hook animation = options.get('animation') if animation is not None: animation.setup(self, painter, rect) painter.setFont(iconic.font(prefix, draw_size)) if 'offset' in options: rect = QRect(rect) rect.translate(options['offset'][0] * rect.width(), options['offset'][1] * rect.height()) if 'vflip' in options and options['vflip'] == True: x_center = rect.width() * 0.5 y_center = rect.height() * 0.5 painter.translate(x_center, y_center) transfrom = QTransform() transfrom.scale(1, -1) painter.setTransform(transfrom, True) painter.translate(-x_center, -y_center) if 'hflip' in options and options['hflip'] == True: x_center = rect.width() * 0.5 y_center = rect.height() * 0.5 painter.translate(x_center, y_center) transfrom = QTransform() transfrom.scale(-1, 1) painter.setTransform(transfrom, True) painter.translate(-x_center, -y_center) if 'rotated' in options: x_center = rect.width() * 0.5 y_center = rect.height() * 0.5 painter.translate(x_center, y_center) painter.rotate(options['rotated']) painter.translate(-x_center, -y_center) painter.setOpacity(options.get('opacity', 1.0)) painter.drawText(rect, Qt.AlignCenter | Qt.AlignVCenter, char) painter.restore()
def qcolor_from_color(color: Color) -> QColor: """Convert :py:class:`.Color` to :py:class:`PyQt5.QtGui.QColor`""" return QColor(color.red, color.green, color.blue)
def light(app): """ Apply Light Theme to the Qt application instance. Args: app (QApplication): QApplication instance. """ globals.applied_style = 'light' 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 renderDocument(self, plot, filename, sizeMM=(300, 200), resolution=85, format_=None): """ Render a plot to a file The format of the document will be auto-detected from the suffix of the file name. :param qwt.plot.QwtPlot plot: Plot widget :param str fileName: Path of the file, where the document will be stored :param QSizeF sizeMM: Size for the document in millimeters :param int resolution: Resolution in dots per Inch (dpi) """ if isinstance(sizeMM, tuple): sizeMM = QSizeF(*sizeMM) if format_ is None: ext = osp.splitext(filename)[1] if not ext: raise TypeError( "Unable to determine target format from filename") format_ = ext[1:] if plot is None or sizeMM.isEmpty() or resolution <= 0: return title = plot.title().text() if not title: title = "Plot Document" mmToInch = 1.0 / 25.4 size = sizeMM * mmToInch * resolution documentRect = QRectF(0.0, 0.0, size.width(), size.height()) fmt = format_.lower() if fmt in ("pdf", "ps"): printer = QPrinter() if fmt == "pdf": printer.setOutputFormat(QPrinter.PdfFormat) else: printer.setOutputFormat(QPrinter.PostScriptFormat) printer.setColorMode(QPrinter.Color) printer.setFullPage(True) printer.setPaperSize(sizeMM, QPrinter.Millimeter) printer.setDocName(title) printer.setOutputFileName(filename) printer.setResolution(resolution) painter = QPainter(printer) self.render(plot, painter, documentRect) painter.end() elif fmt == "svg": generator = QSvgGenerator() generator.setTitle(title) generator.setFileName(filename) generator.setResolution(resolution) generator.setViewBox(documentRect) painter = QPainter(generator) self.render(plot, painter, documentRect) painter.end() elif fmt in QImageWriter.supportedImageFormats(): imageRect = documentRect.toRect() dotsPerMeter = int(round(resolution * mmToInch * 1000.0)) image = QImage(imageRect.size(), QImage.Format_ARGB32) image.setDotsPerMeterX(dotsPerMeter) image.setDotsPerMeterY(dotsPerMeter) image.fill(QColor(Qt.white).rgb()) painter = QPainter(image) self.render(plot, painter, imageRect) painter.end() image.save(filename, fmt) else: raise TypeError("Unsupported file format '%s'" % fmt)
def dark(app): """ Apply Dark Theme to the Qt application instance. Args: app (QApplication): QApplication instance. """ globals.applied_style = 'dark' 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 set_text_color(self, color): self.text_color = color self.lighttext_color = QColor(self.text_color.red() - 30, self.text_color.green() - 30, self.text_color.blue() - 30) self.set_style()
def set_margin_background_color(self, color): self.setMarginsBackgroundColor(QColor(color))
def _show_message(self, text): """Show message on splash screen.""" self.splash.showMessage(text, int(Qt.AlignBottom | Qt.AlignCenter | Qt.AlignAbsolute), QColor(Qt.white))
def test_color_conversion(): color1 = QColor(70, 52, 190) color2 = color_from_qcolor(color1) assert qcolor_from_color(color2) == color1 assert color_from_qcolor(qcolor_from_color(color2)) == color2
def _get_splash_image_name(): # gets the width of the screen where the main window was initialised width = QGuiApplication.primaryScreen().size().width() if width > 2048: return ':/images/MantidSplashScreen_4k.jpg' else: return ':/images/MantidSplashScreen.png' SPLASH = QSplashScreen(QPixmap(_get_splash_image_name()), Qt.WindowStaysOnTopHint) SPLASH.show() SPLASH.showMessage("Starting...", Qt.AlignBottom | Qt.AlignLeft | Qt.AlignAbsolute, QColor(Qt.black)) # The event loop has not started - force event processing QApplication.processEvents(QEventLoop.AllEvents) # ----------------------------------------------------------------------------- # MainWindow # ----------------------------------------------------------------------------- class MainWindow(QMainWindow): DOCKOPTIONS = QMainWindow.AllowTabbedDocks | QMainWindow.AllowNestedDocks def __init__(self): QMainWindow.__init__(self) # -- instance attributes --
def css_rgb(color, a=None): """Get a CSS `rgb` or `rgba` string from a QColor ot Qt.GlobalColor.""" if isinstance(color, Qt.GlobalColor): color = QColor(color) return ("rgba({}, {}, {}, {})" if a else "rgb({}, {}, {})").format( *color.getRgb())
def __init__(self, *args, pen=pg.mkPen(QColor(0, 255, 255)), **kwargs): super(RectROI, self).__init__(*args, pen=pen, **kwargs) self.handle = self.handles[0]
uVRANGE = 250 # uV. y-axis range per channel, use +- this value. YRANGE_RASTER = 8 # Number of rows. NPLOTSRAW = 8 # number of rows in the Raw feature plots NWAVEFORMS = 200 # Default max number of waveforms to plot. NPLOTSEGMENTS = 20 # Divide the Sweep plot into this many segments; each segment will be updated independent of rest. # Colors and Fonts THEMES = { 'dark': { 'pencolors': ["cyan", QColor(0, 255, 0), "magenta", "red", "yellow", "white"], 'bgcolor': Qt.black, 'labelcolor': Qt.gray, 'axiscolor': Qt.gray, 'axiswidth': 1 } } WF_COLORS = ["white", "magenta", "cyan", "yellow", "purple", "green"] LABEL_FONT_POINT_SIZE = 24 # Default settings. If finds a category of features with the same name, will apply the value here. DEPTHSETTINGS = {'threshold': True, 'validity': 90.0}
def create_high_dpi_drop_indicator_pixmap(self, size: QSizeF, area: DockWidgetArea, mode: OverlayMode) -> QPixmap: ''' Create high dpi drop indicator pixmap Parameters ---------- size : QSizeF area : DockWidgetArea mode : OverlayMode Returns ------- value : QPixmap ''' border_color = self.icon_color(IconColor.frame_color) background_color = self.icon_color(IconColor.window_background_color) window = self.public.window() # QT version compatibility (TODO necessary for qtpy?) device_pixel_ratio = (window.devicePixelRatioF() if hasattr( window, 'devicePixelRatioF') else window.devicePixelRatio()) pixmap_size = QSizeF(size * device_pixel_ratio) pm = QPixmap(pixmap_size.toSize()) pm.fill(QColor(0, 0, 0, 0)) p = QPainter(pm) pen = p.pen() shadow_rect = QRectF(pm.rect()) base_rect = QRectF() base_rect.setSize(shadow_rect.size() * 0.7) base_rect.moveCenter(shadow_rect.center()) # Fill shadow_color = self.icon_color(IconColor.shadow_color) if shadow_color.alpha() == 255: shadow_color.setAlpha(64) p.fillRect(shadow_rect, shadow_color) # Drop area rect. p.save() area_rect = QRectF() area_line = QLineF() non_area_rect = QRectF() if area == DockWidgetArea.top: area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width(), base_rect.height() * .5) non_area_rect = QRectF(base_rect.x(), shadow_rect.height() * .5, base_rect.width(), base_rect.height() * .5) area_line = QLineF(area_rect.bottomLeft(), area_rect.bottomRight()) elif area == DockWidgetArea.right: area_rect = QRectF(shadow_rect.width() * .5, base_rect.y(), base_rect.width() * .5, base_rect.height()) non_area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width() * .5, base_rect.height()) area_line = QLineF(area_rect.topLeft(), area_rect.bottomLeft()) elif area == DockWidgetArea.bottom: area_rect = QRectF(base_rect.x(), shadow_rect.height() * .5, base_rect.width(), base_rect.height() * .5) non_area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width(), base_rect.height() * .5) area_line = QLineF(area_rect.topLeft(), area_rect.topRight()) elif area == DockWidgetArea.left: area_rect = QRectF(base_rect.x(), base_rect.y(), base_rect.width() * .5, base_rect.height()) non_area_rect = QRectF(shadow_rect.width() * .5, base_rect.y(), base_rect.width() * .5, base_rect.height()) area_line = QLineF(area_rect.topRight(), area_rect.bottomRight()) baseSize = base_rect.size() if (OverlayMode.container == mode and area != DockWidgetArea.center): base_rect = area_rect p.fillRect(base_rect, background_color) if area_rect.isValid(): pen = p.pen() pen.setColor(border_color) Color = self.icon_color(IconColor.overlay_color) if Color.alpha() == 255: Color.setAlpha(64) p.setBrush(Color) p.setPen(Qt.NoPen) p.drawRect(area_rect) pen = p.pen() pen.setWidth(1) pen.setColor(border_color) pen.setStyle(Qt.DashLine) p.setPen(pen) p.drawLine(area_line) p.restore() p.save() # Draw outer border pen = p.pen() pen.setColor(border_color) pen.setWidth(1) p.setBrush(Qt.NoBrush) p.setPen(pen) p.drawRect(base_rect) # draw window title bar p.setBrush(border_color) frame_rect = QRectF(base_rect.topLeft(), QSizeF(base_rect.width(), baseSize.height() / 10)) p.drawRect(frame_rect) p.restore() # Draw arrow for outer container drop indicators if (OverlayMode.container == mode and area != DockWidgetArea.center): arrow_rect = QRectF() arrow_rect.setSize(baseSize) arrow_rect.setWidth(arrow_rect.width() / 4.6) arrow_rect.setHeight(arrow_rect.height() / 2) arrow_rect.moveCenter(QPointF(0, 0)) arrow = QPolygonF() arrow.append(arrow_rect.topLeft()) arrow.append(QPointF(arrow_rect.right(), arrow_rect.center().y())) arrow.append(arrow_rect.bottomLeft()) p.setPen(Qt.NoPen) p.setBrush(self.icon_color(IconColor.arrow_color)) p.setRenderHint(QPainter.Antialiasing, True) p.translate(non_area_rect.center().x(), non_area_rect.center().y()) if area == DockWidgetArea.top: p.rotate(-90) elif area == DockWidgetArea.right: ... elif area == DockWidgetArea.bottom: p.rotate(90) elif area == DockWidgetArea.left: p.rotate(180) p.drawPolygon(arrow) pm.setDevicePixelRatio(device_pixel_ratio) return pm
def hoverEnterEvent(self, e): self._brush = QBrush(QColor(Qt.white)) print("hover enter") super(RoiHandle, self).hoverEnterEvent(e)
def __set_chart(self, tab_name: str, pos_x: int, pos_y: int) -> None: """Setting charts by data index. pos_x / pos_y: [0], [1], [2] time_fitness: List[List[Tuple[gen, fitness, time]]] """ axis_x = QtCharts.QCategoryAxis() axis_y = QtCharts.QValueAxis() axis_x.setLabelsPosition( QtCharts.QCategoryAxis.AxisLabelsPositionOnValue) axis_x.setMin(0) axis_y.setTickCount(11) if self.algorithm_data: # Just copy references from algorithm data plot: _Plot = [ data['time_fitness'] for data in self.algorithm_data ] # X max max_x = int(max(max(tnf[pos_x] for tnf in data) for data in plot)) * 100 axis_x.setMax(max_x) i10 = int(max_x / 10) if i10: for i in range(0, max_x + 1, i10): axis_x.append(str(i / 100), i) else: for i in range(0, 1000, 100): axis_x.append(str(i / 100), i) # Y max max_y = max(max([tnf[pos_y] for tnf in data]) for data in plot) + 10 else: plot = [] # Y max max_y = 100 max_y -= max_y % 10 axis_y.setRange(0., max_y) chart = DataChart(self.title, axis_x, axis_y, self.monochrome) # Append data set for i, data in enumerate(self.algorithm_data): line = QtCharts.QLineSeries() scatter = QtCharts.QScatterSeries() line.setName(f"{i}: {data['algorithm']}") scatter.setMarkerSize(7) scatter.setColor(QColor(110, 190, 30)) if plot: for e in plot[self.algorithm_data.index(data)]: y = e[pos_y] x = e[pos_x] * 100 line.append(QPointF(x, y)) scatter.append(QPointF(x, y)) for series in (line, scatter): chart.addSeries(series) series.attachAxis(axis_x) series.attachAxis(axis_y) chart.legend().markers(scatter)[0].setVisible(False) # Add chart into tab widget widget = QWidget() self.tabWidget.addTab(widget, QIcon(), tab_name) layout = QVBoxLayout(widget) layout.setContentsMargins(2, 2, 2, 2) chart_view = QtCharts.QChartView(chart) chart_view.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) layout.addWidget(chart_view)
def hoverLeaveEvent(self, e): self._brush = QBrush(QColor(Qt.transparent)) super(RoiHandle, self).hoverLeaveEvent(e)
def populate_tree(self, parentItem, children_list): """Recursive method to create each item (and associated data) in the tree.""" for child_key in children_list: self.item_depth += 1 (filename, line_number, function_name, file_and_line, node_type) = self.function_info(child_key) ((total_calls, total_calls_dif), (loc_time, loc_time_dif), (cum_time, cum_time_dif)) = self.format_output(child_key) child_item = TreeWidgetItem(parentItem) self.item_list.append(child_item) self.set_item_data(child_item, filename, line_number) # FIXME: indexes to data should be defined by a dictionary on init child_item.setToolTip(0, _('Function or module name')) child_item.setData(0, Qt.DisplayRole, function_name) child_item.setIcon(0, self.icon_list[node_type]) child_item.setToolTip(1, _('Time in function '\ '(including sub-functions)')) child_item.setData(1, Qt.DisplayRole, cum_time) child_item.setTextAlignment(1, Qt.AlignRight) child_item.setData(2, Qt.DisplayRole, cum_time_dif[0]) child_item.setForeground(2, QColor(cum_time_dif[1])) child_item.setTextAlignment(2, Qt.AlignLeft) child_item.setToolTip(3, _('Local time in function '\ '(not in sub-functions)')) child_item.setData(3, Qt.DisplayRole, loc_time) child_item.setTextAlignment(3, Qt.AlignRight) child_item.setData(4, Qt.DisplayRole, loc_time_dif[0]) child_item.setForeground(4, QColor(loc_time_dif[1])) child_item.setTextAlignment(4, Qt.AlignLeft) child_item.setToolTip(5, _('Total number of calls '\ '(including recursion)')) child_item.setData(5, Qt.DisplayRole, total_calls) child_item.setTextAlignment(5, Qt.AlignRight) child_item.setData(6, Qt.DisplayRole, total_calls_dif[0]) child_item.setForeground(6, QColor(total_calls_dif[1])) child_item.setTextAlignment(6, Qt.AlignLeft) child_item.setToolTip(7, _('File:line '\ 'where function is defined')) child_item.setData(7, Qt.DisplayRole, file_and_line) #child_item.setExpanded(True) if self.is_recursive(child_item): child_item.setData(7, Qt.DisplayRole, '(%s)' % _('recursion')) child_item.setDisabled(True) else: callees = self.find_callees(child_key) if self.item_depth < 3: self.populate_tree(child_item, callees) elif callees: child_item.setChildIndicatorPolicy( child_item.ShowIndicator) self.items_to_be_shown[id(child_item)] = callees self.item_depth -= 1
def paint(self, p=QPainter(), o=QStyleOptionGraphicsItem(), widget=None): p.setPen(QPen(QColor(255, 255, 255, 200))) p.setBrush(self._brush)
def paintEvent(self, event): """ Override Qt method. Painting the scroll flag area """ make_flag = self.make_flag_qrect # Fill the whole painting area painter = QPainter(self) painter.fillRect(event.rect(), self.editor.sideareas_color) # Paint warnings and todos block = self.editor.document().firstBlock() for line_number in range(self.editor.document().blockCount()+1): data = block.userData() if data: if data.code_analysis: # Paint the warnings color = self.editor.warning_color for source, code, severity, message in data.code_analysis: error = severity == DiagnosticSeverity.ERROR if error: color = self.editor.error_color break self.set_painter(painter, color) painter.drawRect(make_flag(line_number)) if data.todo: # Paint the todos self.set_painter(painter, self.editor.todo_color) painter.drawRect(make_flag(line_number)) if data.breakpoint: # Paint the breakpoints self.set_painter(painter, self.editor.breakpoint_color) painter.drawRect(make_flag(line_number)) block = block.next() # Paint the occurrences if self.editor.occurrences: self.set_painter(painter, self.editor.occurrence_color) for line_number in self.editor.occurrences: painter.drawRect(make_flag(line_number)) # Paint the found results if self.editor.found_results: self.set_painter(painter, self.editor.found_results_color) for line_number in self.editor.found_results: painter.drawRect(make_flag(line_number)) # Paint the slider range if not self._unit_testing: alt = QApplication.queryKeyboardModifiers() & Qt.AltModifier else: alt = self._alt_key_is_down cursor_pos = self.mapFromGlobal(QCursor().pos()) is_over_self = self.rect().contains(cursor_pos) is_over_editor = self.editor.rect().contains( self.editor.mapFromGlobal(QCursor().pos())) # We use QRect.contains instead of QWidget.underMouse method to # determined if the cursor is over the editor or the flag scrollbar # because the later gives a wrong result when a mouse button # is pressed. if ((is_over_self or (alt and is_over_editor)) and self.slider): pen_color = QColor(Qt.gray) pen_color.setAlphaF(.85) painter.setPen(pen_color) brush_color = QColor(Qt.gray) brush_color.setAlphaF(.5) painter.setBrush(QBrush(brush_color)) painter.drawRect(self.make_slider_range(cursor_pos)) self._range_indicator_is_visible = True else: self._range_indicator_is_visible = False
(STEP_COLUMN_ERROR, ids.ERROR), (STEP_COLUMN_STATUS, ids.STATUS), ( STEP_COLUMN_DURATION, DURATION, ), # Duration is based on two data fields, not coming directly from ert (STEP_COLUMN_STDOUT, ids.STDOUT), (STEP_COLUMN_STDERR, ids.STDERR), (STEP_COLUMN_CURRENT_MEMORY_USAGE, ids.CURRENT_MEMORY_USAGE), (STEP_COLUMN_MAX_MEMORY_USAGE, ids.MAX_MEMORY_USAGE), ], NodeType.JOB: [], } _QCOLORS = { state.COLOR_WAITING: QColor(*state.COLOR_WAITING), state.COLOR_PENDING: QColor(*state.COLOR_PENDING), state.COLOR_RUNNING: QColor(*state.COLOR_RUNNING), state.COLOR_FAILED: QColor(*state.COLOR_FAILED), state.COLOR_UNKNOWN: QColor(*state.COLOR_UNKNOWN), state.COLOR_FINISHED: QColor(*state.COLOR_FINISHED), state.COLOR_NOT_ACTIVE: QColor(*state.COLOR_NOT_ACTIVE), } def _estimate_duration(start_time, end_time=None): timezone = None if start_time.tzname() is not None: timezone = tz.gettz(start_time.tzname()) end_time = end_time or datetime.datetime.now(timezone) return end_time - start_time
# Linux packagers, please set this to True if you want to make qtawesome # use system fonts SYSTEM_FONTS = False # MD5 Hashes for font files bundled with qtawesome: MD5_HASHES = { 'fontawesome4.7-webfont.ttf': 'b06871f281fee6b241d60582ae9369b9', 'fontawesome5-regular-webfont.ttf': '6a745dc6a0871f350b0219f5a2678838', 'fontawesome5-solid-webfont.ttf': 'acf50f59802f20d8b45220eaae532a1c', 'fontawesome5-brands-webfont.ttf': 'ed2b8bf117160466ba6220a8f1da54a4', 'elusiveicons-webfont.ttf': '207966b04c032d5b873fd595a211582e', 'materialdesignicons-webfont.ttf': 'b0fd91bb29dcb296a9a37f8bda0a2d85', } _default_options = { 'color': QColor(50, 50, 50), 'color_disabled': QColor(150, 150, 150), 'opacity': 1.0, 'scale_factor': 1.0, } def set_global_defaults(**kwargs): """Set global defaults for the options passed to the icon painter.""" valid_options = [ 'active', 'selected', 'disabled', 'on', 'off', 'on_active', 'on_selected', 'on_disabled', 'off_active', 'off_selected', 'off_disabled', 'color', 'color_on', 'color_off', 'color_active', 'color_selected', 'color_disabled',
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) if qt_version in [4, 'pyside']: view.horizontalHeader().setResizeMode(QHeaderView.Stretch) else: 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()