[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

@@ -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/). 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 ## [0.9.6] 2020-06-26
### Improvements ### Improvements
- AppImage - AppImage

View File

@@ -18,7 +18,8 @@ class ProcessWatcher:
pass pass
def request_confirmation(self, title: str, body: str, components: List[ViewComponent] = None, confirmation_label: str = None, 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. request a user confirmation. In the current GUI implementation, it shows a popup to the user.
:param title: popup title :param title: popup title
@@ -28,6 +29,7 @@ class ProcessWatcher:
:param deny_label: optional deny button label (default to 'no') :param deny_label: optional deny button label (default to 'no')
:param deny_button: if the deny button should be displayed :param deny_button: if the deny button should be displayed
:param window_cancel: if the window cancel button should be visible :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 :return: if the request was confirmed by the user
""" """
pass pass

View File

@@ -12,7 +12,8 @@ from bauh.view.util.translation import I18n
class ConfirmationDialog(QMessageBox): class ConfirmationDialog(QMessageBox):
def __init__(self, title: str, body: str, i18n: I18n, screen_size: QSize, components: List[ViewComponent] = None, 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__() super(ConfirmationDialog, self).__init__()
if not window_cancel: if not window_cancel:
@@ -20,12 +21,19 @@ class ConfirmationDialog(QMessageBox):
self.setWindowTitle(title) self.setWindowTitle(title)
self.setStyleSheet('QLabel { margin-right: 25px; }') 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.bt_yes = None
self.setDefaultButton(self.bt_yes) 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: 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 label = None
if body: if body:
@@ -68,5 +76,5 @@ class ConfirmationDialog(QMessageBox):
self.exec_() self.exec_()
def is_confirmed(self): def is_confirmed(self) -> bool:
return self.clickedButton() == self.bt_yes return bool(self.bt_yes and self.clickedButton() == self.bt_yes)

View File

@@ -50,9 +50,14 @@ class AsyncAction(QThread, ProcessWatcher):
self.stop = False self.stop = False
def request_confirmation(self, title: str, body: str, components: List[ViewComponent] = None, 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.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() self.wait_user()
return self.confirmation_res return self.confirmation_res
@@ -399,10 +404,13 @@ class UpgradeSelected(AsyncAction):
if requirements.to_remove: if requirements.to_remove:
comps.append(self._gen_to_remove_form(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) can_upgrade = False
required_size += updates_size[0] if requirements.to_upgrade:
extra_size += updates_size[1] can_upgrade = True
comps.append(updates_form) 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)) 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(), req_size_text = '{}: {}'.format(self.i18n['action.update.required_size'].capitalize(),
@@ -411,7 +419,8 @@ class UpgradeSelected(AsyncAction):
comps.insert(1, TextComponent('')) comps.insert(1, TextComponent(''))
if not self.request_confirmation(title=self.i18n['action.update.summary'].capitalize(), body='', components=comps, 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.notify_finished({'success': success, 'updated': updated, 'types': updated_types, 'id': None})
self.pkgs = None self.pkgs = None
return return

View File

@@ -548,6 +548,7 @@ class ManageWindow(QWidget):
deny_label=msg['deny_label'], deny_label=msg['deny_label'],
deny_button=msg['deny_button'], deny_button=msg['deny_button'],
window_cancel=msg['window_cancel'], window_cancel=msg['window_cancel'],
confirmation_button=msg.get('confirmation_button', True),
screen_size=self.screen_size) screen_size=self.screen_size)
res = diag.is_confirmed() res = diag.is_confirmed()
self.thread_animate_progress.animate() self.thread_animate_progress.animate()