[ui] -> fix: crashing when nothing can be upgraded

This commit is contained in:
Vinicius Moreira
2020-08-04 09:55:42 -03:00
parent 43f34bba2f
commit 19cd85bc98
5 changed files with 41 additions and 15 deletions

View File

@@ -12,7 +12,8 @@ from bauh.view.util.translation import I18n
class ConfirmationDialog(QMessageBox):
def __init__(self, title: str, body: str, i18n: I18n, screen_size: QSize, components: List[ViewComponent] = None,
confirmation_label: str = None, deny_label: str = None, deny_button: bool = True, window_cancel: bool = True):
confirmation_label: str = None, deny_label: str = None, deny_button: bool = True, window_cancel: bool = True,
confirmation_button: bool = True):
super(ConfirmationDialog, self).__init__()
if not window_cancel:
@@ -20,12 +21,19 @@ class ConfirmationDialog(QMessageBox):
self.setWindowTitle(title)
self.setStyleSheet('QLabel { margin-right: 25px; }')
self.bt_yes = self.addButton(i18n['popup.button.yes'] if not confirmation_label else confirmation_label.capitalize(), QMessageBox.YesRole)
self.bt_yes.setStyleSheet(css.OK_BUTTON)
self.setDefaultButton(self.bt_yes)
self.bt_yes = None
if confirmation_button:
self.bt_yes = self.addButton(i18n['popup.button.yes'] if not confirmation_label else confirmation_label.capitalize(), QMessageBox.YesRole)
self.bt_yes.setStyleSheet(css.OK_BUTTON)
self.setDefaultButton(self.bt_yes)
if deny_button:
self.addButton(i18n['popup.button.no'] if not deny_label else deny_label.capitalize(), QMessageBox.NoRole)
self.bt_no = self.addButton(i18n['popup.button.no'] if not deny_label else deny_label.capitalize(), QMessageBox.NoRole)
if not confirmation_button:
self.bt_no.setStyleSheet(css.OK_BUTTON)
self.setDefaultButton(self.bt_no)
label = None
if body:
@@ -68,5 +76,5 @@ class ConfirmationDialog(QMessageBox):
self.exec_()
def is_confirmed(self):
return self.clickedButton() == self.bt_yes
def is_confirmed(self) -> bool:
return bool(self.bt_yes and self.clickedButton() == self.bt_yes)