22import json
33from os import path , makedirs
44
5- import numpy as np
6-
7- from AnyQt import QtGui
8- from AnyQt .QtCore import QRectF , Qt , QTimer
9- from AnyQt .QtGui import QImage
5+ from AnyQt .QtGui import QImage , QPainter
106from AnyQt .QtWidgets import QGraphicsScene , QApplication , QWidget , QGraphicsView , QHBoxLayout
7+ from AnyQt .QtCore import QRectF , Qt , QTimer
118
129from Orange .canvas import config
1310from Orange .canvas .canvas .items import NodeItem
@@ -20,9 +17,10 @@ def __init__(self, output_dir, image_url_prefix):
2017 self .output_dir = output_dir
2118 self .image_url_prefix = image_url_prefix
2219
20+ QApplication .setAttribute (Qt .AA_EnableHighDpiScaling )
21+ QApplication .setAttribute (Qt .AA_UseHighDpiPixmaps )
22+ QApplication .setAttribute (Qt .AA_ShareOpenGLContexts )
2323 self .app = QApplication ([])
24- self .app .setAttribute (Qt .AA_EnableHighDpiScaling )
25- self .app .setAttribute (Qt .AA_UseHighDpiPixmaps )
2624
2725 print ("Generating widget repository" )
2826 self .registry = self .__get_widget_registry ()
@@ -127,16 +125,17 @@ def set_widget(self, widget_description, category_description):
127125
128126 def render_as_png (self , filename ):
129127 png = self .__transparent_png ()
130- painter = QtGui . QPainter (png )
131- painter .setRenderHint (QtGui . QPainter .Antialiasing , 1 )
128+ painter = QPainter (png )
129+ painter .setRenderHint (QPainter .Antialiasing , 1 )
132130 self .scene .render (painter , QRectF (0 , 0 , 50 , 50 ), QRectF (- 25 , - 25 , 50 , 50 ))
133131 painter .end ()
134132 png .save (filename )
135133
136134 def __transparent_png (self ):
137135 # PyQt is stupid and does not increment reference count on bg
138- self .__bg = bg = np .zeros ((50 , 50 , 4 ), dtype = np .ubyte )
139- return QImage (bg .ctypes .data , bg .shape [1 ], bg .shape [0 ], QtGui .QImage .Format_ARGB32 )
136+ w = h = 50
137+ self .__bg = bg = b"\xff \xff \x00 " * w * h * 4
138+ return QImage (bg , w , h , QImage .Format_ARGB32 )
140139
141140
142141if __name__ == '__main__' :
0 commit comments