This commit is contained in:
emdee@spm.plastiras.org 2024-02-26 08:04:47 +00:00
parent affaa3814b
commit ef68b7e2e2
2 changed files with 22 additions and 13 deletions

View File

@ -8,6 +8,7 @@ import threading
from time import sleep, time from time import sleep, time
from copy import deepcopy from copy import deepcopy
# used only in loop
import gevent import gevent
from qtpy import QtWidgets, QtGui, QtCore from qtpy import QtWidgets, QtGui, QtCore
@ -514,7 +515,9 @@ class App:
interval = self._tox.iteration_interval() interval = self._tox.iteration_interval()
for i in range(n): for i in range(n):
self._tox.iterate() self._tox.iterate()
# Cooperative yield, allow gevent to monitor file handles via libevent
gevent.sleep(interval / 1000.0) gevent.sleep(interval / 1000.0)
#? sleep(interval / 1000.0)
# Profiles # Profiles
@ -844,10 +847,11 @@ class App:
interval = self._tox.iteration_interval() interval = self._tox.iteration_interval()
for i in range(n): for i in range(n):
self._tox.iterate() 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? # NO?
QtCore.QCoreApplication.processEvents() QtCore.QCoreApplication.processEvents()
# sleep(interval / 1000.0)
def _test_tox(self) -> None: def _test_tox(self) -> None:
self.test_net(iMax=8) self.test_net(iMax=8)
@ -1019,6 +1023,7 @@ class App:
util_ui.message_box(text, title) util_ui.message_box(text, title)
self._ms.log_console() self._ms.log_console()
#? unused
class GEventProcessing: class GEventProcessing:
"""Interoperability class between Qt/gevent that allows processing gevent """Interoperability class between Qt/gevent that allows processing gevent
tasks during Qt idle periods.""" tasks during Qt idle periods."""
@ -1042,3 +1047,4 @@ class GEventProcessing:
idle_period = self._idle_period idle_period = self._idle_period
# Cooperative yield, allow gevent to monitor file handles via libevent # Cooperative yield, allow gevent to monitor file handles via libevent
gevent.sleep(idle_period) gevent.sleep(idle_period)
#? QtCore.QCoreApplication.processEvents()

View File

@ -146,8 +146,8 @@ class Settings(dict):
try: try:
with open(path, 'rb') as fl: with open(path, 'rb') as fl:
data = fl.read() data = fl.read()
if toxes.is_data_encrypted(data): if self._toxes.is_data_encrypted(data):
data = toxes.pass_decrypt(data) data = self._toxes.pass_decrypt(data)
info = json.loads(str(data, 'utf-8')) info = json.loads(str(data, 'utf-8'))
LOG.debug('Parsed settings from: ' + str(path)) LOG.debug('Parsed settings from: ' + str(path))
except Exception as ex: except Exception as ex:
@ -210,9 +210,6 @@ class Settings(dict):
text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8'))) text = bytes(self._toxes.pass_encrypt(bytes(text, 'utf-8')))
else: else:
text = bytes(text, 'utf-8') 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()) tmp = json_path + str(os.getpid())
try: try:
@ -271,12 +268,18 @@ class Settings(dict):
p = os.path.join(appdir, 'toxygen.json') p = os.path.join(appdir, 'toxygen.json')
if not os.path.isfile(p): if not os.path.isfile(p):
return None return None
with open(p) as fl:
data = fl.read()
try: 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: 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 = {} auto = {}
if 'profile_path' in auto: if 'profile_path' in auto:
path = str(auto['profile_path']) path = str(auto['profile_path'])
@ -375,7 +378,7 @@ class Settings(dict):
'unread_color': 'red', 'unread_color': 'red',
'compact_mode': False, 'compact_mode': False,
'identicons': True, 'identicons': True,
'show_welcome_screen': True, 'show_welcome_screen': False,
'close_app': 0, 'close_app': 0,
'font': 'Times New Roman', 'font': 'Times New Roman',
'update': 0, 'update': 0,