diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea9145d..9c979da3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.9.7] 2020 +### Fixes +- UI + - crashing when nothing can be upgraded + + ## [0.9.6] 2020-06-26 ### Improvements - AppImage diff --git a/bauh/api/abstract/handler.py b/bauh/api/abstract/handler.py index d4c9f4ed..e87ed0da 100644 --- a/bauh/api/abstract/handler.py +++ b/bauh/api/abstract/handler.py @@ -18,7 +18,8 @@ class ProcessWatcher: pass def request_confirmation(self, title: str, body: str, components: List[ViewComponent] = None, confirmation_label: str = None, - deny_label: str = None, deny_button: bool = True, window_cancel: bool = False) -> bool: + deny_label: str = None, deny_button: bool = True, window_cancel: bool = False, + confirmation_button: bool = True) -> bool: """ request a user confirmation. In the current GUI implementation, it shows a popup to the user. :param title: popup title @@ -28,6 +29,7 @@ class ProcessWatcher: :param deny_label: optional deny button label (default to 'no') :param deny_button: if the deny button should be displayed :param window_cancel: if the window cancel button should be visible + :param confirmation_button: if the confirmation button should be displayed :return: if the request was confirmed by the user """ pass diff --git a/bauh/view/qt/confirmation.py b/bauh/view/qt/confirmation.py index 4d30cd97..85bc8410 100644 --- a/bauh/view/qt/confirmation.py +++ b/bauh/view/qt/confirmation.py @@ -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) diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py index 9d2d638e..6915b7d8 100644 --- a/bauh/view/qt/thread.py +++ b/bauh/view/qt/thread.py @@ -50,9 +50,14 @@ class AsyncAction(QThread, ProcessWatcher): self.stop = False def request_confirmation(self, title: str, body: str, components: List[ViewComponent] = None, - confirmation_label: str = None, deny_label: str = None, deny_button: bool = True, window_cancel: bool = False) -> bool: + confirmation_label: str = None, deny_label: str = None, deny_button: bool = True, + window_cancel: bool = False, + confirmation_button: bool = True) -> bool: self.wait_confirmation = True - self.signal_confirmation.emit({'title': title, 'body': body, 'components': components, 'confirmation_label': confirmation_label, 'deny_label': deny_label, 'deny_button': deny_button, 'window_cancel': window_cancel}) + self.signal_confirmation.emit({'title': title, 'body': body, 'components': components, + 'confirmation_label': confirmation_label, 'deny_label': deny_label, + 'deny_button': deny_button, 'window_cancel': window_cancel, + 'confirmation_button': confirmation_button}) self.wait_user() return self.confirmation_res @@ -399,10 +404,13 @@ class UpgradeSelected(AsyncAction): if requirements.to_remove: comps.append(self._gen_to_remove_form(requirements.to_remove)) - updates_form, updates_size = self._gen_to_update_form(requirements.to_upgrade) - required_size += updates_size[0] - extra_size += updates_size[1] - comps.append(updates_form) + can_upgrade = False + if requirements.to_upgrade: + can_upgrade = True + updates_form, updates_size = self._gen_to_update_form(requirements.to_upgrade) + required_size += updates_size[0] + extra_size += updates_size[1] + comps.append(updates_form) extra_size_text = '{}: {}'.format(self.i18n['action.update.total_size'].capitalize(), get_human_size_str(extra_size)) req_size_text = '{}: {}'.format(self.i18n['action.update.required_size'].capitalize(), @@ -411,7 +419,8 @@ class UpgradeSelected(AsyncAction): comps.insert(1, TextComponent('')) if not self.request_confirmation(title=self.i18n['action.update.summary'].capitalize(), body='', components=comps, - confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize()): + confirmation_label=self.i18n['proceed'].capitalize(), deny_label=self.i18n['cancel'].capitalize(), + confirmation_button=can_upgrade): self.notify_finished({'success': success, 'updated': updated, 'types': updated_types, 'id': None}) self.pkgs = None return diff --git a/bauh/view/qt/window.py b/bauh/view/qt/window.py index 08c85c04..33631520 100755 --- a/bauh/view/qt/window.py +++ b/bauh/view/qt/window.py @@ -548,6 +548,7 @@ class ManageWindow(QWidget): deny_label=msg['deny_label'], deny_button=msg['deny_button'], window_cancel=msg['window_cancel'], + confirmation_button=msg.get('confirmation_button', True), screen_size=self.screen_size) res = diag.is_confirmed() self.thread_animate_progress.animate()