Exemplo n.º 1
0
  def exportSvg(self):
    ''' Called when the user wants to export a view as SVG file.
        The SVG is stored as a file containing the model and view names.
    '''
    path = self.details.getParents()
    model_url = currentFile()
    model_name = urlparse(model_url)[2]
    dirname, basename = os.path.split(model_name)
    fname = '%s.%s.svg'%(basename, '.'.join([p.Name for p in path]))
    fname = os.path.join(dirname, fname)
    fname = str(QtGui.QFileDialog.getSaveFileName(self, 'export as SVG', fname, '*.svg'))
    if fname == '':
      return

    svg = self.scene.exportSvg()
    with open(fname, 'w') as f:
      f.write(svg)
Exemplo n.º 2
0
 def exportPng(self):
   ''' Called when the user wants to export a view as PNG file.
   '''
   # Get a file to store it in.
   path = self.details.getParents()
   model_url = currentFile()
   model_name = urlparse(model_url)[2]
   dirname, basename = os.path.split(model_name)
   fname = '%s.%s.png'%(basename, '.'.join([p.Name for p in path]))
   fname = os.path.join(dirname, fname)
   fname = str(QtGui.QFileDialog.getSaveFileName(self, 'export as PNG', fname, '*.png'))
   if fname == '':
     return
   rect = self.scene.itemsBoundingRect()
   image = QtGui.QImage(rect.width(), rect.height(), QtGui.QImage.Format_ARGB32)
   image.fill(0x000000ff)
   painter = QtGui.QPainter(image)
   painter.setRenderHint(QtGui.QPainter.Antialiasing)
   painter.setRenderHint(QtGui.QPainter.TextAntialiasing)
   self.scene.render(painter)
   image.save(fname)
   del painter