Strumenti Utente

Strumenti Sito


hackish_pygtk_things

Pointer catching

Button release

To catch mouse release, you must enable gtk.gdk.BUTTON_RELEASE_MASK but also gtk.gdk.BUTTON_PRESS_MASK !

So

mywidget.add_events(gtk.gdk.BUTTON_RELEASE_MASK)
mywidget.connect("button_release_event", self.smart_function)

won't do, while

mywidget.add_events(gtk.gdk.BUTTON_RELEASE_MASK | gtk.gdk.BUTTON_PRESS_MASK)
mywidget.connect("button_release_event", self.smart_function)

will.

Release outside widget

Notice that - this may seem hackish but is very smart - release events are targeted to the widget over which the button was pressed, not to the one over which it was released (the only case where you need to know that a button pressed on some other widget was released on yours is drag and drop, which has its own methods).

Motion hints

According to the laconic official documentation and on the tutorial, the goal of gtk.gdk.POINTER_MOTION_HINT_MASK is to send you a motion event and then not send another until you call mywidget.get_pointer(), so that events don't keep queuing waiting for you to handle them.

However, this is plainly false in pygtk 2.13.0, where instead:

  • if you only add gtk.gdk.POINTER_MOTION_HINT_MASK to your event mask, you handler for “motion_notify_event” is never called,
  • if you instead add gtk.gdk.POINTER_MOTION_HINT_MASK | gtk.gdk.POINTER_MOTION_MASK , your handler is called lots of times, even if you don't call get_pointer() (and though every event received has the “is_hint” argument set).

There are 3 possible explanations:

  1. pygtk looks if you are calling get_pointer into you handler, but if you don't and the handler ends execution, assumes that you are just ready for a new event (quite arbitrary and useless, since then pygtk could just
  2. documentation is wrong/outdated
  3. recent pygtk versions are buggy

I see 2 or 3 as more probable, because the widget provided in this article currently doesn't work (tested on Ubuntu Intrepid, Ubuntu Hardy, OpenSolaris 08-11).

Moreover, since C gtk+ documentation tells the same thing (with some more particulars), I definitely see 3 as most probable.

TreeViews and CellRenderers

The 'hadjustment' property of a gtk.TreeView is a gtk.Adjustment which shifts the whole treeview left. Can't find a reason for it.

The 'expander-size' style property just changes the height of rows: try for example

  gtk.rc_parse_string("""    style "expander-big" { 
      GtkTreeView::expander-size = 30 
  }

  class "GtkTreeView" style "expander-big"
""")
hackish_pygtk_things.txt · Ultima modifica: 2009/01/09 15:22 da pietro