1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/XSLForms/Resources/PyQtWebResources.py Wed Oct 26 00:37:36 2005 +0000
1.3 @@ -0,0 +1,95 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +PyQt-compatible resources for use with WebStack.
1.8 +
1.9 +Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This library is free software; you can redistribute it and/or
1.12 +modify it under the terms of the GNU Lesser General Public
1.13 +License as published by the Free Software Foundation; either
1.14 +version 2.1 of the License, or (at your option) any later version.
1.15 +
1.16 +This library is distributed in the hope that it will be useful,
1.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.19 +Lesser General Public License for more details.
1.20 +
1.21 +You should have received a copy of the GNU Lesser General Public
1.22 +License along with this library; if not, write to the Free Software
1.23 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1.24 +"""
1.25 +
1.26 +import XSLForms.Prepare
1.27 +import XSLForms.Resources.Common
1.28 +import XSLForms.Resources.WebResources
1.29 +import os
1.30 +import libxml2dom
1.31 +
1.32 +class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource):
1.33 +
1.34 + """
1.35 + An XSLForms resource supporting PyQt-compatible Web applications for use
1.36 + with WebStack.
1.37 + """
1.38 +
1.39 + widget_resources = {}
1.40 +
1.41 + def get_document(self, document_identifier):
1.42 + return libxml2dom.parse(self.prepare_document(document_identifier))
1.43 +
1.44 + def prepare_widget(self, design_identifier, widget_identifier, parent=None):
1.45 + design_path = self.prepare_design(design_identifier)
1.46 + fragment_name, widget_name = self.widget_resources[widget_identifier]
1.47 + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name))
1.48 + XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name)
1.49 + # NOTE: Implement the equivalent here!
1.50 + return qtui.QWidgetFactory.create(fragment_path, None, parent)
1.51 +
1.52 + def populate_list(self, field, elements):
1.53 + # NOTE: Support this!
1.54 + current_text = field.currentText()
1.55 + while field.count() > 0:
1.56 + field.removeItem(0)
1.57 + item = 0
1.58 + set = 0
1.59 + for element in elements:
1.60 + text = element.getAttribute("value")
1.61 + field.insertItem(text)
1.62 + if text == current_text:
1.63 + field.setCurrentItem(item)
1.64 + set = 1
1.65 + item += 1
1.66 + if not set:
1.67 + field.setCurrentItem(0)
1.68 +
1.69 + def reset_collection(self, field):
1.70 + # NOTE: Support this!
1.71 + layout = field.layout()
1.72 + for child in field.children():
1.73 + if child is not layout:
1.74 + layout.remove(child)
1.75 + child.deleteLater()
1.76 +
1.77 +class Factory:
1.78 +
1.79 + "A widget factory helper class."
1.80 +
1.81 + def __init__(self, ui_filename):
1.82 + self.ui_filename = ui_filename
1.83 + self.ui_doc = libxml2dom.parse(ui_filename)
1.84 +
1.85 + def connect(self, widget, obj):
1.86 + pass
1.87 +
1.88 + def find_widgets(self, widget, name):
1.89 + # NOTE: Support this!
1.90 + widgets = []
1.91 + found = widget.child(name)
1.92 + if found:
1.93 + widgets.append(found)
1.94 + for child in widget.children():
1.95 + widgets += self.find_widgets(child, name)
1.96 + return widgets
1.97 +
1.98 +# vim: tabstop=4 expandtab shiftwidth=4