Implemented CPU/MEM bars in place of graphs.
This commit is contained in:
parent
c1501f2ec9
commit
a2d6f8c9b3
@ -149,6 +149,50 @@ class VmInfoWidget (QWidget):
|
|||||||
def update_vm_state (self, vm):
|
def update_vm_state (self, vm):
|
||||||
self.vm_icon.update()
|
self.vm_icon.update()
|
||||||
|
|
||||||
|
class VmUsageWidget (QWidget):
|
||||||
|
def __init__(self, vm, parent = None):
|
||||||
|
super (VmUsageWidget, self).__init__(parent)
|
||||||
|
|
||||||
|
self.cpu_widget = QProgressBar()
|
||||||
|
self.mem_widget = QProgressBar()
|
||||||
|
self.cpu_widget.setMinimum(0)
|
||||||
|
self.cpu_widget.setMaximum(100)
|
||||||
|
self.mem_widget.setMinimum(0)
|
||||||
|
self.mem_widget.setMaximum(100)
|
||||||
|
self.cpu_label = QLabel("CPU")
|
||||||
|
self.mem_label = QLabel("MEM")
|
||||||
|
|
||||||
|
layout_cpu = QHBoxLayout()
|
||||||
|
layout_cpu.addWidget(self.cpu_label)
|
||||||
|
layout_cpu.addWidget(self.cpu_widget)
|
||||||
|
|
||||||
|
layout_mem = QHBoxLayout()
|
||||||
|
layout_mem.addWidget(self.mem_label)
|
||||||
|
layout_mem.addWidget(self.mem_widget)
|
||||||
|
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
layout.addLayout(layout_cpu)
|
||||||
|
layout.addLayout(layout_mem)
|
||||||
|
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
self.update_load(vm)
|
||||||
|
|
||||||
|
def update_load(self, vm):
|
||||||
|
self.cpu_load = vm.get_cpu_total_load() if vm.is_running() else 0
|
||||||
|
assert self.cpu_load >= 0 and self.cpu_load <= 100, "load = {0}".format(self.load)
|
||||||
|
self.mem_load = vm.get_mem()*100/qubes_host.memory_total if vm.is_running() else 0
|
||||||
|
assert self.mem_load >= 0 and self.mem_load <= 100, "mem = {0}".format(self.load)
|
||||||
|
|
||||||
|
self.cpu_widget.setValue(self.cpu_load)
|
||||||
|
self.mem_widget.setValue(self.mem_load)
|
||||||
|
|
||||||
|
def resizeEvent(self, Event = None):
|
||||||
|
label_width = max(self.mem_label.width(), self.cpu_label.width())
|
||||||
|
self.mem_label.setMinimumWidth(label_width)
|
||||||
|
self.cpu_label.setMinimumWidth(label_width)
|
||||||
|
super (VmUsageWidget, self).resizeEvent(Event)
|
||||||
|
|
||||||
class LoadChartWidget (QWidget):
|
class LoadChartWidget (QWidget):
|
||||||
|
|
||||||
def __init__(self, vm, parent = None):
|
def __init__(self, vm, parent = None):
|
||||||
@ -239,16 +283,20 @@ class VmRowInTable(object):
|
|||||||
self.info_widget = VmInfoWidget(vm)
|
self.info_widget = VmInfoWidget(vm)
|
||||||
table.setCellWidget(row_no, 0, self.info_widget)
|
table.setCellWidget(row_no, 0, self.info_widget)
|
||||||
|
|
||||||
|
self.usage_widget = VmUsageWidget(vm)
|
||||||
|
table.setCellWidget(row_no, 1, self.usage_widget)
|
||||||
|
|
||||||
self.load_widget = LoadChartWidget(vm)
|
self.load_widget = LoadChartWidget(vm)
|
||||||
table.setCellWidget(row_no, 1, self.load_widget)
|
table.setCellWidget(row_no, 2, self.load_widget)
|
||||||
|
|
||||||
self.mem_widget = MemChartWidget(vm)
|
self.mem_widget = MemChartWidget(vm)
|
||||||
table.setCellWidget(row_no, 2, self.mem_widget)
|
table.setCellWidget(row_no, 3, self.mem_widget)
|
||||||
|
|
||||||
|
|
||||||
def update(self, counter):
|
def update(self, counter):
|
||||||
self.info_widget.update_vm_state(self.vm)
|
self.info_widget.update_vm_state(self.vm)
|
||||||
if counter % 3 == 0:
|
if counter % 3 == 0:
|
||||||
|
self.usage_widget.update_load(self.vm)
|
||||||
self.load_widget.update_load(self.vm)
|
self.load_widget.update_load(self.vm)
|
||||||
self.mem_widget.update_load(self.vm)
|
self.mem_widget.update_load(self.vm)
|
||||||
|
|
||||||
@ -296,11 +344,12 @@ class ThreadMonitor(QObject):
|
|||||||
|
|
||||||
|
|
||||||
class VmManagerWindow(QMainWindow):
|
class VmManagerWindow(QMainWindow):
|
||||||
columns_widths = [200, 150, 150]
|
columns_widths = [200, 200, 150, 150]
|
||||||
row_height = 50
|
row_height = 50
|
||||||
max_visible_rows = 14
|
max_visible_rows = 14
|
||||||
update_interval = 1000 # in msec
|
update_interval = 1000 # in msec
|
||||||
show_inactive_vms = True
|
show_inactive_vms = True
|
||||||
|
columns_states = { 0: [0, 1], 1: [0, 2, 3] }
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super(VmManagerWindow, self).__init__(parent)
|
super(VmManagerWindow, self).__init__(parent)
|
||||||
@ -340,8 +389,6 @@ class VmManagerWindow(QMainWindow):
|
|||||||
self.action_shutdownvm.setDisabled(True)
|
self.action_shutdownvm.setDisabled(True)
|
||||||
self.action_updatevm.setDisabled(True)
|
self.action_updatevm.setDisabled(True)
|
||||||
|
|
||||||
self.action_showcpuload.setDisabled(True)
|
|
||||||
|
|
||||||
self.toolbar = self.addToolBar ("Toolbar")
|
self.toolbar = self.addToolBar ("Toolbar")
|
||||||
self.toolbar.setFloatable(False)
|
self.toolbar.setFloatable(False)
|
||||||
self.addActions (self.toolbar, (self.action_createvm, self.action_removevm,
|
self.addActions (self.toolbar, (self.action_createvm, self.action_removevm,
|
||||||
@ -359,26 +406,27 @@ class VmManagerWindow(QMainWindow):
|
|||||||
for (col, width) in enumerate (VmManagerWindow.columns_widths):
|
for (col, width) in enumerate (VmManagerWindow.columns_widths):
|
||||||
self.table.setColumnWidth (col, width)
|
self.table.setColumnWidth (col, width)
|
||||||
|
|
||||||
self.table.horizontalHeader().setStretchLastSection(True)
|
self.table.horizontalHeader().setResizeMode(QHeaderView.Stretch)
|
||||||
|
self.table.horizontalHeader().setResizeMode(0, QHeaderView.Fixed)
|
||||||
self.table.setAlternatingRowColors(True)
|
self.table.setAlternatingRowColors(True)
|
||||||
self.table.verticalHeader().hide()
|
self.table.verticalHeader().hide()
|
||||||
self.table.horizontalHeader().hide()
|
self.table.horizontalHeader().hide()
|
||||||
#self.table.setHorizontalHeaderLabels (["VM name & state", "CPU Load", "Memory Use"])
|
|
||||||
self.table.setGridStyle(Qt.NoPen)
|
self.table.setGridStyle(Qt.NoPen)
|
||||||
self.table.setSortingEnabled(False)
|
self.table.setSortingEnabled(False)
|
||||||
self.table.setSelectionBehavior(QTableWidget.SelectRows)
|
self.table.setSelectionBehavior(QTableWidget.SelectRows)
|
||||||
self.table.setSelectionMode(QTableWidget.SingleSelection)
|
self.table.setSelectionMode(QTableWidget.SingleSelection)
|
||||||
|
|
||||||
|
self.__cpugraphs = self.action_showcpuload.isChecked()
|
||||||
|
self.update_table_columns()
|
||||||
|
|
||||||
self.qvm_collection = QubesVmCollection()
|
self.qvm_collection = QubesVmCollection()
|
||||||
self.setWindowTitle("Qubes VM Manager")
|
self.setWindowTitle("Qubes VM Manager")
|
||||||
|
|
||||||
self.connect(self.table, SIGNAL("itemSelectionChanged()"), self.table_selection_changed)
|
self.connect(self.table, SIGNAL("itemSelectionChanged()"), self.table_selection_changed)
|
||||||
|
|
||||||
self.fill_table()
|
self.fill_table()
|
||||||
|
|
||||||
tbl_W = 0
|
tbl_W = self.get_minimum_table_width()
|
||||||
for (i, w) in enumerate(VmManagerWindow.columns_widths):
|
|
||||||
tbl_W += w
|
|
||||||
|
|
||||||
# TODO: '6' -- WTF?!
|
# TODO: '6' -- WTF?!
|
||||||
tbl_H = self.toolbar.height() + 6 + \
|
tbl_H = self.toolbar.height() + 6 + \
|
||||||
@ -390,7 +438,6 @@ class VmManagerWindow(QMainWindow):
|
|||||||
for i in range (0, n):
|
for i in range (0, n):
|
||||||
tbl_H += self.table.rowHeight(i)
|
tbl_H += self.table.rowHeight(i)
|
||||||
|
|
||||||
self.setMinimumWidth(tbl_W)
|
|
||||||
self.setGeometry(self.x(), self.y(), self.x() + tbl_W, self.y() + tbl_H)
|
self.setGeometry(self.x(), self.y(), self.x() + tbl_W, self.y() + tbl_H)
|
||||||
|
|
||||||
self.counter = 0
|
self.counter = 0
|
||||||
@ -487,6 +534,15 @@ class VmManagerWindow(QMainWindow):
|
|||||||
self.counter += 1
|
self.counter += 1
|
||||||
QTimer.singleShot (self.update_interval, self.update_table)
|
QTimer.singleShot (self.update_interval, self.update_table)
|
||||||
|
|
||||||
|
def update_table_columns(self):
|
||||||
|
state = 1 if self.__cpugraphs else 0
|
||||||
|
columns = self.columns_states[state]
|
||||||
|
|
||||||
|
for i in range(0, self.table.columnCount()):
|
||||||
|
enabled = columns.count(i) > 0
|
||||||
|
self.table.setColumnHidden(i, not enabled)
|
||||||
|
|
||||||
|
self.setMinimumWidth(self.get_minimum_table_width())
|
||||||
|
|
||||||
def table_selection_changed (self):
|
def table_selection_changed (self):
|
||||||
vm = self.get_selected_vm()
|
vm = self.get_selected_vm()
|
||||||
@ -499,6 +555,14 @@ class VmManagerWindow(QMainWindow):
|
|||||||
self.action_shutdownvm.setEnabled(vm.is_running() and vm.qid != 0)
|
self.action_shutdownvm.setEnabled(vm.is_running() and vm.qid != 0)
|
||||||
self.action_editfwrules.setEnabled(vm.is_networked() and (vm.is_appvm() or vm.is_disposablevm()))
|
self.action_editfwrules.setEnabled(vm.is_networked() and (vm.is_appvm() or vm.is_disposablevm()))
|
||||||
|
|
||||||
|
def get_minimum_table_width(self):
|
||||||
|
tbl_W = 0
|
||||||
|
for (col, w) in enumerate(VmManagerWindow.columns_widths):
|
||||||
|
if not self.table.isColumnHidden(col):
|
||||||
|
tbl_W += w
|
||||||
|
|
||||||
|
return tbl_W
|
||||||
|
|
||||||
def closeEvent (self, event):
|
def closeEvent (self, event):
|
||||||
self.hide()
|
self.hide()
|
||||||
event.ignore()
|
event.ignore()
|
||||||
@ -689,7 +753,8 @@ class VmManagerWindow(QMainWindow):
|
|||||||
QTimer.singleShot (vm_shutdown_timeout, self.shutdown_monitor[vm.qid].check_if_vm_has_shutdown)
|
QTimer.singleShot (vm_shutdown_timeout, self.shutdown_monitor[vm.qid].check_if_vm_has_shutdown)
|
||||||
|
|
||||||
def showcpuload(self):
|
def showcpuload(self):
|
||||||
pass
|
self.__cpugraphs = self.action_showcpuload.isChecked()
|
||||||
|
self.update_table_columns()
|
||||||
|
|
||||||
def edit_fw_rules(self):
|
def edit_fw_rules(self):
|
||||||
vm = self.get_selected_vm()
|
vm = self.get_selected_vm()
|
||||||
|
Loading…
Reference in New Issue
Block a user