python - How do I add a menu to a toolbar? gtk3 -


ok figured out way. if have way can still give answer. may have easier way. i'll trying format reply answer in meantime. method discovered little messy have take time. leave answer unaccepted see if else has better way.

i'm using python gtk3.

for gtk3 there menutoolbutton, description of it's usage in documentation not clear enough me.

besides plain button without drop arrow toolbutton used this.

if there way gtk uimanager prefer that.

here's answer.

it's kinda taking long way around works.

one of main problems thought use recent button in grid, gtk seems have recent action toolbars , menus. complicated if want toolbar button popup because toolbar buttons not customizable not have drop arrow.

long story short. took long way around regular popup button , made grid contain , toolbar.

#the popup see here used menu button toolbar_ui = """ <ui>     <toolbar name="toolbar">         <toolitem action="fileopen" />         <toolitem action="filesave"  />         <toolitem action="filesaveas" />         <toolitem action="undo" />         <toolitem action="redo" />     </toolbar>     <popup name="menu">         <menuitem action="bla" />     </popup> </ui> """ class groupview(gtk.grid):      def __init__(self):         gtk.grid.__init__(self, orientation=gtk.orientation.horizontal)         #the toolbar grid placed in grid         #placed in gtk.window         group_toolbar = toolbar()         self.add(group_toolbar)   class toolbar(gtk.grid):     def __init__(self):         gtk.grid.__init__(self, orientation=gtk.orientation.horizontal)         toolbar = tools()         #toolbar grid actual toolbar         #and menu button in grid         self.add(toolbar.display())         self.add(toolbar.extra_menu)  class tools(gtk.uimanager):     text_view = none     def __init__(self):         gtk.uimanager.__init__(self)         self.add_ui_from_string(toolbar_ui)         action_group = gtk.actiongroup("actions")         self.add_toolbar_actions(action_group)      def set_text_view(self, textview):         self.textview = textview      def add_toolbar_actions(self, action_group):         self.insert_action_group(action_group)         #         #..normal toolbar construction here         #          #its menu button menu actions         #need taken care of         action_bla = gtk.action("bla", 'bla', none, none)         action_bla.connect("activate", self.action_bla_clicked)         action_group.add_action(action_bla)         #..the menu button created here         self.extra_menu = extramenu()         self.extra_menu.set_popup(self.get_widget("/menu"))          #start action callbacks         #...placeholder callbacks         #end action callbacks     #get ready export toolbar     def display(self):         toolbar = self.get_widget("/toolbar")         toolbar.set_hexpand(true)         return toolbar  class extramenu(gtk.menubutton):     def __init__(self):         gtk.menubutton.__init__(self)         arrow = self.get_children()[0]         #the arrow destroyed , custom image placed in button         arrow.destroy()         self.add(gtk.image.new_from_stock(gtk.stock_execute, gtk.iconsize.button)) 

if try above code don't forget add window, , action callbacks. if can't tell subclassing gtk lot. :)


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -