![]() ![]() |
May 20 2004, 02:07 AM
Post
#1
|
|
![]() Group: Members Posts: 366 Joined: 4-November 03 From: Slovakia Member No.: 850 |
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 self.editArea.setText(self.diary.currentPage().text)
I could use something like the "with" operator in Pascal whereby I would write: CODE with self do
editArea.setText(diary.currentPage().text) ... As always, any help is appreciated. z. |
|
|
|
May 20 2004, 03:30 AM
Post
#2
|
|
![]() Group: Members Posts: 366 Joined: 4-November 03 From: Slovakia Member No.: 850 |
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 from qtpe import QPEApplication
... app=QPEApplication(sys.args) I wish it was all this easy... z. |
|
|
|
May 20 2004, 04:03 AM
Post
#3
|
|
|
Group: Members Posts: 1,497 Joined: 12-November 03 From: Germany Member No.: 907 |
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 areaSetText = self.editArea.setText
and then later just use it like CODE areaSetText( "bla" )
|
|
|
|
May 21 2004, 04:31 AM
Post
#4
|
|
![]() Group: Members Posts: 366 Joined: 4-November 03 From: Slovakia Member No.: 850 |
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. |
|
|
|
![]() ![]() |
|
Lo-Fi Version | Time is now: 24th May 2013 - 07:04 AM |