[pygtk] gtk.glade missing a get_custom_handler function

Yaakov Nemoy loupgaroublond at gmail.com
Mon Jun 19 14:16:43 WST 2006


Thanks alot Tim,

I ended up doing something similar, but not as elegant.  My module
just keeps track of the previous handler as a global variable, based
on the suggestion of a friend.  I'm gonna take a look to see what I
can do with this though.

Yaakov

On 6/19/06, Tim Evans <t.evans at aranz.com> wrote:
> Yaakov Nemoy wrote:
> > Hello list,
> >
> > I have a number of objects each with their own GladeXML data member.
> > They generate each other recursively, so it's possible that when
> > libglade is not done processing one GladeXML object, it already has to
> > start processing another one.  Each object has their own set of
> > callbacks, and a custom handler that knows where to find them.  Each
> > set of callbacks is instance specific, and really needs to be set per
> > GladeXML object, per instance.
> >
> > Problem is, as best I can figure out, the gtk.glade.set_custom_handler
> > is global, and since there is no gtk.glade.get_custom_handler, there
> > is no way I can change it per object, and then set it back.  Are there
> > any workarounds to this?  Should this be a bug report?
> >
> > Yaakov
>
> You could work around this problem by wrapping
> gtk.glade.set_custom_handler in some code like this (untested):
>
>    class _CustomHandlerStack(object):
>        def __init__(self):
>            self._stack = []
>            gtk.glade.set_custom_handler(self._handler)
>
>        def _handler(self, *args):
>            try:
>                func = self._stack[-1]
>            except IndexError:
>                raise RuntimeError("no custom handler function")
>            return self._stack[-1](*args)
>
>        def push(self, func):
>            self._stack.append(func)
>
>        def pop(self):
>            try:
>                del self._stack[-1]
>            except IndexError:
>                raise RuntimeError("custom handler stack underflow")
>
>    custom_handler = _CustomHandlerStack()
>
> And use it later like this:
>
>    custom_handler.push(my_hander_func)
>    x = gtk.glade.XML(...)
>    custom_handler.pop()
>
> --
> Tim Evans
> Applied Research Associates NZ
> http://www.aranz.co.nz/
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>


More information about the pygtk mailing list