fix: only showing packages of the installed type after the partial refresh

This commit is contained in:
Vinicius Moreira
2019-08-30 10:58:29 -03:00
parent fd6ec1f79f
commit 1b8ce96de1
3 changed files with 46 additions and 44 deletions

View File

@@ -196,14 +196,14 @@ class AppsTable(QTableWidget):
def _get_app_history(self):
self.window.get_app_history(self.get_selected_app())
def _install_app(self, app_v: PackageView):
def _install_app(self, pkgv: PackageView):
if dialog.ask_confirmation(
title=self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.title'],
body=self._parag(self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.body'].format(self._bold(str(app_v)))),
body=self._parag(self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.body'].format(self._bold(str(pkgv)))),
locale_keys=self.window.locale_keys):
self.window.install_app(app_v)
self.window.install(pkgv)
def _load_icon_and_cache(self, http_response):
icon_url = http_response.url().toString()
@@ -270,12 +270,12 @@ class AppsTable(QTableWidget):
return col
def _set_col_installed(self, idx: int, app_v: PackageView):
def _set_col_installed(self, idx: int, pkgv: PackageView):
if app_v.model.installed:
if app_v.model.can_be_uninstalled():
if pkgv.model.installed:
if pkgv.model.can_be_uninstalled():
def uninstall():
self._uninstall_app(app_v)
self._uninstall_app(pkgv)
col = self._gen_row_button(self.window.locale_keys['uninstall'].capitalize(), INSTALL_BT_STYLE.format(back='#cc0000'), uninstall)
else:
@@ -283,9 +283,9 @@ class AppsTable(QTableWidget):
col.setPixmap((QPixmap(resource.get_path('img/checked.svg'))))
col.setAlignment(Qt.AlignCenter)
col.setToolTip(self.window.locale_keys['installed'])
elif app_v.model.can_be_installed():
elif pkgv.model.can_be_installed():
def install():
self._install_app(app_v)
self._install_app(pkgv)
col = self._gen_row_button(self.window.locale_keys['install'].capitalize(), INSTALL_BT_STYLE.format(back='#088A08'), install)
else:
col = None

View File

@@ -106,17 +106,19 @@ class RefreshApps(AsyncAction):
if installed:
idx_found, app_found = None, None
for idx, ins in enumerate(installed):
if self.pkg_types:
refreshed_types.add(ins.__class__)
if self.app and ins.get_type() == self.app.model.get_type() and ins.base_data.id == self.app.model.base_data.id:
idx_found = idx
app_found = ins
break
if self.pkg_types:
refreshed_types.add(ins.__class__)
if app_found:
del installed[idx_found]
installed.insert(0, app_found)
elif self.pkg_types:
refreshed_types = self.pkg_types
self.notify_finished({'installed': installed, 'types': refreshed_types})
self.app = None
@@ -221,9 +223,9 @@ class SearchApps(AsyncAction):
class InstallApp(AsyncAction):
def __init__(self, manager: SoftwareManager, disk_cache: bool, icon_cache: Cache, locale_keys: dict, app: PackageView = None):
def __init__(self, manager: SoftwareManager, disk_cache: bool, icon_cache: Cache, locale_keys: dict, pkg: PackageView = None):
super(InstallApp, self).__init__()
self.app = app
self.pkg = pkg
self.manager = manager
self.icon_cache = icon_cache
self.disk_cache = disk_cache
@@ -231,26 +233,26 @@ class InstallApp(AsyncAction):
self.root_password = None
def run(self):
if self.app:
if self.pkg:
success = False
try:
success = self.manager.install(self.app.model, self.root_password, self)
success = self.manager.install(self.pkg.model, self.root_password, self)
if success and self.disk_cache:
self.app.model.installed = True
self.pkg.model.installed = True
if self.app.model.supports_disk_cache():
icon_data = self.icon_cache.get(self.app.model.base_data.icon_url)
self.manager.cache_to_disk(app=self.app.model,
if self.pkg.model.supports_disk_cache():
icon_data = self.icon_cache.get(self.pkg.model.base_data.icon_url)
self.manager.cache_to_disk(app=self.pkg.model,
icon_bytes=icon_data.get('bytes') if icon_data else None,
only_icon=False)
except (requests.exceptions.ConnectionError, NoInternetException):
success = False
self.print(self.locale_keys['internet.required'])
finally:
self.signal_finished.emit(self.app if success else None)
self.app = None
self.signal_finished.emit(self.pkg if success else None)
self.pkg = None
class AnimateProgress(QThread):

View File

@@ -124,7 +124,7 @@ class ManageWindow(QWidget):
self.bt_installed.setIcon(QIcon(resource.get_path('img/disk.png')))
self.bt_installed.setText(self.locale_keys['manage_window.bt.installed.text'].capitalize())
self.bt_installed.clicked.connect(self._show_installed)
self.bt_installed.setStyleSheet(self._toolbar_button_style('brown'))
self.bt_installed.setStyleSheet(self._toolbar_button_style('#A94E0A'))
self.ref_bt_installed = self.toolbar.addWidget(self.bt_installed)
self.bt_refresh = QPushButton()
@@ -272,7 +272,7 @@ class ManageWindow(QWidget):
self.finish_action()
self.ref_checkbox_only_apps.setVisible(True)
self.ref_bt_upgrade.setVisible(True)
self.update_apps(apps=None, as_installed=True)
self.update_pkgs(new_pkgs=None, as_installed=True)
self.input_search.setText('')
def _show_about(self):
@@ -344,7 +344,7 @@ class ManageWindow(QWidget):
self.finish_action()
self.ref_checkbox_only_apps.setVisible(True)
self.ref_bt_upgrade.setVisible(True)
self.update_apps(res['installed'], as_installed=True, types=res['types'])
self.update_pkgs(res['installed'], as_installed=True, types=res['types'])
self.first_refresh = False
def uninstall_app(self, app: PackageView):
@@ -386,17 +386,17 @@ class ManageWindow(QWidget):
self.thread_refresh_app.root_password = pwd
self.thread_refresh_app.start()
def _finish_uninstall(self, app: PackageView):
def _finish_uninstall(self, pkgv: PackageView):
self.finish_action()
if app:
if pkgv:
if self._can_notify_user():
util.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['uninstalled']))
util.notify_user('{} ({}) {}'.format(pkgv.model.base_data.name, pkgv.model.get_type(), self.locale_keys['uninstalled']))
self.refresh_apps(pkg_types={app.model.__class__})
self.refresh_apps(pkg_types={pkgv.model.__class__})
else:
if self._can_notify_user():
util.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.uninstall.failed']))
util.notify_user('{}: {}'.format(pkgv.model.base_data.name, self.locale_keys['notification.uninstall.failed']))
self.checkbox_console.setChecked(True)
@@ -514,12 +514,12 @@ class ManageWindow(QWidget):
geo.moveCenter(center_point)
self.move(geo.topLeft())
def update_apps(self, apps: List[SoftwarePackage], as_installed: bool, update_check_enabled: bool = True, types: Set[type] = None):
def update_pkgs(self, new_pkgs: List[SoftwarePackage], as_installed: bool, update_check_enabled: bool = True, types: Set[type] = None):
napps = 0 # number of apps (not libraries, runtimes or something else)
available_types = {}
if apps is not None:
if new_pkgs is not None:
self.pkgs = []
old_installed = None
@@ -527,7 +527,7 @@ class ManageWindow(QWidget):
old_installed = self.pkgs_installed
self.pkgs_installed = []
for app in apps:
for app in new_pkgs:
app_model = PackageView(model=app, visible=app.is_application() or not self.checkbox_only_apps.isChecked())
available_types[app.get_type()] = app.get_type_icon_path()
napps += 1 if app.is_application() else 0
@@ -570,7 +570,7 @@ class ManageWindow(QWidget):
self.change_update_state()
self.resize_and_center()
if apps:
if new_pkgs:
self.thread_verify_models.apps = self.pkgs
self.thread_verify_models.start()
@@ -775,11 +775,11 @@ class ManageWindow(QWidget):
def _finish_search(self, apps_found: List[SoftwarePackage]):
self.finish_action()
self.ref_bt_upgrade.setVisible(False)
self.update_apps(apps_found, as_installed=False, update_check_enabled=False)
self.update_pkgs(apps_found, as_installed=False, update_check_enabled=False)
def install_app(self, app: PackageView):
def install(self, pkg: PackageView):
pwd = None
requires_root = self.manager.requires_root('install', app.model)
requires_root = self.manager.requires_root('install', pkg.model)
if not is_root() and requires_root:
pwd, ok = ask_root_password(self.locale_keys)
@@ -788,24 +788,24 @@ class ManageWindow(QWidget):
return
self._handle_console_option(True)
self._begin_action('{} {}'.format(self.locale_keys['manage_window.status.installing'], app.model.base_data.name))
self._begin_action('{} {}'.format(self.locale_keys['manage_window.status.installing'], pkg.model.base_data.name))
self.thread_install.app = app
self.thread_install.pkg = pkg
self.thread_install.root_password = pwd
self.thread_install.start()
def _finish_install(self, app: PackageView):
def _finish_install(self, pkgv: PackageView):
self.input_search.setText('')
self.finish_action()
if app:
if pkgv:
if self._can_notify_user():
util.notify_user(msg='{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['installed']))
util.notify_user(msg='{} ({}) {}'.format(pkgv.model.base_data.name, pkgv.model.get_type(), self.locale_keys['installed']))
self.refresh_apps(top_app=app, pkg_types={app.model.__class__})
self.refresh_apps(top_app=pkgv, pkg_types={pkgv.model.__class__})
else:
if self._can_notify_user():
util.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.install.failed']))
util.notify_user('{}: {}'.format(pkgv.model.base_data.name, self.locale_keys['notification.install.failed']))
self.checkbox_console.setChecked(True)