Ejemplo n.º 1
0
def display (sc, title = "SVG scene") :
	"""Display a scene in a Qdialog
	
	:Parameters:
	 - `sc` (`SVGScene`)
	 - `title` (str) - window title
	"""
	qapp = QApplication.instance()
	if qapp is None :
		qapp = QApplication([])
	
	dial = QDialog()
	dial.setWindowTitle(title)
	dial.setPalette(QPalette(QColor(255,255,255) ) )
	lay = QVBoxLayout(dial)
	
	w = QSvgWidget(dial)
	data = QByteArray(str(to_xml(sc) ) )
	w.load(data)
	
	r = w.renderer()
	w.setMinimumSize(r.defaultSize() )
	lay.addWidget(w)
	
	dial.show()
	
	qapp.exec_()
Ejemplo n.º 2
0
def display(sc, title="SVG scene"):
    """Display a scene in a Qdialog
	
	:Parameters:
	 - `sc` (`SVGScene`)
	 - `title` (str) - window title
	"""
    qapp = QApplication.instance()
    if qapp is None:
        qapp = QApplication([])

    dial = QDialog()
    dial.setWindowTitle(title)
    dial.setPalette(QPalette(QColor(255, 255, 255)))
    lay = QVBoxLayout(dial)

    w = QSvgWidget(dial)
    data = QByteArray(str(to_xml(sc)))
    w.load(data)

    r = w.renderer()
    w.setMinimumSize(r.defaultSize())
    lay.addWidget(w)

    dial.show()

    qapp.exec_()
Ejemplo n.º 3
0
def save_png (filename, sc, background = (255,255,255, 0) ) :
	"""Create a png image from a scene
	
	:Parameters:
	 - `filename` (str) - name to write the image
	 - `sc` (SVGScene)
	 - `background` (int, int, int, int) - background color
	                        as (R, G, B, alpha) 0-255 tuple
	"""
	qapp = QApplication.instance()
	if qapp is None :
		qapp = QApplication([])
	
	r = QSvgRenderer(None)
	data = QByteArray(str(to_xml(sc) ) )
	r.load(data)
	
	pix = QPixmap(r.defaultSize() )
	pix.fill(QColor(*background) )
	painter = QPainter(pix)
	r.render(painter)
	painter.end()
	pix.save(filename)
Ejemplo n.º 4
0
def save_png(filename, sc, background=(255, 255, 255, 0)):
    """Create a png image from a scene
	
	:Parameters:
	 - `filename` (str) - name to write the image
	 - `sc` (SVGScene)
	 - `background` (int, int, int, int) - background color
	                        as (R, G, B, alpha) 0-255 tuple
	"""
    qapp = QApplication.instance()
    if qapp is None:
        qapp = QApplication([])

    r = QSvgRenderer(None)
    data = QByteArray(str(to_xml(sc)))
    r.load(data)

    pix = QPixmap(r.defaultSize())
    pix.fill(QColor(*background))
    painter = QPainter(pix)
    r.render(painter)
    painter.end()
    pix.save(filename)