[PyKDE] Qt Designer imports and general framework

Kenneth Godee Ken at perfect-image.com
Sun Dec 29 18:39:01 GMT 2002


I'm working on my first python/pyqt project and just
wondering if someone could through a bone or two on the
general framework that people use. I'm figuring it out but sure
am running into lots of scope/naming problems and wondering
if I'm going about this the right way.

I'm using Qt Designer for a simple dialog window and 
python database(psycopg) for db routines. 

I have three files....

1. main.py - This calls the main part of the 
program and an instance of the dialog form being designed
in Qt Designer and pyuic converted.

class mainWindow(MainCust):
    def __init__(self,parent = None,name = None,fl = 0):
        MainCust.__init__(self,parent,name,fl)
-----
2. salesform.py (Qt designer dialog .ui form pyuic converted)

class MainCust(QDialog):
    def __init__(self,parent = None,name = None,modal = 0,fl = 0):
        QDialog.__init__(self,parent,name,modal,fl)
------

3. dbfunc.py, this file contains all the database function
routines.

------

First of all I assume the only way to import into Qt Designer
is to edit the source and create a slot/function like this.......
-------------------------------------------
void MainCust::custid_returnPressed()
{
import dbfunc
dbfunc.custlu()
}
-------------------------------------------
Which pyuic then changes to.....
-------------------------------------------
def custid_returnPressed(self):

    import dbfunc
    dbfunc.custlu()
-------------------------------------------
Is this the only way to import thru pyqt/Qt Designer?
This has put me in a tail spin of scope problems and
I would also like to keep a persistant db conection open
which is not possible once the function is exited.
--------------------------------------------

Also the only way I can find to change any values
in the instance of the dialog form is to pass
values thru the function call to dbfunc.py 
and return the values. Like.....

self.connect(self.custid,SIGNAL("returnPressed()"),self.custid_returnPressed)

def custid_returnPressed(self):
    test2 = [self.d_custcon.text()]
    import dbfunc
    dbfunc.custlu(self.custid.text(), test2)
    self.d_custcon.setText(test2[0])

A little sloppy but you should get the idea,
I'd like to change the dialog form values right in
the dbfunc.py file but I can't seem to
get to the changes back to the dialog form in salesform.py / instance from main.py
I keep getting "AttributeError:" when trying
to "mainWindow.d_custcon.setText("whatever")" from the dbfunc.py
back to the dialog form.

Passing the values back and forth thru the function call is ok,
just wondering if I'm going about it correctly?

I hope someone can understand my ramblings.
Any help would be great.

Ken
















More information about the PyQt mailing list