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 = """
        <interface>
          <menu id='TheMenu'>
            <section>
              <attribute name='foo'>Foo</attribute>
              <item>
                <attribute name='bar'>Bar</attribute>
              </item>
            </section>
          </menu>
        </interface>
        """


for every <item> you want to set at least two attributes: "name" and
"action". it should be

self.interface_info = """
        <interface>
          <menu id='TheMenuModel'>
            <section>
              <attribute name='foo'>Foo</attribute>
              <item>
                <attribute name='bar'>Bar</attribute>
                <attribute name="action">win.bar</attribute>
              </item>
            </section>
          </menu>
        </interface>
"""

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 <c buhtz posteo jp>:

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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]