mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 14:24:16 +02:00
thread confirmation sketch
This commit is contained in:
@@ -228,6 +228,7 @@ class SearchApps(QThread):
|
|||||||
class InstallApp(AsyncAction):
|
class InstallApp(AsyncAction):
|
||||||
|
|
||||||
signal_finished = pyqtSignal(object)
|
signal_finished = pyqtSignal(object)
|
||||||
|
signal_confirmation = pyqtSignal(dict)
|
||||||
signal_error = pyqtSignal(dict)
|
signal_error = pyqtSignal(dict)
|
||||||
signal_output = pyqtSignal(str)
|
signal_output = pyqtSignal(str)
|
||||||
|
|
||||||
@@ -240,6 +241,23 @@ class InstallApp(AsyncAction):
|
|||||||
self.locale_keys = locale_keys
|
self.locale_keys = locale_keys
|
||||||
self.root_password = None
|
self.root_password = None
|
||||||
|
|
||||||
|
self.wait_confirmation = False
|
||||||
|
self.msg_confirmation = None
|
||||||
|
|
||||||
|
def request_confirmation(self, title: str, body: str, options: dict) -> dict:
|
||||||
|
self.wait_confirmation = True
|
||||||
|
self.signal_confirmation.emit({'title': title, 'body': body, 'options': options})
|
||||||
|
self.wait_user()
|
||||||
|
return self.msg_confirmation
|
||||||
|
|
||||||
|
def confirm(self, msg: dict):
|
||||||
|
self.msg_confirmation = msg
|
||||||
|
self.wait_confirmation = False
|
||||||
|
|
||||||
|
def wait_user(self) -> bool:
|
||||||
|
while self.wait_confirmation:
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
|
|
||||||
if self.app:
|
if self.app:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import operator
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
from typing import List, Set
|
from typing import List, Set
|
||||||
|
|
||||||
from PyQt5.QtCore import QEvent, Qt, QSize
|
from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal
|
||||||
from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap
|
from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap
|
||||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \
|
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \
|
||||||
QSizePolicy, QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout
|
QSizePolicy, QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout
|
||||||
@@ -28,6 +28,8 @@ DARK_ORANGE = '#FF4500'
|
|||||||
class ManageWindow(QWidget):
|
class ManageWindow(QWidget):
|
||||||
__BASE_HEIGHT__ = 400
|
__BASE_HEIGHT__ = 400
|
||||||
|
|
||||||
|
signal_user_res = pyqtSignal(dict)
|
||||||
|
|
||||||
def __init__(self, locale_keys: dict, icon_cache: Cache, manager: ApplicationManager, disk_cache: bool, download_icons: bool, screen_size, suggestions: bool, tray_icon=None):
|
def __init__(self, locale_keys: dict, icon_cache: Cache, manager: ApplicationManager, disk_cache: bool, download_icons: bool, screen_size, suggestions: bool, tray_icon=None):
|
||||||
super(ManageWindow, self).__init__()
|
super(ManageWindow, self).__init__()
|
||||||
self.locale_keys = locale_keys
|
self.locale_keys = locale_keys
|
||||||
@@ -166,9 +168,11 @@ class ManageWindow(QWidget):
|
|||||||
self.thread_search.signal_finished.connect(self._finish_search)
|
self.thread_search.signal_finished.connect(self._finish_search)
|
||||||
|
|
||||||
self.thread_install = InstallApp(manager=self.manager, disk_cache=self.disk_cache, icon_cache=self.icon_cache, locale_keys=self.locale_keys)
|
self.thread_install = InstallApp(manager=self.manager, disk_cache=self.disk_cache, icon_cache=self.icon_cache, locale_keys=self.locale_keys)
|
||||||
|
self.thread_install.signal_confirmation.connect(self._ask_confirmation)
|
||||||
self.thread_install.signal_output.connect(self._update_action_output)
|
self.thread_install.signal_output.connect(self._update_action_output)
|
||||||
self.thread_install.signal_error.connect(self._show_error)
|
self.thread_install.signal_error.connect(self._show_error)
|
||||||
self.thread_install.signal_finished.connect(self._finish_install)
|
self.thread_install.signal_finished.connect(self._finish_install)
|
||||||
|
self.signal_user_res.connect(self.thread_install.confirm)
|
||||||
|
|
||||||
self.thread_animate_progress = AnimateProgress()
|
self.thread_animate_progress = AnimateProgress()
|
||||||
self.thread_animate_progress.signal_change.connect(self._update_progress)
|
self.thread_animate_progress.signal_change.connect(self._update_progress)
|
||||||
@@ -219,6 +223,10 @@ class ManageWindow(QWidget):
|
|||||||
self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys)
|
self.thread_warnings = ListWarnings(man=manager, locale_keys=locale_keys)
|
||||||
self.thread_warnings.signal_warnings.connect(self._show_warnings)
|
self.thread_warnings.signal_warnings.connect(self._show_warnings)
|
||||||
|
|
||||||
|
def _ask_confirmation(self, msg: dict):
|
||||||
|
res = dialog.ask_confirmation(msg['title'], msg['body'], self.locale_keys)
|
||||||
|
self.signal_user_res.emit({'proceed': res, 'options': {}})
|
||||||
|
|
||||||
def _show_error(self, msg: dict):
|
def _show_error(self, msg: dict):
|
||||||
dialog.show_error(title=msg['title'], body=msg['body'])
|
dialog.show_error(title=msg['title'], body=msg['body'])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user