callbacks update - now callbacks can ask window for repaint

This commit is contained in:
ingvar1995 2016-02-24 11:33:49 +03:00
parent 9145974c7f
commit 4d4c0cb56a
4 changed files with 39 additions and 7 deletions

View file

@ -1,11 +1,39 @@
from PySide import QtCore
# TODO: add all callbacks (replace test callbacks and use wrappers) # TODO: add all callbacks (replace test callbacks and use wrappers)
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
def self_connection_status(st): def self_connection_status(st):
def wrapped(a, b, c): def wrapped(tox, connection, user_data):
print 'WOW, it works!' print 'Connection status: ', str(connection)
print 'Status: ', str(b) st.status = connection
st.status = b invoke_in_main_thread(repaint_widget(st))
return wrapped return wrapped

View file

@ -5,7 +5,6 @@ from profile import Profile, tox_factory
import sys import sys
from PySide import QtCore, QtGui from PySide import QtCore, QtGui
from callbacks import init_callbacks from callbacks import init_callbacks
from tox import Tox
from bootstrap import node_generator from bootstrap import node_generator
@ -74,6 +73,7 @@ def main():
# bootstrap # bootstrap
for data in node_generator(): for data in node_generator():
tox.bootstrap(*data) tox.bootstrap(*data)
# initializing callbacks
init_callbacks(tox, ms) init_callbacks(tox, ms)
# starting thread for tox iterate # starting thread for tox iterate
mainloop = ToxIterateThread(tox) mainloop = ToxIterateThread(tox)

View file

@ -1,4 +1,4 @@
import os
program_version = '0.0.1 (alpha)' program_version = '0.0.1 (alpha)'
@ -15,3 +15,7 @@ def string_to_bin(tox_id):
def bin_to_string(raw_id): def bin_to_string(raw_id):
res = ''.join('{:02x}'.format(ord(x)) for x in raw_id) res = ''.join('{:02x}'.format(ord(x)) for x in raw_id)
return res.upper() return res.upper()
def curr_directory():
return os.path.dirname(os.path.realpath(__file__))

View file

@ -59,7 +59,7 @@ class TestNodeGen():
class TestTox(): class TestTox():
def test_creation(self): def test_loading(self):
data = Profile.open_profile(Settings.get_default_path(), 'tox_save') data = Profile.open_profile(Settings.get_default_path(), 'tox_save')
settings = Settings.get_default_settings() settings = Settings.get_default_settings()
tox = tox_factory(data, settings) tox = tox_factory(data, settings)