mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 04:44:15 +02:00
show_message refactoring | showing warnings as a unique string
This commit is contained in:
@@ -1,31 +1,26 @@
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QMessageBox
|
||||
from bauh_api.abstract.view import MessageType
|
||||
|
||||
from bauh.core import resource
|
||||
|
||||
MSG_TYPE_MAP = {
|
||||
MessageType.ERROR: QMessageBox.Critical,
|
||||
MessageType.INFO: QMessageBox.Information,
|
||||
MessageType.WARNING: QMessageBox.Warning
|
||||
}
|
||||
|
||||
def show_error(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))):
|
||||
error_msg = QMessageBox()
|
||||
error_msg.setIcon(QMessageBox.Critical)
|
||||
error_msg.setWindowTitle(title)
|
||||
error_msg.setText(body)
|
||||
|
||||
def show_message(title: str, body: str, type_: MessageType, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))):
|
||||
popup = QMessageBox()
|
||||
popup.setWindowTitle(title)
|
||||
popup.setText(body)
|
||||
popup.setIcon(MSG_TYPE_MAP[type_])
|
||||
|
||||
if icon:
|
||||
error_msg.setWindowIcon(icon)
|
||||
popup.setWindowIcon(icon)
|
||||
|
||||
error_msg.exec_()
|
||||
|
||||
|
||||
def show_warning(title: str, body: str, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))):
|
||||
msg = QMessageBox()
|
||||
msg.setIcon(QMessageBox.Warning)
|
||||
msg.setWindowTitle(title)
|
||||
msg.setText(body)
|
||||
|
||||
if icon:
|
||||
msg.setWindowIcon(icon)
|
||||
|
||||
msg.exec_()
|
||||
popup.exec_()
|
||||
|
||||
|
||||
def ask_confirmation(title: str, body: str, locale_keys: dict, icon: QIcon = QIcon(resource.get_path('img/logo.svg'))):
|
||||
|
||||
@@ -3,8 +3,9 @@ import os
|
||||
import subprocess
|
||||
|
||||
from PyQt5.QtWidgets import QInputDialog, QLineEdit
|
||||
from bauh_api.abstract.view import MessageType
|
||||
|
||||
from bauh.view.qt.dialog import show_error
|
||||
from bauh.view.qt.dialog import show_message
|
||||
|
||||
|
||||
def is_root():
|
||||
@@ -25,8 +26,9 @@ def ask_root_password(locale_keys: dict):
|
||||
|
||||
if ok:
|
||||
if not validate_password(dialog_pwd.textValue()):
|
||||
show_error(title=locale_keys['popup.root.bad_password.title'],
|
||||
body=locale_keys['popup.root.bad_password.body'])
|
||||
show_message(title=locale_keys['popup.root.bad_password.title'],
|
||||
body=locale_keys['popup.root.bad_password.body'],
|
||||
type_=MessageType.ERROR)
|
||||
ok = False
|
||||
|
||||
return dialog_pwd.textValue(), ok
|
||||
|
||||
@@ -7,7 +7,7 @@ from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from bauh_api.abstract.controller import ApplicationManager
|
||||
from bauh_api.abstract.handler import ProcessWatcher
|
||||
from bauh_api.abstract.model import ApplicationStatus
|
||||
from bauh_api.abstract.view import InputViewComponent
|
||||
from bauh_api.abstract.view import InputViewComponent, MessageType
|
||||
from bauh_api.exception import NoInternetException
|
||||
from bauh_api.util.cache import Cache
|
||||
|
||||
@@ -19,7 +19,7 @@ class AsyncAction(QThread, ProcessWatcher):
|
||||
signal_output = pyqtSignal(str) # print messages to the terminal widget
|
||||
signal_confirmation = pyqtSignal(dict) # asks the users to confirm something
|
||||
signal_finished = pyqtSignal(object) # informs the main window that the action has finished
|
||||
signal_error = pyqtSignal(dict) # asks the GUI to show an error popup
|
||||
signal_message = pyqtSignal(dict) # asks the GUI to show an error popup
|
||||
signal_status = pyqtSignal(str) # changes the GUI status message
|
||||
signal_substatus = pyqtSignal(str) # changes the GUI substatus message
|
||||
|
||||
@@ -46,8 +46,8 @@ class AsyncAction(QThread, ProcessWatcher):
|
||||
if msg:
|
||||
self.signal_output.emit(msg)
|
||||
|
||||
def show_error(self, title: str, body: str):
|
||||
self.signal_error.emit({'title': title, 'body': body})
|
||||
def show_message(self, title: str, body: str, type_: MessageType):
|
||||
self.signal_message.emit({'title': title, 'body': body, 'type': type_})
|
||||
|
||||
def notify_finished(self, res: object):
|
||||
self.signal_finished.emit(res)
|
||||
|
||||
@@ -8,6 +8,7 @@ from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHead
|
||||
QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout
|
||||
from bauh_api.abstract.controller import ApplicationManager
|
||||
from bauh_api.abstract.model import Application
|
||||
from bauh_api.abstract.view import MessageType
|
||||
from bauh_api.util.cache import Cache
|
||||
|
||||
from bauh.core import resource
|
||||
@@ -214,7 +215,7 @@ class ManageWindow(QWidget):
|
||||
if not only_finished:
|
||||
action.signal_confirmation.connect(self._ask_confirmation)
|
||||
action.signal_output.connect(self._update_action_output)
|
||||
action.signal_error.connect(self._show_error)
|
||||
action.signal_message.connect(self._show_message)
|
||||
action.signal_status.connect(self._change_label_status)
|
||||
action.signal_substatus.connect(self._change_label_substatus)
|
||||
self.signal_user_res.connect(action.confirm)
|
||||
@@ -225,13 +226,12 @@ class ManageWindow(QWidget):
|
||||
diag = ConfirmationDialog(msg['title'], msg['body'], self.locale_keys)
|
||||
self.signal_user_res.emit(diag.is_confirmed())
|
||||
|
||||
def _show_error(self, msg: dict):
|
||||
dialog.show_error(title=msg['title'], body=msg['body'])
|
||||
def _show_message(self, msg: dict):
|
||||
dialog.show_message(title=msg['title'], body=msg['body'], type_=msg['type'])
|
||||
|
||||
def _show_warnings(self, warnings: List[str]):
|
||||
if warnings:
|
||||
for warning in warnings:
|
||||
dialog.show_warning(title=self.locale_keys['warning'].capitalize(), body=warning)
|
||||
dialog.show_message(title=self.locale_keys['warning'].capitalize(), body='\n'.join(warnings), type_=MessageType.WARNING)
|
||||
|
||||
def show(self):
|
||||
super(ManageWindow, self).show()
|
||||
|
||||
Reference in New Issue
Block a user