1.1 --- a/examples/Common/QtConfigurator/factory.py Tue Oct 25 15:52:43 2005 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,53 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -from qt import *
1.7 -import qtui
1.8 -import qtxmldom
1.9 -
1.10 -class Factory:
1.11 - def __init__(self, ui_filename):
1.12 - self.ui_filename = ui_filename
1.13 - self.ui_doc = qtxmldom.parse(ui_filename)
1.14 -
1.15 - def connect(self, widget, obj):
1.16 -
1.17 - for connection in self.ui_doc.getElementsByTagName("connection"):
1.18 - sender_name = self.get_text(connection.getElementsByTagName("sender")[0]).encode("utf-8")
1.19 - signal_name = self.get_text(connection.getElementsByTagName("signal")[0]).encode("utf-8")
1.20 - slot_name = self.get_text(connection.getElementsByTagName("slot")[0]).encode("utf-8")
1.21 -
1.22 - if widget.name() == sender_name:
1.23 - senders = [widget]
1.24 - else:
1.25 - senders = self.find_widgets(widget, sender_name)
1.26 -
1.27 - slot = slot_name.split("(")[0]
1.28 - if hasattr(obj, slot):
1.29 - signal = SIGNAL(signal_name)
1.30 - for sender in senders:
1.31 - QObject.connect(sender, signal, getattr(obj, slot))
1.32 -
1.33 - def find_widgets(self, widget, name):
1.34 - widgets = []
1.35 - found = widget.child(name)
1.36 - if found:
1.37 - widgets.append(found)
1.38 - for child in widget.children():
1.39 - widgets += self.find_widgets(child, name)
1.40 - return widgets
1.41 -
1.42 - def get_text(self, node):
1.43 - node.normalize()
1.44 - return node.childNodes[0].nodeValue
1.45 -
1.46 - def find_widget_element(self, name):
1.47 - for widget in self.ui_doc.getElementsByTagName("widget"):
1.48 - for property in widget.getElementsByTagName("property"):
1.49 - if property.getAttribute("name") == "name":
1.50 - for cstring in property.getElementsByTagName("cstring"):
1.51 - found_name = self.get_text(cstring)
1.52 - if found_name == name:
1.53 - return widget
1.54 - return None
1.55 -
1.56 -# vim: tabstop=4 expandtab shiftwidth=4