Skip to content

Commit

Permalink
foo
Browse files Browse the repository at this point in the history
  • Loading branch information
janezd committed Dec 20, 2018
1 parent f2ec533 commit 21be458
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions scripts/create_widget_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
import json
from os import path, makedirs

import numpy as np

from AnyQt import QtGui
from AnyQt.QtCore import QRectF, Qt, QTimer
from AnyQt.QtGui import QImage
from AnyQt.QtGui import QImage, QPainter
from AnyQt.QtWidgets import QGraphicsScene, QApplication, QWidget, QGraphicsView, QHBoxLayout
from AnyQt.QtCore import QRectF, Qt, QTimer

from Orange.canvas import config
from Orange.canvas.canvas.items import NodeItem
Expand All @@ -20,9 +17,10 @@ def __init__(self, output_dir, image_url_prefix):
self.output_dir = output_dir
self.image_url_prefix = image_url_prefix

QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
QApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
self.app = QApplication([])
self.app.setAttribute(Qt.AA_EnableHighDpiScaling)
self.app.setAttribute(Qt.AA_UseHighDpiPixmaps)

print("Generating widget repository")
self.registry = self.__get_widget_registry()
Expand Down Expand Up @@ -127,16 +125,17 @@ def set_widget(self, widget_description, category_description):

def render_as_png(self, filename):
png = self.__transparent_png()
painter = QtGui.QPainter(png)
painter.setRenderHint(QtGui.QPainter.Antialiasing, 1)
painter = QPainter(png)
painter.setRenderHint(QPainter.Antialiasing, 1)
self.scene.render(painter, QRectF(0, 0, 50, 50), QRectF(-25, -25, 50, 50))
painter.end()
png.save(filename)

def __transparent_png(self):
# PyQt is stupid and does not increment reference count on bg
self.__bg = bg = np.zeros((50, 50, 4), dtype=np.ubyte)
return QImage(bg.ctypes.data, bg.shape[1], bg.shape[0], QtGui.QImage.Format_ARGB32)
w = h = 50
self.__bg = bg = b"\xff\xff\x00" * w * h * 4
return QImage(bg, w, h, QImage.Format_ARGB32)


if __name__ == '__main__':
Expand Down

0 comments on commit 21be458

Please sign in to comment.