def test_priority(self): s = GLib.Idle() self.assertEqual(s.priority, GLib.PRIORITY_DEFAULT_IDLE) s.priority = GLib.PRIORITY_HIGH self.assertEqual(s.priority, GLib.PRIORITY_HIGH) s = GLib.Idle(GLib.PRIORITY_LOW) self.assertEqual(s.priority, GLib.PRIORITY_LOW) s = GLib.Timeout(1, GLib.PRIORITY_LOW) self.assertEqual(s.priority, GLib.PRIORITY_LOW) s = GLib.Source() self.assertEqual(s.priority, GLib.PRIORITY_DEFAULT)
def _idle_add(self, callback, args, context=None, frame=None) -> 'GLibSourceHandle': source = GLib.Idle() return self._schedule_callback(source, callback, args, context, frame)
def call_later(self, delay, callback, *args): return GLibHandle( loop=self, source=GLib.Timeout(delay*1000) if delay > 0 else GLib.Idle(), repeat=False, callback=callback, args=args)
def source(self, func): timeout = self.timeout if timeout > 0: s = GLib.Timeout(timeout) else: s = GLib.Idle() s.set_callback(func) s.priority = self.priority return s
def call_later(self, delay, callback, *args): self._check_not_coroutine(callback, 'call_later') return GLibHandle( loop=self, source=GLib.Timeout(delay * 1000) if delay > 0 else GLib.Idle(), repeat=False, callback=callback, args=args)
def call_soon(self, callback, *args): self._check_not_coroutine(callback, 'call_soon') source = GLib.Idle() source.set_priority(GLib.PRIORITY_DEFAULT) return GLibHandle(loop=self, source=source, repeat=False, callback=callback, args=args)
def _invoke(self, delay, callback, args): event = GLib.Timeout(delay * 1000) if delay > 0 else GLib.Idle() self.pending_events.add(event) def fire(context): self.pending_events.remove(event) event.destroy() callback(*args) event.set_callback(fire, None) event.attach(self._context)
def test_get_current_time(self): # Note, deprecated API s = GLib.Idle() with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') time = s.get_current_time() self.assertTrue(issubclass(w[0].category, PyGIDeprecationWarning)) self.assertTrue(isinstance(time, float)) # plausibility check, and check magnitude of result self.assertGreater(time, 1300000000.0) self.assertLess(time, 2000000000.0)
def call_soon(self, callback, *args): source = GLib.Idle() # XXX: we set the source's priority to high for the following scenario: # # - loop.sock_connect() begins asynchronous connection # - this adds a write callback to detect when the connection has # completed # - this write callback sets the result of a future # - future.Future schedules callbacks with call_later. # - the callback for this future removes the write callback # - GLib.Idle() has a much lower priority than that of the GSource for # the writer, so it never gets scheduled. source.set_priority(GLib.PRIORITY_HIGH) return GLibHandle( loop=self, source=source, repeat=False, callback=callback, args=args)
def test_out_of_scope_before_dispatch(self): # https://bugzilla.gnome.org/show_bug.cgi?id=504337 GLib.Timeout(20) GLib.Idle()
def test_recurse_property(self): s = GLib.Idle() self.assertTrue(s.can_recurse in [False, True]) s.can_recurse = False self.assertFalse(s.can_recurse)
def test_source_attach_implicit_context(self): context = GLib.MainContext.default() source = GLib.Idle() source_id = source.attach() self.assertEqual(context, source.get_context()) self.assertTrue(GLib.Source.remove(source_id))
def test504337(self): GLib.Timeout(20) GLib.Idle()
def idle_add(context: GLib.MainContext, callback) -> GLib.Source: source = GLib.Idle() source.set_callback(lambda data: callback()) source.attach(context) return source