Skip to content

Commit

Permalink
More documentation and added another column for default_dispvm to Qub…
Browse files Browse the repository at this point in the history
…e 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
  • Loading branch information
marmarta committed Apr 3, 2019
1 parent cf1dd0d commit c2e7010
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 23 deletions.
31 changes: 23 additions & 8 deletions qubesmanager/qube_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -136,10 +134,16 @@ def __init__(self, vm, row_no, table):
'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):
Expand Down Expand Up @@ -167,6 +171,10 @@ def update(self, update_size_on_disk=False, event=None):
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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -384,7 +393,8 @@ def __init__(self, qt_app, qubes_app, dispatcher, parent=None):
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)
Expand Down Expand Up @@ -1187,8 +1197,13 @@ def on_action_netvm_toggled(self, checked):
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')
Expand Down
28 changes: 21 additions & 7 deletions qubesmanager/table_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ def update_vm_state(self):
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)
Expand All @@ -281,16 +293,18 @@ def __init__(self, vm, property_name, empty_function=(lambda x: False),
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:
Expand Down
40 changes: 32 additions & 8 deletions ui/qubemanager.ui
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@
<number>10</number>
</property>
<property name="columnCount">
<number>12</number>
<number>13</number>
</property>
<attribute name="horizontalHeaderCascadingSectionResizes">
<bool>false</bool>
Expand Down Expand Up @@ -211,7 +211,8 @@
</column>
<column>
<property name="text">
<string>Disk usage</string>
<string>Disk
usage</string>
</property>
</column>
<column>
Expand All @@ -226,7 +227,8 @@
</column>
<column>
<property name="text">
<string>Include in backups</string>
<string>Include
in backups</string>
</property>
</column>
<column>
Expand All @@ -236,7 +238,14 @@
</column>
<column>
<property name="text">
<string>Template for DispVMs</string>
<string>Default
DisposableVM</string>
</property>
</column>
<column>
<property name="text">
<string>Is template for
DisposableVMs</string>
</property>
</column>
</widget>
Expand Down Expand Up @@ -281,8 +290,9 @@
<addaction name="action_ip"/>
<addaction name="action_backups"/>
<addaction name="action_last_backup"/>
<addaction name="action_dispvm_template"/>
<addaction name="action_is_dvm_template"/>
<addaction name="separator"/>
<addaction name="action_dvm_template"/>
<addaction name="action_toolbar"/>
<addaction name="action_menubar"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -836,18 +846,32 @@
<string>Launch a tool that allows multiple templates to be changed at once</string>
</property>
</action>
<action name="action_dvm_template">
<action name="action_dispvm_template">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Default DisposableVMs</string>
</property>
<property name="toolTip">
<string>Default DisposableVMs</string>
</property>
</action>
<action name="action_is_dvm_template">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Template for DispVMs</string>
<string>Is Template for DisposableVMs</string>
</property>
<property name="toolTip">
<string>Template for DispVMs</string>
<string>Is Template for DisposableVMs</string>
</property>
</action>
</widget>
Expand Down

0 comments on commit c2e7010

Please sign in to comment.