From c2e7010b25492f08c9431a6c57cf60db65a81df5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marta=20Marczykowska-G=C3=B3recka?= Date: Wed, 3 Apr 2019 18:47:15 +0200 Subject: [PATCH] More documentation and added another column for default_dispvm to Qube Manager Including also a minor visual fix - the headers in Qube Manager will now be multi-line when it looks needed. fixes QubesOS/qubes-issues#4912 --- qubesmanager/qube_manager.py | 31 ++++++++++++++++++++------- qubesmanager/table_widgets.py | 28 ++++++++++++++++++------ ui/qubemanager.ui | 40 ++++++++++++++++++++++++++++------- 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/qubesmanager/qube_manager.py b/qubesmanager/qube_manager.py index 3330204..85b0405 100644 --- a/qubesmanager/qube_manager.py +++ b/qubesmanager/qube_manager.py @@ -75,8 +75,6 @@ class VmRowInTable: # pylint: disable=too-few-public-methods def __init__(self, vm, row_no, table): self.vm = vm - # TODO: replace a various different widgets with a more generic - # VmFeatureWidget or VMPropertyWidget table_widgets.row_height = VmManagerWindow.row_height table.setRowHeight(row_no, VmManagerWindow.row_height) @@ -136,10 +134,16 @@ class VmRowInTable: 'Last backup'], self.last_backup_widget) self.dvm_template_widget = table_widgets.VMPropertyItem( - vm, "template_for_dispvms", empty_function=(lambda x: not x)) - table.setItem(row_no, VmManagerWindow.columns_indices['DVM Template'], + vm, "default_dispvm") + table.setItem(row_no, VmManagerWindow.columns_indices['Default DispVM'], self.dvm_template_widget) + self.is_dispvm_template_widget = table_widgets.VMPropertyItem( + vm, "template_for_dispvms", empty_function=(lambda x: not x)) + table.setItem( + row_no, VmManagerWindow.columns_indices['Is DVM Template'], + self.is_dispvm_template_widget) + self.table = table def update(self, update_size_on_disk=False, event=None): @@ -167,6 +171,10 @@ class VmRowInTable: self.include_in_backups_widget.update() if not event or event.endswith(':backup_timestamp'): self.last_backup_widget.update() + if not event or event.endswith(':default_dispvm'): + self.dvm_template_widget.update() + if not event or event.endswith(':template_for_dispvms'): + self.is_dispvm_template_widget.update() if update_size_on_disk: self.size_widget.update() except exc.QubesPropertyAccessError: @@ -340,7 +348,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): "IP": 8, "Include in backups": 9, "Last backup": 10, - "DVM Template": 11 + "Default DispVM": 11, + "Is DVM Template": 12 } def __init__(self, qt_app, qubes_app, dispatcher, parent=None): @@ -384,7 +393,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): self.columns_indices["IP"]: self.action_ip, self.columns_indices["Include in backups"]: self.action_backups, self.columns_indices["Last backup"]: self.action_last_backup, - self.columns_indices["DVM Template"]: self.action_dvm_template + self.columns_indices["Default DispVM"]: self.action_dispvm_template, + self.columns_indices["Is DVM Template"]: self.action_is_dvm_template } self.visible_columns_count = len(self.columns_indices) @@ -1187,8 +1197,13 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow): def on_action_size_on_disk_toggled(self, checked): self.showhide_column(self.columns_indices['Size'], checked) - def on_action_dvm_template_toggled(self, checked): - self.showhide_column(self.columns_indices['DVM Template'], checked) + # pylint: disable=invalid-name + def on_action_dispvm_template_toggled(self, checked): + self.showhide_column(self.columns_indices['Default DispVM'], checked) + + # pylint: disable=invalid-name + def on_action_is_dvm_template_toggled(self, checked): + self.showhide_column(self.columns_indices['Is DVM Template'], checked) # noinspection PyArgumentList @QtCore.pyqtSlot(name='on_action_about_qubes_triggered') diff --git a/qubesmanager/table_widgets.py b/qubesmanager/table_widgets.py index 55ed83f..438dba6 100644 --- a/qubesmanager/table_widgets.py +++ b/qubesmanager/table_widgets.py @@ -267,6 +267,18 @@ class VmInfoWidget(QtGui.QWidget): class VMPropertyItem(QtGui.QTableWidgetItem): def __init__(self, vm, property_name, empty_function=(lambda x: False), check_default=False): + """ + Class used to represent Qube Manager table widget. + :param vm: vm object + :param property_name: name of the property the widget represents + :param empty_function: a function that, when applied to values of + vm.property_name, returns True when the property value should be + represented as an empty string and False otherwise; by default this + function always returns false (vm.property_name is represented by an + empty string only when it actually is one) + :param check_default: if True, the widget will prepend its text with + "default" if the if the property is set to DEFAULT + """ super(VMPropertyItem, self).__init__() self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.setTextAlignment(QtCore.Qt.AlignVCenter) @@ -281,16 +293,18 @@ class VMPropertyItem(QtGui.QTableWidgetItem): def update(self): val = getattr(self.vm, self.property_name, None) if self.empty_function(val): - self.setText("") + text = "" elif val is None: - self.setText("n/a") - elif self.check_default and \ - self.vm.property_is_default(self.property_name): - self.setText('default (' + str(val) + ')') + text = "n/a" elif val is True: - self.setText("Yes") + text = "Yes" else: - self.setText(str(val)) + text = str(val) + + if self.check_default and hasattr(self.vm, self.property_name) and \ + self.vm.property_is_default(self.property_name): + text = 'default (' + text + ')' + self.setText(text) def __lt__(self, other): if self.qid == 0: diff --git a/ui/qubemanager.ui b/ui/qubemanager.ui index 4a272e3..e234aac 100644 --- a/ui/qubemanager.ui +++ b/ui/qubemanager.ui @@ -136,7 +136,7 @@ 10 - 12 + 13 false @@ -211,7 +211,8 @@ - Disk usage + Disk +usage @@ -226,7 +227,8 @@ - Include in backups + Include +in backups @@ -236,7 +238,14 @@ - Template for DispVMs + Default +DisposableVM + + + + + Is template for +DisposableVMs @@ -281,8 +290,9 @@ + + - @@ -836,7 +846,7 @@ Launch a tool that allows multiple templates to be changed at once - + true @@ -844,10 +854,24 @@ true - Template for DispVMs + Default DisposableVMs - Template for DispVMs + Default DisposableVMs + + + + + true + + + true + + + Is Template for DisposableVMs + + + Is Template for DisposableVMs