Пример #1
0
    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)
Пример #2
0
 def _idle_add(self,
               callback,
               args,
               context=None,
               frame=None) -> 'GLibSourceHandle':
     source = GLib.Idle()
     return self._schedule_callback(source, callback, args, context, frame)
Пример #3
0
 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)
Пример #4
0
 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
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
    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)
Пример #8
0
    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)
Пример #9
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)
Пример #10
0
 def test_out_of_scope_before_dispatch(self):
     # https://bugzilla.gnome.org/show_bug.cgi?id=504337
     GLib.Timeout(20)
     GLib.Idle()
Пример #11
0
 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)
Пример #12
0
 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))
Пример #13
0
 def test504337(self):
     GLib.Timeout(20)
     GLib.Idle()
Пример #14
0
def idle_add(context: GLib.MainContext, callback) -> GLib.Source:
    source = GLib.Idle()
    source.set_callback(lambda data: callback())
    source.attach(context)

    return source