2016-02-18 17:15:38 +01:00
|
|
|
from loginscreen import LoginScreen
|
|
|
|
from settings import Settings
|
2016-02-19 11:41:54 +01:00
|
|
|
from mainscreen import MainWindow
|
2016-02-25 21:40:00 +01:00
|
|
|
from profile import ProfileHelper, tox_factory
|
2016-02-18 17:15:38 +01:00
|
|
|
import sys
|
|
|
|
from PySide import QtCore, QtGui
|
2016-02-22 22:18:58 +01:00
|
|
|
from callbacks import init_callbacks
|
2016-02-20 12:50:49 +01:00
|
|
|
from bootstrap import node_generator
|
2016-03-03 17:44:01 +01:00
|
|
|
from util import curr_directory, get_style
|
2016-02-18 17:15:38 +01:00
|
|
|
|
|
|
|
|
2016-02-19 11:41:54 +01:00
|
|
|
class login(object):
|
2016-02-19 16:04:53 +01:00
|
|
|
|
2016-02-19 11:41:54 +01:00
|
|
|
def __init__(self, arr):
|
|
|
|
self.arr = arr
|
|
|
|
|
|
|
|
def login_screen_close(self, t, number=-1, default=False, name=None):
|
2016-02-19 16:04:53 +01:00
|
|
|
""" Function which processes data from login screen
|
|
|
|
:param t: 0 - window was closed, 1 - new profile was created, 2 - profile loaded
|
|
|
|
:param number: num of choosen profile in list (-1 by default)
|
|
|
|
:param default: was or not choosen profile marked as default
|
|
|
|
:param name: name of new profile
|
|
|
|
"""
|
2016-02-19 11:41:54 +01:00
|
|
|
print str(t), str(number), str(default), str(name)
|
|
|
|
self.t = t
|
|
|
|
self.num = number
|
|
|
|
self.default = default
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def get_data(self):
|
|
|
|
return self.arr[self.num]
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2016-02-19 16:04:53 +01:00
|
|
|
"""
|
2016-02-20 21:50:10 +01:00
|
|
|
main function of app. loads loginscreen if needed and starts mainscreen
|
2016-02-19 16:04:53 +01:00
|
|
|
"""
|
2016-02-18 17:15:38 +01:00
|
|
|
app = QtGui.QApplication(sys.argv)
|
2016-02-24 18:26:12 +01:00
|
|
|
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
2016-03-02 17:05:03 +01:00
|
|
|
auto_profile = Settings.get_auto_profile()
|
|
|
|
if not auto_profile:
|
2016-02-18 17:15:38 +01:00
|
|
|
# show login screen if default profile not found
|
|
|
|
ls = LoginScreen()
|
2016-02-19 11:41:54 +01:00
|
|
|
ls.setWindowIconText("Toxygen")
|
2016-02-25 21:40:00 +01:00
|
|
|
profiles = ProfileHelper.find_profiles()
|
2016-02-18 18:13:55 +01:00
|
|
|
ls.update_select(map(lambda x: x[1], profiles))
|
2016-02-19 11:41:54 +01:00
|
|
|
_login = login(profiles)
|
|
|
|
ls.update_on_close(_login.login_screen_close)
|
|
|
|
ls.show()
|
2016-02-18 17:15:38 +01:00
|
|
|
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
|
|
|
app.exec_()
|
2016-02-19 11:41:54 +01:00
|
|
|
if not _login.t:
|
|
|
|
return
|
|
|
|
elif _login.t == 1: # create new profile
|
2016-02-25 10:35:42 +01:00
|
|
|
name = _login.name if _login.name else 'toxygen_user'
|
2016-03-02 17:05:03 +01:00
|
|
|
settings = Settings(name)
|
2016-02-23 22:03:50 +01:00
|
|
|
tox = tox_factory()
|
2016-02-28 16:25:18 +01:00
|
|
|
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
|
|
|
tox.self_set_status_message('Toxing on Toxygen')
|
2016-02-25 21:40:00 +01:00
|
|
|
ProfileHelper.save_profile(tox.get_savedata(), name)
|
2016-02-19 11:41:54 +01:00
|
|
|
else: # load existing profile
|
|
|
|
path, name = _login.get_data()
|
2016-03-02 17:05:03 +01:00
|
|
|
settings = Settings(name)
|
2016-02-19 11:41:54 +01:00
|
|
|
if _login.default:
|
2016-03-02 17:05:03 +01:00
|
|
|
Settings.set_auto_profile(path, name)
|
2016-02-25 21:40:00 +01:00
|
|
|
data = ProfileHelper.open_profile(path, name)
|
2016-02-23 22:03:50 +01:00
|
|
|
tox = tox_factory(data, settings)
|
2016-02-18 18:13:55 +01:00
|
|
|
else:
|
2016-03-02 17:05:03 +01:00
|
|
|
path, name = auto_profile
|
|
|
|
settings = Settings(name)
|
2016-02-25 21:40:00 +01:00
|
|
|
data = ProfileHelper.open_profile(path, name)
|
2016-02-23 22:03:50 +01:00
|
|
|
tox = tox_factory(data, settings)
|
|
|
|
|
2016-02-24 16:32:35 +01:00
|
|
|
ms = MainWindow(tox)
|
2016-02-21 15:32:38 +01:00
|
|
|
ms.show()
|
2016-03-03 17:44:01 +01:00
|
|
|
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
2016-03-10 21:04:43 +01:00
|
|
|
|
|
|
|
# init thread
|
|
|
|
init = InitThread(tox, ms)
|
|
|
|
init.start()
|
|
|
|
|
2016-02-19 22:10:24 +01:00
|
|
|
# starting thread for tox iterate
|
|
|
|
mainloop = ToxIterateThread(tox)
|
|
|
|
mainloop.start()
|
|
|
|
|
2016-02-19 11:41:54 +01:00
|
|
|
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
|
|
|
app.exec_()
|
2016-02-19 22:10:24 +01:00
|
|
|
mainloop.stop = True
|
|
|
|
mainloop.wait()
|
2016-02-29 22:23:03 +01:00
|
|
|
data = tox.get_savedata()
|
|
|
|
ProfileHelper.save_profile(data)
|
2016-02-19 16:04:53 +01:00
|
|
|
del tox
|
|
|
|
|
|
|
|
|
2016-03-10 21:04:43 +01:00
|
|
|
class InitThread(QtCore.QThread):
|
|
|
|
|
|
|
|
def __init__(self, tox, ms):
|
|
|
|
QtCore.QThread.__init__(self)
|
|
|
|
self.tox, self.ms = tox, ms
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
# initializing callbacks
|
|
|
|
init_callbacks(self.tox, self.ms)
|
|
|
|
# bootstrap
|
|
|
|
for data in node_generator():
|
|
|
|
self.tox.bootstrap(*data)
|
|
|
|
|
|
|
|
|
2016-02-19 16:04:53 +01:00
|
|
|
class ToxIterateThread(QtCore.QThread):
|
|
|
|
|
2016-02-19 22:10:24 +01:00
|
|
|
def __init__(self, tox):
|
2016-02-19 16:04:53 +01:00
|
|
|
QtCore.QThread.__init__(self)
|
2016-02-19 22:10:24 +01:00
|
|
|
self.tox = tox
|
|
|
|
self.stop = False
|
2016-02-19 16:04:53 +01:00
|
|
|
|
|
|
|
def run(self):
|
2016-02-19 22:10:24 +01:00
|
|
|
while not self.stop:
|
|
|
|
self.tox.iterate()
|
|
|
|
self.msleep(self.tox.iteration_interval())
|
2016-02-19 11:41:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2016-03-13 13:06:06 +01:00
|
|
|
# TODO: add command line options (example: portable, multiprofile)
|
2016-02-19 11:41:54 +01:00
|
|
|
main()
|