From ef68b7e2e2e3e9b341f86f7b71e5df7aaa853f2b Mon Sep 17 00:00:00 2001 From: "emdee@spm.plastiras.org" Date: Mon, 26 Feb 2024 08:04:47 +0000 Subject: [PATCH] fixes --- toxygen/app.py | 10 ++++++++-- toxygen/user_data/settings.py | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/toxygen/app.py b/toxygen/app.py index 54417b7..4326849 100644 --- a/toxygen/app.py +++ b/toxygen/app.py @@ -8,6 +8,7 @@ import threading from time import sleep, time from copy import deepcopy +# used only in loop import gevent from qtpy import QtWidgets, QtGui, QtCore @@ -514,7 +515,9 @@ class App: interval = self._tox.iteration_interval() for i in range(n): self._tox.iterate() + # Cooperative yield, allow gevent to monitor file handles via libevent gevent.sleep(interval / 1000.0) +#? sleep(interval / 1000.0) # Profiles @@ -844,10 +847,11 @@ class App: interval = self._tox.iteration_interval() for i in range(n): self._tox.iterate() - QtCore.QThread.msleep(interval) + #? QtCore.QThread.msleep(interval) + # Cooperative yield, allow gevent to monitor file handles via libevent + gevent.sleep(interval / 1000.0) # NO? QtCore.QCoreApplication.processEvents() - # sleep(interval / 1000.0) def _test_tox(self) -> None: self.test_net(iMax=8) @@ -1019,6 +1023,7 @@ class App: util_ui.message_box(text, title) self._ms.log_console() +#? unused class GEventProcessing: """Interoperability class between Qt/gevent that allows processing gevent tasks during Qt idle periods.""" @@ -1042,3 +1047,4 @@ class GEventProcessing: idle_period = self._idle_period # Cooperative yield, allow gevent to monitor file handles via libevent gevent.sleep(idle_period) + #? QtCore.QCoreApplication.processEvents() diff --git a/toxygen/user_data/settings.py b/toxygen/user_data/settings.py index 7c9a2fc..c87eec3 100644 --- a/toxygen/user_data/settings.py +++ b/toxygen/user_data/settings.py @@ -146,8 +146,8 @@ class Settings(dict): try: with open(path, 'rb') as fl: data = fl.read() - if toxes.is_data_encrypted(data): - data = toxes.pass_decrypt(data) + if self._toxes.is_data_encrypted(data): + data = self._toxes.pass_decrypt(data) info = json.loads(str(data, 'utf-8')) LOG.debug('Parsed settings from: ' + str(path)) except Exception as ex: @@ -210,10 +210,7 @@ class Settings(dict): text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8'))) else: text = bytes(text, 'utf-8') - json_path = self._path.replace('.tox', '.json') - if not json_path: - #? - json_path = os.path.join(get_user_config_path(), 'toxygen.json') + json_path = os.path.join(get_user_config_path(), 'toxygen.json') tmp = json_path + str(os.getpid()) try: with open(tmp, 'wb') as fl: @@ -271,12 +268,18 @@ class Settings(dict): p = os.path.join(appdir, 'toxygen.json') if not os.path.isfile(p): return None - with open(p) as fl: - data = fl.read() try: - auto = json.loads(data) + with open(p, 'rb') as fl: + data = fl.read() + if self._toxes.is_data_encrypted(data): + data = self._toxes.pass_decrypt(data) except Exception as ex: - LOG.warn(f"json.loads {data}: {ex}") + LOG.warn(f"fl.read {p}: {ex}") + return None + try: + auto = json.loads(str(data, 'utf-8')) + except Exception as ex: + LOG.warn(f"json.loads {p}: {ex}") auto = {} if 'profile_path' in auto: path = str(auto['profile_path']) @@ -375,7 +378,7 @@ class Settings(dict): 'unread_color': 'red', 'compact_mode': False, 'identicons': True, - 'show_welcome_screen': True, + 'show_welcome_screen': False, 'close_app': 0, 'font': 'Times New Roman', 'update': 0,