Re: Using Gtk.Builder to create a menubar.
Yes, actions get a prefix depending on where you put them. Every "action container" has a prefix. In your case you add_action() to GtkApplicationWindow and its prefix is "win" I used your code to create an answer to my StackOverflow question > https://stackoverflow.com/a/50051155/4865723 > great! Luca 2018-04-27 12:24 GMT+02:00 Marius Gedminas : > On Thu, Apr 26, 2018 at 09:46:57PM +0200, c.bu...@posteo.jp wrote: > > Thank you very much. Your example works for me but I don't understand > > why. ;) > > > > > win.bar > > > > > action_bar = Gio.SimpleAction.new('bar', None) > > > > The name of the action in the XML and the code is different. Why? What > > is the system behind it? > > "bar" is the name of the action. "win" describes the action's scope. > > Check out the "Action scopes" section in https://developer.gnome.org/ > GAction/ > and a brief discussion on "quit" vs "app.quit" in the GActionMap > section. > > Marius Gedminas > -- > My own take on it as a writer is that I am passing my story across to Ms. > Average Reader, who works all day (or night) as a nurse in a children's > cancer > hospice. She doesn't need some writer lecturing her about the human > condition. > She needs someone to hand her a drink. > -- Lois McMaster Bujold's take on grimdark fiction > > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
On Thu, Apr 26, 2018 at 09:46:57PM +0200, c.bu...@posteo.jp wrote: > Thank you very much. Your example works for me but I don't understand > why. ;) > > > win.bar > > > action_bar = Gio.SimpleAction.new('bar', None) > > The name of the action in the XML and the code is different. Why? What > is the system behind it? "bar" is the name of the action. "win" describes the action's scope. Check out the "Action scopes" section in https://developer.gnome.org/GAction/ and a brief discussion on "quit" vs "app.quit" in the GActionMap section. Marius Gedminas -- My own take on it as a writer is that I am passing my story across to Ms. Average Reader, who works all day (or night) as a nurse in a children's cancer hospice. She doesn't need some writer lecturing her about the human condition. She needs someone to hand her a drink. -- Lois McMaster Bujold's take on grimdark fiction ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
On 2018-04-26 18:10 Luca Bacci wrote: > Hi, I did test it out, here's a working version: I used your code to create an answer to my StackOverflow question https://stackoverflow.com/a/50051155/4865723 ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
Thank you very much. Your example works for me but I don't understand why. ;) > win.bar > action_bar = Gio.SimpleAction.new('bar', None) The name of the action in the XML and the code is different. Why? What is the system behind it? ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
"1. It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would prefere this way instead of an XML string. It should be possible in Python, too? Gtk.Menu or Gio.Menu?" My understanding of this is that the GMenu is used with the GtkApplication and a GtkMenu is used with the "regular" GTK setup. You can use either one in code depending on what your program needs and how your program is structured. Eric ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
Hi, I did test it out, here's a working version: import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gio class Window(Gtk.ApplicationWindow): def __init__(self): Gtk.Window.__init__(self) self.set_default_size(200, 100) # self.interface_info = """ Foo Bar win.bar """ builder = Gtk.Builder.new_from_string(self.interface_info, -1) action_bar = Gio.SimpleAction.new('bar', None) action_bar.connect('activate', self.on_menu) self.add_action(action_bar) menumodel = builder.get_object('TheMenuModel') menubar = Gtk.MenuBar.new_from_model(menumodel) # layout self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.layout.pack_start(menubar, False, False, 0) self.add(self.layout) self.connect('destroy', Gtk.main_quit) self.show_all() def on_menu(self, action, value): print('on_menu') if __name__ == '__main__': win = Window() Gtk.main() 2018-04-26 11:01 GMT+02:00 Luca Bacci : > it should be like that (I can't test it right now, try yourself) > > #!/usr/bin/env python3 > import gi > gi.require_version('Gtk', '3.0') > from gi.repository import Gtk > from gi.repository import Gio > > class Window(Gtk.ApplicationWindow): > def __init__(self): > Gtk.Window.__init__(self) > self.set_default_size(200, 100) > > # > self.interface_info = """ > > > > Foo > > Bar > win.bar > > > > > """ > > builder = Gtk.Builder.new_from_string(self.interface_info, -1) > > action_bar = Gio.SimpleAction.new('bar', None) > action_bar.connect('activate', self.on_menu) > self.add_action(action_bar) > > menumodel = builder.get_object('TheMenuModel') > menubar = Gtk.MenuBar.new_from_model(menumodel) > > # layout > self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) > self.layout.pack_start(menubar, True, True, 0) > self.add(self.layout) > > self.connect('destroy', Gtk.main_quit) > self.show_all() > > def on_menu(self, action, value): > print('on_menu') > > if __name__ == '__main__': > win = Window() > Gtk.main() > > > 2018-04-26 10:44 GMT+02:00 Luca Bacci : > >> see here: >> >> https://wiki.gnome.org/HowDoI/GMenu >> https://wiki.gnome.org/HowDoI/GAction >> >> self.interface_info = """ >>> >>> >>> >>> Foo >>> >>> Bar >>> >>> >>> >>> >>> """ >> >> >> for every you want to set at least two attributes: "name" and >> "action". it should be >> >> self.interface_info = """ >> >> >> >> Foo >> >> Bar >> win.bar >> >> >> >> >> """ >> >> you get the GMenuModel from the builder >> menumodel = builder.get_object('TheMenuModel') >> and you create a menubar widget from the menumodel: >> >> menubar = Gtk.MenuBar.new_from_model(menumodel) >> >> >> 2018-04-26 7:10 GMT+02:00 : >> >>> Dear Eric, >>> >>> thank you for your quick reply. >>> >>> > There is a basic setup for the Gtk Application in Python here >>> > https://developer.gnome.org/gnome-devel-demos/stable/hello-w >>> orld.py.html.en >>> >>> Nice to know. Very helpful. >>> >>> > For C you can check >>> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/mast >>> er/Misc/Csamples/gtk_app1.c >>> > which has a menu but doesn't use builder with an application. Maybe >>> > partial help. >>> >>> This code doesn't help me with my problem but brings up two questions. >>> >>> 1. >>> It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would >>> prefere this way instead of an XML string. It should be possible >>> in Python, too? Gtk.Menu or Gio.Menu? >>> >>> 2. >>> It uses " gtk_application_set_menubar()" which I don't want to use. >>> Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar >>> and the toolbar as a widget to add them myself to the main window. >>> Or a " gtk_application_set_toolbar()" - don't understand why there >>> isn't one. >>> >>> It couldn't be so hard to create a menubar and a toolbar with >>> PyGObject?! Am I the first one who tries this? ;) >>> ___ >>> gtk-app-devel-list mailing list >>> gtk-app-devel-list@gnome.org >>> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list >>> >> >> > ___ gtk-app-devel-list mailing list gtk-app-devel-li
Re: Using Gtk.Builder to create a menubar.
it should be like that (I can't test it right now, try yourself) #!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gio class Window(Gtk.ApplicationWindow): def __init__(self): Gtk.Window.__init__(self) self.set_default_size(200, 100) # self.interface_info = """ Foo Bar win.bar """ builder = Gtk.Builder.new_from_string(self.interface_info, -1) action_bar = Gio.SimpleAction.new('bar', None) action_bar.connect('activate', self.on_menu) self.add_action(action_bar) menumodel = builder.get_object('TheMenuModel') menubar = Gtk.MenuBar.new_from_model(menumodel) # layout self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.layout.pack_start(menubar, True, True, 0) self.add(self.layout) self.connect('destroy', Gtk.main_quit) self.show_all() def on_menu(self, action, value): print('on_menu') if __name__ == '__main__': win = Window() Gtk.main() 2018-04-26 10:44 GMT+02:00 Luca Bacci : > see here: > > https://wiki.gnome.org/HowDoI/GMenu > https://wiki.gnome.org/HowDoI/GAction > > self.interface_info = """ >> >> >> >> Foo >> >> Bar >> >> >> >> >> """ > > > for every you want to set at least two attributes: "name" and > "action". it should be > > self.interface_info = """ > > > > Foo > > Bar > win.bar > > > > > """ > > you get the GMenuModel from the builder > menumodel = builder.get_object('TheMenuModel') > and you create a menubar widget from the menumodel: > > menubar = Gtk.MenuBar.new_from_model(menumodel) > > > 2018-04-26 7:10 GMT+02:00 : > >> Dear Eric, >> >> thank you for your quick reply. >> >> > There is a basic setup for the Gtk Application in Python here >> > https://developer.gnome.org/gnome-devel-demos/stable/hello-w >> orld.py.html.en >> >> Nice to know. Very helpful. >> >> > For C you can check >> > https://github.com/cecashon/OrderedSetVelociRaptor/blob/mast >> er/Misc/Csamples/gtk_app1.c >> > which has a menu but doesn't use builder with an application. Maybe >> > partial help. >> >> This code doesn't help me with my problem but brings up two questions. >> >> 1. >> It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would >> prefere this way instead of an XML string. It should be possible >> in Python, too? Gtk.Menu or Gio.Menu? >> >> 2. >> It uses " gtk_application_set_menubar()" which I don't want to use. >> Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar >> and the toolbar as a widget to add them myself to the main window. >> Or a " gtk_application_set_toolbar()" - don't understand why there >> isn't one. >> >> It couldn't be so hard to create a menubar and a toolbar with >> PyGObject?! Am I the first one who tries this? ;) >> ___ >> gtk-app-devel-list mailing list >> gtk-app-devel-list@gnome.org >> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list >> > > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
see here: https://wiki.gnome.org/HowDoI/GMenu https://wiki.gnome.org/HowDoI/GAction self.interface_info = """ > > > > Foo > > Bar > > > > > """ for every you want to set at least two attributes: "name" and "action". it should be self.interface_info = """ Foo Bar win.bar """ you get the GMenuModel from the builder menumodel = builder.get_object('TheMenuModel') and you create a menubar widget from the menumodel: menubar = Gtk.MenuBar.new_from_model(menumodel) 2018-04-26 7:10 GMT+02:00 : > Dear Eric, > > thank you for your quick reply. > > > There is a basic setup for the Gtk Application in Python here > > https://developer.gnome.org/gnome-devel-demos/stable/ > hello-world.py.html.en > > Nice to know. Very helpful. > > > For C you can check > > https://github.com/cecashon/OrderedSetVelociRaptor/blob/ > master/Misc/Csamples/gtk_app1.c > > which has a menu but doesn't use builder with an application. Maybe > > partial help. > > This code doesn't help me with my problem but brings up two questions. > > 1. > It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would > prefere this way instead of an XML string. It should be possible > in Python, too? Gtk.Menu or Gio.Menu? > > 2. > It uses " gtk_application_set_menubar()" which I don't want to use. > Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar > and the toolbar as a widget to add them myself to the main window. > Or a " gtk_application_set_toolbar()" - don't understand why there > isn't one. > > It couldn't be so hard to create a menubar and a toolbar with > PyGObject?! Am I the first one who tries this? ;) > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list > ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
Dear Eric, thank you for your quick reply. > There is a basic setup for the Gtk Application in Python here > https://developer.gnome.org/gnome-devel-demos/stable/hello-world.py.html.en Nice to know. Very helpful. > For C you can check > https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/gtk_app1.c > which has a menu but doesn't use builder with an application. Maybe > partial help. This code doesn't help me with my problem but brings up two questions. 1. It uses "QMenu" (from Gtk or Gio?) to build a menu structure. I would prefere this way instead of an XML string. It should be possible in Python, too? Gtk.Menu or Gio.Menu? 2. It uses " gtk_application_set_menubar()" which I don't want to use. Because there is no "gtk_application_set_TOOLBAR()"! I need the menubar and the toolbar as a widget to add them myself to the main window. Or a " gtk_application_set_toolbar()" - don't understand why there isn't one. It couldn't be so hard to create a menubar and a toolbar with PyGObject?! Am I the first one who tries this? ;) ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Using Gtk.Builder to create a menubar.
There is a basic setup for the Gtk Application in Python here https://developer.gnome.org/gnome-devel-demos/stable/hello-world.py.html.en For C you can check https://github.com/cecashon/OrderedSetVelociRaptor/blob/master/Misc/Csamples/gtk_app1.c which has a menu but doesn't use builder with an application. Maybe partial help. Eric ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Using Gtk.Builder to create a menubar.
X-Post: I was redirected from https://mail.gnome.org/archives/python-hackers-list/2018-April/msg4.html to here. I try to use Gtk.Builder to create a menubar. It is not working because the documentation is not clear for me. There is no exmple for a IMO usual thing like a menubar. To improve documentation and the help other new users I created a question with example code on StackOverflow. https://stackoverflow.com/q/49964906/4865723 Currently I can put the XML-string and the Gio.Action together. Not sure if this is the correct way!? But the next step is the main problem. I don't know how to create a menubar widget out of it. btw: I don't want to use Gtk.Application.set_menubar(). Because there is no Gtk.Application.set_toolbar() and currently I see no advantage on having a Gtk-based application object. This is the code #!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk from gi.repository import Gio class Window(Gtk.ApplicationWindow): def __init__(self): Gtk.Window.__init__(self) self.set_default_size(200, 100) # self.interface_info = """ Foo Bar """ builder = Gtk.Builder.new_from_string(self.interface_info, -1) action_bar = Gio.SimpleAction.new('bar', None) action_bar.connect('activate', self.on_menu) self.add_action(action_bar) menubar = builder.get_object('TheMenu') # layout self.layout = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.layout.pack_start(menubar, True, True, 0) self.add(self.layout) self.connect('destroy', Gtk.main_quit) self.show_all() def on_menu(self, widget): print(widget) if __name__ == '__main__': win = Window() Gtk.main() ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list