From 629f16f24c16dcab1560202413be5d4dd726f746 Mon Sep 17 00:00:00 2001 From: donoban Date: Thu, 22 Oct 2020 19:24:13 +0200 Subject: [PATCH 1/8] Fix SelectionMode on ui file --- qubesmanager/qube_manager.py | 1 - ui/qubemanager.ui | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 91f290e..ecdb867 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -715,7 +715,6 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.table.setModel(self.proxy) self.table.setItemDelegateForColumn(3, StateIconDelegate()) self.table.resizeColumnsToContents() - self.table.setSelectionMode(QAbstractItemView.ExtendedSelection) selection_model = self.table.selectionModel() selection_model.selectionChanged.connect(self.table_selection_changed) diff --git a/ui/qubemanager.ui b/ui/qubemanager.ui index 47fd249..b33b6f8 100644 --- a/ui/qubemanager.ui +++ b/ui/qubemanager.ui @@ -108,7 +108,7 @@ true - QAbstractItemView::SingleSelection + QAbstractItemView::ExtendedSelection QAbstractItemView::SelectRows From 0200f2a0b40bc0c8b9dc5a572a9f500cf916cd0b Mon Sep 17 00:00:00 2001 From: donoban Date: Mon, 26 Oct 2020 14:34:48 +0100 Subject: [PATCH 2/8] Added 'Show' Checkboxes to .ui --- ui/qubemanager.ui | 196 +++++++++++++++++++--------------------------- 1 file changed, 79 insertions(+), 117 deletions(-) diff --git a/ui/qubemanager.ui b/ui/qubemanager.ui index b33b6f8..a5a641a 100644 --- a/ui/qubemanager.ui +++ b/ui/qubemanager.ui @@ -52,23 +52,6 @@ QLayout::SetDefaultConstraint - - - - 6 - - - 6 - - - - - Search: - - - - - @@ -134,108 +117,87 @@ false - - - Nowy wiersz - - - - - - - - - - - - - - - - - - - - - - - - Name - - - Qube name - - - - - State - - - Update info - - - - - Template - - - Qube template - - - - - NetVM - - - Qube netVM - - - - - Disk -usage - - - - - Internal - - - - - IP - - - - - Include -in backups - - - - - Last backup - - - - - Default DisposableVM -Template - - - - - DisposableVM -Template - - - - - Virtualization Mode - - + + + + 6 + + + 6 + + + + + Search: + + + + + + + Show: + + + + + + + Running + + + + + + + Halted + + + + + + + Network + + + + + + + Templates + + + + + + + Standalone + + + + + + + All + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + From 0794a60e4c61406e8aa1c355fe91197c39fa7d22 Mon Sep 17 00:00:00 2001 From: donoban Date: Tue, 27 Oct 2020 00:46:24 +0100 Subject: [PATCH 3/8] Added filterAcceptsRow() to QubesProxyModel Created _init_context_menu() due pylint warning (too much statements) --- qubesmanager/qube_manager.py | 94 +++++++++++++++++++++++++----------- 1 file changed, 66 insertions(+), 28 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index ecdb867..682ebf5 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -621,8 +621,11 @@ class RunCommandThread(common_threads.QubesThread): except (ChildProcessError, exc.QubesException) as ex: self.msg = (self.tr("Error while running command!"), str(ex)) - class QubesProxyModel(QSortFilterProxyModel): + def __init__(self, window): + super().__init__() + self.window = window + def lessThan(self, left, right): if left.data(self.sortRole()) != right.data(self.sortRole()): return super().lessThan(left, right) @@ -632,6 +635,31 @@ class QubesProxyModel(QSortFilterProxyModel): return left_vm.name.lower() < right_vm.name.lower() + # pylint: disable=too-many-return-statements + def filterAcceptsRow(self, sourceRow, sourceParent): + if self.window.show_all.isChecked(): + return super().filterAcceptsRow(sourceRow, sourceParent) + + index = self.sourceModel().index(sourceRow, 0, sourceParent) + vm = self.sourceModel().data(index, Qt.UserRole) + + if self.window.show_running.isChecked() and \ + vm.state['power'] == 'Running': + return super().filterAcceptsRow(sourceRow, sourceParent) + if self.window.show_halted.isChecked() and \ + vm.state['power'] == 'Halted': + return super().filterAcceptsRow(sourceRow, sourceParent) + if self.window.show_network.isChecked() and \ + getattr(vm.vm, 'provides_network', False): + return super().filterAcceptsRow(sourceRow, sourceParent) + if self.window.show_templates.isChecked() and vm.klass == 'TemplateVM': + return super().filterAcceptsRow(sourceRow, sourceParent) + if self.window.show_standalone.isChecked() \ + and vm.klass == 'StandaloneVM': + return super().filterAcceptsRow(sourceRow, sourceParent) + + return False + class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): # suppress saving settings while initializing widgets @@ -650,38 +678,14 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.searchbox.setValidator(QRegExpValidator( QRegExp("[a-zA-Z0-9_-]*", Qt.CaseInsensitive), None)) self.searchbox.textChanged.connect(self.do_search) - self.searchContainer.addWidget(self.searchbox) + self.searchContainer.insertWidget(1, self.searchbox) self.settings_windows = {} self.frame_width = 0 self.frame_height = 0 - self.context_menu = QMenu(self) - - self.context_menu.addAction(self.action_settings) - self.context_menu.addAction(self.action_editfwrules) - self.context_menu.addAction(self.action_appmenus) - self.context_menu.addAction(self.action_set_keyboard_layout) - self.context_menu.addSeparator() - - self.context_menu.addAction(self.action_updatevm) - self.context_menu.addAction(self.action_run_command_in_vm) - self.context_menu.addAction(self.action_open_console) - self.context_menu.addAction(self.action_resumevm) - self.context_menu.addAction(self.action_startvm_tools_install) - self.context_menu.addAction(self.action_pausevm) - self.context_menu.addAction(self.action_shutdownvm) - self.context_menu.addAction(self.action_restartvm) - self.context_menu.addAction(self.action_killvm) - self.context_menu.addSeparator() - - self.context_menu.addAction(self.action_clonevm) - self.context_menu.addAction(self.action_removevm) - self.context_menu.addSeparator() - - self.context_menu.addMenu(self.logs_menu) - self.context_menu.addSeparator() + self.__init_context_menu() self.tools_context_menu = QMenu(self) self.tools_context_menu.addAction(self.action_toolbar) @@ -704,7 +708,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.fill_cache() self.qubes_model = QubesTableModel(self.qubes_cache) - self.proxy = QubesProxyModel() + self.proxy = QubesProxyModel(self) self.proxy.setSourceModel(self.qubes_model) self.proxy.setSortRole(Qt.UserRole + 1) self.proxy.setSortCaseSensitivity(Qt.CaseInsensitive) @@ -712,6 +716,13 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.proxy.setFilterCaseSensitivity(Qt.CaseInsensitive) self.proxy.layoutChanged.connect(self.save_sorting) + self.show_running.stateChanged.connect(self.invalidate) + self.show_halted.stateChanged.connect(self.invalidate) + self.show_network.stateChanged.connect(self.invalidate) + self.show_templates.stateChanged.connect(self.invalidate) + self.show_standalone.stateChanged.connect(self.invalidate) + self.show_all.stateChanged.connect(self.invalidate) + self.table.setModel(self.proxy) self.table.setItemDelegateForColumn(3, StateIconDelegate()) self.table.resizeColumnsToContents() @@ -784,12 +795,39 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.check_updates() + def __init_context_menu(self): + self.context_menu = QMenu(self) + self.context_menu.addAction(self.action_settings) + self.context_menu.addAction(self.action_editfwrules) + self.context_menu.addAction(self.action_appmenus) + self.context_menu.addAction(self.action_set_keyboard_layout) + self.context_menu.addSeparator() + self.context_menu.addAction(self.action_updatevm) + self.context_menu.addAction(self.action_run_command_in_vm) + self.context_menu.addAction(self.action_open_console) + self.context_menu.addAction(self.action_resumevm) + self.context_menu.addAction(self.action_startvm_tools_install) + self.context_menu.addAction(self.action_pausevm) + self.context_menu.addAction(self.action_shutdownvm) + self.context_menu.addAction(self.action_restartvm) + self.context_menu.addAction(self.action_killvm) + self.context_menu.addSeparator() + self.context_menu.addAction(self.action_clonevm) + self.context_menu.addAction(self.action_removevm) + self.context_menu.addSeparator() + self.context_menu.addMenu(self.logs_menu) + self.context_menu.addSeparator() + def save_sorting(self): self.manager_settings.setValue('view/sort_column', self.proxy.sortColumn()) self.manager_settings.setValue('view/sort_order', self.proxy.sortOrder()) + def invalidate(self): + self.proxy.invalidate() + self.table.resizeColumnsToContents() + def fill_cache(self): progress = QProgressDialog( self.tr( From ca1b41ecea6d656995b8b77055c7da027fefffc1 Mon Sep 17 00:00:00 2001 From: donoban Date: Tue, 27 Oct 2020 00:48:26 +0100 Subject: [PATCH 4/8] Enable 'Show' checkboxes by default --- ui/qubemanager.ui | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ui/qubemanager.ui b/ui/qubemanager.ui index a5a641a..761f2f1 100644 --- a/ui/qubemanager.ui +++ b/ui/qubemanager.ui @@ -146,6 +146,9 @@ Running + + true + @@ -153,6 +156,9 @@ Halted + + true + @@ -160,6 +166,9 @@ Network + + true + @@ -167,6 +176,9 @@ Templates + + true + @@ -174,6 +186,9 @@ Standalone + + true + @@ -181,6 +196,9 @@ All + + true + From 8b8ab7c474eed0344acf79b47646c0c9241d60d9 Mon Sep 17 00:00:00 2001 From: donoban Date: Tue, 27 Oct 2020 23:32:58 +0100 Subject: [PATCH 5/8] Removed unused import --- qubesmanager/qube_manager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 682ebf5..fac9ea1 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -37,7 +37,7 @@ from PyQt5.QtCore import (Qt, QAbstractTableModel, QObject, pyqtSlot, QEvent, # pylint: disable=import-error from PyQt5.QtWidgets import (QLineEdit, QStyledItemDelegate, QToolTip, QMenu, QInputDialog, QMainWindow, QProgressDialog, QStyleOptionViewItem, - QAbstractItemView, QMessageBox) + QMessageBox) # pylint: disable=import-error from PyQt5.QtGui import (QIcon, QPixmap, QRegExpValidator, QFont, QColor) From 526dbd5aad0b69494a31c37666f4fb2779f6d5a3 Mon Sep 17 00:00:00 2001 From: donoban Date: Sun, 1 Nov 2020 13:51:53 +0100 Subject: [PATCH 6/8] Added saving and restore settings for showing checkboxes --- qubesmanager/qube_manager.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index fac9ea1..9a978fe 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -818,6 +818,14 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.context_menu.addMenu(self.logs_menu) self.context_menu.addSeparator() + def save_showing(self): + self.manager_settings.setValue('show/running', self.show_running.isChecked()) + self.manager_settings.setValue('show/halted', self.show_halted.isChecked()) + self.manager_settings.setValue('show/network', self.show_network.isChecked()) + self.manager_settings.setValue('show/templates', self.show_templates.isChecked()) + self.manager_settings.setValue('show/standalone', self.show_standalone.isChecked()) + self.manager_settings.setValue('show/all', self.show_all.isChecked()) + def save_sorting(self): self.manager_settings.setValue('view/sort_column', self.proxy.sortColumn()) @@ -976,6 +984,20 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): defaultValue=True): self.action_toolbar.setChecked(False) + # Restore show checkboxes + self.show_running.setChecked(self.manager_settings.value( + 'show/running', "true") == "true") + self.show_halted.setChecked(self.manager_settings.value( + 'show/halted', "true") == "true") + self.show_network.setChecked(self.manager_settings.value( + 'show/network', "true") == "true") + self.show_templates.setChecked(self.manager_settings.value( + 'show/templates', "true") == "true") + self.show_standalone.setChecked(self.manager_settings.value( + 'show/standalone', "true") == "true") + self.show_all.setChecked(self.manager_settings.value( + 'show/all', "true") == "true") + # load last window size self.resize(self.manager_settings.value("window_size", QSize(1100, 600))) @@ -1292,6 +1314,9 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): "\nError: {}".format(str(ex)))) return + def closeEvent(self, event): + self.save_showing() + # noinspection PyArgumentList @pyqtSlot(name='on_action_settings_triggered') def action_settings_triggered(self): From bdaa421a9c56551ce362376a8505d4b61299284b Mon Sep 17 00:00:00 2001 From: donoban Date: Sun, 1 Nov 2020 14:02:57 +0100 Subject: [PATCH 7/8] Fix pylint warnings --- qubesmanager/qube_manager.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 9a978fe..ebb5d5e 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -819,11 +819,16 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.context_menu.addSeparator() def save_showing(self): - self.manager_settings.setValue('show/running', self.show_running.isChecked()) - self.manager_settings.setValue('show/halted', self.show_halted.isChecked()) - self.manager_settings.setValue('show/network', self.show_network.isChecked()) - self.manager_settings.setValue('show/templates', self.show_templates.isChecked()) - self.manager_settings.setValue('show/standalone', self.show_standalone.isChecked()) + self.manager_settings.setValue('show/running', + self.show_running.isChecked()) + self.manager_settings.setValue('show/halted', + self.show_halted.isChecked()) + self.manager_settings.setValue('show/network', + self.show_network.isChecked()) + self.manager_settings.setValue('show/templates', + self.show_templates.isChecked()) + self.manager_settings.setValue('show/standalone', + self.show_standalone.isChecked()) self.manager_settings.setValue('show/all', self.show_all.isChecked()) def save_sorting(self): @@ -992,7 +997,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): self.show_network.setChecked(self.manager_settings.value( 'show/network', "true") == "true") self.show_templates.setChecked(self.manager_settings.value( - 'show/templates', "true") == "true") + 'show/templates', "true") == "true") self.show_standalone.setChecked(self.manager_settings.value( 'show/standalone', "true") == "true") self.show_all.setChecked(self.manager_settings.value( @@ -1314,7 +1319,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QMainWindow): "\nError: {}".format(str(ex)))) return - def closeEvent(self, event): + def closeEvent(self, _): self.save_showing() # noinspection PyArgumentList From ad63ac7de9a1e019d9844d14b6df6e4a4108d20b Mon Sep 17 00:00:00 2001 From: donoban Date: Sun, 1 Nov 2020 16:37:38 +0100 Subject: [PATCH 8/8] Restored removed lines by accident (although I think that are useless at this moment) --- ui/qubemanager.ui | 100 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/ui/qubemanager.ui b/ui/qubemanager.ui index 761f2f1..a543d42 100644 --- a/ui/qubemanager.ui +++ b/ui/qubemanager.ui @@ -117,6 +117,106 @@ false + + + Nowy wiersz + + + + + + + + + + + + + + + + + + + + + + + + Name + + + Qube name + + + + + State + + + Update info + + + + + Template + + + Qube template + + + + + NetVM + + + Qube netVM + + + + + Disk +usage + + + + + Internal + + + + + IP + + + + + Include +in backups + + + + + Last backup + + + + + Default DisposableVM +Template + + + + + DisposableVM +Template + + + + + Virtualization Mode + +