1.1 --- a/XSLForms/Resources/PyQtResources.py Sun Oct 12 19:28:30 2008 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,88 +0,0 @@
1.4 -#!/usr/bin/env python
1.5 -
1.6 -"""
1.7 -Resources for use with PyQt.
1.8 -
1.9 -Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
1.10 -
1.11 -This program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU Lesser General Public License as published by the Free
1.13 -Software Foundation; either version 3 of the License, or (at your option) any
1.14 -later version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.19 -details.
1.20 -
1.21 -You should have received a copy of the GNU Lesser General Public License along
1.22 -with this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -"""
1.24 -
1.25 -import XSLForms.Prepare
1.26 -import XSLForms.Resources.PyQtCommon
1.27 -import qt, qtui, qtxmldom
1.28 -import os
1.29 -
1.30 -class XSLFormsResource(XSLForms.Resources.PyQtCommon.PyQtCommonResource):
1.31 -
1.32 - "An XSLForms resource for use with PyQt."
1.33 -
1.34 - widget_resources = {}
1.35 -
1.36 - def __init__(self, design_identifier):
1.37 - self.factory = Factory(self.prepare_design(design_identifier))
1.38 -
1.39 - def get_document(self, document_identifier):
1.40 - return qtxmldom.parse(self.prepare_document(document_identifier))
1.41 -
1.42 - def prepare_widget(self, design_identifier, widget_identifier, parent=None):
1.43 - design_path = self.prepare_design(design_identifier)
1.44 - fragment_name, widget_name = self.widget_resources[widget_identifier]
1.45 - fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name))
1.46 - XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name)
1.47 - return qtui.QWidgetFactory.create(fragment_path, None, parent)
1.48 -
1.49 - def request_refresh(self, *kw, **args):
1.50 - self.form_refresh(*kw, **args)
1.51 -
1.52 -class Factory:
1.53 -
1.54 - "A widget factory helper class."
1.55 -
1.56 - def __init__(self, ui_filename):
1.57 - self.ui_filename = ui_filename
1.58 - self.ui_doc = qtxmldom.parse(ui_filename)
1.59 -
1.60 - def connect(self, widget, obj):
1.61 -
1.62 - for connection in self.ui_doc.getElementsByTagName("connection"):
1.63 - sender_name = self.get_text(connection.getElementsByTagName("sender")[0]).encode("utf-8")
1.64 - signal_name = self.get_text(connection.getElementsByTagName("signal")[0]).encode("utf-8")
1.65 - slot_name = self.get_text(connection.getElementsByTagName("slot")[0]).encode("utf-8")
1.66 -
1.67 - if widget.name() == sender_name:
1.68 - senders = [widget]
1.69 - else:
1.70 - senders = self.find_widgets(widget, sender_name)
1.71 -
1.72 - slot = slot_name.split("(")[0]
1.73 - if hasattr(obj, slot):
1.74 - signal = qt.SIGNAL(signal_name)
1.75 - for sender in senders:
1.76 - qt.QObject.connect(sender, signal, getattr(obj, slot))
1.77 -
1.78 - def get_text(self, node):
1.79 - node.normalize()
1.80 - return node.childNodes[0].nodeValue
1.81 -
1.82 - def find_widgets(self, widget, name):
1.83 - widgets = []
1.84 - found = widget.child(name)
1.85 - if found:
1.86 - widgets.append(found)
1.87 - for child in widget.children() or []:
1.88 - widgets += self.find_widgets(child, name)
1.89 - return widgets
1.90 -
1.91 -# vim: tabstop=4 expandtab shiftwidth=4