2016-02-24 09:33:49 +01:00
|
|
|
from PySide import QtCore
|
2016-02-22 22:18:58 +01:00
|
|
|
# TODO: add all callbacks (replace test callbacks and use wrappers)
|
2016-02-22 16:55:04 +01:00
|
|
|
|
|
|
|
|
2016-02-24 09:33:49 +01:00
|
|
|
class InvokeEvent(QtCore.QEvent):
|
|
|
|
EVENT_TYPE = QtCore.QEvent.Type(QtCore.QEvent.registerEventType())
|
|
|
|
|
|
|
|
def __init__(self, fn, *args, **kwargs):
|
|
|
|
QtCore.QEvent.__init__(self, InvokeEvent.EVENT_TYPE)
|
|
|
|
self.fn = fn
|
|
|
|
self.args = args
|
|
|
|
self.kwargs = kwargs
|
|
|
|
|
|
|
|
|
|
|
|
class Invoker(QtCore.QObject):
|
|
|
|
|
|
|
|
def event(self, event):
|
|
|
|
event.fn(*event.args, **event.kwargs)
|
|
|
|
return True
|
|
|
|
|
|
|
|
_invoker = Invoker()
|
|
|
|
|
|
|
|
|
|
|
|
def invoke_in_main_thread(fn, *args, **kwargs):
|
|
|
|
QtCore.QCoreApplication.postEvent(_invoker, InvokeEvent(fn, *args, **kwargs))
|
|
|
|
|
|
|
|
|
|
|
|
def repaint_widget(widget):
|
|
|
|
return widget.repaint
|
|
|
|
|
|
|
|
|
2016-02-23 13:07:15 +01:00
|
|
|
def self_connection_status(st):
|
2016-02-24 09:33:49 +01:00
|
|
|
def wrapped(tox, connection, user_data):
|
|
|
|
print 'Connection status: ', str(connection)
|
|
|
|
st.status = connection
|
|
|
|
invoke_in_main_thread(repaint_widget(st))
|
2016-02-23 13:07:15 +01:00
|
|
|
return wrapped
|
2016-02-22 16:55:04 +01:00
|
|
|
|
|
|
|
|
2016-02-22 22:18:58 +01:00
|
|
|
def friend_status(a, b, c, d):
|
|
|
|
print "Friend connected! Friend's data: ", str(a), str(b), str(c)
|
2016-02-22 16:55:04 +01:00
|
|
|
|
|
|
|
|
2016-02-22 22:18:58 +01:00
|
|
|
def friend_message(a, b, c, d, e, f):
|
2016-02-23 12:11:00 +01:00
|
|
|
print 'Message: ', str(d)
|
2016-02-22 22:18:58 +01:00
|
|
|
|
|
|
|
|
2016-02-23 12:11:00 +01:00
|
|
|
def init_callbacks(tox, window):
|
|
|
|
"""
|
|
|
|
:param tox: tox instance
|
|
|
|
:param window: main window
|
|
|
|
:return: None
|
|
|
|
"""
|
2016-02-22 22:18:58 +01:00
|
|
|
tox.callback_friend_status(friend_status, 0)
|
|
|
|
tox.callback_friend_message(friend_message, 0)
|
2016-02-23 13:07:15 +01:00
|
|
|
tox.callback_self_connection_status(self_connection_status(window.connection_status), 0)
|