Example #1
0
 def draw_shapes(self):
   # really ugly redraw everything
   self.scene.clear()
   self.webview = QGraphicsWebView()
   self.webview.setZoomFactor(3.0)
   self.scene.setBackgroundBrush(Qt.black)
   self.scene.addItem(self.webview)
   w = self.width()*.5
   h = self.height()*.5
   width = "%spx" % (w)
   height = "%spx" % (h)
   dx = (int(self.parent.gl_dx + 1)/2)*2
   dy = (int(self.parent.gl_dy + 1)/2)*2
   vx = dx
   dy = dy
   self.dx = dx
   self.dy = dy
   print dx, dy
   # TODO: clever viewbox calculation     
   viewbox = "%d %d %d %d" % (-self.q*dx/2, -self.q*dy/2, self.q*dx, self.q*dy)
   rect = svgfig.Rect(-dx/2,-dy/2,dx/2,dy/2, fill='black', stroke=None).SVG(trans=self.trans)
   dot_field = self.draw_dot_field()
   print self.box.contentsRect()
   print width, height, viewbox
   svg_g = svgfig.SVG("g")
   svg_g.append(rect)
   for x in dot_field:
     svg_g.append(x)
   for shape in self.shapes:
     self.set_color(shape['type'])
     if 'shape' in shape:
       dispatch = {
         'circle': self.circle,
         'disc': self.disc,
         'label': self.label,
         'line': self.vertex,
         'vertex': self.vertex,
         'octagon': self.octagon,
         'rect': self.rect,
         'polygon': self.polygon,
         'hole': self.hole,
       }
       shape_svg = dispatch.get(shape['shape'], self.skip)(shape)
       print shape_svg
       for x in shape_svg:
         svg_g.append(x)
   
   #print subs
   canvas = svgfig.canvas(svg_g, width=width, height=height, viewBox=viewbox)
   xml = canvas.standalone_xml()
   print xml
   self.webview.setContent(QtCore.QByteArray(xml))
Example #2
0
 def __init__(self, parent, box):
   self.scene = QtGui.QGraphicsScene()
   super(JYDSVGWidget, self).__init__(self.scene, parent)
   self.parent = parent
   self.box = box
   self.webview = QGraphicsWebView()
   self.webview.setZoomFactor(3.0)
   self.scene.setBackgroundBrush(Qt.black)
   self.scene.addItem(self.webview)
   #self.scene.addText('Hello, world')
   self.zoomfactor = 42
   self.is_gl = False
   self.color_scheme = color_schemes[str(parent.setting('gl/colorscheme'))]
   self.trans = trans
   self.q = Q