Beispiel #1
0
class _EngineWrap:
    """wrapper around Tk|Tix.Tk"""
    def __init(self, engine, styles, appicon, aperiod, title, onerror, *a, **kw):
        """aperiod - period of async. command executions"""
        engine.title(title)
        self.engine = engine
        try:
            if styles:
                self.engine.option_readfile(styles)
        except: pass
        try:
            if appicon:
                self.engine.iconbitmap(default=appicon)
        except: pass
        onerror = onerror or self.__report_callback_exception
        #self.engine.tk.createcommand("tkerror", self.tkerror)
        #self.engine.tk.createcommand("bgerror", self.tkerror)
        self.engine.report_callback_exception = onerror
        self.tkasync = TkAsync(self, aperiod)

    @staticmethod
    def wrap(engine_class, styles=None, appicon=None, aperiod=20, title="No title", onerror=None, *a, **kw):
        """create engine instance with (*a, **kw) then bind it with self;
        returns own instance"""
        engine = engine_class(*a, **kw)
        we = _EngineWrap()
        we.__init(engine, styles, appicon, aperiod, title, onerror, *a, **kw)
        return we

    def __getattr__(self, atr):
        return getattr(self.engine, atr)

    def destroy(self):
        self.tkasync.clear()
        self.engine.destroy()

    def __report_callback_exception(self, exc, val, tb):
        """Report about errors, must be set as self.engine.report_callback_exception"""
        try:
            type_ = exc.__name__
            text = u"%s: %s"%(type_, getattr(val, "message", None) or unicode(val) or "Unknown error")
            tkMessageBox.showerror("Error", text)
        except Exception, x:
            print "Error in error handler: %s"%str(x)
Beispiel #2
0
 def __init(self, engine, styles, appicon, aperiod, title, onerror, *a, **kw):
     """aperiod - period of async. command executions"""
     engine.title(title)
     self.engine = engine
     try:
         if styles:
             self.engine.option_readfile(styles)
     except: pass
     try:
         if appicon:
             self.engine.iconbitmap(default=appicon)
     except: pass
     onerror = onerror or self.__report_callback_exception
     #self.engine.tk.createcommand("tkerror", self.tkerror)
     #self.engine.tk.createcommand("bgerror", self.tkerror)
     self.engine.report_callback_exception = onerror
     self.tkasync = TkAsync(self, aperiod)