From 0467b6267506c80077a0c0e59d7a6dfa7b4dd569 Mon Sep 17 00:00:00 2001 From: Vinicius Moreira Date: Mon, 19 Aug 2019 18:41:47 -0300 Subject: [PATCH] thread confirmation sketch --- bauh/view/qt/thread.py | 18 ++++++++++++++++++ bauh/view/qt/window.py | 10 +++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index c870726c..c2d796f0 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -228,6 +228,7 @@ class SearchApps(QThread): class InstallApp(AsyncAction): signal_finished = pyqtSignal(object) + signal_confirmation = pyqtSignal(dict) signal_error = pyqtSignal(dict) signal_output = pyqtSignal(str) @@ -240,6 +241,23 @@ class InstallApp(AsyncAction): self.locale_keys = locale_keys 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): if self.app: diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 03e4b347..a1aa252e 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -2,7 +2,7 @@ import operator from functools import reduce 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.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \ QSizePolicy, QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout @@ -28,6 +28,8 @@ DARK_ORANGE = '#FF4500' class ManageWindow(QWidget): __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): super(ManageWindow, self).__init__() self.locale_keys = locale_keys @@ -166,9 +168,11 @@ class ManageWindow(QWidget): 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.signal_confirmation.connect(self._ask_confirmation) self.thread_install.signal_output.connect(self._update_action_output) self.thread_install.signal_error.connect(self._show_error) 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.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.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): dialog.show_error(title=msg['title'], body=msg['body'])