daisy
daisy

Reputation: 23499

Juxtapose a GtkMenuBar with other widgets?

Is it possible to place a GtkMenuBar with other widgets together , instead of showing at the top of that window ?

Or i could use buttons , but when you hover your mouse over those buttons , the menu on the buttons won't just behave like a menu , which is , when you are close to one menu item , the menu pops down directly , without click , and other menu hide automatically. Can i make buttons like that ? Or other widgets that could have: label , image , and pop down menu item is cool.

Any ideas is appreciated.

Upvotes: 0

Views: 119

Answers (1)

Louis
Louis

Reputation: 2890

Maybe the "enter-notify-event" and "leave-notify-event", connected to buttons, may help you do the thing, with for example, a popup menu show and hide respectively.


EDIT

I finally forgot those "enter" and "leave" events whose behaviour was a little complex, and just used the "motion-notify-event"...

Now I hope it is what you want !

#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk

class MenuExample:
    def __init__(self):
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_size_request(200, 100)
        self.window.set_title("GTK Menu Test")
        self.window.connect("delete_event", lambda w,e: gtk.main_quit())

        # A vbox to put a button in:
        vbox = gtk.VBox(False, 0)
        self.window.add(vbox)
        vbox.show()
        self.popped = False

        # Create a button to simulate a menu
        button = gtk.Button("press me")
        vbox.pack_start(button, False, False, 2)
        self.window.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.window.connect("motion-notify-event", self.wakeup)
        self.window.show_all()
        self.bmenu = gtk.Button("A single entry menu")
        self.bmenu.connect("clicked", self. menuitem_response, "Click on the magic menu !")
        vbox.pack_start(self.bmenu, False, False, 2)

    def wakeup(self, widget, event):
        #print "Event number %d woke me up" % event.type
        (x, y) = self.window.get_pointer() 
        if y < 30:
            if self.popped == False:
                self.popped = True
                self.bmenu.show()
        elif y > 60:
            if self.popped == True:
                self.popped = False
                self.bmenu.hide()

    # Print a string when a menu item is selected
    def menuitem_response(self, widget, string):
        print "%s" % string

def main():
    gtk.main()
    return 0

if __name__ == "__main__":
    MenuExample()
    main()

Upvotes: 1

Related Questions