[pyxpcom] A first Python / XULRunner app - impressions and problems
by Rasjid Wilcox other posts by this author
Feb 18 2009 7:45AM messages near this date
view in the new Beta List Site
Re: [pyxpcom] Why isn't everyone in the Python world using this?
|
Re: [pyxpcom] A first Python / XULRunner app - impressions and problems
Hi all,
I have my first Python / XULRunner app in production at work. It is
not a very big app, but enough to get a feel for the platform.
First and foremost, my overwhelming feeling is one of huge potential.
Python is beautiful to work with, and for GUI design so is XUL. Both
are highly dynamic and make complex tasks simple. They are also well
matched.
As for the experience of writing my first app, given that I was
learning quite a lot of stuff from scratch (I've never worked with XUL
or XPCOM before), it was really good. The trickiest part in many ways
was finding the correct bit of documentation to read and digest. And
a big thank-you to Todd Whiteman and his pre-packaged download. It
would have taken me much longer to get started without it.
For reference, at the moment I'm doing all this on Windows XP,
although I'm hoping to use this knowledge on Linux too. I want to
stay in Python land as much as possible - using pyDOM rather than
Javascript for all business logic and screen behaviour.
Now to the problems so far, in no particular order.
1. Python threads interacting with the GUI
As far as I can tell, gui calls should always be made from the main
thread. A post from Toms Baugis suggested using the observer-service,
but attempting to add a python function as an observer gives a
ValueError, 'The object <MyObserver ...> can not be used as a COM
obejct'.
I got a work-around happening using window.setInterval and python
queues, but it is a bit of a hack (since it is a polling approach) and
what I really want is a way for the background thread to post 'custom'
events to the event queue, that the main thread can just listen (and
react) to.
2. Multiple 'main screens'.
I noticed that if I start my app multiple times, there is only one
process (and only one console if started with -console), but I get
multiple main screens. I would prefer that it just brings the first
instance to the foreground. I attempted to solve this by having a
'splash' screen that does the initial data loading, checks for the
existence of the main screen, and starts the app proper, but then I
discovered that I didn't know how to get ...
3. Python objects shared between windows.
I tried several of the ideas in
https://developer.mozilla.org/En/Working_with_windows_in_chrome_code,
but most of them seem to be either too limited (my data could not be
converted to a nsIVarient so passing as an argument didn't work) or
JavaScript specific. In this particular instance I could re-work the
class to be passed to be an XPCOM component, although that adds to the
complexity somewhat. But in general it would be nice to be able to
pass python objects between windows without resorting to XPCOM. On
reflection, I assume that each window gets its own python instance, so
perhaps this is much more tricky that it seems.
Other issues, not directly related to the app in question, but
relevant for future use are,
4. Creating a hidden (non-visible) window.
I could not work out how to do this. Not sure if it is even possible.
5. Working with XBL widgets (partly solved).
Initially I was concerned that I could not use XBL based widgets
methods from pyDOM. This distressed me greatly, since being able to
create new widgets with XBL is one of the attractions of the platform.
But with a bit of playing around, I found that it is possible to
write a JavaScript XPCOM component that can 'expose' the XBL component
to pyDOM. This could all be done by hand, but it seems an obvious
candidate for code generation.
All suggestions and ideas greatly appreciated.
Thanks,
Rasjid.
_______________________________________________
pyxpcom mailing list
pyxpcom@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Thread:
Rasjid Wilcox
Rasjid Wilcox
Rasjid Wilcox
|