def test_is_destroyed_simple(self):
        s = GLib.Source()

        self.assertFalse(s.is_destroyed())
        s.destroy()
        self.assertTrue(s.is_destroyed())

        c = GLib.MainContext()
        s = GLib.Source()
        s.attach(c)
        self.assertFalse(s.is_destroyed())
        s.destroy()
        self.assertTrue(s.is_destroyed())
 def test_add_remove_poll(self):
     # FIXME: very shallow test, only verifies the API signature
     pollfd = GLib.PollFD(99, GLib.IOCondition.IN | GLib.IOCondition.HUP)
     self.assertEqual(pollfd.fd, 99)
     source = GLib.Source()
     source.add_poll(pollfd)
     source.remove_poll(pollfd)
Beispiel #3
0
    def select_setup_new(self):
        """
        The newer implementation using GLib.Source.add_unix_fd()
        
        .. TODO::
        
            Too cutting edge right now, unfortunately. Implementation
            is not complete.
        """
        #self.source.remove()
        if self.source is not None:
            self.source.destroy()
        self.source = source = GLib.Source()

        rlist, wlist, xlist = self.select_args()
        print('select_setup', rlist, wlist, xlist)
        fds = set(rlist + wlist + xlist)

        # should use GLib.Source.add_unix_fd, but thats too cutting edge right now
        assert len(fds) == 1
        fd = next(iter(fds))

        condition = GLib.IOCondition(0)
        if fd in rlist:
            condition |= GLib.IOCondition.IN
        if fd in wlist:
            condition |= GLib.IOCondition.OUT
        if fd in xlist:
            condition |= GLib.IOCondition.ERR
        if condition.real != 0:
            source.add_unix_fd(fd, condition)

        source.set_callback(self.glib_select_callback, fd)
    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)
Beispiel #5
0
    def __init__(self, ctx=None):
        super().__init__()
        if ctx is None:
            ctx = GLib.MainContext.default()
        self.ctx = ctx
        self.tags = {}

        self.source = GLib.Source()
        self.source.attach(self.ctx)
        self.source.prepare = lambda: (False, self.timeout)
        self.source.check = lambda: False
        self.source.dispatch = self.dispatch
        self.timeout = None
        self.ready_fds = None
 def f():
     c = GLib.MainContext()
     s = GLib.Source()
     s.attach(c)
     return s
Beispiel #7
0
 def cleanup(self, widget, event):
     #GLib.Source().remove(self.timeout)
     if self.idle:
         GLib.Source().remove(self.idle)
     Gtk.main_quit()