def __init__(self, wowner, configuration, recno): expedition = Everest.Expedition(configuration, recno) self.li_routes, self.current, svg, label = expedition.gen_routes() titulo = _("Everest") icono = Iconos.Trekking() extparam = "expedition" QTVarios.WDialogo.__init__(self, wowner, titulo, icono, extparam) self.selected = False wsvg = QtSvg.QSvgWidget() wsvg.load(QtCore.QByteArray(svg)) wsvg.setFixedSize(762, int(762.0 * 520.0 / 1172.0)) lySVG = Colocacion.H().relleno(1).control(wsvg).relleno(1) li_acciones = ( (_("Climb"), Iconos.Empezar(), self.climb), None, (_("Close"), Iconos.MainMenu(), self.cancel), None, ) tb = Controles.TBrutina(self, li_acciones).vertical() if self.current is None: tb.setAccionVisible(self.climb, False) lyRot = Colocacion.H() for elem in label: lb_rotulo = Controles.LB(self, elem).align_center() lb_rotulo.setStyleSheet( "QWidget { border-style: groove; border-width: 2px; border-color: LightSlateGray ;}" ) lb_rotulo.ponTipoLetra(puntos=12, peso=700) lyRot.control(lb_rotulo) o_columns = Columnas.ListaColumnas() o_columns.nueva("ROUTE", _("Route"), 240, centered=True) o_columns.nueva("GAMES", _("Games"), 80, centered=True) o_columns.nueva("DONE", _("Done"), 80, centered=True) o_columns.nueva("TIME", _("Time"), 80, centered=True) o_columns.nueva("MTIME", _("Average time"), 80, centered=True) o_columns.nueva("MPOINTS", _("Av. lost points"), 80, centered=True) o_columns.nueva("TRIES", _("Max tries"), 80, centered=True) o_columns.nueva("TOLERANCE", _("Tolerance"), 80, centered=True) grid = Grid.Grid(self, o_columns, siSelecFilas=True, siSeleccionMultiple=False) grid.setMinimumWidth(grid.anchoColumnas() + 20) grid.coloresAlternados() lyG = Colocacion.V().otro(lyRot).control(grid).margen(0) lyR = Colocacion.H().control(tb).otro(lyG).margen(0) ly = Colocacion.V().otro(lySVG).otro(lyR).margen(3) self.setLayout(ly) self.restore_video(siTam=True, anchoDefecto=784, altoDefecto=670)
def __init__(self, escena, bloqueMarker, rutinaPulsada=None, siEditando=False): super(MarkerSC, self).__init__(escena, bloqueMarker) self.rutinaPulsada = rutinaPulsada self.rutinaPulsadaCarga = None self.distBordes = 0.20 * bloqueMarker.anchoCasilla self.pixmap = QtSvg.QSvgRenderer( QtCore.QByteArray(bloqueMarker.xml.encode())) self.posicion2xy() self.siMove = False self.tpSize = None self.siEditando = siEditando self.siRecuadro = False if siEditando: self.setAcceptHoverEvents(True)
def __init__(self, procesador): route = self.route = Routes.Transsiberian(procesador.configuration) titulo = "%s (%d)" % (_("Transsiberian Railway"), route.level) icono = Iconos.Train() extparam = "transsiberian" QTVarios.WDialogo.__init__(self, procesador.main_window, titulo, icono, extparam) self.procesador = procesador wsvg = QtSvg.QSvgWidget() x = self.route.get_txt().encode("utf-8") wsvg.load(QtCore.QByteArray(x)) wsvg.setFixedSize(762, 762.0 * 658.0 / 1148.0) lySVG = Colocacion.H().relleno(1).control(wsvg).relleno(1) # Title lbTit = self.LINE(_("Moscow"), _("Vladivostok"), 14, 500).altoFijo(26) lbKM = self.KM(route.total_km, 12, 500).altoFijo(26) self.set_style("White", "#33322C", lbTit, lbKM) lbKMdone = self.KM(route.km, 12, 500).altoFijo(26) self.set_border(lbKMdone) lyTitle = Colocacion.H().control(lbTit).control(lbKM).control(lbKMdone) if route.is_ended(): self.init_ended(route, lyTitle, lySVG) else: self.init_working(route, lyTitle, lySVG) self.restore_video(siTam=False)
def make_thumbnail(self, src_path, tgt_path, size, src_format): # generate a thumbnail stat = os.stat(src_path) ta, tm = stat.st_atime, stat.st_mtime if src_format == "svg": renderer = QtSvg.QSvgRenderer(src_path) rnd_size = renderer.defaultSize() rw, rh = rnd_size.width(), rnd_size.height() scale = max(rw / size, rh / size) w, h = int(round(rw / scale)), int(round(rh / scale)) pixmap = QtGui.QPixmap(w, h) pixmap.fill(QtCore.Qt.white) painter = QtGui.QPainter(pixmap) renderer.render(painter) pixmap.save(tgt_path) painter.end() else: try: icon = Image.open(src_path).convert("RGB") except: return icon.thumbnail((size, size), Image.ANTIALIAS) icon.save(tgt_path, quality=100) icon.close() os.utime(tgt_path, (ta, tm))
def show(self, *args, **kwargs): """ Displays this window """ # Transparent Background # # See: https://doc.qt.io/qt-5/qt.html#WindowType-enum # This combination works on Windows 10 # Note: It may not work on Ubuntu... # Has Keyboard Focus self.setWindowFlags( Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint ) # Not Sure if this is needed at all # window.setStyleSheet("background:transparent;") self.setAttribute(Qt.WA_TranslucentBackground) # Load SVG Data self._svg = QtSvg.QSvgWidget(parent=self) self._redraw() # Adopt size self.resize(self._width, self._height) self._svg.resize(self._width, self._height) self._start_timer() super().show(*args, **kwargs)
def reset(self): self.posicion2xy() bm = self.bloqueDatos self.pixmap = QtSvg.QSvgRenderer(QtCore.QByteArray(bm.xml.encode())) self.setOpacity(bm.opacidad) self.setZValue(bm.position.orden) self.update()
def generaPM(piezas): # dicPM["V"] = Iconos.pmComentario() dicPM["R"] = Iconos.pmOpening() dicPM["M"] = Iconos.pmComentarioMas() dicPM["S"] = Iconos.pmOpeningComentario() dicPM["O"] = Iconos.pmOpening() dicPM["C"] = Iconos.pmComment() dicPM["V"] = Iconos.pmVariation() dicPM["OC"] = Iconos.pmOpeningComment() dicPM["OV"] = Iconos.pmOpeningVariation() dicPM["VC"] = Iconos.pmVariationComment() dicPM["OVC"] = Iconos.pmOpeningVariationComment() dicPM["T"] = Iconos.pmThemes() for k in "KQRNBkqrnb": dicPZ[k] = piezas.render(k) nags_folder = Code.path_resource("IntFiles", "NAGs") for f in os.listdir(nags_folder): if f.endswith(".svg") and f.startswith("$") and len(f) > 5: nag = f[1:-4] if nag.isdigit(): fsvg = nags_folder + "/" + f dicNG[nag] = QtSvg.QSvgRenderer(fsvg)
def __initSVGFile(self, filename): generator = QtSvg.QSvgGenerator() generator.setFileName(os.path.join(self.__startDir, filename)) generator.setSize(QtCore.QSize(self.__width, self.__height)) generator.setViewBox(QtCore.QRect(0, 0, self.__width, self.__height)) painter = QtGui.QPainter(generator) painter.setClipRect(QtCore.QRect(0, 0, self.__width, self.__height)) return generator, painter
def intrinsicSize(self, doc, posInDocument, format): renderer = QtSvg.QSvgRenderer(format.property(Window.SvgData).toByteArray()) size = renderer.defaultSize() if size.height() > 25: size *= 25.0 / size.height() return QtCore.QSizeF(size)
def _render_svg(self): renderer = QtSvg.QSvgRenderer(self.path) self._image = QtGui.QImage(QtCore.QSize(self.px, self.px), QtGui.QImage.Format_ARGB32) self._painter = QtGui.QPainter(self._image) if self._alpha is not None: self._painter.setOpacity(self._alpha) renderer.render(self._painter)
def __init__(self, properties: Properties, character_controller: CharacterController, **kwargs) -> None: self._rendered_img = None self.pixmap: QIcon = QIcon() self.properties = properties self.editable_properties = [] self.uid = uuid.uuid4() self.svg_renderer = QtSvg.QSvgRenderer() self.character_controller = character_controller
def svg2pm(svg, tam): pm = QtGui.QPixmap(tam, tam) pm.fill(QtCore.Qt.transparent) qb = QtCore.QByteArray(svg) render = QtSvg.QSvgRenderer(qb) painter = QtGui.QPainter() painter.begin(pm) render.render(painter) painter.end() return pm
def __init__(self, svgImage, labelname, max, min): super().__init__() self.svgWidget = QtSvg.QSvgWidget(svgImage) self.label = QLabel(labelname, self) self.labelMin = QLabel(str(min)) self.labelMax = QLabel(str(max)) # Instance: self.schemeLabelMinMax = QGridLayout() self.widgetMinMax = QWidget() self.scheme = QGridLayout() self.init_ui()
def IconFromSvg(svg_path: str): labelImage = QtWidgets.QLabel() svg_renderer = QtSvg.QSvgRenderer(svg_path) image = QtGui.QImage(64, 64, QtGui.QImage.Format_ARGB32) image.fill(QtCore.Qt.darkGreen) svg_renderer.render(QtGui.QPainter(image)) pixmap = QtGui.QPixmap.fromImage(image) pixmap_small = pixmap.scaled(20, 20, QtCore.Qt.KeepAspectRatio) labelImage.setPixmap(pixmap) return labelImage
def iconFromPath(filePath): if QtGui != QtWidgets: return QtGui.QIcon(filePath) renderer = QtSvg.QSvgRenderer(filePath) pixmap = QtGui.QPixmap(renderer.defaultSize()) pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) renderer.render(painter) painter.end() return QtGui.QIcon(pixmap)
def SvgIcon(img_path: str): svg_widg = QtSvg.QSvgWidget() svg_widg.load(img_path) svg_widg.setStyleSheet(""" background-color: transparent; border: none; fill: white; color: white; """) svg_widg.setFixedSize(QtCore.QSize(20, 20)) return svg_widg
def __init__(self, context_menu): super().__init__() self._port = '' self._color = OFFLINE_COLOR self.context_menu = context_menu self.arrows = set() self.renderer = QtSvg.QSvgRenderer() self.update_svg() self.setSharedRenderer(self.renderer) #self.setScale(2.0) #self.setTransformOriginPoint(24, 24) self.setFlag(QtWidgets.QGraphicsItem.ItemIsMovable, True) self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True)
def icono(self, pieza, name): fich = Code.path_resource("Pieces", name, "%s%s.svg" % ("w" if pieza.isupper() else "b", pieza.lower())) with open(fich, "rb") as f: qb = QtCore.QByteArray(f.read()) pm = QtGui.QPixmap(32, 32) pm.fill(QtCore.Qt.transparent) render = QtSvg.QSvgRenderer(qb) painter = QtGui.QPainter() painter.begin(pm) render.render(painter) painter.end() icon = QtGui.QIcon(pm) return icon
def __init__(self, parent=None): super(BusyIndicator, self).__init__(parent) self.resize(80, 80) layout = QtWidgets.QHBoxLayout() svg = QtSvg.QSvgWidget() path = os.path.join(PATH, 'svg', 'oval.svg') svg.load(path) layout.addWidget(svg) self.setLayout(layout) self.hide()
def _loadSvgIcon(iconName, size): svgRenderer = QtSvg.QSvgRenderer(iconName) if svgRenderer.isValid(): pixmap = QtGui.QPixmap(QtCore.QSize(size, size)) if not pixmap.isNull(): pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) svgRenderer.render(painter) painter.end() return QtGui.QIcon(pixmap) return None
def saveAllPNG(self, name, px): for pieza in "pnbrqk": for color in "wb": fich = Code.path_resource("Pieces", name, "%s%s.svg" % (color, pieza)) with open(fich, "rb") as f: qb = QtCore.QByteArray(f.read()) pm = QtGui.QPixmap(px, px) pm.fill(QtCore.Qt.transparent) render = QtSvg.QSvgRenderer(qb) painter = QtGui.QPainter() painter.begin(pm) render.render(painter) painter.end() pm.save(Code.path_resource("IntFiles", "Figs", "%s%s.png" % (color, pieza)), "PNG")
def __init__(self, parent=None): super(BusyIndicator, self).__init__(parent) self.resize(100, 100) self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint) layout = QtWidgets.QHBoxLayout() svg = QtSvg.QSvgWidget() svg.load(u":/svg/tail-spin.svg") layout.addWidget(svg) self.setLayout(layout) self.hide()
def update_tooltip(self, gap=5): nodes = [node() for node in self.children] n_side = len(nodes) if n_side > 3: n_side = max(1, int(n_side**0.5)) x = 0 y = 0 h_max = 0 n = 0 x_max, y_max = 0, 0 positions = [] for node in nodes: positions.append([x + gap, y + gap]) w, h = node._rect.width() + gap, node._rect.height() + gap h_max = max(h_max, h) x += w n += 1 if n > n_side: x = 0 y += h_max h_max = 0 n = 0 x_max = max(x_max, x + w) y_max = max(y_max, y + h) if n_side == len(nodes): x_max -= w scale = SCALE_TOOLTIP / SCALE_DRAWINGS buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.WriteOnly) gen = QtSvg.QSvgGenerator() gen.setOutputDevice(buffer) painter = QtGui.QPainter(gen) painter.scale(scale, scale) painter.setPen(QtGui.QPen(QtCore.Qt.white, 0)) painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) rect = QtCore.QRectF(0, 0, x_max, y_max) painter.drawRect(rect) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.5)) for i in range(len(nodes)): x, y = positions[i] painter.drawPicture(x, y, nodes[i].picture) painter.drawText(rect, QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom, self.label) painter.end() self.tool_tip = "<img src=\"data:image/png;base64,%s\">" % (bytes( buffer.data().toBase64()).decode())
def generaPM(piezas): dicPM["V"] = Iconos.pmComentario() dicPM["R"] = Iconos.pmApertura() dicPM["M"] = Iconos.pmComentarioMas() dicPM["S"] = Iconos.pmAperturaComentario() for k in "KQRNBkqrnb": dicPZ[k] = piezas.render(k) carpNAGs = Code.path_resource("IntFiles", "NAGs") for f in os.listdir(carpNAGs): if f.endswith(".svg") and f.startswith("$") and len(f) > 5: nag = f[1:-4] if nag.isdigit(): fsvg = carpNAGs + "/" + f dicNG[nag] = QtSvg.QSvgRenderer(fsvg)
def __loadSvgIcon(self, iconName, size): currentDir = os.path.dirname(__file__) iconFile = os.path.abspath(os.path.join(currentDir, iconName + '.svg')) svgRenderer = QtSvg.QSvgRenderer(iconFile) if svgRenderer.isValid(): pixmap = QtGui.QPixmap(QtCore.QSize(size, size)) if not pixmap.isNull(): pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) svgRenderer.render(painter) painter.end() return QtGui.QIcon(pixmap) return None
def load_svg_icon(icon_name, size): current_dir = Path(__file__).resolve().parent icon_file = current_dir / "res" / (icon_name + '.svg') svg_renderer = QtSvg.QSvgRenderer(str(icon_file)) if svg_renderer.isValid(): pixmap = QtGui.QPixmap(QtCore.QSize(size, size)) if not pixmap.isNull(): pixmap.fill(QtCore.Qt.transparent) painter = QtGui.QPainter(pixmap) svg_renderer.render(painter) painter.end() return QtGui.QIcon(pixmap) return None
def _update_graph(self, dot_scene): basename = op.join(tempfile.gettempdir(), 'ngl_scene.') dotfile = basename + 'dot' svgfile = basename + 'svg' open(dotfile, 'w').write(dot_scene.decode('ascii')) try: subprocess.call(['dot', '-Tsvg', dotfile, '-o' + svgfile]) except OSError as e: QtWidgets.QMessageBox.critical(self, 'Graphviz error', 'Error while executing dot (Graphviz): %s' % e.strerror, QtWidgets.QMessageBox.Ok) return item = QtSvg.QGraphicsSvgItem(svgfile) self._scene.clear() self._scene.addItem(item) self._scene.setSceneRect(item.boundingRect())
def update_tooltip(self): buffer = QtCore.QBuffer() buffer.open(QtCore.QIODevice.WriteOnly) scale = SCALE_TOOLTIP / SCALE_DRAWINGS gen = QtSvg.QSvgGenerator() gen.setOutputDevice(buffer) painter = QtGui.QPainter(gen) painter.scale(scale, scale) rect = self._rect.marginsAdded(QtCore.QMargins(10, 10, 10, 10)) rect = QtCore.QRectF(rect.x(), rect.y(), rect.width() * 0.8, rect.height()) painter.setPen(QtGui.QPen(QtCore.Qt.white, 0)) painter.setBrush(QtGui.QBrush(QtCore.Qt.white)) painter.drawRect(rect) painter.setPen(QtGui.QPen(QtCore.Qt.black, 0.5)) painter.drawPicture(0, 0, self.picture) painter.drawText(rect, QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom, self.label) painter.end() self.tool_tip = "<img src=\"data:image/png;base64,%s\">" % (bytes( buffer.data().toBase64()).decode())
def batchConvert(tpList, delay=0.1): '''Convert thumbnails, using tiered convert method. ''' # Primary convert_primary = MIB_CONVERTERMAP[cfg.convert_primary] # Secondary convert_secondary = None if cfg.convert_secondary and cfg.convert_secondary != 'None': convert_secondary = MIB_CONVERTERMAP[cfg.convert_secondary] if utils.makeCachePath(cfg.cache): for tp in tpList: useError = False result = convert_primary.run(tp, cfg.max_size) if not result and convert_secondary: result = convert_secondary.run(tp, cfg.max_size) if not result: useError = True elif not result and not convert_secondary: useError = True # Render placeholder error thumbnail, SVG for max size flexibility if useError: utils.warn('Could not build thumbnail for: %s' % tp.sourcePath) svgRenderer = QtSvg.QSvgRenderer( utils.getCustomIconPath(cfg.resourcePath, 'error.svg')) svgImage = QtGui.QImage(cfg.max_size, cfg.max_size, QtGui.QImage.Format_ARGB32) painter = QtGui.QPainter(svgImage) svgRenderer.render(painter) svgImage.save(tp.thumbnailPath) painter.end() # delay to for responsiveness time.sleep(delay)
def __init__(self, escena, bloqueImgSVG, rutinaPulsada=None, siEditando=False): super(SVGSC, self).__init__(escena, bloqueImgSVG) self.rutinaPulsada = rutinaPulsada self.rutinaPulsadaCarga = None self.distBordes = 0.30 * bloqueImgSVG.width_square self.pixmap = QtSvg.QSvgRenderer( QtCore.QByteArray(bloqueImgSVG.xml.encode("utf-8"))) self.physical_pos2xy() self.siMove = False self.tpSize = None self.siRecuadro = False if siEditando: self.setAcceptHoverEvents(True)