View Single Post
Posts: 105 | Thanked: 48 times | Joined on Aug 2008
#6
this is from panucci, a media player that uses the directional for playback control.

Code:
            # Disable focus for all widgets, so we can use the cursor
            # keys + enter to directly control our media player, which
            # is handled by "key-press-event"
            for w in (
                    self.rrewind_button, self.rewind_button,
                    self.play_pause_button, self.forward_button,
                    self.fforward_button, self.progress, 
                    self.bookmarks_button, self.volume_button, ):
                w.unset_flags(gtk.CAN_FOCUS)
The code block is in GTK_Main.make_main_window() inside file panucci.py

Each "w" is a gtk.Button() object.

There's probably a more extensible way of doing this - like looping through each property of self, testing to see if it is focusable, and then unsetting the CAN_FOCUS flag. That way, you don't have to worry about keeping the list of controls in sync with the actual controls on the window. You just have to remember to make every focusable control a member of self.
 

The Following 3 Users Say Thank You to MattZTexasu For This Useful Post: