show_message refactoring | showing warnings as a unique string

This commit is contained in:
Vinicius Moreira
2019-08-23 16:36:50 -03:00
parent 18c044e27b
commit 0ce710575e
4 changed files with 28 additions and 31 deletions

View File

@@ -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'))):