3 beginner questions!
Alex Martelli
aleax at aleax.it
Wed May 7 17:53:46 EDT 2003
<posted & mailed>
Ali Dada wrote:
>>
>> Before *instantiating* widgets, you need to instantiate QApplication.
>> Did you do that...?
>
> nope! how should i do that (i should give it an argument but i don't
> know the type of this argument) and where should i do that (seperate
> file than that generated?)
The general pattern is:
import sys
import qt
# make the application object (it needs the list of arguments)
app = qt.QApplication(sys.argv)
# ensure the application ends when its last window is closed
qt.QObject.connect(a,qt.SIGNAL('lastWindowClosed()'),a,qt.SLOT('quit()'))
# let's see the form that lives in myform.py
import myform
form = myform.Form1()
app.setMainWidget(form)
form.show()
app.exec_loop()
That's all! You don't need to alter myform.py to display the form, etc.
Actually, pyuic has several handy switches, one of which basically
generates this "let's see the form" code as a part of form.py --
AND nicely protected, as Python idiom requires, by a guard of the form
if __name__ == '__main__':
so that the "let's see the form" code won't execute if what you're doing
is (normal case) IMPORTING the form module -- only if you're RUNNING this
generated Python file as the main script!
So, a command such as:
pyuic -x myform.ui > myform.py
will make you a Python script myform.py which, as well as importing for
use by a program, you can ALSO execute directly with
python myform.py
in order to see the form it contains.
Run:
pyuic -help
for a summary of pyuic's handy commandline options.
Alex
More information about the Python-list
mailing list