logo       

Re: using the same callback for a check menu and a toggle toolbutton: msg#00115

gnome.gtk+.python

Subject: Re: using the same callback for a check menu and a toggle toolbutton

Yes you can mix glade and UIManager, but not in the most intuitive way.

You can use glade to define everything but your toolbars and menus,
then when you load your interface, specify a base widget to load, by
default the XML object loads everything. You will then have to create
your own main window and add the widgets that are necessary to it.

So if you take the UIManager example which comes with the pygtk source:
http://cvs.gnome.org/viewcvs/gnome-python/pygtk/examples/gtk/uimanager.py?view=auto

Lets say we are going to have the ScrolledWindow and any other widget
elements that the ScrolledWindow contains in our glade file, insead
of:
sw = gtk.ScrolledWindow()
sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw)

we would have:
widget_tree = gtk.XML('myui.glade', 'scrolledwindow1')
sw = widget_tree.get_widget('scrolledwindow1')
vbox.pack_start(sw)


In order to be able to define scrolledwindow1 in our glade file, we
would just put it in a dummy window, which based on the call above is
not loaded. If you had multiple windows, or you also wanted to load
some dialog boxes from the same glade file, you would have to load
each of those individually as above. As a side note, you could also
use this technique to load scrolledwindow1 multiple times into
separate windows or notebook pages, or any other kind of container for
that matter. Each time you create a new XML object, libglade will
create a new bunch of widgets for you based on the glade file
specification.

If UIManager sounds like a lot of work compared to just using glade,
you could always create a wrapper object that keeps everything in
sync, which is what I did before I swiched to using UIManager.

One gotcha with using UIManager is that you will need to set up any
images you are using that are not stock icons as stock icons. There
was a breif discussion about that a couple of weeks ago in this list.

-Chris


On Mon, 20 Dec 2004 16:56:33 +0200, Ionutz Borcoman <borco@xxxxx> wrote:
> John Finlay wrote:
> > Ionutz Borcoman wrote:
> >
> >> Hi,
> >>
> >> I have a toggle button on my toolbar and a check menu in my menu. They
> >> do the same thing and must stay sincronized - when I check the menu,
> >> the toggle button get's activated, for example.
> >>
> >> Both widgets show the state of an internal flag (for example
> >> __zoomBestFit).
> >>
> >> What's the simplest way to handle this? What is the best way?
> >>
> > I recommend using PyGTK 2.4 which has Action, ActionGroup and UIManager
> > objects that can be used to create and manage menuitems and toolitems.
> > See the example in the examples/pygtk-demo/ui_manager.py program in the
> > PyGTK 2.4 source code.
> >
> > John
> >
> >
> Does this work with glade? My windows are designed with glade and then
> loaded with libglade.
>
> TIA,
>
> Ionutz
>
> _______________________________________________
> pygtk mailing list pygtk@xxxxxxxxxx
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>


--
Christopher Lambacher
lambacck@xxxxxxxxxxxx
_______________________________________________
pygtk mailing list pygtk@xxxxxxxxxx
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise