XSLTools

examples/Common/QtConfigurator/__init__.py

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