Re: GtkApplicationWindow and its menubar

2014-05-21 Thread Pierre Wieser

 Test you stuff in python first, then move it to c/c++ if need be.  This
 allows for rapid testing of what you really need to do.  Whatever you
 are trying to do, it is possible, for complete menubar, menus, menuitems
 on any platform.  Windowing APIs for windows, linux, mac all can handle
 this.

Thanks for your help, David, but I was not searching how to build a menubar
in a Gtk application. I've already done this in Nautilus-Actions whose I am
the maintainer.

What I am searching for is an explanation on how to use the new Gtk3 API,
and how it can suit my needs, which are rather simple here: change all the
menubar depending of the context of the application..

So the question stays opened. I'd be very pleased if someone could explains
 the rationale with this API..

Regards
Pierre
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: GtkApplicationWindow and its menubar

2014-05-11 Thread David Marceau
Test you stuff in python first, then move it to c/c++ if need be.  This
allows for rapid testing of what you really need to do.  Whatever you
are trying to do, it is possible, for complete menubar, menus, menuitems
on any platform.  Windowing APIs for windows, linux, mac all can handle
this.

gtk3-demo has tool-palette sample.
The gtk api jargon has set/unset, remove, append, show.
http://www.pygtk.org/pygtk2tutorial/sec-Toolbar.html
http://www.pygtk.org/pygtk2tutorial/examples/toolbar.py

Don't forget to disconnect callbacks before unsetting toolbars, menus,
menu items. Rule of thumb: if you connect it, you have to disconnect it
if you change the gui dynamically.  Don't rely on
smart-pointers/garbage-collection to take care of these things.
http://zetcode.com/tutorials/gtktutorial/gtkevents/

This is a tweaked applicationmenu.py
#!/usr/bin/env python

import gtk

class ApplicationMenu:
def __init__(self):
window = gtk.Window()

menubar = gtk.MenuBar()

self.menu_file = gtk.Menu()
self.menu_edit = gtk.Menu()
self.menu_help = gtk.Menu()

item_open = gtk.MenuItem(Open)
item_save = gtk.MenuItem(Save)
item_quit = gtk.MenuItem(Quit)
self.menu_file.append(item_open)
self.menu_file.append(item_save)
self.menu_file.append(item_quit)

item_cut = gtk.MenuItem(Cut)
item_copy = gtk.MenuItem(Copy)
item_paste = gtk.MenuItem(Paste)
item_change_menus = gtk.MenuItem(Change Menus)
self.menu_edit.append(item_cut)
self.menu_edit.append(item_copy)
self.menu_edit.append(item_paste)
self.menu_edit.append(item_change_menus)

item_about = gtk.MenuItem(About)
self.menu_help.append(item_about)

item_file = gtk.MenuItem(File)
item_edit = gtk.MenuItem(Edit)
item_help = gtk.MenuItem(Help)

item_file.set_submenu(self.menu_file)
item_edit.set_submenu(self.menu_edit)
item_help.set_submenu(self.menu_help)

menubar.append(item_file)
menubar.append(item_edit)
menubar.append(item_help)

window.connect(destroy, lambda w: gtk.main_quit())
item_change_menus.connect(activate, self.menu_change_menus)

window.add(menubar)
window.show_all()


def menu_foo(self, widget):
print menu_foo clicked


def menu_change_menus(self, widget):
print menu_change_menus clicked
for widget in self.menu_edit.get_children():
self.menu_edit.remove(widget)
self.item_foo1 = gtk.MenuItem(foo1)
self.item_foo2 = gtk.MenuItem(foo2)
self.item_foo3 = gtk.MenuItem(foo3)
self.item_foo1.connect(activate, self.menu_foo)
self.item_foo2.connect(activate, self.menu_foo)
self.item_foo3.connect(activate, self.menu_foo)
self.menu_edit.append(self.item_foo1)
self.menu_edit.append(self.item_foo2)
self.menu_edit.append(self.item_foo3)
self.item_foo1.show()
self.item_foo2.show()
self.item_foo3.show()
self.menu_edit.show()


ApplicationMenu()
gtk.main()

On 05/11/2014 12:29 PM, Pierre Wieser wrote:
 Hi all,
 
 I am starting with a small app which will handle documents. 
 I want this app has two different menubars :
 - a first one when there is no document
 - another one when the document is opened.
 
 I have tried to use gtk_application_set_menubar with two
 different GMenuModel, but no luck: the GtkApplicationWindow
 menubar never changes.
 
 After having searched in the sources, I found that the GtkWidget 
 menubar is automatically rebuilt from a GMenu menubar_section.
 But the menubar_section itself is initially built in real_realize,
 thenonly rebuilt when some gtk-shell settings changes 
 (notify::gtk-shell-shows-menubar exactly, but this not relevant here).
 
 So it appears to me that it is just impossible to replace the menubar.
 Am I right ? Is it the expected behavior ?
 As a side effect, I do not understand the rationale behind
 gtk_application_set_menubar: why are we allowed to change the GMenuModel
 if the visible GtkWidget is not updated ?
 
 Thanks for some explanations..
 Regards
 Pierre
 
 ___
 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