Skip to content Skip to sidebar Skip to footer

Right-click On A Pygtk Hbox In An Expander

I've got a gtk.Expander object, containing in its label a gtk.HBox, which packed a gtk.Image and a gtk.Label. I want to launch a Webbrowser when the HBox is right-clicked. Here is

Solution 1:

Small change in your code.

Add "button-press-event" on Expander widget instead of Label widget

import pygtk
pygtk.require('2.0')
import gtk

classMainWindow(gtk.Window):
   def__init__(self):
     gtk.Window.__init__(self)
     self.set_default_size(300, 300)
     self.addServer()

   deflaunchBrowser(self, widget, event, host, *args):
      if event.type == gtk.gdk.BUTTON_PRESS:
        if event.button == 3:
            print"click"# Normal behaviour of Expander on single click
      expand = widget.get_expanded()
      ifnot expand: widget.set_expanded(True)
      else: widget.set_expanded(False)

  defaddServer(self):
    main_expand = gtk.Expander()
    main_led = gtk.Image()
    main_led.set_from_stock(gtk.STOCK_STOP, gtk.ICON_SIZE_BUTTON)

    main_srvname = gtk.Label("srvname")
    main_expand.add_events(gtk.gdk.BUTTON_PRESS_MASK)
    main_expand.connect('button-press-event', self.launchBrowser, 'host')

    expand_title = gtk.HBox(False, 2)
    expand_title.pack_start(main_led, False, True, 0)
    expand_title.pack_start(main_srvname, True, True, 0)
    main_expand.set_property("label-widget", expand_title)

    self.add(main_expand)
    self.show_all()

defmain():
 MainWindow()
 gtk.main()

if __name__ == '__main__':
 main()

Post a Comment for "Right-click On A Pygtk Hbox In An Expander"