I'm new to GUIs, but thinking about writing a GUI that is a little bit
like a simple vector drawing program. So I've been looking at various
toolkit and language options.

So far, it looks like my first choice would be PyQt... but it seems
slow. I wrote the attached code. If you select more than a couple dozen
shapes and move them, there's substantial lag, and I see python pegging
the CPU. The question:

1) Is there something I'm doing that is seriously inefficient and could
   be rewritten for speed?

2) What sort of speedup might I expect from this same program if it were
   rewritten in C++ with qt?

   Vadim
from PyQt4.Qt import *
import random
import sys


def addshape(scene,x,y):
    shapefunc=random.choice((scene.addRect,scene.addEllipse))
    c=shapefunc(QRectF(x,y,random.randint(10,20),random.randint(10,20)))
    c.setFlag(c.ItemIsMovable)
    c.setFlag(c.ItemIsSelectable)

class myGui(QWidget):

    def __init__(self,parent=None):
        QWidget.__init__(self,parent)

        quitButton=QPushButton("&Quit")
        QObject.connect(quitButton,SIGNAL("clicked()"),qApp,SLOT("quit()"))

        self.pane=QGraphicsScene()
        self.view=QGraphicsView(self.pane)
        self.view.setDragMode(QGraphicsView.RubberBandDrag)
        
        zoomInButton=QPushButton("ZoomIn")
        QObject.connect(zoomInButton,SIGNAL("clicked()"),lambda : self.view.scale(1.2,1.2))

        zoomOutButton=QPushButton("ZoomOut")
        QObject.connect(zoomOutButton,SIGNAL("clicked()"),lambda : self.view.scale(.8,.8))

        [addshape(self.pane,x,y) for x in range(0,1000,25) for y in range(0,1000,25)]
    
        lButtons=QHBoxLayout()
        lButtons.addWidget(quitButton)
        lButtons.addWidget(zoomInButton)
        lButtons.addWidget(zoomOutButton)
        
        layout=QVBoxLayout()
        layout.addLayout(lButtons)
        layout.addWidget(self.view)
        self.setLayout(layout)



app=QApplication(sys.argv)
firstP=myGui()
firstP.show()

app.exec_()
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to