paulb@342 | 1 | #!/usr/bin/env python |
paulb@342 | 2 | |
paulb@349 | 3 | import XSLForms.PyQt |
paulb@332 | 4 | import QtConfigurator.Forms |
paulb@332 | 5 | import os |
paulb@332 | 6 | |
paulb@349 | 7 | class Configurator(QtConfigurator.Forms.Configurator, XSLForms.PyQt.XSLFormsResource): |
paulb@332 | 8 | |
paulb@342 | 9 | # Standard attributes. |
paulb@342 | 10 | |
paulb@332 | 11 | resource_dir = os.path.join(os.path.split(__file__)[0], "Resources") |
paulb@342 | 12 | |
paulb@342 | 13 | template_resources = { |
paulb@342 | 14 | "configuration" : "config.ui" |
paulb@342 | 15 | } |
paulb@342 | 16 | |
paulb@342 | 17 | widget_resources = { |
paulb@345 | 18 | "hard-disk" : ("config_hard_disk.ui", "hard_disk"), |
paulb@345 | 19 | "memory-unit" : ("config_memory_unit.ui", "memory_unit"), |
paulb@345 | 20 | "storage-unit" : ("config_storage_unit.ui", "storage_unit") |
paulb@345 | 21 | #"hard-disks" : ("config_hard_disks.ui", "hard_disks"), |
paulb@345 | 22 | #"memory-units" : ("config_memory_units.ui", "memory_units"), |
paulb@345 | 23 | #"storage-units" : ("config_storage_units.ui", "storage_units") |
paulb@342 | 24 | } |
paulb@342 | 25 | |
paulb@342 | 26 | document_resources = { |
paulb@342 | 27 | "base-system" : "config_base_system.xml", |
paulb@342 | 28 | "cpu" : "config_cpu.xml", |
paulb@342 | 29 | "hard-disk" : "config_hard_disk.xml", |
paulb@342 | 30 | "keyboard" : "config_keyboard.xml", |
paulb@342 | 31 | "mouse" : "config_mouse.xml", |
paulb@342 | 32 | "screen" : "config_screen.xml" |
paulb@342 | 33 | } |
paulb@342 | 34 | |
paulb@342 | 35 | # Initialisation. |
paulb@332 | 36 | |
paulb@332 | 37 | def __init__(self, *args, **kw): |
paulb@332 | 38 | QtConfigurator.Forms.Configurator.__init__(self, *args, **kw) |
paulb@349 | 39 | self.factory = XSLForms.PyQt.Factory(self.prepare_template("configuration")) |
paulb@342 | 40 | |
paulb@342 | 41 | # Get field data. |
paulb@342 | 42 | # NOTE: This would be done for whole page updates in a Web application. |
paulb@342 | 43 | |
paulb@342 | 44 | self.populate_list(self.base_system, self.get_elements("base-system")) |
paulb@342 | 45 | self.populate_list(self.keyboard, self.get_elements("keyboard")) |
paulb@342 | 46 | self.populate_list(self.mouse, self.get_elements("mouse")) |
paulb@342 | 47 | self.populate_list(self.screen, self.get_elements("screen")) |
paulb@342 | 48 | |
paulb@342 | 49 | # General functionality. |
paulb@342 | 50 | |
paulb@342 | 51 | def refresh(self, current_text=None): |
paulb@342 | 52 | |
paulb@342 | 53 | # Ensure consistency. |
paulb@342 | 54 | # NOTE: This would be done for whole page updates in a Web application. |
paulb@342 | 55 | # NOTE: This would also be done for page updates where the information |
paulb@342 | 56 | # NOTE: involved was important. |
paulb@342 | 57 | |
paulb@342 | 58 | current_text = current_text or self.base_system.currentText() |
paulb@332 | 59 | |
paulb@342 | 60 | # Find the CPU socket and the interface of the current base system. |
paulb@342 | 61 | cpu_socket = None |
paulb@342 | 62 | interface = None |
paulb@342 | 63 | for element in self.get_elements("base-system"): |
paulb@342 | 64 | text = element.getAttribute("value") |
paulb@342 | 65 | if text == current_text: |
paulb@342 | 66 | cpu_socket = element.getAttribute("cpu-socket") |
paulb@342 | 67 | interface = element.getAttribute("interface") |
paulb@342 | 68 | |
paulb@342 | 69 | # Find all valid CPUs. |
paulb@342 | 70 | valid = [] |
paulb@342 | 71 | for element in self.get_elements("cpu"): |
paulb@342 | 72 | if not element.hasAttribute("cpu-socket") or element.getAttribute("cpu-socket") == cpu_socket: |
paulb@342 | 73 | valid.append(element) |
paulb@342 | 74 | self.populate_list(self.cpu, valid) |
paulb@342 | 75 | |
paulb@342 | 76 | # Find all valid hard disks. |
paulb@342 | 77 | valid = [] |
paulb@342 | 78 | for element in self.get_elements("hard-disk"): |
paulb@342 | 79 | if not element.hasAttribute("interface") or element.getAttribute("interface") == interface: |
paulb@342 | 80 | valid.append(element) |
paulb@342 | 81 | for hard_disk_value in self.factory.find_widgets(self, "hard_disk_value"): |
paulb@342 | 82 | self.populate_list(hard_disk_value, valid) |
paulb@342 | 83 | |
paulb@342 | 84 | # Slots. |
paulb@342 | 85 | |
paulb@342 | 86 | def baseSystemChanged(self, current_text): |
paulb@342 | 87 | self.refresh(current_text) |
paulb@332 | 88 | |
paulb@332 | 89 | def addHardDisk(self): |
paulb@345 | 90 | #hard_disks = self.prepare_widget("configuration", "hard-disks") |
paulb@345 | 91 | #tab_pages = hard_disks.child("tab pages") |
paulb@345 | 92 | #tab = tab_pages.child("tab") |
paulb@345 | 93 | #self.hard_disks.addTab(tab, hard_disks.tabLabel(tab)) |
paulb@345 | 94 | #self.factory.connect(tab, self) |
paulb@345 | 95 | hard_disk = self.prepare_widget("configuration", "hard-disk", self.hard_disks) |
paulb@345 | 96 | self.hard_disks.layout().add(hard_disk) |
paulb@345 | 97 | hard_disk.show() |
paulb@345 | 98 | self.factory.connect(hard_disk, self) |
paulb@332 | 99 | |
paulb@342 | 100 | # Perform the consistency check. |
paulb@342 | 101 | # NOTE: This is not as efficient as it could be since the general check |
paulb@342 | 102 | # NOTE: refreshes all fields, not just newly added ones. |
paulb@342 | 103 | self.refresh() |
paulb@342 | 104 | |
paulb@332 | 105 | def addMemoryUnit(self): |
paulb@345 | 106 | #memory_units = self.prepare_widget("configuration", "memory-units") |
paulb@345 | 107 | #tab_pages = memory_units.child("tab pages") |
paulb@345 | 108 | #tab = tab_pages.child("tab") |
paulb@345 | 109 | #self.memory_units.addTab(tab, memory_units.tabLabel(tab)) |
paulb@345 | 110 | #self.factory.connect(tab, self) |
paulb@345 | 111 | memory_unit = self.prepare_widget("configuration", "memory-unit", self.memory_units) |
paulb@345 | 112 | self.memory_units.layout().add(memory_unit) |
paulb@345 | 113 | memory_unit.show() |
paulb@345 | 114 | self.factory.connect(memory_unit, self) |
paulb@332 | 115 | |
paulb@342 | 116 | # Perform the consistency check. |
paulb@342 | 117 | # NOTE: This is not as efficient as it could be since the general check |
paulb@342 | 118 | # NOTE: refreshes all fields, not just newly added ones. |
paulb@342 | 119 | self.refresh() |
paulb@342 | 120 | |
paulb@332 | 121 | def addStorageUnit(self): |
paulb@345 | 122 | #storage_units = self.prepare_widget("configuration", "storage-units") |
paulb@345 | 123 | #tab_pages = storage_units.child("tab pages") |
paulb@345 | 124 | #tab = tab_pages.child("tab") |
paulb@345 | 125 | #self.storage_units.addTab(tab, storage_units.tabLabel(tab)) |
paulb@345 | 126 | #self.factory.connect(tab, self) |
paulb@345 | 127 | storage_unit = self.prepare_widget("configuration", "storage-unit", self.storage_units) |
paulb@345 | 128 | self.storage_units.layout().add(storage_unit) |
paulb@345 | 129 | storage_unit.show() |
paulb@345 | 130 | self.factory.connect(storage_unit, self) |
paulb@332 | 131 | |
paulb@342 | 132 | # Perform the consistency check. |
paulb@342 | 133 | # NOTE: This is not as efficient as it could be since the general check |
paulb@342 | 134 | # NOTE: refreshes all fields, not just newly added ones. |
paulb@342 | 135 | self.refresh() |
paulb@342 | 136 | |
paulb@332 | 137 | def removeHardDisk(self): |
paulb@345 | 138 | #page = self.hard_disks.currentPage() |
paulb@345 | 139 | #self.hard_disks.removePage(page) |
paulb@345 | 140 | #page.deleteLater() |
paulb@345 | 141 | remove_hard_disk = self.sender() |
paulb@345 | 142 | hard_disk = remove_hard_disk.parent() |
paulb@345 | 143 | self.hard_disks.layout().remove(hard_disk) |
paulb@345 | 144 | hard_disk.deleteLater() |
paulb@332 | 145 | |
paulb@332 | 146 | def removeMemoryUnit(self): |
paulb@345 | 147 | #page = self.memory_units.currentPage() |
paulb@345 | 148 | #self.memory_units.removePage(page) |
paulb@345 | 149 | #page.deleteLater() |
paulb@345 | 150 | remove_memory_unit = self.sender() |
paulb@345 | 151 | memory_unit = remove_memory_unit.parent() |
paulb@345 | 152 | self.memory_units.layout().remove(memory_unit) |
paulb@345 | 153 | memory_unit.deleteLater() |
paulb@332 | 154 | |
paulb@332 | 155 | def removeStorageUnit(self): |
paulb@345 | 156 | #page = self.storage_units.currentPage() |
paulb@345 | 157 | #self.storage_units.removePage(page) |
paulb@345 | 158 | #page.deleteLater() |
paulb@345 | 159 | remove_storage_unit = self.sender() |
paulb@345 | 160 | storage_unit = remove_storage_unit.parent() |
paulb@345 | 161 | self.storage_units.layout().remove(storage_unit) |
paulb@345 | 162 | storage_unit.deleteLater() |
paulb@332 | 163 | |
paulb@332 | 164 | def updateConfig(self): |
paulb@342 | 165 | self.refresh() |
paulb@332 | 166 | |
paulb@332 | 167 | def exportConfig(self): |
paulb@332 | 168 | print "configuration.exportConfig(): Not implemented yet" |
paulb@332 | 169 | |
paulb@332 | 170 | # vim: tabstop=4 expandtab shiftwidth=4 |