Author Topic: Python+Qtopia: styles, events, quickexec etc.  (Read 6358 times)

zenyatta

  • Sr. Member
  • ****
  • Posts: 366
    • View Profile
    • http://
Python+Qtopia: styles, events, quickexec etc.
« on: May 20, 2004, 06:07:11 am »
Hi all,

I\'ve been working on a little diary application for the Z using Python and Qt. It\'s my first Python project and so far it\'s been nothing but instant gratification. I\'m very happy.

There are, however, a few things I could use some help with:

1. How can I apply Qtopia\'s current widget style and window decorations to my app? I would like to have my program visually integrated but when I try app.setStyle() nothing works except QWindowsStyle. How can I find out which QStyles are available? Or is there some other mechanism for doing this than app.setStyle()? And how do I find out which style is being used in Qtopia?

2. To persist the state of my app, I override hideEvent() in my main widget. I think there must be a better way but I couldn\'t find any closeEvent() handler to override. (By the way, if someone could explain to me how class members are sorted in Qt documentation I would be quite grateful. Alphabet it isn\'t, that\'s for sure.)

3. I can\'t close my app with the Cancel key (on the 5500), I have to pull out the stylus and tap the title bar button. Any advice on how to get the Cancel key working?

4. I realize the slow start-up is largely due to the Python runtime being launched but I was wondering whether it would be possible to write a quicklauncher/quickexec app in Python and what it would take. Or maybe whether it would be possible to have the Python runtime pre-loaded, including PyQt. A Python quickexec!

5. Finally, a pure Python question. Since I am a complete newbie, my code (all 139 lines of it) may not be quite up to scratch. In particular, I get irritated by having to reference \'self\' all the time in instance methods. I get lines like:
Code: [Select]
self.editArea.setText(self.diary.currentPage().text)

I could use something like the \"with\" operator in Pascal whereby I would write:
Code: [Select]
with self do

 editArea.setText(diary.currentPage().text)

 ...


As always, any help is appreciated.

z.
SL-5500, 256MB Kingston CF card, 128MB EDGE SD card, Thomson HED-155 headphones
OpenZaurus 3.5.3 / Opie (kernel 64-0)

zenyatta

  • Sr. Member
  • ****
  • Posts: 366
    • View Profile
    • http://
Python+Qtopia: styles, events, quickexec etc.
« Reply #1 on: May 20, 2004, 07:30:50 am »
The great thing about Python apps is that you always have the source to learn from. I had a quick look at Markus Biermaier\'s ImageBrowser and pressto: items 1 and 3 are solved by
Code: [Select]
from qtpe import QPEApplication

...

app=QPEApplication(sys.args)

I wish it was all this easy...

z.
SL-5500, 256MB Kingston CF card, 128MB EDGE SD card, Thomson HED-155 headphones
OpenZaurus 3.5.3 / Opie (kernel 64-0)

Mickeyl

  • Hero Member
  • *****
  • Posts: 1495
    • View Profile
    • http://www.Vanille.de
Python+Qtopia: styles, events, quickexec etc.
« Reply #2 on: May 20, 2004, 08:03:59 am »
Can you give us a bit more details about what you want to achieve with 2.)?
4.) is something I have wanted to think about for long but since I have pretty much to do I didn\'t have time to yet.
5.) Don\'t be lazy. The self is important to see what scope you are referring to. There is no such thing as a \'with\' in Python. However, if you absolutely need to abbreviate,
then remember that every function in python is just a normal attribute like anything else. So you could do something like that:
Code: [Select]
areaSetText = self.editArea.setText
and then later just use it like
Code: [Select]
areaSetText( "bla" )
Cheers,

Michael 'Mickey' Lauer | Embedded Linux Freelancer | www.Vanille-Media.de
Consider donating, if you like the software I contribute to.

zenyatta

  • Sr. Member
  • ****
  • Posts: 366
    • View Profile
    • http://
Python+Qtopia: styles, events, quickexec etc.
« Reply #3 on: May 21, 2004, 08:31:31 am »
2.) Well, the first version of the app does not use a \"document paradigm\", i.e. it always reads the same diary file on startup and writes it on exit. I have trouble with the \"on exit\" part. First I tried overriding __del__() in my main widget and it worked but I read in the Python docs that __del__() is not guaranteed to run when the interpreter is shutting down. It made me feel uncomfortable so I switched to hideEvent(). I\'ve since discovered closeEvent() and QApplication::lastWindowClosed() so point 2 is solved (I guess I\'ll go with closeEvent(), don\'t know why I didn\'t see it the first time I was looking).

5.) Thanks for the tip. I understand it makes the code a bit opaque but I don\'t see a problem with it if it\'s used judiciously and perhaps commented.

As I\'ve now moved on a bit I have another question:

6.) The section on document-oriented applications in Qtopia docs says my main widget should implement the setDocument() slot. If I read PyQt documentation correctly, I don\'t need to designate a Python callable as a slot in any way, I simply use it in a connect(). Since Qtopia will be doing the connecting, how is it to know that my main widget\'s setDocument() method is the slot, especially since I can\'t declare its argument to be a string?

Thanks for the help,

z.
SL-5500, 256MB Kingston CF card, 128MB EDGE SD card, Thomson HED-155 headphones
OpenZaurus 3.5.3 / Opie (kernel 64-0)