mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-10 01:54:15 +02:00
improvement -> all suported types now display a 'Checking configuration file' task during the initialization process
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import datetime
|
||||
import operator
|
||||
import time
|
||||
from functools import reduce
|
||||
from threading import Lock
|
||||
from typing import Tuple, Optional
|
||||
|
||||
from PyQt5.QtCore import QSize, Qt, QThread, pyqtSignal, QCoreApplication
|
||||
@@ -34,7 +36,10 @@ class Prepare(QThread, TaskManager):
|
||||
self.context = context
|
||||
self.waiting_password = False
|
||||
self.password_response = None
|
||||
self._registered = 0
|
||||
self._tasks_added = set()
|
||||
self._tasks_finished = set()
|
||||
self._add_lock = Lock()
|
||||
self._finish_lock = Lock()
|
||||
|
||||
def ask_password(self) -> Tuple[bool, Optional[str]]:
|
||||
self.waiting_password = True
|
||||
@@ -58,20 +63,42 @@ class Prepare(QThread, TaskManager):
|
||||
QCoreApplication.exit(1)
|
||||
|
||||
self.manager.prepare(self, root_pwd, None)
|
||||
self.signal_started.emit(self._registered)
|
||||
self._add_lock.acquire()
|
||||
self.signal_started.emit(len(self._tasks_added))
|
||||
self._add_lock.release()
|
||||
|
||||
def update_progress(self, task_id: str, progress: float, substatus: str):
|
||||
self.signal_update.emit(task_id, progress, substatus)
|
||||
if task_id in self._tasks_added:
|
||||
self.signal_update.emit(task_id, progress, substatus)
|
||||
|
||||
def update_output(self, task_id: str, output: str):
|
||||
self.signal_output.emit(task_id, output)
|
||||
if task_id in self._tasks_added:
|
||||
self.signal_output.emit(task_id, output)
|
||||
|
||||
def register_task(self, id_: str, label: str, icon_path: str):
|
||||
self._registered += 1
|
||||
self.signal_register.emit(id_, label, icon_path)
|
||||
self._add_lock.acquire()
|
||||
|
||||
if id_ not in self._tasks_added:
|
||||
self._tasks_added.add(id_)
|
||||
self.signal_register.emit(id_, label, icon_path)
|
||||
|
||||
self._add_lock.release()
|
||||
|
||||
def finish_task(self, task_id: str):
|
||||
self.signal_finished.emit(task_id)
|
||||
self._add_lock.acquire()
|
||||
task_registered = task_id in self._tasks_added
|
||||
self._add_lock.release()
|
||||
|
||||
if not task_registered:
|
||||
return
|
||||
|
||||
self._finish_lock.acquire()
|
||||
|
||||
if task_id not in self._tasks_finished:
|
||||
self._tasks_finished.add(task_id)
|
||||
self.signal_finished.emit(task_id)
|
||||
|
||||
self._finish_lock.release()
|
||||
|
||||
|
||||
class CheckFinished(QThread):
|
||||
@@ -84,7 +111,7 @@ class CheckFinished(QThread):
|
||||
|
||||
def run(self):
|
||||
while True:
|
||||
if self.total == self.finished:
|
||||
if self.finished == self.total:
|
||||
break
|
||||
|
||||
self.msleep(5)
|
||||
@@ -134,6 +161,7 @@ class PreparePanel(QWidget, TaskManager):
|
||||
self.output = {}
|
||||
self.added_tasks = 0
|
||||
self.ftasks = 0
|
||||
self.started_at = None
|
||||
self.self_close = False
|
||||
|
||||
self.prepare_thread = Prepare(self.context, manager, self.i18n)
|
||||
@@ -263,6 +291,7 @@ class PreparePanel(QWidget, TaskManager):
|
||||
centralize(self)
|
||||
|
||||
def start(self, tasks: int):
|
||||
self.started_at = time.time()
|
||||
self.check_thread.total = tasks
|
||||
self.check_thread.start()
|
||||
self.skip_thread.start()
|
||||
@@ -387,9 +416,8 @@ class PreparePanel(QWidget, TaskManager):
|
||||
|
||||
def finish_task(self, task_id: str):
|
||||
task = self.tasks[task_id]
|
||||
task['lb_sub'].setText('')
|
||||
|
||||
for key in ('lb_prog', 'lb_status'):
|
||||
for key in ('lb_prog', 'lb_status', 'lb_sub'):
|
||||
label = task[key]
|
||||
label.setProperty('status', 'done')
|
||||
label.style().unpolish(label)
|
||||
@@ -402,10 +430,9 @@ class PreparePanel(QWidget, TaskManager):
|
||||
self.ftasks += 1
|
||||
self.signal_status.emit(self.ftasks)
|
||||
|
||||
if self.table.rowCount() == self.ftasks:
|
||||
self.label_top.setText(self.i18n['ready'].capitalize())
|
||||
|
||||
def finish(self):
|
||||
now = time.time()
|
||||
self.context.logger.info("{0} tasks finished in {1:.9f} seconds".format(self.ftasks, (now - self.started_at)))
|
||||
if self.isVisible():
|
||||
self.manage_window.show()
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from PyQt5.QtWidgets import QLineEdit, QApplication, QDialog, QPushButton, QVBox
|
||||
|
||||
from bauh.api.abstract.context import ApplicationContext
|
||||
from bauh.commons.system import new_subprocess
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.qt.components import QtComponentsManager, new_spacer
|
||||
from bauh.view.util import util
|
||||
from bauh.view.util.translation import I18n
|
||||
@@ -131,7 +131,7 @@ class RootDialog(QDialog):
|
||||
def ask_password(context: ApplicationContext, i18n: I18n, app_config: Optional[dict] = None,
|
||||
comp_manager: Optional[QtComponentsManager] = None, tries: int = 3) -> Tuple[bool, Optional[str]]:
|
||||
|
||||
current_config = read_config() if not app_config else app_config
|
||||
current_config = CoreConfigManager().get_config() if not app_config else app_config
|
||||
|
||||
store_password = bool(current_config['store_root_password'])
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@ from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import user
|
||||
from bauh.commons.html import bold
|
||||
from bauh.commons.system import get_human_size_str, ProcessHandler, SimpleProcess
|
||||
from bauh.view.core import timeshift, config
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.core import timeshift
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.qt import commons
|
||||
from bauh.view.qt.view_model import PackageView, PackageViewStatus
|
||||
from bauh.view.util.translation import I18n
|
||||
@@ -466,7 +466,7 @@ class UpgradeSelected(AsyncAction):
|
||||
|
||||
self.change_substatus('')
|
||||
|
||||
app_config = read_config()
|
||||
app_config = CoreConfigManager().get_config()
|
||||
|
||||
# backup dialog ( if enabled, supported and accepted )
|
||||
should_backup = bkp_supported
|
||||
@@ -572,7 +572,7 @@ class UninstallPackage(AsyncAction):
|
||||
pkg=self.pkg,
|
||||
i18n=self.i18n,
|
||||
root_password=self.root_pwd,
|
||||
app_config=read_config())
|
||||
app_config=CoreConfigManager().get_config())
|
||||
if not proceed:
|
||||
self.notify_finished({'success': False, 'removed': None, 'pkg': self.pkg})
|
||||
self.pkg = None
|
||||
@@ -615,7 +615,7 @@ class DowngradePackage(AsyncAction):
|
||||
pkg=self.pkg,
|
||||
i18n=self.i18n,
|
||||
root_password=self.root_pwd,
|
||||
app_config=read_config())
|
||||
app_config=CoreConfigManager().get_config())
|
||||
|
||||
if not proceed:
|
||||
self.notify_finished({'app': self.pkg, 'success': success})
|
||||
@@ -707,7 +707,7 @@ class InstallPackage(AsyncAction):
|
||||
pkg=self.pkg,
|
||||
i18n=self.i18n,
|
||||
root_password=self.root_pwd,
|
||||
app_config=read_config())
|
||||
app_config=CoreConfigManager().get_config())
|
||||
|
||||
if not proceed:
|
||||
self.signal_finished.emit(res)
|
||||
@@ -1007,7 +1007,7 @@ class CustomAction(AsyncAction):
|
||||
res = {'success': False, 'pkg': self.pkg, 'action': self.custom_action, 'error': None, 'error_type': MessageType.ERROR}
|
||||
|
||||
if self.custom_action.backup:
|
||||
proceed, _ = self.request_backup(app_config=read_config(),
|
||||
proceed, _ = self.request_backup(app_config=CoreConfigManager.get_config(),
|
||||
action_key=None,
|
||||
i18n=self.i18n,
|
||||
root_password=self.root_pwd,
|
||||
@@ -1081,10 +1081,11 @@ class SaveTheme(QThread):
|
||||
|
||||
def run(self):
|
||||
if self.theme_key:
|
||||
core_config = read_config()
|
||||
configman = CoreConfigManager()
|
||||
core_config = configman.get_config()
|
||||
core_config['ui']['theme'] = self.theme_key
|
||||
|
||||
try:
|
||||
config.save(core_config)
|
||||
configman.save_config(core_config)
|
||||
except:
|
||||
traceback.print_exc()
|
||||
|
||||
@@ -22,7 +22,7 @@ from bauh.commons import user
|
||||
from bauh.commons.html import bold
|
||||
from bauh.context import set_theme
|
||||
from bauh.stylesheet import read_all_themes_metadata, ThemeMetadata
|
||||
from bauh.view.core.config import read_config
|
||||
from bauh.view.core.config import CoreConfigManager
|
||||
from bauh.view.core.tray_client import notify_tray
|
||||
from bauh.view.qt import dialog, commons, qt_utils
|
||||
from bauh.view.qt.about import AboutDialog
|
||||
@@ -1586,7 +1586,7 @@ class ManageWindow(QWidget):
|
||||
menu_row.exec_()
|
||||
|
||||
def _map_theme_actions(self, menu: QMenu) -> List[QCustomMenuAction]:
|
||||
core_config = read_config()
|
||||
core_config = CoreConfigManager().get_config()
|
||||
|
||||
current_theme_key, current_action = core_config['ui']['theme'], None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user