diff --git a/fpakman/view/qt/apps_table.py b/fpakman/view/qt/apps_table.py index 6fe4e93f..e98983b6 100644 --- a/fpakman/view/qt/apps_table.py +++ b/fpakman/view/qt/apps_table.py @@ -15,7 +15,7 @@ from fpakman.util.cache import Cache from fpakman.view.qt import dialog from fpakman.view.qt.view_model import ApplicationView, ApplicationViewStatus -INSTALL_BT_STYLE = 'background: {back}; color: white; margin-top: 6px; padding: 1px; font-size: 9px; font-weight: bold' +INSTALL_BT_STYLE = 'background: {back}; color: white; font-size: 9px; font-weight: bold' class UpdateToggleButton(QToolButton): @@ -135,13 +135,11 @@ class AppsTable(QTableWidget): def get_selected_app_icon(self) -> QIcon: return self.item(self.currentRow(), 0).icon() - def _uninstall_app(self): - selected_app = self.get_selected_app() - + def _uninstall_app(self, app_v: ApplicationView): if dialog.ask_confirmation(title=self.window.locale_keys['manage_window.apps_table.row.actions.uninstall.popup.title'], - body=self.window.locale_keys['manage_window.apps_table.row.actions.uninstall.popup.body'].format(selected_app), + body=self.window.locale_keys['manage_window.apps_table.row.actions.uninstall.popup.body'].format(app_v), locale_keys=self.window.locale_keys): - self.window.uninstall_app(selected_app) + self.window.uninstall_app(app_v) def _downgrade_app(self): selected_app = self.get_selected_app() @@ -160,15 +158,14 @@ class AppsTable(QTableWidget): def _get_app_history(self): self.window.get_app_history(self.get_selected_app()) - def _install_app(self): - selected_app = self.get_selected_app() + def _install_app(self, app_v: ApplicationView): if dialog.ask_confirmation( title=self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.title'], - body=self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.body'].format(selected_app), + body=self.window.locale_keys['manage_window.apps_table.row.actions.install.popup.body'].format(app_v), locale_keys=self.window.locale_keys): - self.window.install_app(self.get_selected_app()) + self.window.install_app(app_v) def _load_icon_and_cache(self, http_response): icon_url = http_response.url().toString() @@ -218,26 +215,38 @@ class AppsTable(QTableWidget): self.setCellWidget(idx, 5, col_update) + def _gen_row_button(self, text: str, style: str, callback) -> QWidget: + col = QWidget() + col_bt = QPushButton() + col_bt.setText(text) + col_bt.setStyleSheet('QPushButton { ' + style + '}') + col_bt.clicked.connect(callback) + + layout = QHBoxLayout() + layout.setContentsMargins(3, 3, 3, 3) + layout.setAlignment(Qt.AlignCenter) + layout.addWidget(col_bt) + col.setLayout(layout) + + return col + def _set_col_installed(self, idx: int, app_v: ApplicationView): if app_v.model.installed: if app_v.model.can_be_uninstalled(): - col = QPushButton() - col.setText(self.window.locale_keys['uninstall'].capitalize()) - col.setStyleSheet('QPushButton { ' + INSTALL_BT_STYLE.format(back='#cc0000') + '}') - col.setMaximumHeight(20) - col.clicked.connect(self._uninstall_app) + def uninstall(): + self._uninstall_app(app_v) + + col = self._gen_row_button(self.window.locale_keys['uninstall'].capitalize(), INSTALL_BT_STYLE.format(back='#cc0000'), uninstall) else: col = QLabel() 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(): - col = QPushButton() - col.setText(self.window.locale_keys['install'].capitalize()) - col.setStyleSheet('QPushButton { ' + INSTALL_BT_STYLE.format(back='green') + '}') - col.setMaximumHeight(20) - col.clicked.connect(self._install_app) + def install(): + self._install_app(app_v) + col = self._gen_row_button(self.window.locale_keys['install'].capitalize(), INSTALL_BT_STYLE.format(back='green'), install) else: col = None diff --git a/fpakman/view/qt/window.py b/fpakman/view/qt/window.py index f5162dc7..f0c54c93 100755 --- a/fpakman/view/qt/window.py +++ b/fpakman/view/qt/window.py @@ -271,7 +271,7 @@ class ManageWindow(QWidget): def uninstall_app(self, app: ApplicationView): pwd = None - requires_root = self.manager.requires_root('uninstall', self.table_apps.get_selected_app().model) + requires_root = self.manager.requires_root('uninstall', app.model) if not is_root() and requires_root: pwd, ok = ask_root_password(self.locale_keys) @@ -622,7 +622,7 @@ class ManageWindow(QWidget): def install_app(self, app: ApplicationView): pwd = None - requires_root = self.manager.requires_root('install', self.table_apps.get_selected_app().model) + requires_root = self.manager.requires_root('install', app.model) if not is_root() and requires_root: pwd, ok = ask_root_password(self.locale_keys)