1.1 --- a/examples/Common/QtConfigurator/__init__.py Mon Oct 24 18:13:53 2005 +0000
1.2 +++ b/examples/Common/QtConfigurator/__init__.py Mon Oct 24 18:17:02 2005 +0000
1.3 @@ -1,5 +1,6 @@
1.4 import QtConfigurator.Forms
1.5 -#import factory
1.6 +import XSLForms.Prepare
1.7 +import factory
1.8 import qtui
1.9 import os
1.10
1.11 @@ -8,46 +9,54 @@
1.12 resource_dir = os.path.join(os.path.split(__file__)[0], "Resources")
1.13 ui_filename = os.path.join(resource_dir, "config.ui")
1.14 ui_hard_disks_filename = os.path.join(resource_dir, "config_hard_disks.ui")
1.15 + ui_memory_units_filename = os.path.join(resource_dir, "config_memory_units.ui")
1.16 + ui_storage_units_filename = os.path.join(resource_dir, "config_storage_units.ui")
1.17
1.18 def __init__(self, *args, **kw):
1.19 QtConfigurator.Forms.Configurator.__init__(self, *args, **kw)
1.20 - #self.factory = factory.Factory(self.ui_filename)
1.21 + self.factory = factory.Factory(self.ui_filename)
1.22 + XSLForms.Prepare.ensure_qt_fragment(self.ui_filename, self.ui_hard_disks_filename, "hard_disks")
1.23 + XSLForms.Prepare.ensure_qt_fragment(self.ui_filename, self.ui_memory_units_filename, "memory_units")
1.24 + XSLForms.Prepare.ensure_qt_fragment(self.ui_filename, self.ui_storage_units_filename, "storage_units")
1.25
1.26 def baseSystemChanged(self):
1.27 print self.base_system.currentItem()
1.28
1.29 def addHardDisk(self):
1.30 hard_disks = qtui.QWidgetFactory.create(self.ui_hard_disks_filename)
1.31 - print str(hard_disks.name())
1.32 - #top = qtui.QWidgetFactory.create(self.ui_filename)
1.33 - #print [str(c.name()) for c in top.children()]
1.34 - #hard_disks = top.child("hard_disks")
1.35 - print [str(c.name()) for c in hard_disks.children()]
1.36 tab_pages = hard_disks.child("tab pages")
1.37 - print [str(c.name()) for c in tab_pages.children()]
1.38 tab = tab_pages.child("tab")
1.39 self.hard_disks.addTab(tab, hard_disks.tabLabel(tab))
1.40 + self.factory.connect(tab, self)
1.41
1.42 def addMemoryUnit(self):
1.43 - print "configuration.addMemoryUnit(): Not implemented yet"
1.44 + memory_units = qtui.QWidgetFactory.create(self.ui_memory_units_filename)
1.45 + tab_pages = memory_units.child("tab pages")
1.46 + tab = tab_pages.child("tab")
1.47 + self.memory_units.addTab(tab, memory_units.tabLabel(tab))
1.48 + self.factory.connect(tab, self)
1.49
1.50 def addStorageUnit(self):
1.51 - print "configuration.addStorageUnit(): Not implemented yet"
1.52 + storage_units = qtui.QWidgetFactory.create(self.ui_storage_units_filename)
1.53 + tab_pages = storage_units.child("tab pages")
1.54 + tab = tab_pages.child("tab")
1.55 + self.storage_units.addTab(tab, storage_units.tabLabel(tab))
1.56 + self.factory.connect(tab, self)
1.57
1.58 def removeHardDisk(self):
1.59 page = self.hard_disks.currentPage()
1.60 self.hard_disks.removePage(page)
1.61 - del page
1.62 + page.deleteLater()
1.63
1.64 def removeMemoryUnit(self):
1.65 page = self.memory_units.currentPage()
1.66 self.memory_units.removePage(page)
1.67 - del page
1.68 + page.deleteLater()
1.69
1.70 def removeStorageUnit(self):
1.71 page = self.storage_units.currentPage()
1.72 self.storage_units.removePage(page)
1.73 - del page
1.74 + page.deleteLater()
1.75
1.76 def updateConfig(self):
1.77 print "configuration.updateConfig(): Not implemented yet"
2.1 --- a/examples/Common/QtConfigurator/factory.py Mon Oct 24 18:13:53 2005 +0000
2.2 +++ b/examples/Common/QtConfigurator/factory.py Mon Oct 24 18:17:02 2005 +0000
2.3 @@ -1,22 +1,56 @@
2.4 #!/usr/bin/env python
2.5
2.6 from qt import *
2.7 +import qtui
2.8 import qtxmldom
2.9
2.10 class Factory:
2.11 def __init__(self, ui_filename):
2.12 - self.ui = qtxmldom.parse(ui_filename)
2.13 + self.ui_filename = ui_filename
2.14 + self.ui_doc = qtxmldom.parse(ui_filename)
2.15 +
2.16 + def connect(self, widget, obj):
2.17 +
2.18 + for connection in self.ui_doc.getElementsByTagName("connection"):
2.19 + sender_name = self.get_text(connection.getElementsByTagName("sender")[0]).encode("utf-8")
2.20 + signal_name = self.get_text(connection.getElementsByTagName("signal")[0]).encode("utf-8")
2.21 + slot_name = self.get_text(connection.getElementsByTagName("slot")[0]).encode("utf-8")
2.22 +
2.23 + if widget.name() == sender_name:
2.24 + sender = widget
2.25 + else:
2.26 + sender = self.find_widget(widget, sender_name)
2.27 +
2.28 + if sender:
2.29 + signal = SIGNAL(signal_name)
2.30 + slot = slot_name.split("(")[0]
2.31 +
2.32 + if hasattr(obj, slot):
2.33 + QObject.connect(sender, signal, getattr(obj, slot))
2.34
2.35 - def findWidget(self, widget_class, name):
2.36 - for widget in self.ui.getElementsByTagName("widget"):
2.37 - if widget.getAttribute("class") == widget_class:
2.38 - for property in widget.getElementsByTagName("property"):
2.39 - if property.getAttribute("name") == "name":
2.40 - for cstring in property.getElementsByTagName("cstring"):
2.41 - cstring.normalize()
2.42 - found_name = cstring.childNodes[0].nodeValue
2.43 - if found_name == name:
2.44 - return widget
2.45 + def find_widget(self, widget, name):
2.46 + found = widget.child(name)
2.47 + if found:
2.48 + return found
2.49 + else:
2.50 + for child in widget.children():
2.51 + found = self.find_widget(child, name)
2.52 + if found:
2.53 + return found
2.54 + return None
2.55 +
2.56 + def get_text(self, node):
2.57 + node.normalize()
2.58 + return node.childNodes[0].nodeValue
2.59 +
2.60 + def find_widget_element(self, name):
2.61 + for widget in self.ui_doc.getElementsByTagName("widget"):
2.62 + for property in widget.getElementsByTagName("property"):
2.63 + if property.getAttribute("name") == "name":
2.64 + for cstring in property.getElementsByTagName("cstring"):
2.65 + found_name = self.get_text(cstring)
2.66 + if found_name == name:
2.67 + return widget
2.68 return None
2.69
2.70 # vim: tabstop=4 expandtab shiftwidth=4