Opened 6 years ago
Last modified 6 years ago
#5422 enhancement new
pbgtk2.py example is excessively complex
Reported by: | frontendloader | Owned by: | jesstess |
---|---|---|---|
Priority: | low | Milestone: | |
Component: | core | Keywords: | gtk2 |
Cc: | oubiwann, jesstess, frontendloader | Branch: |
branches/pygtk-example-5422
branch-diff, diff-cov, branch-cov, buildbot |
Author: | frontendloader, jesstess |
Description
The pbgtk2.py example is a fairly complex example. In addition to that example, I think there needs to be a simpler "Hello World" type example. I have included a lightly commentated one that is a near exact copy of the pygtk Hello World example with the needed changes made to use the reactor loop instead of the main gtk loop.
Comparing the pygtk Hello World example with my example will show a user how to get a simple gtk2/twisted application up and running.
Attachments (1)
Change History (10)
comment:1 Changed 6 years ago by
Cc: | oubiwann added |
---|
Changed 6 years ago by
Attachment: | twgtk2helloworld.py added |
---|
comment:2 Changed 6 years ago by
Component: | website → core |
---|---|
Keywords: | review added |
Thanks. Putting it up for review as described on ReviewProcess#Authors:Howtogetyourchangereviewed.
comment:3 Changed 6 years ago by
Cc: | jesstess added |
---|---|
Owner: | set to jesstess |
comment:4 Changed 6 years ago by
Author: | → jesstess |
---|---|
Branch: | → branches/pygtk-example-5422 |
(In [33331]) Branching to 'pygtk-example-5422'
comment:6 Changed 6 years ago by
comment:7 Changed 6 years ago by
Author: | jesstess → frontendloader |
---|---|
Cc: | frontendloader added |
Keywords: | review removed |
Owner: | changed from jesstess to frontendloader |
Thanks for this example, frontendloader! We definitely need a simpler intro example for GTK2 integration.
I've added your example in branches/pygtk-example-5422. I also added it to the examples index and made some cosmetic tweaks to conform to our coding standard.
After checking out some StackOverflow complaints about pbgtk2.py
and looking at wxdemo.py
, it seems like people want a tiny example of actually using some Twisted function beyond starting and stopping the reactor, so I added a little reactor.callLater
call to your example.
If this is a friendly amendment, let me know and I'll go ahead and merge.
comment:8 Changed 6 years ago by
Keywords: | review added |
---|---|
Owner: | frontendloader deleted |
I've made enough changes that someone else should review this.
comment:9 Changed 6 years ago by
Author: | frontendloader → frontendloader, jesstess |
---|---|
Keywords: | review removed |
Owner: | set to jesstess |
Thanks frontendloader, jesstess.
The new example seems to work. I observe several things about its behavior:
- It displays a Gtk window with a "hello world" button in it.
- It counts down from 10 and exits when it reaches 0.
- Clicking the button prints a message and exits immediately.
- Clicking the window manager close-window button exits immediately.
If this is what it's supposed to do, then it is working fine on Ubuntu Oneiric.
Here are a few other things I observe about it:
- There's no explanation of what one should expect it to do.
- If the expected behavior is different from the observed behavior (eg, the behavior I observed and enumerated above), an end user has no way of knowing it's not working properly.
- An end user has no way to know if it's an example of something they're interested in except by running it, hoping it is working correctly, and then interacting with it until they discover it implements a behaviour they are interested in learning about or getting bored and giving up.
- There's little explanation of the implementation. It's a pretty simple example, but presumably if no explanation were required, the example itself wouldn't be desired either.
- The filename is somewhat redundant. "tw" prefixes are not necessary for most code in Twisted. :)
- The example uses the global reactor in
HelloWorld
instead of making it a parameter. - The
delete_event
callback method doesn't follow the Twisted naming convention. - It would probably be nice to update the index to explain that the pb gtk example is ... more complicated?
I hesitate to observe one final thing, because I suspect that it might derail this ticket entirely. Nevertheless it seems I should. Few real, complicated Gtk2 applications are written in the style where the GUI is constructed from the ground up using Gtk2 API calls directly. Instead, glade is used to construct the widgets and only as much of the Gtk2 API as is needed to define behavior for those widgets is actually used. This is how twisted/manhole/ is written, for example (albeit for Gtk1). To someone with a lot of Gtk experience, it probably doesn't matter what style our example uses, because they know how to do it right and can translate from one to the other. However, for anyone with less experience, this example will perhaps set them on the wrong course, or will at least leave them confused about how to use Twisted and a glade-based Gtk2 programming style together.
If you (anyone) feel up to translating the example to use glade, that would be really great. Otherwise, just address the rest of the points and file a ticket for the glade improvement.
twisted gtk2 "hello world" type example