From 565d800a6e5b734cb290ac2e0c0f04b20c5337ee Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Sat, 20 Feb 2016 00:10:24 +0300 Subject: [PATCH] main.py update --- .gitignore | 1 + src/main.py | 25 +++++++++++++++++++++---- src/tox.py | 2 +- src/util.py | 7 +++++++ 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 3989d3f..1216695 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ src/libs *~ *.iml *.so +*.log diff --git a/src/main.py b/src/main.py index 80722bc..57af4c2 100644 --- a/src/main.py +++ b/src/main.py @@ -29,6 +29,11 @@ class login(object): return self.arr[self.num] +def status(a, b, c): + print 'WOW, it works!' + print str(b) + + def main(): """ main function of app. loads loginscreen if needed and starts mainscreen @@ -64,22 +69,34 @@ def main(): # loading profile print str(path), str(name) data = Profile.open_profile(path, name) - # TODO: start tox iterate and set callbacks - tox = Tox(data, settings) ms = MainWindow() + # creating tox instance + tox = Tox(data, settings) + # TODO: set callbacks + #tox.callback_self_connection_status(status, 0) + # starting thread for tox iterate + mainloop = ToxIterateThread(tox) + mainloop.start() + ms.show() app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()")) app.exec_() + mainloop.stop = True + mainloop.wait() del tox class ToxIterateThread(QtCore.QThread): - def __init__(self): + def __init__(self, tox): QtCore.QThread.__init__(self) + self.tox = tox + self.stop = False def run(self): - pass + while not self.stop: + self.tox.iterate() + self.msleep(self.tox.iteration_interval()) if __name__ == '__main__': diff --git a/src/tox.py b/src/tox.py index f145964..6f05276 100644 --- a/src/tox.py +++ b/src/tox.py @@ -202,7 +202,7 @@ class Tox(object): Return the time in milliseconds before tox_iterate() should be called again for optimal performance. :return: time in milliseconds """ - return int(self.libtoxcore.tox_iteration_interval(self._tox_pointer).value) + return int(self.libtoxcore.tox_iteration_interval(self._tox_pointer)) def iterate(self): """ diff --git a/src/util.py b/src/util.py index e69de29..1c941d8 100644 --- a/src/util.py +++ b/src/util.py @@ -0,0 +1,7 @@ +# TODO: add string to bin and bin to string (TOX ID) (and DHT connection?) + + +def log(data): + with open("logs.log", "a") as fl: + fl.write(str(data)) +