Rewritten Qube Manager widgets
Less duplicate code and more extendability - now most widgets are based on a single class.
This commit is contained in:
parent
ee8bce269f
commit
2ce6e8b1cc
@ -78,7 +78,6 @@ class VmRowInTable:
|
|||||||
# TODO: replace a various different widgets with a more generic
|
# TODO: replace a various different widgets with a more generic
|
||||||
# VmFeatureWidget or VMPropertyWidget
|
# VmFeatureWidget or VMPropertyWidget
|
||||||
|
|
||||||
|
|
||||||
table_widgets.row_height = VmManagerWindow.row_height
|
table_widgets.row_height = VmManagerWindow.row_height
|
||||||
table.setRowHeight(row_no, VmManagerWindow.row_height)
|
table.setRowHeight(row_no, VmManagerWindow.row_height)
|
||||||
|
|
||||||
@ -94,7 +93,7 @@ class VmRowInTable:
|
|||||||
table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['Label'],
|
||||||
self.label_widget.table_item)
|
self.label_widget.table_item)
|
||||||
|
|
||||||
self.name_widget = table_widgets.VmNameItem(vm)
|
self.name_widget = table_widgets.VMPropertyItem(vm, "name")
|
||||||
table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['Name'],
|
||||||
self.name_widget)
|
self.name_widget)
|
||||||
|
|
||||||
@ -108,7 +107,8 @@ class VmRowInTable:
|
|||||||
table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['Template'],
|
||||||
self.template_widget)
|
self.template_widget)
|
||||||
|
|
||||||
self.netvm_widget = table_widgets.VmNetvmItem(vm)
|
self.netvm_widget = table_widgets.VMPropertyItem(vm, "netvm",
|
||||||
|
check_default=True)
|
||||||
table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['NetVM'],
|
||||||
self.netvm_widget)
|
self.netvm_widget)
|
||||||
|
|
||||||
@ -120,16 +120,18 @@ class VmRowInTable:
|
|||||||
table.setItem(row_no, VmManagerWindow.columns_indices['Internal'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['Internal'],
|
||||||
self.internal_widget)
|
self.internal_widget)
|
||||||
|
|
||||||
self.ip_widget = table_widgets.VmIPItem(vm)
|
self.ip_widget = table_widgets.VMPropertyItem(vm, "ip")
|
||||||
table.setItem(row_no, VmManagerWindow.columns_indices['IP'],
|
table.setItem(row_no, VmManagerWindow.columns_indices['IP'],
|
||||||
self.ip_widget)
|
self.ip_widget)
|
||||||
|
|
||||||
self.include_in_backups_widget = \
|
self.include_in_backups_widget = table_widgets.VMPropertyItem(
|
||||||
table_widgets.VmIncludeInBackupsItem(vm)
|
vm, "include_in_backups",
|
||||||
|
empty_function=(lambda x: True if x is None or not x else False))
|
||||||
table.setItem(row_no, VmManagerWindow.columns_indices[
|
table.setItem(row_no, VmManagerWindow.columns_indices[
|
||||||
'Backups'], self.include_in_backups_widget)
|
'Include in backups'], self.include_in_backups_widget)
|
||||||
|
|
||||||
self.last_backup_widget = table_widgets.VmLastBackupItem(vm)
|
self.last_backup_widget = table_widgets.VmLastBackupItem(
|
||||||
|
vm, "backup_timestamp")
|
||||||
table.setItem(row_no, VmManagerWindow.columns_indices[
|
table.setItem(row_no, VmManagerWindow.columns_indices[
|
||||||
'Last backup'], self.last_backup_widget)
|
'Last backup'], self.last_backup_widget)
|
||||||
|
|
||||||
@ -331,7 +333,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
|
|||||||
"Size": 6,
|
"Size": 6,
|
||||||
"Internal": 7,
|
"Internal": 7,
|
||||||
"IP": 8,
|
"IP": 8,
|
||||||
"Backups": 9,
|
"Include in backups": 9,
|
||||||
"Last backup": 10,
|
"Last backup": 10,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,7 +376,7 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
|
|||||||
self.columns_indices["Size"]: self.action_size_on_disk,
|
self.columns_indices["Size"]: self.action_size_on_disk,
|
||||||
self.columns_indices["Internal"]: self.action_internal,
|
self.columns_indices["Internal"]: self.action_internal,
|
||||||
self.columns_indices["IP"]: self
|
self.columns_indices["IP"]: self
|
||||||
.action_ip, self.columns_indices["Backups"]: self
|
.action_ip, self.columns_indices["Include in backups"]: self
|
||||||
.action_backups, self.columns_indices["Last backup"]: self
|
.action_backups, self.columns_indices["Last backup"]: self
|
||||||
.action_last_backup
|
.action_last_backup
|
||||||
}
|
}
|
||||||
@ -1164,7 +1166,8 @@ class VmManagerWindow(ui_qubemanager.Ui_VmManagerWindow, QtGui.QMainWindow):
|
|||||||
self.showhide_column(self.columns_indices['IP'], checked)
|
self.showhide_column(self.columns_indices['IP'], checked)
|
||||||
|
|
||||||
def on_action_backups_toggled(self, checked):
|
def on_action_backups_toggled(self, checked):
|
||||||
self.showhide_column(self.columns_indices['Backups'], checked)
|
self.showhide_column(
|
||||||
|
self.columns_indices['Include in backups'], checked)
|
||||||
|
|
||||||
def on_action_last_backup_toggled(self, checked):
|
def on_action_last_backup_toggled(self, checked):
|
||||||
self.showhide_column(self.columns_indices['Last backup'], checked)
|
self.showhide_column(self.columns_indices['Last backup'], checked)
|
||||||
|
@ -71,7 +71,6 @@ class VmIconWidget(QtGui.QWidget):
|
|||||||
self.label_icon.setFixedSize(icon_sz)
|
self.label_icon.setFixedSize(icon_sz)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class VmTypeWidget(VmIconWidget):
|
class VmTypeWidget(VmIconWidget):
|
||||||
class VmTypeItem(QtGui.QTableWidgetItem):
|
class VmTypeItem(QtGui.QTableWidgetItem):
|
||||||
def __init__(self, value, vm):
|
def __init__(self, value, vm):
|
||||||
@ -160,22 +159,6 @@ class VmLabelWidget(VmIconWidget):
|
|||||||
self.set_icon(icon_path)
|
self.set_icon(icon_path)
|
||||||
|
|
||||||
|
|
||||||
class VmNameItem(QtGui.QTableWidgetItem):
|
|
||||||
def __init__(self, vm):
|
|
||||||
super(VmNameItem, self).__init__()
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.setText(vm.name)
|
|
||||||
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
|
||||||
self.qid = vm.qid
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
return super(VmNameItem, self).__lt__(other)
|
|
||||||
|
|
||||||
|
|
||||||
class VmStatusIcon(QtGui.QLabel):
|
class VmStatusIcon(QtGui.QLabel):
|
||||||
def __init__(self, vm, parent=None):
|
def __init__(self, vm, parent=None):
|
||||||
super(VmStatusIcon, self).__init__(parent)
|
super(VmStatusIcon, self).__init__(parent)
|
||||||
@ -281,16 +264,48 @@ class VmInfoWidget(QtGui.QWidget):
|
|||||||
self.upd_info.update_outdated()
|
self.upd_info.update_outdated()
|
||||||
|
|
||||||
|
|
||||||
class VmTemplateItem(QtGui.QTableWidgetItem):
|
class VMPropertyItem(QtGui.QTableWidgetItem):
|
||||||
def __init__(self, vm):
|
def __init__(self, vm, property_name, empty_function=(lambda x: False),
|
||||||
super(VmTemplateItem, self).__init__()
|
check_default=False):
|
||||||
|
super(VMPropertyItem, self).__init__()
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
||||||
|
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
||||||
self.vm = vm
|
self.vm = vm
|
||||||
self.qid = vm.qid
|
self.qid = vm.qid
|
||||||
|
self.property_name = property_name
|
||||||
self.name = vm.name
|
self.name = vm.name
|
||||||
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
self.empty_function = empty_function
|
||||||
|
self.check_default = check_default
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
def update(self):
|
||||||
|
val = getattr(self.vm, self.property_name, None)
|
||||||
|
if self.empty_function(val):
|
||||||
|
self.setText("")
|
||||||
|
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) + ')')
|
||||||
|
elif val is True:
|
||||||
|
self.setText("Yes")
|
||||||
|
else:
|
||||||
|
self.setText(str(val))
|
||||||
|
|
||||||
|
def __lt__(self, other):
|
||||||
|
if self.qid == 0:
|
||||||
|
return True
|
||||||
|
if other.qid == 0:
|
||||||
|
return False
|
||||||
|
if self.text() == other.text():
|
||||||
|
return self.name < other.name
|
||||||
|
return super(VMPropertyItem, self).__lt__(other)
|
||||||
|
|
||||||
|
|
||||||
|
class VmTemplateItem(VMPropertyItem):
|
||||||
|
def __init__(self, vm):
|
||||||
|
super(VmTemplateItem, self).__init__(vm, "template")
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if getattr(self.vm, 'template', None) is not None:
|
if getattr(self.vm, 'template', None) is not None:
|
||||||
self.setText(self.vm.template.name)
|
self.setText(self.vm.template.name)
|
||||||
@ -302,68 +317,14 @@ class VmTemplateItem(QtGui.QTableWidgetItem):
|
|||||||
|
|
||||||
self.setText(self.vm.klass)
|
self.setText(self.vm.klass)
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.text() == other.text():
|
|
||||||
return self.name < other.name
|
|
||||||
return super(VmTemplateItem, self).__lt__(other)
|
|
||||||
|
|
||||||
|
class VmInternalItem(VMPropertyItem):
|
||||||
class VmNetvmItem(QtGui.QTableWidgetItem):
|
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
super(VmNetvmItem, self).__init__()
|
super(VmInternalItem, self).__init__(vm, None)
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
self.vm = vm
|
|
||||||
self.qid = vm.qid
|
|
||||||
self.name = vm.name
|
|
||||||
self.setTextAlignment(QtCore.Qt.AlignVCenter)
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
if getattr(self.vm, 'netvm', None) is None:
|
internal = self.vm.features.get('internal', False)
|
||||||
self.setText("n/a")
|
self.setText("Yes" if internal else "")
|
||||||
else:
|
|
||||||
if self.vm.property_is_default('netvm'):
|
|
||||||
text = 'default (' + self.vm.netvm.name +')'
|
|
||||||
else:
|
|
||||||
text = self.vm.netvm.name
|
|
||||||
self.setText(text)
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.text() == other.text():
|
|
||||||
return self.name < other.name
|
|
||||||
return super(VmNetvmItem, self).__lt__(other)
|
|
||||||
|
|
||||||
|
|
||||||
class VmInternalItem(QtGui.QTableWidgetItem):
|
|
||||||
def __init__(self, vm):
|
|
||||||
super(VmInternalItem, self).__init__()
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
|
|
||||||
self.vm = vm
|
|
||||||
self.qid = vm.qid
|
|
||||||
self.name = vm.name
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.internal = self.vm.features.get('internal', False)
|
|
||||||
self.setText("Yes" if self.internal else "")
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.internal == other.internal:
|
|
||||||
return self.name < other.name
|
|
||||||
return super(VmInternalItem, self).__lt__(other)
|
|
||||||
|
|
||||||
|
|
||||||
# features man qvm-features
|
# features man qvm-features
|
||||||
@ -474,6 +435,7 @@ class VmUpdateInfoWidget(QtGui.QWidget):
|
|||||||
alignment=QtCore.Qt.AlignCenter)
|
alignment=QtCore.Qt.AlignCenter)
|
||||||
self.icon.setVisible(True)
|
self.icon.setVisible(True)
|
||||||
|
|
||||||
|
|
||||||
class VmSizeOnDiskItem(QtGui.QTableWidgetItem):
|
class VmSizeOnDiskItem(QtGui.QTableWidgetItem):
|
||||||
def __init__(self, vm):
|
def __init__(self, vm):
|
||||||
super(VmSizeOnDiskItem, self).__init__()
|
super(VmSizeOnDiskItem, self).__init__()
|
||||||
@ -504,87 +466,15 @@ class VmSizeOnDiskItem(QtGui.QTableWidgetItem):
|
|||||||
return self.value < other.value
|
return self.value < other.value
|
||||||
|
|
||||||
|
|
||||||
class VmIPItem(QtGui.QTableWidgetItem):
|
class VmLastBackupItem(VMPropertyItem):
|
||||||
def __init__(self, vm):
|
def __init__(self, vm, property_name):
|
||||||
super(VmIPItem, self).__init__()
|
super(VmLastBackupItem, self).__init__(vm, property_name)
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
|
|
||||||
self.vm = vm
|
|
||||||
self.qid = vm.qid
|
|
||||||
self.name = vm.name
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
self.ip = getattr(self.vm, 'ip', None)
|
backup_timestamp = getattr(self.vm, 'backup_timestamp', None)
|
||||||
self.setText(self.ip if self.ip is not None else 'n/a')
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
if backup_timestamp:
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.ip == other.ip:
|
|
||||||
return self.name < other.name
|
|
||||||
return super(VmIPItem, self).__lt__(other)
|
|
||||||
|
|
||||||
|
|
||||||
class VmIncludeInBackupsItem(QtGui.QTableWidgetItem):
|
|
||||||
def __init__(self, vm):
|
|
||||||
super(VmIncludeInBackupsItem, self).__init__()
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
|
|
||||||
self.vm = vm
|
|
||||||
self.name = vm.name
|
|
||||||
self.qid = vm.qid
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
if getattr(self.vm, 'include_in_backups', None):
|
|
||||||
self.setText("Yes")
|
|
||||||
self.include_in_backups = True
|
|
||||||
else:
|
|
||||||
self.setText("")
|
|
||||||
self.include_in_backups = False
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.include_in_backups == other.include_in_backups:
|
|
||||||
return self.name < other.name
|
|
||||||
return self.include_in_backups < other.include_in_backups
|
|
||||||
|
|
||||||
|
|
||||||
class VmLastBackupItem(QtGui.QTableWidgetItem):
|
|
||||||
def __init__(self, vm):
|
|
||||||
super(VmLastBackupItem, self).__init__()
|
|
||||||
self.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled)
|
|
||||||
|
|
||||||
self.vm = vm
|
|
||||||
self.qid = vm.qid
|
|
||||||
self.name = vm.name
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
self.backup_timestamp = getattr(self.vm, 'backup_timestamp', None)
|
|
||||||
|
|
||||||
if self.backup_timestamp:
|
|
||||||
self.setText(
|
self.setText(
|
||||||
str(datetime.datetime.fromtimestamp(self.backup_timestamp)))
|
str(datetime.datetime.fromtimestamp(backup_timestamp)))
|
||||||
else:
|
else:
|
||||||
self.setText("")
|
self.setText("")
|
||||||
|
|
||||||
#pylint: disable=too-many-return-statements
|
|
||||||
def __lt__(self, other):
|
|
||||||
if self.qid == 0:
|
|
||||||
return True
|
|
||||||
if other.qid == 0:
|
|
||||||
return False
|
|
||||||
if self.backup_timestamp == other.backup_timestamp:
|
|
||||||
return self.name < other.name
|
|
||||||
if not self.backup_timestamp:
|
|
||||||
return False
|
|
||||||
if not other.backup_timestamp:
|
|
||||||
return True
|
|
||||||
return self.backup_timestamp < other.backup_timestamp
|
|
||||||
|
@ -226,7 +226,7 @@
|
|||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Backups</string>
|
<string>Include in backups</string>
|
||||||
</property>
|
</property>
|
||||||
</column>
|
</column>
|
||||||
<column>
|
<column>
|
||||||
|
Loading…
Reference in New Issue
Block a user