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@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to