Opened 5 years ago

Last modified 5 years ago

#5422 enhancement new 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


The 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) (1.1 KB) - added by frontendloader 5 years ago.
twisted gtk2 "hello world" type example

Download all attachments as: .zip

Change History (10)

comment:1 Changed 5 years ago by DefaultCC Plugin

Cc: oubiwann added

Changed 5 years ago by frontendloader

Attachment: added

twisted gtk2 "hello world" type example

comment:2 Changed 5 years ago by Thijs Triemstra

Component: websitecore
Keywords: review added

Thanks. Putting it up for review as described on ReviewProcess#Authors:Howtogetyourchangereviewed.

comment:3 Changed 5 years ago by jesstess

Cc: jesstess added
Owner: set to jesstess

comment:4 Changed 5 years ago by jesstess

Author: jesstess
Branch: branches/pygtk-example-5422

(In [33331]) Branching to 'pygtk-example-5422'

comment:5 Changed 5 years ago by jesstess

(In [33332]) Add by frontendloader.

refs #5422

comment:6 Changed 5 years ago by jesstess

(In [33334]) Show that you can use the reactor/Twisted beyond starting and stopping.

refs #5422

comment:7 Changed 5 years ago by jesstess

Author: jesstessfrontendloader
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 and looking at, 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 5 years ago by jesstess

Keywords: review added
Owner: frontendloader deleted

I've made enough changes that someone else should review this.

comment:9 Changed 5 years ago by Jean-Paul Calderone

Author: frontendloaderfrontendloader, jesstess
Keywords: review removed
Owner: set to jesstess

Thanks frontendloader, jesstess.

The new example seems to work. I observe several things about its behavior:

  1. It displays a Gtk window with a "hello world" button in it.
  2. It counts down from 10 and exits when it reaches 0.
  3. Clicking the button prints a message and exits immediately.
  4. 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:

  1. There's no explanation of what one should expect it to do.
    1. 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.
    2. 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.
  2. 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.
  3. The filename is somewhat redundant. "tw" prefixes are not necessary for most code in Twisted. :)
  4. The example uses the global reactor in HelloWorld instead of making it a parameter.
  5. The delete_event callback method doesn't follow the Twisted naming convention.
  6. 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.

Note: See TracTickets for help on using tickets.