Commits

Denis Bilenko committed ee15df0

some fixes

  • Participants
  • Parent commits ceb4493

Comments (0)

Files changed (1)

+import sys
 import glib, gtk
 
 class GtkLoop(object):
     def __init__(self, flags=None, default=True):
         assert default
 
-    def io(self, fd, events):
+    def handle_error(self, context, type, value, tb):
+        error_handler = self.error_handler
+        if error_handler is not None:
+            # we do want to do getattr every time so that setting Hub.handle_error property just works
+            handle_error = getattr(error_handler, 'handle_error', error_handler)
+            handle_error(context, type, value, tb)
+        else:
+            self._default_handle_error(context, type, value, tb)
+
+    def _default_handle_error(self, context, type, value, tb):
+        import traceback
+        traceback.print_exception(type, value, tb)
+        raise AssertionError
+
+    def io(self, fd, events, ref=None):
         return io(self, fd, events)
 
-    def timer(self, after, repeat=0):
+    def timer(self, after, repeat=0, ref=None):
         return timer(self, after, repeat)
 
-    def callback(self):
+    def callback(self, ref=None):
         return callback(self)
 
-    def fork(self, ref=True):
-        return fork(self)
+    def fork(self, ref=None):
+        return noop(self)
 
-    def handle_error(self, *exc_info):
-        pass #XXX:
+    def async(self, ref=None):
+        return async(self)
 
     def run(self):
         gtk.main()
 
 
-
-class watcher(object):
-    @property
-    def active(self):
-        return self.callback is not None
-
-
-class io(watcher):
+class io(object):
     def __init__(self, loop, fd, events):
         self.loop = loop
         self.fd = fd
             glib.source_remove(self.source_id)
             self.source_id = None
 
-class timer(watcher):
+
+class timer(object):
     def __init__(self, loop, after, repeat=0):
         self.loop = loop
         self.after = after
         self.source_id = None
         self.callback = None
         self.args = None
-        self.pending = False
 
-    
+    @property
+    def pending(self):
+        return False  # XXX TODO
+
+    @property
+    def active(self):
+        # proper implementation should ask gtkloop is this timer is active
+        return self.callback is not None
+
     def first_callback(self):
         print 'sleep callback'
         try:
     def start(self, callback, *args):
         self.callback = callback
         self.args = args
-        self.pending = True #XXX
 
         self.source_id = glib.timeout_add(
             self.after*1000,
     def stop(self):
         self.callback = None
         self.args = None
-        self.pending = False
         #XXX: check this never raises
-        print type(self.source_id), self.source_id
         if self.source_id is not None:
             glib.source_remove(self.source_id)
             self.source_id = None
 
-class callback(watcher):
+
+class callback(object):
     def __init__(self, loop):
         self.callback = None
         self.args = None
     def stop(self):
         pass
 
-class fork(watcher):
-    #XXX: noop
+    @property
+    def active(self):
+        return self.callback is not None
+
+
+class noop(object):
+
     def __init__(self, loop):
         pass
-    def start(self, callback):
+
+    def start(self, *args):
         pass
+
+    def stop(self, *args):
+        pass
+
+    @property
+    def active(self):
+        return False
+
+
+class async(object):
+
+    def __init__(self, loop):
+        pass
+
+    def start(self, *args):
+        raise NotImplementedError
+
+    def stop(self, *args):
+        pass
+
+    @property
+    def active(self):
+        return False