[PyKDE] App structure feedback please

Dave S eric3 at pusspaws.net
Mon Sep 4 20:52:42 BST 2006


This is my first reasonably complex GUI app (read baby app for you guys :) 
Having read quite a bit the structure has evolved as ...

##########################################

class control (1)
(The glue between the GUI ------ model scanning engine script to generate
script & the scanning engine.     data (2)
   |
   |
class view  (3)
(Enhances the GUI interface ------ sub class Form1 to capture method calls
tweaking the script from             when GUI events happen (4)
QT designer with options not
available in the designer GUI)
   |
   |
class Form1 from QT designer the main GUI screen (5)

###########################################

(1) is the glue and core of the program, 
(3) insulates (1) from the specific calls into (5) and handles the subclassing 
to get GUI data
(5) the scripts generated by QT designer (defaults class to Form1) QT designer 
only allows slots within its class so the need for subclassing to catch the 
signal.

To change or write data to the GUI is easy. The layers are just one on another 
I just self.progressBar1.setProgress(pc, 100) from (3) ... or even (1) but 
that breaks my ideal structure :)

Getting data from the GUI is a bit messy. I use a subclassed method that 
generates a PYSIGNAL

###########################################

class Form1(dialogs.mainscreen.Form1):
    """ A subclasses of Form1 to enable PyQt to access signals generated by 
designer-qt"""
    def __init__(self, *args):
        apply(dialogs.mainscreen.Form1.__init__,(self, ) + args)
  
    def TableClicked(self, row, col):
        if col != 3: return  # Only interested in the 'action' column
        self.emit(PYSIGNAL("sigClicked"), ())

###########################################

And in (1) I start the whole QT 'thing' with 

###########################################

def main(args):

    app = QApplication(args)
    docview = Control()
    QObject.connect(docview, PYSIGNAL("sigClicked"), docview.Audit)
    app.setMainWidget(docview)
    docview.show()
    
    QObject.connect(app, SIGNAL('lastWindowClosed()'),app, SLOT('quit()'))
    app.exec_loop()
    
if __name__=="__main__":
    main(sys.argv)

###########################################

Causing my TableClicked (5) signal to eventually call Audit() in (1) ... 
phew !

OK so I am green to this. It works, seems a bit clunky & am aware that there 
may well be a better way.

Any feedback would be great

Dave













More information about the PyQt mailing list