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