Пример #1
0
    def add_timer(self, interval, callback, threshold=0):
        """ Add timer.

        @note: should return an ID assigned to the timer, so that it can be
               removed by rem_timer().
        """
        return ecore.Timer(interval, callback)
Пример #2
0
    def __init__(self):
        # Sets initial parameters
        self.core = purple.Purple(__NAME__, __VERSION__, __WEBSITE__, \
                __DEV_WEBSITE__, debug_enabled=True, default_path='/tmp')
        ecore.Timer(0.01, self.core.iterate_main_loop)
        self.account = None
        self.buddies = {}
        self.conversations = {}
        self.protocol = purple.Protocol('prpl-jabber')
        self.window = MainWindow()

        # Adds libpurple core callbacks

        # Updates buddy list
        self.core.add_callback('blist', 'update', \
                self.__update_blist_cb)

        # Updates connection progress
        self.core.add_callback('connection', 'connect-progress', \
                self.__connection_progress_cb)

        # Activates when an account is connected
        self.core.add_callback('connection', 'connected', \
                self.__connected_cb)

        # Activates when an account is disconnected
        self.core.add_callback('connection', 'disconnected', \
                self.__disconected_cb)

        # Activates when a message is sent or received from conversation
        self.core.add_callback('conversation', 'write-im', \
                self.__write_im_cb)

        # Signal when account signed on
        self.core.signal_connect('signed-on', self.__signed_on_cb)

        # Signal when account signed off
        self.core.signal_connect('signed-off', self.__signed_off_cb)

        # Signal when buddy signed on
        self.core.signal_connect('buddy-signed-on', self.__buddy_signed_on_cb)

        # Signed when buddy signed off
        self.core.signal_connect('buddy-signed-off',
                                 self.__buddy_signed_off_cb)

        # Adds UI callbacks
        self.window.add_connection_button_cb(self.connect)
        self.window.add_send_button_cb(self.send_message)
        self.window.add_exit_cb(self.exit)

        # Initializes libpurple
        self.core.purple_init()

        # Initializes UI
        self.window.init_window()
Пример #3
0
def print_every_300ms():
    global counter2
    counter2 += 1
    print "every 300ms, run:", counter2
    return True  # keep running, stop_print_every_300ms will stop me


def stop_print_every_300ms(my_timer):
    print "stopping 'print_every_300ms' timer"
    my_timer.delete()


if __name__ == "__main__":
    # Use C-like API
    ecore.timer_add(0.5, print_every_500ms, "arg1", 1234, q=890, p=567)
    ecore.timer_add(0.6, print_every_600ms_twice)
    ecore.timer_add(0.7, print_once_after_700ms)

    # Use pythonic API, ecore.Timer() is a class
    ecore.Timer(1.0, print_every_1s, "arg1.1", 1234.1, p=567.1)

    # keep timer object so we can stop it from the other timer
    my_timer = ecore.timer_add(0.3, print_every_300ms)
    ecore.timer_add(1.5, stop_print_every_300ms, my_timer)

    # regular timer using C-like API, will trigger ecore.main_loop_quit()
    ecore.timer_add(3.0, quit_after_3s)

    # without a main loop, timers will not work
    ecore.main_loop_begin()
Пример #4
0
#!/usr/bin/env python

import ecore

def cb(n, t, a):
    print "cb:", n, t, a
    return True

t0 = ecore.timer_add(0.2, cb, 123, "teste", a=456)
t1 = ecore.timer_add(1, ecore.main_loop_quit)
t2 = ecore.Timer(0.5, cb, 789, "bla", a="something in a")
print "before: t0=", t0
print "before: t1=", t1
print "before: t2=", t2

ecore.main_loop_begin()
print "main loop stopped"

print "after:  t0=", t0
print "after:  t1=", t1
print "after:  t2=", t2

t0.delete()
del t0
del t1 # already deleted since returned false
t2.delete()
del t2

ecore.shutdown()