From 91d3f885c0fe0dabc74968ab0b962c26101ca090 Mon Sep 17 00:00:00 2001 From: ingvar1995 Date: Mon, 16 Apr 2018 23:35:55 +0300 Subject: [PATCH] create profile screen, main screen opens now --- .gitignore | 1 - toxygen/app.py | 131 ++++++++++------------ toxygen/contacts/basecontact.py | 1 + toxygen/contacts/profile.py | 3 +- toxygen/main.py | 2 +- toxygen/ui/create_profile_screen.py | 43 +++++++ toxygen/ui/login_screen.py | 10 +- toxygen/ui/main_screen.py | 31 +++-- toxygen/ui/menu.py | 2 +- toxygen/ui/views/create_profile_screen.ui | 106 +++++++++++++++++ toxygen/updater/updater.py | 41 +++++-- toxygen/user_data/profile_manager.py | 3 - toxygen/user_data/settings.py | 11 +- toxygen/util/ui.py | 6 + toxygen/util/util.py | 13 ++- 15 files changed, 286 insertions(+), 118 deletions(-) create mode 100644 toxygen/ui/create_profile_screen.py create mode 100644 toxygen/ui/views/create_profile_screen.ui diff --git a/.gitignore b/.gitignore index 78c26f5..f31ca4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ *.pyc *.pyo -*.ui toxygen/toxcore tests/tests tests/libs diff --git a/toxygen/app.py b/toxygen/app.py index b4c5d55..8a7c799 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -2,20 +2,24 @@ import communication.callbacks import threads from PyQt5 import QtWidgets, QtGui, QtCore import ui.password_screen as passwordscreen -from util.util import curr_directory, get_platform, get_images_directory, get_styles_directory, log +from util.util import * import updater.updater as updater import os from communication.tox_factory import tox_factory -import wrapper.libtox as libtox +import wrapper.toxencryptsave as tox_encrypt_save import user_data.toxes from user_data.settings import Settings from ui.login_screen import LoginScreen from user_data.profile_manager import ProfileManager +from plugin_support.plugin_support import PluginLoader +from ui.main_screen import MainWindow class App: - def __init__(self, path_to_profile=None, uri=None): + def __init__(self, version, path_to_profile=None, uri=None): + self._version = version + self._app = None self.tox = self.ms = self.init = self.app = self.tray = self.mainloop = self.avloop = None self.uri = self.path = self.toxes = None if uri is not None and uri.startswith('tox:'): @@ -44,7 +48,7 @@ class App: app = QtWidgets.QApplication([]) icon_file = os.path.join(get_images_directory(), 'icon.png') app.setWindowIcon(QtGui.QIcon(icon_file)) - self.app = app + self._app = app if get_platform() == 'Linux': QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads) @@ -53,17 +57,18 @@ class App: style = fl.read() app.setStyleSheet(style) - encrypt_save = libtox.LibToxEncryptSave() - toxes = user_data.toxes.ToxES(encrypt_save) + encrypt_save = tox_encrypt_save.ToxEncryptSave() + self._toxes = user_data.toxes.ToxES(encrypt_save) if self.path is not None: path = os.path.dirname(self.path) + '/' name = os.path.basename(self.path)[:-4] - data = ProfileManager(path, name).open_profile() + self._settings = Settings(self._toxes, self.path.replace('.tox', '.json')) + self._profile_manager = ProfileManager(self._settings, self._toxes, path) + data = self._profile_manager.open_profile() if encrypt_save.is_data_encrypted(data): data = self.enter_pass(data) - settings = Settings(name) - self.tox = profile.tox_factory(data, settings) + self.tox = tox_factory(data, self._settings) else: auto_profile = Settings.get_auto_profile() if not auto_profile[0]: @@ -87,7 +92,7 @@ class App: if result is None: return elif result.is_new_profile(): # create new profile - name = _login.name if _login.name else 'toxygen_user' + name = get_profile_name_from_path(result.profile_path) or 'toxygen_user' pr = map(lambda x: x[1], ProfileManager.find_profiles()) if name in list(pr): msgBox = QtWidgets.QMessageBox() @@ -98,8 +103,8 @@ class App: msgBox.setText(text) msgBox.exec_() return - self.tox = profile.tox_factory() - self.tox.self_set_name(bytes(_login.name, 'utf-8') if _login.name else b'Toxygen User') + self.tox = tox_factory() + self.tox.self_set_name(bytes(name, 'utf-8') if name else b'Toxygen User') self.tox.self_set_status_message(b'Toxing on Toxygen') reply = QtWidgets.QMessageBox.question(None, 'Profile {}'.format(name), @@ -133,28 +138,30 @@ class App: msgBox.exec_() return path = Settings.get_default_path() - settings = Settings(name) + self._settings = Settings() if curr_lang in langs: - settings['language'] = curr_lang - settings.save() + self._settings['language'] = curr_lang + self._settings.save() else: # load existing profile path = result.profile_path if result.load_as_default: Settings.set_auto_profile(path) - settings = Settings(toxes, path) - data = ProfileManager(settings, toxes, path).open_profile() - if toxes.is_data_encrypted(data): + self._settings = Settings(self._toxes, path.replace('.tox', '.json')) + self._profile_manager = ProfileManager(self._settings, self._toxes, path) + data = self._profile_manager.open_profile() + if self._toxes.is_data_encrypted(data): data = self.enter_pass(data) - self.tox = communication.tox_factory.tox_factory(data, settings) + self._tox = tox_factory(data, self._settings) else: path, name = auto_profile - data = ProfileManager(path, name).open_profile() + self._settings = Settings(self._toxes, path + name + '.json') + self._profile_manager = ProfileManager(self._settings, self._toxes, path) + data = self._profile_manager.open_profile() if encrypt_save.is_data_encrypted(data): data = self.enter_pass(data) - settings = Settings(name) - self.tox = profile.tox_factory(data, settings) + self.tox = tox_factory(data, self._settings) - if Settings.is_active_profile(path, name): # profile is in use + if Settings.is_active_profile(path, get_profile_name_from_path(path)): # profile is in use reply = QtWidgets.QMessageBox.question(None, 'Profile {}'.format(name), QtWidgets.QApplication.translate("login", 'Other instance of Toxygen uses this profile or profile was not properly closed. Continue?'), @@ -163,63 +170,36 @@ class App: if reply != QtWidgets.QMessageBox.Yes: return else: - settings.set_active_profile() + self._settings.set_active_profile() - # application color scheme - for theme in settings.built_in_themes().keys(): - if settings['theme'] == theme: - with open(curr_directory() + settings.built_in_themes()[theme]) as fl: - style = fl.read() - app.setStyleSheet(style) - - lang = Settings.supported_languages()[settings['language']] - translator = QtCore.QTranslator() - translator.load(curr_directory() + '/translations/' + lang) - app.installTranslator(translator) - app.translator = translator + self.load_app_styles() + self.load_app_translations() # tray icon - + self.ms = MainWindow(self._settings, self._tox, self.reset, self.tray) + self._profile = self.ms.profile self.ms.show() - updating = False - if settings['update'] and updater.updater_available() and updater.connection_available(): # auto update - version = updater.check_for_updates() - if version is not None: - if settings['update'] == 2: - updater.download(version) - updating = True - else: - reply = QtWidgets.QMessageBox.question(None, - 'Toxygen', - QtWidgets.QApplication.translate("login", - 'Update for Toxygen was found. Download and install it?'), - QtWidgets.QMessageBox.Yes, - QtWidgets.QMessageBox.No) - if reply == QtWidgets.QMessageBox.Yes: - updater.download(version) - updating = True - + updating = updater.start_update_if_needed(self._version, self._settings) if updating: data = self.tox.get_savedata() - ProfileManager.get_instance().save_profile(data) - settings.close() + self._profile_manager.save_profile(data) + self._settings.close() del self.tox return - plugin_helper = PluginLoader(self.tox, settings) # plugin support + plugin_helper = PluginLoader(self._tox, self._toxes, self._profile, self._settings) # plugin support plugin_helper.load() - start() # init thread - self.init = self.InitThread(self.tox, self.ms, self.tray) + self.init = threads.InitThread(self.tox, self.ms, self.tray) self.init.start() # starting threads for tox iterate and toxav iterate - self.mainloop = self.ToxIterateThread(self.tox) + self.mainloop = threads.ToxIterateThread(self._tox) self.mainloop.start() - self.avloop = self.ToxAVIterateThread(self.tox.AV) + self.avloop = threads.ToxAVIterateThread(self._tox.AV) self.avloop.start() if self.uri is not None: @@ -232,14 +212,13 @@ class App: self.mainloop.stop = True self.avloop.stop = True plugin_helper.stop() - stop() self.mainloop.wait() self.init.wait() self.avloop.wait() self.tray.hide() data = self.tox.get_savedata() - ProfileManager.get_instance().save_profile(data) - settings.close() + self._profile_manager.save_profile(data) + self._settings.close() del self.tox def reset(self): @@ -254,10 +233,10 @@ class App: self.init.wait() self.avloop.wait() data = self.tox.get_savedata() - ProfileManager.get_instance().save_profile(data) + self._profile_manager.save_profile(data) del self.tox # create new tox instance - self.tox = profile.tox_factory(data, Settings.get_instance()) + self.tox = tox_factory(data, self._settings) # init thread self.init = threads.InitThread(self.tox, self.ms, self.tray) self.init.start() @@ -269,7 +248,21 @@ class App: self.avloop = threads.ToxAVIterateThread(self.tox.AV) self.avloop.start() - plugin_helper = PluginLoader.get_instance() - plugin_helper.set_tox(self.tox) + self._plugin_loader.set_tox(self.tox) return self.tox + + def load_app_styles(self): + # application color scheme + for theme in self._settings.built_in_themes().keys(): + if self._settings['theme'] == theme: + with open(curr_directory(__file__) + self._settings.built_in_themes()[theme]) as fl: + style = fl.read() + self._app.setStyleSheet(style) + + def load_app_translations(self): + lang = Settings.supported_languages()[self._settings['language']] + translator = QtCore.QTranslator() + translator.load(curr_directory(__file__) + '/translations/' + lang) + self._app.installTranslator(translator) + self._app.translator = translator diff --git a/toxygen/contacts/basecontact.py b/toxygen/contacts/basecontact.py index 6e2d55a..34c100c 100644 --- a/toxygen/contacts/basecontact.py +++ b/toxygen/contacts/basecontact.py @@ -81,6 +81,7 @@ class BaseContact: """ Tries to load avatar of contact or uses default avatar """ + return prefix = ProfileManager.get_path() + 'avatars/' avatar_path = prefix + '{}.png'.format(self._tox_id[:TOX_PUBLIC_KEY_SIZE * 2]) if not os.path.isfile(avatar_path) or not os.path.getsize(avatar_path): # load default image diff --git a/toxygen/contacts/profile.py b/toxygen/contacts/profile.py index eb69044..ae7767a 100644 --- a/toxygen/contacts/profile.py +++ b/toxygen/contacts/profile.py @@ -39,8 +39,7 @@ class Profile(basecontact.BaseContact): self._load_history = True self._waiting_for_reconnection = False self._factory = items_factory.ItemsFactory(self._screen.friends_list, self._messages) - settings = Settings.get_instance() - self._show_avatars = settings['show_avatars'] + #self._show_avatars = settings['show_avatars'] # ----------------------------------------------------------------------------------------------------------------- diff --git a/toxygen/main.py b/toxygen/main.py index 42e8b76..4230668 100644 --- a/toxygen/main.py +++ b/toxygen/main.py @@ -42,7 +42,7 @@ def main(): reset() return - toxygen = app.App(path_to_profile=args.profile_path) + toxygen = app.App(__version__, path_to_profile=args.profile_path) toxygen.main() diff --git a/toxygen/ui/create_profile_screen.py b/toxygen/ui/create_profile_screen.py new file mode 100644 index 0000000..f461719 --- /dev/null +++ b/toxygen/ui/create_profile_screen.py @@ -0,0 +1,43 @@ +from ui.widgets import * +from PyQt5 import uic +import util.util as util +import util.ui as util_ui + + +class CreateProfileScreenResult: + + def __init__(self, save_into_default_folder, password): + self._save_into_default_folder = save_into_default_folder + self._password = password + + def get_save_into_default_folder(self): + return self._save_into_default_folder + + save_into_default_folder = property(get_save_into_default_folder) + + def get_password(self): + return self._password + + password = property(get_password) + + +class CreateProfileScreen(CenteredWidget, DialogWithResult): + + def __init__(self): + CenteredWidget.__init__(self) + DialogWithResult.__init__(self) + uic.loadUi(util.get_views_path('create_profile_screen')) + self.center() + self.createProfile.clicked.connect(self.create_profile) + + def retranslateUi(self): + self.defaultFolder.setPlaceholderText(util_ui.tr('Save in default folder')) + self.programFolder.setPlaceholderText(util_ui.tr('Save in program folder')) + self.createProfile.setText(util_ui.tr('Create profile')) + self.passwordLabel.setText(util_ui.tr('Password:')) + + def create_profile(self): + if self.password.text() != self.confirmPassword.text(): + return # TODO : error + result = CreateProfileScreenResult(self.defaultFolder.isChecked(), self.password.text()) + self.close_with_result(result) diff --git a/toxygen/ui/login_screen.py b/toxygen/ui/login_screen.py index a5c91e1..bbafef9 100644 --- a/toxygen/ui/login_screen.py +++ b/toxygen/ui/login_screen.py @@ -5,7 +5,7 @@ import os.path class NickEdit(LineEdit): def __init__(self, parent): - super(NickEdit, self).__init__(parent) + super().__init__(parent) self.parent = parent def keyPressEvent(self, event): @@ -108,7 +108,7 @@ class LoginScreen(CenteredWidget, DialogWithResult): def load_existing_profile(self): index = self.comboBox.currentIndex() load_as_default = self.default.isChecked() - path = os.path.join(self._profiles[index][0], self._profiles[index][1] + '.tox') + path = os.path.join(self._profiles[index][0], self._profiles[index][1] + '.tox') result = LoginScreenResult(path, load_as_default) self.close_with_result(result) @@ -118,9 +118,3 @@ class LoginScreen(CenteredWidget, DialogWithResult): self.comboBox.addItems(list(map(lambda p: p[1], profiles))) self.load_profile.setEnabled(len(profiles) > 0) - def update_on_close(self, func): - self.onclose = func - - def closeEvent(self, event): - self.onclose(self.type, self.number, self.load_as_default, self.name) - event.accept() diff --git a/toxygen/ui/main_screen.py b/toxygen/ui/main_screen.py index c2912d6..d3896be 100644 --- a/toxygen/ui/main_screen.py +++ b/toxygen/ui/main_screen.py @@ -5,19 +5,20 @@ from ui.widgets import MultilineEdit, ComboBox import plugin_support from ui.main_screen_widgets import * from user_data import toxes, settings +import util.util as util -class MainWindow(QtWidgets.QMainWindow, Singleton): +class MainWindow(QtWidgets.QMainWindow): - def __init__(self, tox, reset, tray): + def __init__(self, settings, tox, reset, tray): super().__init__() - Singleton.__init__(self) + self._settings = settings self.reset = reset self.tray = tray self.setAcceptDrops(True) self.initUI(tox) self._saved = False - if settings.Settings.get_instance()['show_welcome_screen']: + if settings['show_welcome_screen']: self.ws = WelcomeScreen() def setup_menu(self, window): @@ -137,7 +138,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.online_contacts.addItem(QtWidgets.QApplication.translate("MainWindow", "Name")) self.online_contacts.addItem(QtWidgets.QApplication.translate("MainWindow", "Online and by name")) self.online_contacts.addItem(QtWidgets.QApplication.translate("MainWindow", "Online first and by name")) - ind = Settings.get_instance()['sorting'] + ind = self._settings['sorting'] d = {0: 0, 1: 1, 2: 2, 3: 4, 1 | 4: 4, 2 | 4: 5} self.online_contacts.setCurrentIndex(d[ind]) self.importPlugin.setText(QtWidgets.QApplication.translate("MainWindow", "Import plugin")) @@ -150,7 +151,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.messageEdit.setObjectName("messageEdit") font = QtGui.QFont() font.setPointSize(11) - font.setFamily(settings.Settings.get_instance()['font']) + font.setFamily(self._settings['font']) self.messageEdit.setFont(font) self.sendMessageButton = QtWidgets.QPushButton(Form) @@ -207,7 +208,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.name = Form.name = DataLabel(Form) Form.name.setGeometry(QtCore.QRect(75, 15, 150, 25)) font = QtGui.QFont() - font.setFamily(settings.Settings.get_instance()['font']) + font.setFamily(self._settings['font']) font.setPointSize(14) font.setBold(True) Form.name.setFont(font) @@ -235,7 +236,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.account_name.setGeometry(QtCore.QRect(100, 0, 400, 25)) self.account_name.setTextInteractionFlags(QtCore.Qt.LinksAccessibleByMouse) font = QtGui.QFont() - font.setFamily(settings.Settings.get_instance()['font']) + font.setFamily(self._settings['font']) font.setPointSize(14) font.setBold(True) self.account_name.setFont(font) @@ -297,10 +298,9 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): def initUI(self, tox): self.setMinimumSize(920, 500) - s = Settings.get_instance() + s = self._settings self.setGeometry(s['x'], s['y'], s['width'], s['height']) self.setWindowTitle('Toxygen') - os.chdir(curr_directory() + '/images/') menu = QtWidgets.QWidget() main = QtWidgets.QWidget() grid = QtWidgets.QGridLayout() @@ -317,7 +317,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.setup_right_bottom(message_buttons) self.setup_left_center(main_list) self.setup_menu(menu) - if not Settings.get_instance()['mirror_mode']: + if not self._settings['mirror_mode']: grid.addWidget(search, 2, 0) grid.addWidget(name, 1, 0) grid.addWidget(messages, 2, 1, 2, 1) @@ -391,7 +391,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.account_name.setGeometry(QtCore.QRect(100, 15, self.width() - 560, 25)) self.account_status.setGeometry(QtCore.QRect(100, 35, self.width() - 560, 25)) self.messageEdit.setFocus() - self.profile.update() + #self.profile.update() def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Escape and QtWidgets.QSystemTrayIcon.isSystemTrayAvailable(): @@ -561,14 +561,13 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): self.update_call_state('call') def update_call_state(self, state): - os.chdir(curr_directory() + '/images/') - pixmap = QtGui.QPixmap(curr_directory() + '/images/{}.png'.format(state)) + pixmap = QtGui.QPixmap(os.path.join(util.get_images_directory(), '{}.png'.format(state))) icon = QtGui.QIcon(pixmap) self.callButton.setIcon(icon) self.callButton.setIconSize(QtCore.QSize(50, 50)) - pixmap = QtGui.QPixmap(curr_directory() + '/images/{}_video.png'.format(state)) + pixmap = QtGui.QPixmap(os.path.join(util.get_images_directory(), '{}_video.png'.format(state))) icon = QtGui.QIcon(pixmap) self.videocallButton.setIcon(icon) self.videocallButton.setIconSize(QtCore.QSize(35, 35)) @@ -732,7 +731,7 @@ class MainWindow(QtWidgets.QMainWindow, Singleton): def show(self): super().show() - self.profile.update() + #self.profile.update() def filtering(self): ind = self.online_contacts.currentIndex() diff --git a/toxygen/ui/menu.py b/toxygen/ui/menu.py index 606c545..1aa12dc 100644 --- a/toxygen/ui/menu.py +++ b/toxygen/ui/menu.py @@ -1,7 +1,7 @@ from PyQt5 import QtCore, QtGui, QtWidgets from user_data.settings import * from contacts.profile import Profile -from util import curr_directory, copy +from util.util import curr_directory, copy from ui.widgets import CenteredWidget, DataLabel, LineEdit, RubberBandWindow import pyaudio from user_data import toxes diff --git a/toxygen/ui/views/create_profile_screen.ui b/toxygen/ui/views/create_profile_screen.ui new file mode 100644 index 0000000..f9d3241 --- /dev/null +++ b/toxygen/ui/views/create_profile_screen.ui @@ -0,0 +1,106 @@ + + + Form + + + + 0 + 0 + 400 + 300 + + + + + 400 + 300 + + + + + 400 + 300 + + + + Form + + + + + 30 + 240 + 341 + 51 + + + + PushButton + + + + + + 30 + 190 + 341 + 41 + + + + + + + 30 + 140 + 341 + 41 + + + + + + + 30 + 100 + 67 + 17 + + + + TextLabel + + + + + + 30 + 10 + 112 + 23 + + + + RadioButton + + + true + + + + + + 30 + 50 + 112 + 23 + + + + RadioButton + + + + + + diff --git a/toxygen/updater/updater.py b/toxygen/updater/updater.py index af80624..575dbfe 100644 --- a/toxygen/updater/updater.py +++ b/toxygen/updater/updater.py @@ -1,4 +1,5 @@ -import util +import util.util as util +import util.ui as util_ui import os from user_data import settings import platform @@ -24,12 +25,11 @@ def updater_available(): return os.path.exists(util.curr_directory() + '/toxygen_updater') -def check_for_updates(): - current_version = util.program_version +def check_for_updates(current_version, settings): major, minor, patch = list(map(lambda x: int(x), current_version.split('.'))) versions = generate_versions(major, minor, patch) for version in versions: - if send_request(version): + if send_request(version, settings): return version return None # no new version was found @@ -79,14 +79,13 @@ def download(version): util.log('Exception: running updater failed with ' + str(ex)) -def send_request(version): - s = settings.Settings.get_instance() +def send_request(version, settings): netman = QtNetwork.QNetworkAccessManager() proxy = QtNetwork.QNetworkProxy() - if s['proxy_type']: - proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy if s['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy) - proxy.setHostName(s['proxy_host']) - proxy.setPort(s['proxy_port']) + if settings['proxy_type']: + proxy.setType(QtNetwork.QNetworkProxy.Socks5Proxy if settings['proxy_type'] == 2 else QtNetwork.QNetworkProxy.HttpProxy) + proxy.setHostName(settings['proxy_host']) + proxy.setPort(settings['proxy_port']) netman.setProxy(proxy) url = test_url(version) try: @@ -108,3 +107,25 @@ def generate_versions(major, minor, patch): new_minor = '.'.join([str(major), str(minor + 1), '0']) new_patch = '.'.join([str(major), str(minor), str(patch + 1)]) return new_major, new_minor, new_patch + + +def start_update_if_needed(version, settings): + updating = False + if settings['update'] and updater_available() and connection_available(): # auto update + version = check_for_updates(version, settings) + if version is not None: + if settings['update'] == 2: + download(version) + updating = True + else: + reply = QtWidgets.QMessageBox.question(None, + 'Toxygen', + QtWidgets.QApplication.translate("login", + 'Update for Toxygen was found. Download and install it?'), + QtWidgets.QMessageBox.Yes, + QtWidgets.QMessageBox.No) + if reply == QtWidgets.QMessageBox.Yes: + download(version) + updating = True + + return updating diff --git a/toxygen/user_data/profile_manager.py b/toxygen/user_data/profile_manager.py index a810105..b897fc3 100644 --- a/toxygen/user_data/profile_manager.py +++ b/toxygen/user_data/profile_manager.py @@ -70,6 +70,3 @@ class ProfileManager: result.append((path + '/', name)) return result - @staticmethod - def get_path(): - return ProfileManager.get_instance().get_dir() diff --git a/toxygen/user_data/settings.py b/toxygen/user_data/settings.py index f879e53..39fd333 100644 --- a/toxygen/user_data/settings.py +++ b/toxygen/user_data/settings.py @@ -14,6 +14,7 @@ class Settings(dict): def __init__(self, toxes, path): self._path = path + self._profile_path = path.replace('.json', '.tox') self._toxes = toxes if os.path.isfile(path): with open(path, 'rb') as fl: @@ -25,10 +26,10 @@ class Settings(dict): except Exception as ex: info = Settings.get_default_settings() log('Parsing settings error: ' + str(ex)) - super(Settings, self).__init__(info) + super().__init__(info) self.upgrade() else: - super(Settings, self).__init__(Settings.get_default_settings()) + super().__init__(Settings.get_default_settings()) self.save() smileys.SmileyLoader(self) self.locked = False @@ -181,8 +182,7 @@ class Settings(dict): fl.write(text) def close(self): - profile_path = ProfileManager.get_path() - path = str(profile_path + str(self.name) + '.lock') + path = self._profile_path + '.lock' if os.path.isfile(path): os.remove(path) @@ -190,8 +190,7 @@ class Settings(dict): """ Mark current profile as active """ - profile_path = ProfileManager.get_path() - path = str(profile_path + str(self.name) + '.lock') + path = self._profile_path + '.lock' with open(path, 'w') as fl: fl.write('active') diff --git a/toxygen/util/ui.py b/toxygen/util/ui.py index a0d950d..be613cb 100644 --- a/toxygen/util/ui.py +++ b/toxygen/util/ui.py @@ -5,4 +5,10 @@ def tr(s): return PyQt5.QtWidgets.QApplication.translate('Toxygen', s) +def question(text): + reply = PyQt5.QtWidgets.QMessageBox.question(None, 'Toxygen', text, + PyQt5.QtWidgets.QMessageBox.Yes, + PyQt5.QtWidgets.QMessageBox.No) + return reply == PyQt5.QtWidgets.QMessageBox.Yes + # TODO: move all dialogs here diff --git a/toxygen/util/util.py b/toxygen/util/util.py index 45bc345..91a4aec 100644 --- a/toxygen/util/util.py +++ b/toxygen/util/util.py @@ -32,7 +32,7 @@ def curr_directory(current_file=None): def get_base_directory(current_file=None): - return os.path.dirname(curr_directory()) + return os.path.dirname(curr_directory(current_file or __file__)) def get_images_directory(): @@ -43,6 +43,17 @@ def get_styles_directory(): return os.path.join(get_base_directory(), 'styles') +def get_profile_name_from_path(path): + return os.path.basename(path)[:-4] + + +def get_views_path(view_name): + ui_folder = os.path.join(get_base_directory(), 'ui') + views_folder = os.path.join(ui_folder, 'views') + + return os.path.join(views_folder, view_name + '.ui') + + def curr_time(): return time.strftime('%H:%M')