network settings update
This commit is contained in:
parent
03d3983d83
commit
bc975826b5
5 changed files with 150 additions and 108 deletions
|
@ -5,7 +5,8 @@ from PySide import QtGui, QtCore
|
||||||
class MessageEdit(QtGui.QPlainTextEdit):
|
class MessageEdit(QtGui.QPlainTextEdit):
|
||||||
def __init__(self, text, width, parent=None):
|
def __init__(self, text, width, parent=None):
|
||||||
super(MessageEdit, self).__init__(parent)
|
super(MessageEdit, self).__init__(parent)
|
||||||
|
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
|
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
|
||||||
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
self.setWordWrapMode(QtGui.QTextOption.WrapAtWordBoundaryOrAnywhere)
|
||||||
self.setPlainText(text)
|
self.setPlainText(text)
|
||||||
self.document().setTextWidth(parent.width() - 100)
|
self.document().setTextWidth(parent.width() - 100)
|
||||||
|
|
220
src/main.py
220
src/main.py
|
@ -1,124 +1,160 @@
|
||||||
|
import sys
|
||||||
from loginscreen import LoginScreen
|
from loginscreen import LoginScreen
|
||||||
from settings import Settings
|
from settings import Settings
|
||||||
|
from PySide import QtCore, QtGui
|
||||||
|
from bootstrap import node_generator
|
||||||
from mainscreen import MainWindow
|
from mainscreen import MainWindow
|
||||||
from profile import ProfileHelper, tox_factory
|
from profile import ProfileHelper, tox_factory
|
||||||
import sys
|
|
||||||
from PySide import QtCore, QtGui
|
|
||||||
from callbacks import init_callbacks
|
from callbacks import init_callbacks
|
||||||
from bootstrap import node_generator
|
|
||||||
from util import curr_directory, get_style
|
from util import curr_directory, get_style
|
||||||
|
|
||||||
|
|
||||||
class Login(object):
|
class Toxygen(object):
|
||||||
|
|
||||||
def __init__(self, arr):
|
def __init__(self):
|
||||||
self.arr = arr
|
super(Toxygen, self).__init__()
|
||||||
|
self.tox = self.ms = self.init = self.mainloop = None
|
||||||
|
|
||||||
def login_screen_close(self, t, number=-1, default=False, name=None):
|
def main(self):
|
||||||
""" 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
|
|
||||||
"""
|
"""
|
||||||
print str(t), str(number), str(default), str(name)
|
main function of app. loads login screen if needed and starts main screen
|
||||||
self.t = t
|
"""
|
||||||
self.num = number
|
app = QtGui.QApplication(sys.argv)
|
||||||
self.default = default
|
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
||||||
self.name = name
|
auto_profile = Settings.get_auto_profile()
|
||||||
|
if not auto_profile:
|
||||||
|
# show login screen if default profile not found
|
||||||
|
ls = LoginScreen()
|
||||||
|
ls.setWindowIconText("Toxygen")
|
||||||
|
profiles = ProfileHelper.find_profiles()
|
||||||
|
ls.update_select(map(lambda x: x[1], profiles))
|
||||||
|
_login = self.Login(profiles)
|
||||||
|
ls.update_on_close(_login.login_screen_close)
|
||||||
|
ls.show()
|
||||||
|
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
||||||
|
app.exec_()
|
||||||
|
if not _login.t:
|
||||||
|
return
|
||||||
|
elif _login.t == 1: # create new profile
|
||||||
|
name = _login.name if _login.name else 'toxygen_user'
|
||||||
|
settings = Settings(name)
|
||||||
|
self.tox = tox_factory()
|
||||||
|
self.tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
||||||
|
self.tox.self_set_status_message('Toxing on Toxygen')
|
||||||
|
ProfileHelper.save_profile(self.tox.get_savedata(), name)
|
||||||
|
else: # load existing profile
|
||||||
|
path, name = _login.get_data()
|
||||||
|
settings = Settings(name)
|
||||||
|
if _login.default:
|
||||||
|
Settings.set_auto_profile(path, name)
|
||||||
|
data = ProfileHelper.open_profile(path, name)
|
||||||
|
self.tox = tox_factory(data, settings)
|
||||||
|
else:
|
||||||
|
path, name = auto_profile
|
||||||
|
settings = Settings(name)
|
||||||
|
data = ProfileHelper.open_profile(path, name)
|
||||||
|
self.tox = tox_factory(data, settings)
|
||||||
|
|
||||||
def get_data(self):
|
self.ms = MainWindow(self.tox, self.reset)
|
||||||
return self.arr[self.num]
|
self.ms.show()
|
||||||
|
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
||||||
|
|
||||||
|
# init thread
|
||||||
|
self.init = self.InitThread(self.tox, self.ms)
|
||||||
|
self.init.start()
|
||||||
|
|
||||||
def main():
|
# starting thread for tox iterate
|
||||||
"""
|
self.mainloop = self.ToxIterateThread(self.tox)
|
||||||
main function of app. loads login screen if needed and starts main screen
|
self.mainloop.start()
|
||||||
"""
|
|
||||||
app = QtGui.QApplication(sys.argv)
|
|
||||||
app.setWindowIcon(QtGui.QIcon(curr_directory() + '/images/icon.png'))
|
|
||||||
auto_profile = Settings.get_auto_profile()
|
|
||||||
if not auto_profile:
|
|
||||||
# show login screen if default profile not found
|
|
||||||
ls = LoginScreen()
|
|
||||||
ls.setWindowIconText("Toxygen")
|
|
||||||
profiles = ProfileHelper.find_profiles()
|
|
||||||
ls.update_select(map(lambda x: x[1], profiles))
|
|
||||||
_login = Login(profiles)
|
|
||||||
ls.update_on_close(_login.login_screen_close)
|
|
||||||
ls.show()
|
|
||||||
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
||||||
app.exec_()
|
app.exec_()
|
||||||
if not _login.t:
|
self.mainloop.stop = True
|
||||||
return
|
self.mainloop.wait()
|
||||||
elif _login.t == 1: # create new profile
|
data = self.tox.get_savedata()
|
||||||
name = _login.name if _login.name else 'toxygen_user'
|
ProfileHelper.save_profile(data)
|
||||||
settings = Settings(name)
|
del self.tox
|
||||||
tox = tox_factory()
|
|
||||||
tox.self_set_name(_login.name if _login.name else 'Toxygen User')
|
|
||||||
tox.self_set_status_message('Toxing on Toxygen')
|
|
||||||
ProfileHelper.save_profile(tox.get_savedata(), name)
|
|
||||||
else: # load existing profile
|
|
||||||
path, name = _login.get_data()
|
|
||||||
settings = Settings(name)
|
|
||||||
if _login.default:
|
|
||||||
Settings.set_auto_profile(path, name)
|
|
||||||
data = ProfileHelper.open_profile(path, name)
|
|
||||||
tox = tox_factory(data, settings)
|
|
||||||
else:
|
|
||||||
path, name = auto_profile
|
|
||||||
settings = Settings(name)
|
|
||||||
data = ProfileHelper.open_profile(path, name)
|
|
||||||
tox = tox_factory(data, settings)
|
|
||||||
|
|
||||||
ms = MainWindow(tox)
|
def reset(self):
|
||||||
ms.show()
|
"""
|
||||||
QtGui.QApplication.setStyle(get_style(settings['theme'])) # set application style
|
Create new tox instance (new network settings)
|
||||||
|
:return: tox instance
|
||||||
|
"""
|
||||||
|
self.mainloop.stop = True
|
||||||
|
self.mainloop.wait()
|
||||||
|
self.init.terminate()
|
||||||
|
data = self.tox.get_savedata()
|
||||||
|
length = self.tox.get_savedata_size()
|
||||||
|
savedata = ''.join('{}'.format(data[i]) for i in xrange(length))
|
||||||
|
ProfileHelper.save_profile(savedata)
|
||||||
|
del self.tox
|
||||||
|
# create new tox instance
|
||||||
|
self.tox = tox_factory(savedata, Settings.get_instance())
|
||||||
|
# init thread
|
||||||
|
self.init = self.InitThread(self.tox, self.ms)
|
||||||
|
self.init.start()
|
||||||
|
|
||||||
# init thread
|
# starting thread for tox iterate
|
||||||
init = InitThread(tox, ms)
|
self.mainloop = self.ToxIterateThread(self.tox)
|
||||||
init.start()
|
self.mainloop.start()
|
||||||
|
return self.tox
|
||||||
|
|
||||||
# starting thread for tox iterate
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
mainloop = ToxIterateThread(tox)
|
# Inner classes
|
||||||
mainloop.start()
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
app.connect(app, QtCore.SIGNAL("lastWindowClosed()"), app, QtCore.SLOT("quit()"))
|
class InitThread(QtCore.QThread):
|
||||||
app.exec_()
|
|
||||||
mainloop.stop = True
|
|
||||||
mainloop.wait()
|
|
||||||
data = tox.get_savedata()
|
|
||||||
ProfileHelper.save_profile(data)
|
|
||||||
del tox
|
|
||||||
|
|
||||||
|
def __init__(self, tox, ms):
|
||||||
|
QtCore.QThread.__init__(self)
|
||||||
|
self.tox, self.ms = tox, ms
|
||||||
|
|
||||||
class InitThread(QtCore.QThread):
|
def run(self):
|
||||||
|
# initializing callbacks
|
||||||
|
init_callbacks(self.tox, self.ms)
|
||||||
|
# bootstrap
|
||||||
|
for data in node_generator():
|
||||||
|
self.tox.bootstrap(*data)
|
||||||
|
self.msleep(10000)
|
||||||
|
while not self.tox.self_get_connection_status():
|
||||||
|
for data in node_generator():
|
||||||
|
self.tox.bootstrap(*data)
|
||||||
|
self.msleep(5000)
|
||||||
|
|
||||||
def __init__(self, tox, ms):
|
class ToxIterateThread(QtCore.QThread):
|
||||||
QtCore.QThread.__init__(self)
|
|
||||||
self.tox, self.ms = tox, ms
|
|
||||||
|
|
||||||
def run(self):
|
def __init__(self, tox):
|
||||||
# initializing callbacks
|
QtCore.QThread.__init__(self)
|
||||||
init_callbacks(self.tox, self.ms)
|
self.tox = tox
|
||||||
# bootstrap
|
self.stop = False
|
||||||
for data in node_generator():
|
|
||||||
self.tox.bootstrap(*data)
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while not self.stop:
|
||||||
|
self.tox.iterate()
|
||||||
|
self.msleep(self.tox.iteration_interval())
|
||||||
|
|
||||||
class ToxIterateThread(QtCore.QThread):
|
class Login(object):
|
||||||
|
|
||||||
def __init__(self, tox):
|
def __init__(self, arr):
|
||||||
QtCore.QThread.__init__(self)
|
self.arr = arr
|
||||||
self.tox = tox
|
|
||||||
self.stop = False
|
|
||||||
|
|
||||||
def run(self):
|
def login_screen_close(self, t, number=-1, default=False, name=None):
|
||||||
while not self.stop:
|
""" Function which processes data from login screen
|
||||||
self.tox.iterate()
|
:param t: 0 - window was closed, 1 - new profile was created, 2 - profile loaded
|
||||||
self.msleep(self.tox.iteration_interval())
|
: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
|
||||||
|
"""
|
||||||
|
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]
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# TODO: add command line options
|
# TODO: add command line options
|
||||||
main()
|
toxygen = Toxygen()
|
||||||
|
toxygen.main()
|
||||||
|
|
|
@ -20,10 +20,10 @@ class MessageArea(QtGui.QPlainTextEdit):
|
||||||
|
|
||||||
class MainWindow(QtGui.QMainWindow):
|
class MainWindow(QtGui.QMainWindow):
|
||||||
|
|
||||||
def __init__(self, tox):
|
def __init__(self, tox, reset):
|
||||||
super(MainWindow, self).__init__()
|
super(MainWindow, self).__init__()
|
||||||
self.tox = tox
|
self.reset = reset
|
||||||
self.initUI()
|
self.initUI(tox)
|
||||||
|
|
||||||
def setup_menu(self, MainWindow):
|
def setup_menu(self, MainWindow):
|
||||||
self.menubar = QtGui.QMenuBar(MainWindow)
|
self.menubar = QtGui.QMenuBar(MainWindow)
|
||||||
|
@ -194,7 +194,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.messages = QtGui.QListWidget(widget)
|
self.messages = QtGui.QListWidget(widget)
|
||||||
self.messages.setGeometry(0, 0, 600, 250)
|
self.messages.setGeometry(0, 0, 600, 250)
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self, tox):
|
||||||
self.setMinimumSize(900, 550)
|
self.setMinimumSize(900, 550)
|
||||||
self.setMaximumSize(900, 550)
|
self.setMaximumSize(900, 550)
|
||||||
self.setGeometry(400, 400, 900, 550)
|
self.setGeometry(400, 400, 900, 550)
|
||||||
|
@ -227,7 +227,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
self.setup_menu(self)
|
self.setup_menu(self)
|
||||||
self.user_info = name
|
self.user_info = name
|
||||||
self.friend_info = info
|
self.friend_info = info
|
||||||
self.profile = Profile(self.tox, self)
|
self.profile = Profile(tox, self)
|
||||||
|
|
||||||
def closeEvent(self, *args, **kwargs):
|
def closeEvent(self, *args, **kwargs):
|
||||||
self.profile.save_history()
|
self.profile.save_history()
|
||||||
|
@ -244,7 +244,7 @@ class MainWindow(QtGui.QMainWindow):
|
||||||
msgBox.exec_()
|
msgBox.exec_()
|
||||||
|
|
||||||
def network_settings(self):
|
def network_settings(self):
|
||||||
self.n_s = NetworkSettings()
|
self.n_s = NetworkSettings(self.reset)
|
||||||
self.n_s.show()
|
self.n_s.show()
|
||||||
|
|
||||||
def add_contact(self):
|
def add_contact(self):
|
||||||
|
|
|
@ -188,8 +188,9 @@ class ProfileSettings(CenteredWidget):
|
||||||
class NetworkSettings(CenteredWidget):
|
class NetworkSettings(CenteredWidget):
|
||||||
"""Network settings form: UDP, Ipv6 and proxy"""
|
"""Network settings form: UDP, Ipv6 and proxy"""
|
||||||
# TODO: add possibility to change network settings
|
# TODO: add possibility to change network settings
|
||||||
def __init__(self):
|
def __init__(self, reset):
|
||||||
super(NetworkSettings, self).__init__()
|
super(NetworkSettings, self).__init__()
|
||||||
|
self.reset = reset
|
||||||
self.initUI()
|
self.initUI()
|
||||||
|
|
||||||
def initUI(self):
|
def initUI(self):
|
||||||
|
@ -248,10 +249,10 @@ class NetworkSettings(CenteredWidget):
|
||||||
settings['udp_enabled'] = self.udp.isChecked()
|
settings['udp_enabled'] = self.udp.isChecked()
|
||||||
settings['proxy_type'] = int(self.proxy.isChecked())
|
settings['proxy_type'] = int(self.proxy.isChecked())
|
||||||
settings['proxy_host'] = self.proxyip.text()
|
settings['proxy_host'] = self.proxyip.text()
|
||||||
settings['proxy_port'] = self.proxyport.text()
|
settings['proxy_port'] = int(self.proxyport.text())
|
||||||
settings.save()
|
settings.save()
|
||||||
# recreate tox instance
|
# recreate tox instance
|
||||||
Profile.get_instance().reset()
|
Profile.get_instance().reset(self.reset)
|
||||||
|
|
||||||
|
|
||||||
class PrivacySettings(CenteredWidget):
|
class PrivacySettings(CenteredWidget):
|
||||||
|
|
|
@ -393,7 +393,7 @@ class Profile(Contact, Singleton):
|
||||||
self.screen.account_status.setText('')
|
self.screen.account_status.setText('')
|
||||||
self._active_friend = -1
|
self._active_friend = -1
|
||||||
self.screen.account_avatar.setHidden(True)
|
self.screen.account_avatar.setHidden(True)
|
||||||
self.screen.messages.clear()
|
self._messages.clear()
|
||||||
self.screen.messageEdit.clear()
|
self.screen.messageEdit.clear()
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
|
@ -402,7 +402,7 @@ class Profile(Contact, Singleton):
|
||||||
friend = self._friends[value]
|
friend = self._friends[value]
|
||||||
self._friends[self._active_friend].set_messages(False)
|
self._friends[self._active_friend].set_messages(False)
|
||||||
self.screen.messageEdit.clear()
|
self.screen.messageEdit.clear()
|
||||||
self.screen.messages.clear()
|
self._messages.clear()
|
||||||
friend.load_corr()
|
friend.load_corr()
|
||||||
messages = friend.get_corr()[-42:]
|
messages = friend.get_corr()[-42:]
|
||||||
for message in messages:
|
for message in messages:
|
||||||
|
@ -410,6 +410,7 @@ class Profile(Contact, Singleton):
|
||||||
convert_time(message[2]),
|
convert_time(message[2]),
|
||||||
friend.name if message[1] else self._name,
|
friend.name if message[1] else self._name,
|
||||||
message[3])
|
message[3])
|
||||||
|
self._messages.scrollToBottom()
|
||||||
else:
|
else:
|
||||||
friend = self._friends[self._active_friend]
|
friend = self._friends[self._active_friend]
|
||||||
self.screen.account_name.setText(friend.name)
|
self.screen.account_name.setText(friend.name)
|
||||||
|
@ -637,14 +638,17 @@ class Profile(Contact, Singleton):
|
||||||
# Reset
|
# Reset
|
||||||
# -----------------------------------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
def reset(self):
|
def reset(self, restart):
|
||||||
"""
|
"""
|
||||||
Recreate tox instance
|
Recreate tox instance
|
||||||
|
:param restart: method which calls restart and returns new tox instance
|
||||||
"""
|
"""
|
||||||
print 'In reset'
|
print 'In reset'
|
||||||
data = self.tox.get_savedata()
|
del self.tox
|
||||||
ProfileHelper.save_profile(data)
|
self.tox = restart()
|
||||||
# TODO: recreate tox
|
self.status = None
|
||||||
|
for friend in self._friends:
|
||||||
|
friend.status = None
|
||||||
|
|
||||||
|
|
||||||
def tox_factory(data=None, settings=None):
|
def tox_factory(data=None, settings=None):
|
||||||
|
|
Loading…
Reference in a new issue