class CompassWidget(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) self.compass = QSvgRenderer("compassBody.svg") self.needle = QSvgRenderer("compassNeedle.svg") self.angle = 0 def paintEvent(self, event): painter = QPainter(self) margin = 10 length = min(self.width(), self.height()) - 2*margin xpos = (self.width() - length)/2 ypos = (self.height() - length)/2 bounds = QRectF( xpos, ypos, length, length) #painter.setBrush(Qt.NoBrush) #painter.drawRect(bounds) self.compass.render(painter, bounds) painter.translate(self.width() / 2, self.height() / 2) painter.rotate(self.angle) painter.translate(-self.width() / 2, -self.height() / 2) #painter.translate(xrad/2, yrad/2) self.needle.render(painter, bounds) def setDirection(self, angle): self.angle = angle self.repaint()
def setIcon(self, icon, name): name = name.lower() icon_path = "" if icon == ICON_APPLICATION: self.p_size = QRectF(3, 2, 19, 18) if "audacious" in name: icon_path = ":/scalable/pb_audacious.svg" self.p_size = QRectF(5, 4, 16, 16) elif "clementine" in name: icon_path = ":/scalable/pb_clementine.svg" self.p_size = QRectF(5, 4, 16, 16) elif "distrho" in name: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif "jamin" in name: icon_path = ":/scalable/pb_jamin.svg" self.p_size = QRectF(5, 3, 16, 16) elif "mplayer" in name: icon_path = ":/scalable/pb_mplayer.svg" self.p_size = QRectF(5, 4, 16, 16) elif "vlc" in name: icon_path = ":/scalable/pb_vlc.svg" self.p_size = QRectF(5, 3, 16, 16) else: icon_path = ":/scalable/pb_generic.svg" self.p_size = QRectF(4, 3, 16, 16) elif icon == ICON_HARDWARE: icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(5, 2, 16, 16) elif icon == ICON_DISTRHO: icon_path = ":/scalable/pb_distrho.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_FILE: icon_path = ":/scalable/pb_file.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_PLUGIN: icon_path = ":/scalable/pb_plugin.svg" self.p_size = QRectF(5, 4, 16, 16) elif icon == ICON_LADISH_ROOM: # TODO - make a unique ladish-room icon icon_path = ":/scalable/pb_hardware.svg" self.p_size = QRectF(5, 2, 16, 16) else: self.p_size = QRectF(0, 0, 0, 0) qCritical("PatchCanvas::CanvasIcon.setIcon(%s, %s) - unsupported icon requested" % ( icon2str(icon), name.encode())) return self.m_renderer = QSvgRenderer(icon_path, canvas.scene) self.setSharedRenderer(self.m_renderer) self.update()
def __init__(self, canvas, color, svg=None, width=0.0, length=0.0, orientation=True, marker_mode=False, config=None): super(CanvasMarker, self).__init__(canvas) self.canvas = canvas self.config = config self.size = 20 self.changing_scale = 400 self.marker_mode = marker_mode self.color = color self.pointbrush = QBrush(self.color) self.pointpen = QPen(Qt.black) self.pointpen.setWidth(1) self.map_pos = QgsPointXY(0.0, 0.0) self.heading = 0 self.width = width self.length = length self.orientation = orientation if svg is not None: # set crs and ellipsoid crs = self.canvas.mapSettings().destinationCrs() self.distance_calc = QgsDistanceArea() self.distance_calc.setSourceCrs(crs, QgsProject.instance().transformContext()) self.distance_calc.setEllipsoid(crs.ellipsoidAcronym()) self.svg = QSvgRenderer(svg) else: self.svg = None
class CompassWidget(QWidget): def __init__(self, parent): QWidget.__init__(self, parent) self.compass = QSvgRenderer("compassBody.svg") self.needle = QSvgRenderer("compassNeedle.svg") self.angle = 0 def paintEvent(self, event): painter = QPainter(self) margin = 10 length = min(self.width(), self.height()) - 2 * margin xpos = (self.width() - length) / 2 ypos = (self.height() - length) / 2 bounds = QRectF(xpos, ypos, length, length) #painter.setBrush(Qt.NoBrush) #painter.drawRect(bounds) self.compass.render(painter, bounds) painter.translate(self.width() / 2, self.height() / 2) painter.rotate(self.angle) painter.translate(-self.width() / 2, -self.height() / 2) #painter.translate(xrad/2, yrad/2) self.needle.render(painter, bounds) def setDirection(self, angle): self.angle = angle self.repaint()
def flush(self): self._renderer = QSvgRenderer(self.dot.pipe()) max_h = self._renderer.defaultSize().height() / self._height if max_h <= 1: max_h = 0 max_h = int(self.delta() * max_h) self.scrollbar.setMaximum(max_h)
class Vectorgraphic(DesignItem): def __init__(self, filename, scene): super(Vectorgraphic, self).__init__(scene) self.renderer = QSvgRenderer() self.renderer.load(filename) self.svg = QGraphicsSvgItem(self) self.svg.setSharedRenderer(self.renderer) self.setRect(0, 0, self.svg.boundingRect().width(), self.svg.boundingRect().height()) def typeName(self): return "Vectorgraphic" def paint(self, paint, option, widget): if option.state & QStyle.State_Selected: self.drawHighlightSelected(paint, option) def scaleObjects(self): self.xscale = self.rect.width() / self.svg.boundingRect().width() self.yscale = self.rect.height() / self.svg.boundingRect().height() trans = QTransform() trans.scale(self.xscale, self.yscale) self.svg.setTransform(trans) def setScale(self, x, y): self.xscale = x self.yscale = y trans = QTransform() trans.scale(self.xscale, self.yscale) self.svg.setTransform(trans) self.setRect(0, 0, self.svg.boundingRect().width() * x, self.svg.boundingRect().height() * y)
class BasicSvgPage(page.AbstractPage): """A page that can display a SVG document.""" paperColor = QColor(Qt.white) def __init__(self, load_file=None): self._svg_r = QSvgRenderer() if load_file: self.load(load_file) def load(self, load_file): """Load filename or QByteArray.""" success = self._svg_r.load(load_file) if success: self.pageWidth = self._svg_r.defaultSize().width() self.pageHeight = self._svg_r.defaultSize().height() return success def paint(self, painter, rect, callback=None): painter.fillRect(rect, self.paperColor) page = QRect(0, 0, self.width, self.height) painter.translate(page.center()) painter.rotate(self.computedRotation * 90) if self.computedRotation & 1: page.setSize(page.size().transposed()) painter.translate(-page.center()) self._svg_r.render(painter, QRectF(page))
class ShadowWidget(QWidget): def __init__(self, parentWidget): QWidget.__init__(self, parentWidget) self.texture = QImage("ui/gras.png") self.tree = QSvgRenderer("ui/tree.svg") self.compass = QSvgRenderer("ui/compass2.svg") # set the gras texture as the background image self.setAutoFillBackground(True) pal = self.palette() pal.setBrush(QPalette.Window, QBrush(self.texture)) self.setPalette(pal) self.angle = 0 self.shadowLength = 10 def setAngle(self, value): self.angle = value self.repaint() def setShadowLength(self, value): if (value < 0): value = 0 self.shadowLength = value self.repaint() def paintEvent(self, event): radius = 50 treeSize = QSizeF(2 * radius, 2 * radius) bounds = QRectF( (self.width() - treeSize.height()) / 2, (self.height() - treeSize.width()) / 2, treeSize.width(), treeSize.height()) painter = QPainter(self) # draw the shadow painter.setBrush(Qt.black) painter.setPen(Qt.NoPen) painter.setOpacity(0.5) xrad = 95 yrad = self.shadowLength * 20 rect = QRectF(-xrad, -yrad, xrad, yrad) painter.translate(self.width() / 2, self.height() / 2) painter.rotate(self.angle) painter.translate(xrad/2, yrad/2) painter.drawChord(rect, 0, 180*16) painter.resetTransform() # draw the tree painter.setOpacity(1) self.tree.render(painter, bounds) # draw the compass bounds = QRectF( 10, 10, 50, 50) self.compass.render(painter, bounds)
def intrinsicSize(self, doc, posInDocument, format): renderer = QSvgRenderer(format.property(Window.SvgData)) size = renderer.defaultSize() if size.height() > 25: size *= 25.0 / size.height() return QSizeF(size)
def load_svg_sized_pixmap(path, w=100, h=100): svg_renderer = QSvgRenderer(path) image = QImage(w, h, QImage.Format_ARGB32) painter = QPainter(image) painter.eraseRect(0, 0, w, h) svg_renderer.render(painter) painter.end() return QPixmap.fromImage(image)
def __init__(self, proj, canvas): super(NorthArrow, self).__init__(canvas) self.proj = proj self.canvas = canvas self.map_pos = QgsPointXY(0.0, 0.0) self.svg = QSvgRenderer(":/resources/arrow.svg") self.size = QSize(42, 64) self.corner = 1
def from_svg_bytes(self, svg_bytes): """Paints an svg from a bytes object""" renderer = QSvgRenderer(svg_bytes) painter = QPainter(self) painter.eraseRect(self.rect()) renderer.render(painter) painter.end()
class ShadowWidget(QWidget): def __init__(self, parentWidget): QWidget.__init__(self, parentWidget) self.texture = QImage("ui/gras.png") self.tree = QSvgRenderer("ui/tree.svg") self.compass = QSvgRenderer("ui/compass2.svg") # set the gras texture as the background image self.setAutoFillBackground(True) pal = self.palette() pal.setBrush(QPalette.Window, QBrush(self.texture)) self.setPalette(pal) self.angle = 0 self.shadowLength = 10 def setAngle(self, value): self.angle = value self.repaint() def setShadowLength(self, value): if (value < 0): value = 0 self.shadowLength = value self.repaint() def paintEvent(self, event): radius = 50 treeSize = QSizeF(2 * radius, 2 * radius) bounds = QRectF((self.width() - treeSize.height()) / 2, (self.height() - treeSize.width()) / 2, treeSize.width(), treeSize.height()) painter = QPainter(self) # draw the shadow painter.setBrush(Qt.black) painter.setPen(Qt.NoPen) painter.setOpacity(0.5) xrad = 95 yrad = self.shadowLength * 20 rect = QRectF(-xrad, -yrad, xrad, yrad) painter.translate(self.width() / 2, self.height() / 2) painter.rotate(self.angle) painter.translate(xrad / 2, yrad / 2) painter.drawChord(rect, 0, 180 * 16) painter.resetTransform() # draw the tree painter.setOpacity(1) self.tree.render(painter, bounds) # draw the compass bounds = QRectF(10, 10, 50, 50) self.compass.render(painter, bounds)
def __init__(self, filename, scene): super(Vectorgraphic, self).__init__(scene) self.renderer = QSvgRenderer() self.renderer.load(filename) self.svg = QGraphicsSvgItem(self) self.svg.setSharedRenderer(self.renderer) self.setRect(0, 0, self.svg.boundingRect().width(), self.svg.boundingRect().height())
class NorthArrow(QgsMapCanvasItem): def __init__(self, proj, canvas): super(NorthArrow, self).__init__(canvas) self.proj = proj self.canvas = canvas self.map_pos = QgsPointXY(0.0, 0.0) self.svg = QSvgRenderer(":/resources/arrow.svg") self.size = QSize(42, 64) self.corner = 1 def paint(self, painter, xxx, xxx2): """Paint north arrow on painter""" if self.svg.isValid(): pos = self.set_position(self.corner, painter.device().width(), painter.device().height()) rotation = QgsBearingUtils.bearingTrueNorth( self.canvas.mapSettings().destinationCrs(), self.canvas.mapSettings().transformContext(), self.canvas.extent().center()) rotation += self.canvas.rotation() painter.save() painter.rotate(-rotation) # To translate correctly painter.translate(pos.x(), pos.y()) painter.rotate( rotation ) # To rotate north arrow along with canvas, always pointing north # do the drawing, and draw a smooth north arrow even when rotated rectangle = QRectF(-self.size.width() / 2, -self.size.height() / 2, self.size.width(), self.size.height()) self.svg.render(painter, rectangle) painter.restore() def set_position(self, corner, width, height): """ Returns the position of the specified corner with a concrete width and height :param corner: can be 1, 2, 3 or 4. top left, top right, bot left and bot right respectively :param width: width of the paint space :param height: height of the paint space :return: QgsPointXY of the specified corner """ if corner == 1: # top left corner return QgsPointXY(0 + self.size.height() / 2, 0 + self.size.height() / 2) elif corner == 2: # top right corner return QgsPointXY(width - self.size.height() / 2, 0 + self.size.height() / 2) elif corner == 3: # bottom left corner return QgsPointXY(0 + self.size.height() / 2, height - self.size.height() / 2) elif corner == 4: # bottom right corner return QgsPointXY(width - self.size.height() / 2, height - self.size.height() / 2)
class SVGEngine: """ Renders SVG data on Qt paint devices. """ def __init__(self, *, render_hints=QPainter.Antialiasing) -> None: self._data = b"" # Current XML SVG binary data. self._renderer = QSvgRenderer() # Qt SVG renderer. self._render_hints = render_hints # SVG rendering quality hints (such as anti-aliasing). def loads(self, data: QtSVGData) -> None: """ Load the renderer with SVG data. """ if isinstance(data, str): data = data.encode('utf-8') self._data = data self._renderer.load(data) def load(self, filename: str) -> None: """ Load SVG data directly from disk. """ with open(filename) as fp: data = fp.read() self.loads(data) def viewbox_size(self) -> QSize: """ If no valid viewbox is defined, 100x100 is a typical default. """ size = self._renderer.viewBox().size() if size.isEmpty(): size = QSize(100, 100) return size def render(self, target: QPaintDevice, bounds: QRectF = None) -> None: """ Render the current SVG data on <target> with optional <bounds> on the area. """ args = () if bounds is None else (bounds, ) with QPainter(target) as p: p.setRenderHints(self._render_hints) self._renderer.render(p, *args) def render_fit(self, target: QPaintDevice) -> None: """ Render the current SVG data on <target>, centered at maximum scale while preserving aspect ratio. """ width = target.width() height = target.height() v_size = self.viewbox_size() vw = v_size.width() vh = v_size.height() scale = min(width / vw, height / vh) rw = vw * scale rh = vh * scale rx = (width - rw) / 2 ry = (height - rh) / 2 bounds = QRectF(rx, ry, rw, rh) self.render(target, bounds) def dumps(self) -> str: """ Return the current SVG data as a string. """ return self._data.decode('utf-8') def dump(self, filename: str) -> None: """ Save the current SVG data directly to disk. """ with open(filename, 'wb') as fp: fp.write(self._data)
def __init__(self, parent=None, **kwargs): self.m_value = False self.m_onColour = QLed.Red self.m_offColour = QLed.Grey self.m_shape = QLed.Circle QWidget.__init__(self, parent, **kwargs) self._pressed = False self.renderer = QSvgRenderer()
def _render(self, data: XMLIconData) -> QIcon: """ Create a template image, render the XML data in place, and convert it to an icon. Use the viewbox dimensions as pixel sizes. """ svg = QSvgRenderer(data) viewbox = svg.viewBox().size() im = QImage(viewbox, QImage.Format_ARGB32) im.fill(self._bg_color) with QPainter(im) as p: p.setRenderHints(self._render_hints) svg.render(p) return QIcon(QPixmap.fromImage(im))
def load(cls, filename, renderer=None): """Load a SVG document from filename, which may also be a QByteArray. Yields only one Page instance, as SVG currently supports one page per file. If the file can't be loaded by the underlying QSvgRenderer, no Page is yielded. """ r = QSvgRenderer() if r.load(filename): yield cls(r, renderer)
def setDigitsFile(self, filemon): self.m_digitsFile = filemon if self.m_svg: del self.m_svg self.m_svg = QSvgRenderer(self) if not self.m_svg.load(self.m_digitsFile): print("Cannot load resource File") self.m_digitsFile = ":/default/resources/train_digits.svg" self.m_svg.load(self.m_digitsFile) else: print("Train digits correctly loaded") self.update()
def foo(percent=0, size=32): """Returns QIcon""" svgstr = svgFactory(svgExamples[0], percent, size) svg_bytes = bytearray(svgstr, encoding="utf-8") r = QSvgRenderer(svg_bytes) i = QImage(32, 32, QImage.Format_ARGB32) i.fill(0xffffffff) p = QPainter(i) r.render(p) a = QPixmap.fromImage(i) p.end() return a
def load_icon(name: AutoKeyIcon) -> QIcon: file_path = ICON_PATH_PREFIX + "/" + name.value icon = QIcon(file_path) if not icon.availableSizes() and file_path.endswith(".svg"): # FIXME: Work around Qt Bug: https://bugreports.qt.io/browse/QTBUG-63187 # Manually render the SVG to some common icon sizes. icon = QIcon() # Discard the bugged QIcon renderer = QSvgRenderer(file_path) for size in (16, 22, 24, 32, 64, 128): pixmap = QPixmap(QSize(size, size)) pixmap.fill(QColor(255, 255, 255, 0)) renderer.render(QPainter(pixmap)) icon.addPixmap(pixmap) return icon
def __init__(self, parentWidget): QWidget.__init__(self, parentWidget) self.texture = QImage("ui/gras.png") self.tree = QSvgRenderer("ui/tree.svg") self.compass = QSvgRenderer("ui/compass2.svg") # set the gras texture as the background image self.setAutoFillBackground(True) pal = self.palette() pal.setBrush(QPalette.Window, QBrush(self.texture)) self.setPalette(pal) self.angle = 0 self.shadowLength = 10
def __init__(self, parent): super().__init__(parent) self._y = 0 self._width = 1 self._height = 1 self.dot = Digraph(format='svg', strict=True) self._declared_count = 1 self._declared = dict() self._renderer = QSvgRenderer(self.dot.pipe(), self) self.scrollbar = QScrollBar(self.parent()) self.scrollbar.setRange(0, 0) self.parent().wheelEvent = self.wheelEvent
class SVGButton(QGraphicsObject): def __init__(self, fname, parent=None): super(SVGButton, self).__init__(parent) self.svg = QSvgRenderer(fname) def paint(self, painter, options, widget): self.svg.render(painter, self.boundingRect()) def boundingRect(self): return self.svg.viewBoxF() clicked = pyqtSignal() def mousePressEvent(self, event): self.clicked.emit()
def __init__(self, text, scene): super(Text, self).__init__(scene) self.font = QFont("Arial") self.font.setPointSize(14) self.font.setStyleName("Standard") self.text = text self.textcolor = QColor(Qt.black) self.data = str.encode(self.getSvg()) self.renderer = QSvgRenderer() self.renderer.load(self.data) self.svg = QGraphicsSvgItem(self) self.svg.setSharedRenderer(self.renderer) self.setRect(0, 0, self.svg.boundingRect().width(), self.svg.boundingRect().height())
def initialize_loading_page(self): svg_container = QGraphicsScene(self.window().loading_svg_view) svg_item = QGraphicsSvgItem() svg = QSvgRenderer(get_image_path("loading_animation.svg")) svg.repaintNeeded.connect(svg_item.update) svg_item.setSharedRenderer(svg) svg_container.addItem(svg_item) self.window().loading_svg_view.setScene(svg_container) self.window().core_manager.events_manager.upgrader_tick.connect(self.set_loading_text) self.window().core_manager.events_manager.upgrader_started.connect( lambda: self.set_loading_text("Upgrading...")) self.window().core_manager.events_manager.upgrader_finished.connect(lambda: self.loading_label.hide()) # Create a loading label that displays the status during upgrading self.loading_label = QLabel(self) self.loading_label.setStyleSheet("color: #ddd; font-size: 22px;") self.loading_label.setAlignment(Qt.AlignCenter) self.on_window_resize() self.loading_label.hide() # Hide the force shutdown button initially. Should be triggered by shutdown timer from main window. self.window().force_shutdown_btn.hide()
def __init__(self, parent=None): super(GameWidget, self).__init__(parent) self.game = Game() self.renderer = QSvgRenderer("theme.svg") self.boardWidget = BoardWidget(self.game, self.renderer, self) self.stackLayoutWidget = QWidget(self) self.stackLayoutWidget.setFixedWidth(150) self.initWidget = GameInitWidget(self.game, self.stackLayoutWidget) self.playWidget = GamePlayWidget(self.game, self.stackLayoutWidget) self.finishedWidget = GameFinishedWidget(self.game, self.stackLayoutWidget) self.stackLayout = QStackedLayout() self.stackLayout.addWidget(self.initWidget) self.stackLayout.addWidget(self.playWidget) self.stackLayout.addWidget(self.finishedWidget) self.stackLayoutWidget.setLayout(self.stackLayout) self.hboxLayout = QHBoxLayout() self.hboxLayout.addWidget(self.boardWidget) self.hboxLayout.addWidget(self.stackLayoutWidget) self.hboxLayout.setStretch(0, 1) self.hboxLayout.setContentsMargins(0, 0, 0, 0) self.setLayout(self.hboxLayout) self.game.phaseChanged.connect(self.update) self.update()
def pixmap(name, size, mode, state): """Returns a (possibly cached) pixmap of the name and size with the default text color. The state argument is ignored for now. """ if mode == QIcon.Selected: color = QApplication.palette().highlightedText().color() else: color = QApplication.palette().text().color() key = (name, size.width(), size.height(), color.rgb(), mode) try: return _pixmaps[key] except KeyError: i = QImage(size, QImage.Format_ARGB32_Premultiplied) i.fill(0) painter = QPainter(i) # render SVG symbol QSvgRenderer(os.path.join(__path__[0], name + ".svg")).render(painter) # recolor to text color painter.setCompositionMode(QPainter.CompositionMode_SourceIn) painter.fillRect(i.rect(), color) painter.end() # let style alter the drawing based on mode, and create QPixmap pixmap = QApplication.style().generatedIconPixmap( mode, QPixmap.fromImage(i), QStyleOption()) _pixmaps[key] = pixmap return pixmap
def _render(self, svg_data: str) -> QImage: """ Create a new raster image with the current background color and render an SVG image to it. Pixel dimensions will fit the viewbox at maximum scale. """ svg = QSvgRenderer(svg_data.encode("utf-8")) v_size = svg.viewBox().size() vw = v_size.width() vh = v_size.height() scale = min(self._w_max / vw, self._h_max / vh) w = round(vw * scale) h = round(vh * scale) im = QImage(w, h, QImage.Format_ARGB32) im.fill(self._bg_color) with QPainter(im) as p: p.setRenderHints(QPainter.Antialiasing) svg.render(p, QRectF(0, 0, w, h)) return im
def __init__(self, parent=None): # TODO should know its name super(NetArchitecture, self).__init__() self.renderer = QSvgRenderer() self.source_url = QUrl("") self.settings = QSettings('dt', 'DeepThought') self.graph = None self.update_source()
def __getitem__(key): if key not in IconCache.icons: if not key.endswith('.svg') and not key.endswith('.svgz'): image = QImage(key).scaled(24, 24) else: svg = QSvgRenderer(key) image = QImage(24, 24, QImage.Format_ARGB32) image.fill(0) painter = QPainter(image) svg.render(painter) painter.end() bytes = QByteArray() buff = QBuffer(bytes) buff.open(QIODevice.WriteOnly) image.save(buff, 'png') IconCache.icons[key] = bytes return QIcon(QPixmap.fromImage(QImage.fromData(IconCache.icons[key])))
def svg2png(fName, width=600, app=None, oFilename=""): """ Smart convertion to PNG files; stroke widths are widened when necessary, so traces on an oscilloscope screen will be visible even if it is downscaled. A PNG file is written. :param fname: file name of a SVG drawing :param width: the width of the wanted PNG drawing; its height will be :param app: the current application :param oFilename: facultative file name for the output PNG file calculated automatically :returns: the effective file name of the written PNG file """ from xml.dom import minidom from PyQt5.QtSvg import QSvgRenderer from PyQt5.QtGui import QImage, QPainter, QColor, QGuiApplication from math import sqrt if not app: app = QGuiApplication([]) doc = minidom.parse(open(fName)) svg = doc.getElementsByTagName("svg")[0] sizeMatch = re.match(r"(\d+) (\d+) (\d+) (\d+)", svg.getAttribute("viewBox")) w, h = int(sizeMatch.group(3)), int(sizeMatch.group(3)) groups = svg.getElementsByTagName("g") scale = width / w for g in groups: if "stroke-width" in g.attributes: g.setAttribute( "stroke-width", str(float(g.getAttribute("stroke-width")) / sqrt(scale))) qsr = QSvgRenderer(svg.toxml().encode("utf-8")) # I do not know why, but without the correction, the height of the # PNG image is too big. Are the viewport units misleading? correction = 1.33 img = QImage(int(w * scale), int(h * scale / correction), QImage.Format_ARGB32) img.fill(QColor("white")) p = QPainter(img) qsr.render(p) p.end() if not oFilename: oFilename = re.sub(r"\.svg$", f"-{width}px.png", fName) img.save(oFilename) return oFilename
def load_icon(name: str) -> QIcon: """ Load a QIcon with the given file name. Files are loaded from the ICON_PATH_PREFIX, which depends on the installation style. """ file_path = ICON_PATH_PREFIX + "/" + name icon = QIcon(file_path) if not icon.availableSizes() and file_path.endswith(".svg"): # FIXME: Work around Qt Bug: https://bugreports.qt.io/browse/QTBUG-63187 # Manually render the SVG to some common icon sizes. icon = QIcon() # Discard the bugged QIcon renderer = QSvgRenderer(file_path) for size in (16, 22, 24, 32, 64, 128): pixmap = QPixmap(QSize(size, size)) pixmap.fill(QColor(255, 255, 255, 0)) renderer.render(QPainter(pixmap)) icon.addPixmap(pixmap) return icon
class NetArchitecture(QObject): def __init__(self, parent=None): # TODO should know its name super(NetArchitecture, self).__init__() self.renderer = QSvgRenderer() self.source_url = QUrl("") self.settings = QSettings('dt', 'DeepThought') self.graph = None self.update_source() def source_setting_changed(self): return not self.settings.value('protofile') == self.source_url def update_source(self): if self.settings.contains('protofile'): source_url = QUrl(self.settings.value('protofile')) source = source_url.toDisplayString(QUrl.RemoveScheme) if os.path.isfile(source): self.source_url = source_url self.set_source(source) return not self.source_url.isEmpty() def set_source(self, caffeproto_file): net = caffe_pb2.NetParameter() text_format.Merge(open(caffeproto_file).read(), net) self.graph = caffe.draw.draw_net(net, 'LR', 'svg') # self.sourceChanged.emit('network_architecture') def get_image(self, size): if self.source_setting_changed(): self.update_source() image = QImage(size.width(), size.height(), QImage.Format_ARGB32) painter = QPainter(image) if self.graph is None: if self.settings.contains('protofile'): url = QUrl(self.settings.value('protofile')) self.set_source(url.toDisplayString(QUrl.RemoveScheme)) else: image.fill(QColor(200, 200, 200)) return image self.renderer.load(QByteArray(self.graph)) self.renderer.render(painter) return image
def __init__(self, parent=None, **kwargs): self.m_value=False self.m_onColour=QLed.Red self.m_offColour=QLed.Grey self.m_shape=QLed.Circle QWidget.__init__(self, parent, **kwargs) self._pressed=False self.renderer=QSvgRenderer()
def __init__(self, xy, parent=None, extra=None): super().__init__(xy, parent, extra) self.setwh((1, 1)) self.color = extra[0] if self.color == '': self.color = '(0, 180, 0)' self.setcolort(self.color) ico = extra[1] icon = None if ico.split('.')[-1] == 'svg' or ico.split('.')[-1] == 'svgz': icon = QImage(int(self.w * UNIT / 2), int(self.h * UNIT / 2), QImage.Format_ARGB32) icon.fill(QColor(120, 120, 120, 0)) renderer = QSvgRenderer(ico) painter = QPainter(icon) renderer.render(painter) del painter else: icon = QImage(ico) self.setPixmap(QPixmap(icon).scaledToHeight(self.height(), Qt.SmoothTransformation))
def read_cards(): """ A function for importing the .svg image files depicting the playing cards. """ all_cards = dict() for suit in 'HDSC': for value in ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']: file = value + suit all_cards[file] = QSvgRenderer('cards/' + file + '.svg') return all_cards
def __init__(self, xy, parent=None, extra=None): super().__init__(xy, parent, extra) if len(self.extra) == 4: self.d, self.exe, self.ico, self.name = self.extra elif len(self.extra) == 3: self.d, self.exe, self.ico = self.extra self.name = self.exe.split()[0] self.setwh((self.d, self.d)) icon = None if self.ico.split('.')[-1] == 'svg' or self.ico.split('.')[-1] == 'svgz': icon = QImage(int(self.d * UNIT / 2), int(self.d * UNIT / 2), QImage.Format_ARGB32) icon.fill(QColor(120, 120, 120, 0)) renderer = QSvgRenderer(self.ico) painter = QPainter(icon) renderer.render(painter) del painter else: icon = QImage(self.ico) iconm = icon.scaled(2, 2) b1 = (QColor(iconm.pixel(0, 0)).getRgb(), QColor(iconm.pixel(0, 1)).getRgb(), QColor(iconm.pixel(1, 0)).getRgb(), QColor(iconm.pixel(1, 1)).getRgb(),) b = (0, 0, 0) for c in b1: b = (b[0] + c[0] // 4, b[1] + c[1] // 4, b[2] + c[2] // 4) self.setcolor(b) scale = min(icon.height(), icon.width(), self.d * UNIT / 2) self.setPixmap(QPixmap(icon).scaledToHeight(scale, Qt.SmoothTransformation)) if self.d > 1: font = QFont('sans') # font.setStretch(QFont.SemiExpanded) font.setPixelSize(UNIT / 4) nametext = QLabel(parent=self) nametext.setFont(font) nametext.move(UNIT / 10, self.height() - UNIT / 10 - nametext.height() / 2) nametext.setAlignment(Qt.AlignBottom | Qt.AlignCenter) nametext.setIndent(self.d * UNIT / 20) nametext.setText('<font color=white>%s</font>' % self.name)
def __init__(self, fname, parent=None): super(SVGButton, self).__init__(parent) self.svg = QSvgRenderer(fname)
def __init__(self, load_file=None): self._svg_r = QSvgRenderer() if load_file: self.load(load_file)
def _createBarcode(self): if self.barcode["value"] == "": return if self.barcode["type"] == BARCODE_ANY: logger.warning("Usando %s por defecto" % self.typeToName(BARCODE_128)) self.barcode["type"] = BARCODE_128 type_ = self.typeToName(self.barcode["type"]) value_ = self.barcode["value"] bg_ = self.barcode["bg"] fg_ = self.barcode["fg"] if not isinstance(self.barcode["bg"], str): bg_ = QColor(self.barcode["bg"]).name() if not isinstance(self.barcode["fg"], str): fg_ = QColor(self.barcode["fg"]).name() margin_ = self.barcode["margin"] / 10 render_options = {} render_options['module_width'] = 0.6 render_options['module_height'] = 10 render_options['background'] = bg_.lower() render_options['foreground'] = fg_.lower() render_options['font_size'] = 8 render_options['write_text'] = self.barcode["text"] render_options['text_distance'] = 35 render_options['quiet_zone'] = margin_ if self.barcode["text"]: render_options['text'] = value_ else: render_options['text'] = " " import barcode from barcode.writer import ImageWriter from PyQt5.QtSvg import QSvgRenderer barC = barcode.get_barcode_class(type_.lower()) try: bar_ = barC(u'%s' % value_) except Exception: bar_ = barC('000000000000') svg = bar_.render(render_options) xml_svg = load2xml(svg.decode("utf-8")) svg_w = (3.779 * float(xml_svg.get("width")[0:6])) svg_h = (3.779 * float(xml_svg.get("height")[0:6])) self.p = QPixmap(svg_w, svg_h) render = QSvgRenderer(svg) self.p.fill(QtCore.Qt.transparent) painter = Qt.QPainter(self.p) render.render(painter, QRectF(0,0,svg_w * 3.4 , svg_h * 3.4)) if self.p.isNull(): self.barcode["valid"] = False else: if self.barcode["scale"] != 1.0: wS_ = self.barcode["x"] * self.barcode["scale"] hS_ = self.barcode["y"] * self.barcode["scale"] self.p = self.p.scaled(wS_, hS_) self.barcode["x"] = self.p.width() self.barcode["y"] = self.p.height() self.barcode["valid"] = True
class QLed(QWidget): Circle = 1 Round = 2 Square = 3 Triangle = 4 Red = 1 Green = 2 Yellow = 3 Grey = 4 Orange = 5 Purple = 6 Blue = 7 shapes={ Circle:""" <svg height="50.000000px" id="svg9493" width="50.000000px" xmlns="http://www.w3.org/2000/svg"> <defs id="defs9495"> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient6650" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient6494"> <stop id="stop6496" offset="0.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> <stop id="stop6498" offset="1.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient6648" x1="23.213980" x2="23.201290" xlink:href="#linearGradient6494" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient6646" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient6644" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient id="linearGradient6506"> <stop id="stop6508" offset="0.0000000" style="stop-color:#ffffff;stop-opacity:0.0000000;"/> <stop id="stop6510" offset="1.0000000" style="stop-color:#ffffff;stop-opacity:0.87450981;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7498" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient7464"> <stop id="stop7466" offset="0.0000000" style="stop-color:#00039a;stop-opacity:1.0000000;"/> <stop id="stop7468" offset="1.0000000" style="stop-color:#afa5ff;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7496" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient id="linearGradient5756"> <stop id="stop5758" offset="0.0000000" style="stop-color:#828282;stop-opacity:1.0000000;"/> <stop id="stop5760" offset="1.0000000" style="stop-color:#929292;stop-opacity:0.35294119;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9321" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient id="linearGradient5742"> <stop id="stop5744" offset="0.0000000" style="stop-color:#adadad;stop-opacity:1.0000000;"/> <stop id="stop5746" offset="1.0000000" style="stop-color:#f0f0f0;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7492" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9527" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9529" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9531" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9533" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> </defs> <g id="layer1"> <g id="g9447" style="overflow:visible" transform="matrix(31.25000,0.000000,0.000000,31.25000,-625.0232,-1325.000)"> <path d="M 24.000001,43.200001 C 24.000001,43.641601 23.641601,44.000001 23.200001,44.000001 C 22.758401,44.000001 22.400001,43.641601 22.400001,43.200001 C 22.400001,42.758401 22.758401,42.400001 23.200001,42.400001 C 23.641601,42.400001 24.000001,42.758401 24.000001,43.200001 z " id="path6596" style="fill:url(#linearGradient6644);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="translate(-2.399258,-1.000000e-6)"/> <path d="M 23.906358,43.296204 C 23.906358,43.625433 23.639158,43.892633 23.309929,43.892633 C 22.980700,43.892633 22.713500,43.625433 22.713500,43.296204 C 22.713500,42.966975 22.980700,42.699774 23.309929,42.699774 C 23.639158,42.699774 23.906358,42.966975 23.906358,43.296204 z " id="path6598" style="fill:url(#linearGradient6646);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="matrix(1.082474,0.000000,0.000000,1.082474,-4.431649,-3.667015)"/> <path d="M 23.906358,43.296204 C 23.906358,43.625433 23.639158,43.892633 23.309929,43.892633 C 22.980700,43.892633 22.713500,43.625433 22.713500,43.296204 C 22.713500,42.966975 22.980700,42.699774 23.309929,42.699774 C 23.639158,42.699774 23.906358,42.966975 23.906358,43.296204 z " id="path6600" style="fill:url(#linearGradient6648);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="matrix(0.969072,0.000000,0.000000,0.969072,-1.788256,1.242861)"/> <path d="M 23.906358,43.296204 C 23.906358,43.625433 23.639158,43.892633 23.309929,43.892633 C 22.980700,43.892633 22.713500,43.625433 22.713500,43.296204 C 22.713500,42.966975 22.980700,42.699774 23.309929,42.699774 C 23.639158,42.699774 23.906358,42.966975 23.906358,43.296204 z " id="path6602" style="fill:url(#linearGradient6650);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="matrix(0.773196,0.000000,0.000000,0.597938,2.776856,17.11876)"/> </g> </g> </svg> """, Round:""" <svg height="50.000000px" id="svg9493" width="100.00000px" xmlns="http://www.w3.org/2000/svg"> <defs id="defs9495"> <linearGradient gradientTransform="matrix(0.928127,0.000000,0.000000,0.639013,13.55634,12.87587)" gradientUnits="userSpaceOnUse" id="linearGradient13424" x1="21.593750" x2="21.593750" xlink:href="#linearGradient6506" y1="47.917328" y2="46.774261"/> <linearGradient id="linearGradient6494"> <stop id="stop6496" offset="0.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> <stop id="stop6498" offset="1.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientTransform="translate(12.00000,-4.000002)" gradientUnits="userSpaceOnUse" id="linearGradient13427" x1="21.591305" x2="21.593750" xlink:href="#linearGradient6494" y1="46.617390" y2="47.781250"/> <linearGradient gradientTransform="translate(12.00000,-4.000002)" gradientUnits="userSpaceOnUse" id="linearGradient13430" x1="21.408695" x2="21.834784" xlink:href="#linearGradient5756" y1="46.556522" y2="47.843750"/> <linearGradient gradientTransform="translate(12.00000,-4.000002)" gradientUnits="userSpaceOnUse" id="linearGradient13433" x1="21.594427" x2="21.600000" xlink:href="#linearGradient5742" y1="46.376728" y2="48.000000"/> <linearGradient gradientTransform="matrix(0.928127,0.000000,0.000000,0.639013,21.55634,15.27587)" gradientUnits="userSpaceOnUse" id="linearGradient13472" x1="21.593750" x2="21.593750" xlink:href="#linearGradient6506" y1="47.917328" y2="46.774261"/> <linearGradient gradientTransform="translate(20.00000,-1.600002)" gradientUnits="userSpaceOnUse" id="linearGradient13475" x1="21.591305" x2="21.593750" xlink:href="#linearGradient9163" y1="46.617390" y2="47.781250"/> <linearGradient gradientTransform="translate(20.00000,-1.600002)" gradientUnits="userSpaceOnUse" id="linearGradient13478" x1="21.408695" x2="21.834784" xlink:href="#linearGradient5756" y1="46.556522" y2="47.843750"/> <linearGradient gradientTransform="translate(20.00000,-1.600002)" gradientUnits="userSpaceOnUse" id="linearGradient13481" x1="21.594427" x2="21.600000" xlink:href="#linearGradient5742" y1="46.376728" y2="48.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9199" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient9163"> <stop id="stop9165" offset="0.0000000" style="stop-color:#000000;stop-opacity:1.0000000;"/> <stop id="stop9167" offset="1.0000000" style="stop-color:#8c8c8c;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9197" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9195" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9193" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient id="linearGradient6506"> <stop id="stop6508" offset="0.0000000" style="stop-color:#ffffff;stop-opacity:0.0000000;"/> <stop id="stop6510" offset="1.0000000" style="stop-color:#ffffff;stop-opacity:0.87450981;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7498" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient7464"> <stop id="stop7466" offset="0.0000000" style="stop-color:#00039a;stop-opacity:1.0000000;"/> <stop id="stop7468" offset="1.0000000" style="stop-color:#afa5ff;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7496" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient id="linearGradient5756"> <stop id="stop5758" offset="0.0000000" style="stop-color:#828282;stop-opacity:1.0000000;"/> <stop id="stop5760" offset="1.0000000" style="stop-color:#929292;stop-opacity:0.35294119;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9321" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient id="linearGradient5742"> <stop id="stop5744" offset="0.0000000" style="stop-color:#adadad;stop-opacity:1.0000000;"/> <stop id="stop5746" offset="1.0000000" style="stop-color:#f0f0f0;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7492" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9527" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9529" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9531" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9533" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(24.16238,0.000000,0.000000,18.68556,-538.2464,-790.0391)" gradientUnits="userSpaceOnUse" id="linearGradient1336" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(30.28350,0.000000,0.000000,30.28350,-680.9062,-1286.161)" gradientUnits="userSpaceOnUse" id="linearGradient1339" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientTransform="matrix(33.82731,0.000000,0.000000,33.82731,-763.5122,-1439.594)" gradientUnits="userSpaceOnUse" id="linearGradient1342" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientTransform="matrix(31.25000,0.000000,0.000000,31.25000,-700.0000,-1325.000)" gradientUnits="userSpaceOnUse" id="linearGradient1345" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> </defs> <g id="layer1"> <g id="g13543" style="overflow:visible" transform="matrix(31.25000,0.000000,0.000000,31.25000,-999.9999,-1325.000)"> <path d="M 32.799998,42.400000 L 34.399998,42.400000 C 34.843198,42.400000 35.199998,42.756800 35.199998,43.200000 C 35.199998,43.643200 34.843198,44.000000 34.399998,44.000000 L 32.799998,44.000000 C 32.356798,44.000000 31.999998,43.643200 31.999998,43.200000 C 31.999998,42.756800 32.356798,42.400000 32.799998,42.400000 z " id="path13335" style="fill:url(#linearGradient13433);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> <path d="M 32.812498,42.562498 C 32.447387,42.562498 32.156248,42.829606 32.156248,43.187498 C 32.156248,43.545390 32.454607,43.843750 32.812498,43.843748 L 34.406248,43.843748 C 34.764141,43.843748 35.031248,43.552611 35.031248,43.187498 C 35.031248,42.822387 34.771358,42.562498 34.406248,42.562498 L 32.812498,42.562498 z " id="path13337" style="fill:url(#linearGradient13430);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> <path d="M 32.812498,42.624998 C 32.485887,42.624998 32.218748,42.871665 32.218748,43.187498 C 32.218748,43.503332 32.496667,43.781249 32.812498,43.781248 L 34.406248,43.781248 C 34.722082,43.781248 34.968748,43.514111 34.968748,43.187498 C 34.968748,42.860887 34.732858,42.624998 34.406248,42.624998 L 32.812498,42.624998 z " id="path13339" style="fill:url(#linearGradient13427);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> <path d="M 32.872983,42.669849 C 32.569847,42.669849 32.321908,42.827473 32.321908,43.029294 C 32.321908,43.231116 32.579852,43.408709 32.872983,43.408708 L 34.352185,43.408708 C 34.645320,43.408708 34.874257,43.238004 34.874257,43.029294 C 34.874257,42.820585 34.655321,42.669849 34.352185,42.669849 L 32.872983,42.669849 z " id="path13341" style="fill:url(#linearGradient13424);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> </g> </g> </svg> """, Square:""" <svg height="50.000000px" id="svg9493" width="50.000000px" xmlns="http://www.w3.org/2000/svg"> <defs id="defs9495"> <linearGradient gradientTransform="matrix(0.388435,0.000000,0.000000,0.618097,2.806900,2.626330)" gradientUnits="userSpaceOnUse" id="linearGradient31681" x1="21.593750" x2="21.593750" xlink:href="#linearGradient6506" y1="47.917328" y2="46.774261"/> <linearGradient id="linearGradient6494"> <stop id="stop6496" offset="0.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> <stop id="stop6498" offset="1.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient31704" x1="18.390625" x2="18.390625" xlink:href="#linearGradient6494" y1="43.400002" y2="44.593750"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient31624" x1="17.728125" x2="19.031250" xlink:href="#linearGradient5756" y1="43.337502" y2="44.656250"/> <linearGradient gradientTransform="matrix(0.500000,0.000000,0.000000,1.000000,-3.600000,-8.800000)" gradientUnits="userSpaceOnUse" id="linearGradient31686" x1="29.600000" x2="29.600000" xlink:href="#linearGradient5742" y1="39.991302" y2="41.599998"/> <linearGradient gradientTransform="matrix(0.388435,0.000000,0.000000,0.618097,7.606900,5.026330)" gradientUnits="userSpaceOnUse" id="linearGradient31649" x1="21.593750" x2="21.593750" xlink:href="#linearGradient6506" y1="47.917328" y2="46.774261"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient31710" x1="18.390625" x2="18.390625" xlink:href="#linearGradient9163" y1="43.400002" y2="44.593750"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient31570" x1="17.728125" x2="19.031250" xlink:href="#linearGradient5756" y1="43.337502" y2="44.656250"/> <linearGradient gradientTransform="matrix(0.500000,0.000000,0.000000,1.000000,1.200000,-6.400000)" gradientUnits="userSpaceOnUse" id="linearGradient31654" x1="29.600000" x2="29.600000" xlink:href="#linearGradient5742" y1="39.991302" y2="41.599998"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9199" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient9163"> <stop id="stop9165" offset="0.0000000" style="stop-color:#000000;stop-opacity:1.0000000;"/> <stop id="stop9167" offset="1.0000000" style="stop-color:#8c8c8c;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9197" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9195" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9193" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient id="linearGradient6506"> <stop id="stop6508" offset="0.0000000" style="stop-color:#ffffff;stop-opacity:0.0000000;"/> <stop id="stop6510" offset="1.0000000" style="stop-color:#ffffff;stop-opacity:0.87450981;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7498" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient7464"> <stop id="stop7466" offset="0.0000000" style="stop-color:#00039a;stop-opacity:1.0000000;"/> <stop id="stop7468" offset="1.0000000" style="stop-color:#afa5ff;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7496" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient id="linearGradient5756"> <stop id="stop5758" offset="0.0000000" style="stop-color:#828282;stop-opacity:1.0000000;"/> <stop id="stop5760" offset="1.0000000" style="stop-color:#929292;stop-opacity:0.35294119;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9321" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient id="linearGradient5742"> <stop id="stop5744" offset="0.0000000" style="stop-color:#adadad;stop-opacity:1.0000000;"/> <stop id="stop5746" offset="1.0000000" style="stop-color:#f0f0f0;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7492" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9527" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9529" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9531" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9533" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(24.16238,0.000000,0.000000,18.68556,-538.2464,-790.0391)" gradientUnits="userSpaceOnUse" id="linearGradient1336" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(30.28350,0.000000,0.000000,30.28350,-680.9062,-1286.161)" gradientUnits="userSpaceOnUse" id="linearGradient1339" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientTransform="matrix(33.82731,0.000000,0.000000,33.82731,-763.5122,-1439.594)" gradientUnits="userSpaceOnUse" id="linearGradient1342" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientTransform="matrix(31.25000,0.000000,0.000000,31.25000,-700.0000,-1325.000)" gradientUnits="userSpaceOnUse" id="linearGradient1345" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> </defs> <g id="layer1"> <g id="g31718" style="overflow:visible" transform="matrix(31.25000,0.000000,0.000000,31.25000,-325.0000,-975.0000)"> <path d="M 10.400000,31.200000 L 12.000000,31.200000 L 12.000000,32.800000 L 10.400000,32.800000 L 10.400000,31.200000 z " id="path31614" style="fill:url(#linearGradient31686);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> <path d="M 17.750000,43.343750 L 17.750000,44.656250 L 19.031250,44.656250 L 19.031250,43.343750 L 17.750000,43.343750 z " id="path31616" style="fill:url(#linearGradient31624);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="translate(-7.190625,-12.00000)"/> <path d="M 17.812500,43.406250 L 17.812500,44.593750 L 18.968750,44.593750 L 18.968750,43.406250 L 17.812500,43.406250 z " id="path31618" style="fill:url(#linearGradient31704);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible" transform="translate(-7.190625,-12.00000)"/> <path d="M 10.891195,31.445120 C 10.630356,31.445967 10.660563,31.393294 10.660563,31.792800 C 10.660563,31.988016 10.768517,32.159796 10.891195,32.159795 L 11.510263,32.159795 C 11.632945,32.159795 11.728757,31.994678 11.728757,31.792800 C 11.728757,31.389990 11.754584,31.441761 11.510263,31.445120 L 10.891195,31.445120 z " id="path31620" sodipodi:nodetypes="csccscc" style="fill:url(#linearGradient31681);fill-opacity:1.0000000;stroke:none;stroke-width:0.80000001;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> </g> </g> </svg> """, Triangle:""" <svg height="50.000000px" id="svg9493" width="50.000000px" xmlns="http://www.w3.org/2000/svg" > <defs id="defs9495"> <linearGradient gradientTransform="matrix(0.389994,0.000000,0.000000,0.403942,4.557010,29.83582)" gradientUnits="userSpaceOnUse" id="linearGradient28861" x1="23.187498" x2="23.187498" xlink:href="#linearGradient6506" y1="28.449617" y2="26.670279"/> <linearGradient id="linearGradient6494"> <stop id="stop6496" offset="0.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> <stop id="stop6498" offset="1.0000000" style="stop-color:%s;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientTransform="translate(-9.587500,13.60000)" gradientUnits="userSpaceOnUse" id="linearGradient28864" x1="23.181250" x2="23.187500" xlink:href="#linearGradient6494" y1="26.793751" y2="27.843750"/> <linearGradient gradientTransform="translate(-9.587500,13.60000)" gradientUnits="userSpaceOnUse" id="linearGradient28867" x1="22.762501" x2="23.812500" xlink:href="#linearGradient5756" y1="26.687500" y2="27.906250"/> <linearGradient gradientTransform="translate(-9.600000,13.60000)" gradientUnits="userSpaceOnUse" id="linearGradient28870" x1="23.187500" x2="23.200001" xlink:href="#linearGradient5742" y1="26.400000" y2="28.000000"/> <linearGradient gradientTransform="matrix(0.389994,0.000000,0.000000,0.403942,9.357010,32.23582)" gradientUnits="userSpaceOnUse" id="linearGradient28801" x1="23.187498" x2="23.187498" xlink:href="#linearGradient6506" y1="28.449617" y2="26.670279"/> <linearGradient gradientTransform="translate(-4.787500,16.00000)" gradientUnits="userSpaceOnUse" id="linearGradient28804" x1="23.181250" x2="23.187500" xlink:href="#linearGradient9163" y1="26.793751" y2="27.843750"/> <linearGradient gradientTransform="translate(-4.787500,16.00000)" gradientUnits="userSpaceOnUse" id="linearGradient28807" x1="22.762501" x2="23.812500" xlink:href="#linearGradient5756" y1="26.687500" y2="27.906250"/> <linearGradient gradientTransform="translate(-4.800000,16.00000)" gradientUnits="userSpaceOnUse" id="linearGradient28810" x1="23.187500" x2="23.200001" xlink:href="#linearGradient5742" y1="26.400000" y2="28.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9199" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient9163"> <stop id="stop9165" offset="0.0000000" style="stop-color:#000000;stop-opacity:1.0000000;"/> <stop id="stop9167" offset="1.0000000" style="stop-color:#8c8c8c;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9197" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9195" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9193" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient id="linearGradient6506"> <stop id="stop6508" offset="0.0000000" style="stop-color:#ffffff;stop-opacity:0.0000000;"/> <stop id="stop6510" offset="1.0000000" style="stop-color:#ffffff;stop-opacity:0.87450981;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7498" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient id="linearGradient7464"> <stop id="stop7466" offset="0.0000000" style="stop-color:#00039a;stop-opacity:1.0000000;"/> <stop id="stop7468" offset="1.0000000" style="stop-color:#afa5ff;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7496" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient id="linearGradient5756"> <stop id="stop5758" offset="0.0000000" style="stop-color:#828282;stop-opacity:1.0000000;"/> <stop id="stop5760" offset="1.0000000" style="stop-color:#929292;stop-opacity:0.35294119;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9321" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient id="linearGradient5742"> <stop id="stop5744" offset="0.0000000" style="stop-color:#adadad;stop-opacity:1.0000000;"/> <stop id="stop5746" offset="1.0000000" style="stop-color:#f0f0f0;stop-opacity:1.0000000;"/> </linearGradient> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient7492" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9527" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9529" x1="22.935030" x2="23.662106" xlink:href="#linearGradient5756" y1="42.699776" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9531" x1="23.213980" x2="23.201290" xlink:href="#linearGradient7464" y1="42.754631" y2="43.892632"/> <linearGradient gradientUnits="userSpaceOnUse" id="linearGradient9533" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(24.16238,0.000000,0.000000,18.68556,-538.2464,-790.0391)" gradientUnits="userSpaceOnUse" id="linearGradient1336" x1="23.402565" x2="23.389874" xlink:href="#linearGradient6506" y1="44.066776" y2="42.883698"/> <linearGradient gradientTransform="matrix(30.28350,0.000000,0.000000,30.28350,-680.9062,-1286.161)" gradientUnits="userSpaceOnUse" id="linearGradient1339" x1="23.213980" x2="23.201290" xlink:href="#linearGradient9163" y1="42.754631" y2="43.892632"/> <linearGradient gradientTransform="matrix(33.82731,0.000000,0.000000,33.82731,-763.5122,-1439.594)" gradientUnits="userSpaceOnUse" id="linearGradient1342" x1="23.349695" x2="23.440580" xlink:href="#linearGradient5756" y1="42.767944" y2="43.710873"/> <linearGradient gradientTransform="matrix(31.25000,0.000000,0.000000,31.25000,-700.0000,-1325.000)" gradientUnits="userSpaceOnUse" id="linearGradient1345" x1="23.193102" x2="23.200001" xlink:href="#linearGradient5742" y1="42.429230" y2="44.000000"/> </defs> <g id="layer1"> <g id="g28884" style="overflow:visible" transform="matrix(31.25000,0.000000,0.000000,31.25000,-400.0000,-1250.000)"> <path d="M 14.400000,41.600000 L 12.800000,41.600000 L 13.600000,40.000000 L 14.400000,41.600000 z " id="path28664" sodipodi:nodetypes="cccc" style="fill:url(#linearGradient28870);fill-opacity:1.0000000;stroke:none;stroke-width:0.064000003;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000"/> <path d="M 13.600000,40.256250 L 12.975000,41.506250 L 14.225000,41.506250 L 13.600000,40.256250 z " id="path28666" style="fill:url(#linearGradient28867);fill-opacity:1.0000000;stroke:none;stroke-width:0.064000003;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> <path d="M 13.600000,40.381250 L 13.068750,41.443750 L 14.131250,41.443750 L 13.600000,40.381250 z " id="path28668" style="fill:url(#linearGradient28864);fill-opacity:1.0000000;stroke:none;stroke-width:0.064000003;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> <path d="M 13.575621,40.552906 C 13.555816,40.559679 13.538695,40.572979 13.526872,40.590776 C 13.522451,40.594595 13.518372,40.598819 13.514685,40.603399 L 13.307500,41.032587 C 13.299161,41.047990 13.294953,41.065424 13.295313,41.083080 C 13.296850,41.096430 13.300996,41.109315 13.307500,41.120950 C 13.310377,41.129925 13.314481,41.138427 13.319688,41.146196 C 13.323375,41.150775 13.327454,41.155000 13.331875,41.158819 C 13.339376,41.164212 13.347584,41.168462 13.356250,41.171442 C 13.367483,41.178179 13.379923,41.182474 13.392812,41.184066 L 13.807180,41.184066 C 13.835802,41.183428 13.862639,41.169530 13.880304,41.146196 C 13.884725,41.142377 13.888804,41.138152 13.892491,41.133573 C 13.898995,41.121938 13.903142,41.109053 13.904679,41.095703 C 13.905039,41.078047 13.900831,41.060614 13.892491,41.045211 C 13.892751,41.041007 13.892751,41.036791 13.892491,41.032587 L 13.685307,40.603399 C 13.681620,40.598819 13.677541,40.594595 13.673120,40.590776 C 13.650701,40.559305 13.612491,40.544463 13.575621,40.552906 z " id="path28670" style="fill:url(#linearGradient28861);fill-opacity:1.0000000;stroke:none;stroke-width:0.064000003;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4.0000000;stroke-opacity:1.0000000;overflow:visible"/> </g> </g> </svg> """ } colours={Red : (0xCF, 0x00, 0x00), Green : (0x0f, 0x69, 0x00), Yellow : (0xd2, 0xcd, 0x00), Grey : (0x5a, 0x5a, 0x5a), Orange : (0xda, 0x46, 0x15), Purple : (0x87, 0x00, 0x83), Blue : (0x00, 0x03, 0x9a)} clicked=pyqtSignal() def __init__(self, parent=None, **kwargs): self.m_value=False self.m_onColour=QLed.Red self.m_offColour=QLed.Grey self.m_shape=QLed.Circle QWidget.__init__(self, parent, **kwargs) self._pressed=False self.renderer=QSvgRenderer() def value(self): return self.m_value def setValue(self, value): self.m_value=value self.update() value=pyqtProperty(bool, value, setValue) def onColour(self): return self.m_onColour def setOnColour(self, newColour): self.m_onColour=newColour self.update() onColour=pyqtProperty(int, onColour, setOnColour) def offColour(self): return self.m_offColour def setOffColour(self, newColour): self.m_offColour=newColour self.update() offColour=pyqtProperty(int, offColour, setOffColour) def shape(self): return self.m_shape def setShape(self, newShape): self.m_shape=newShape self.update() shape=pyqtProperty(int, shape, setShape) def sizeHint(self): if self.m_shape==QLed.Triangle: return QSize(64,48) elif self.m_shape==QLed.Round: return QSize(96, 48) return QSize(48,48) def adjust(self, r, g, b): def normalise(x): return x/255.0 def denormalise(x): return int(x*255.0) (h,l,s)=rgb_to_hls(normalise(r),normalise(g),normalise(b)) (nr,ng,nb)=hls_to_rgb(h,l*1.5,s) return (denormalise(nr),denormalise(ng),denormalise(nb)) def paintEvent(self, event): option=QStyleOption() option.initFrom(self) h=option.rect.height() w=option.rect.width() if self.m_shape in (QLed.Triangle, QLed.Round): aspect=(4/3.0) if self.m_shape==QLed.Triangle else 2.0 ah=w/aspect aw=w if ah>h: ah=h aw=h*aspect x=abs(aw-w)/2.0 y=abs(ah-h)/2.0 bounds=QRectF(x,y,aw,ah) else: size=min(w,h) x=abs(size-w)/2.0 y=abs(size-h)/2.0 bounds=QRectF(x,y,size,size) painter=QPainter(self); painter.setRenderHint(QPainter.Antialiasing, True); (dark_r,dark_g,dark_b)=self.colours[self.m_onColour if self.m_value else self.m_offColour] dark_str="rgb(%d,%d,%d)" % (dark_r,dark_g,dark_b) light_str="rgb(%d,%d,%d)" % self.adjust(dark_r,dark_g,dark_b) shape = self.shapes[self.m_shape] % (dark_str, light_str) shape = shape.encode('utf-8') self.renderer.load(QByteArray(shape)) self.renderer.render(painter, bounds) def mousePressEvent(self, event): self._pressed=True QWidget.mousePressEvent(self, event) def mouseReleaseEvent(self, event): if self._pressed: self._pressed=False self.clicked.emit() QWidget.mouseReleaseEvent(self, event) def toggleValue(self): self.m_value=not self.m_value; self.update()
def drawObject(self, painter, rect, doc, posInDocument, format): renderer = QSvgRenderer(format.property(Window.SvgData)) renderer.render(painter, rect)
def __init__(self, parent): QWidget.__init__(self, parent) self.compass = QSvgRenderer("compassBody.svg") self.needle = QSvgRenderer("compassNeedle.svg") self.angle = 0