Example #1
0
 def setEventHandler(self, geo, evt, code):
     el = self.factory.get_element(geo)
     print "Setting event listener for", el.label
     if not code.strip():
         try:
             delattr(el, "on" + evt)
         except AttributeError:
             pass
         return
     code = pythonify(code)
     code = "\n".join("\t" + line for line in code.split("\n"))
     code = "def __handle_event__(self=__el__):\n%s" % code
     try:
         self.namespace['__el__'] = el
         handler_def = compile(code, "<%s %s>" % (evt, el.label), 'exec')
         exec handler_def in self.namespace
         setattr(el, "on" + evt, self.namespace['__handle_event__'])
         del self.namespace['__handle_event__']
     except SyntaxError:
         header = "Error while compiling '%s' action for '%s'" % (evt, geo)
         self.show_traceback(header)
         raise
     finally:
         del self.namespace['__el__']
Example #2
0
 def format_source(self, source):
     if isinstance(source, basestring):
         return pythonify(source)
     else:
         return source