1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/XSLForms/Resources/Common.py Wed Oct 26 00:37:36 2005 +0000
1.3 @@ -0,0 +1,61 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Common resource class functionality.
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 os
1.27 +
1.28 +class CommonResource:
1.29 +
1.30 + "Common resource methods."
1.31 +
1.32 + document_resources = {}
1.33 + resource_dir = None
1.34 +
1.35 + def prepare_document(self, document_identifier):
1.36 +
1.37 + """
1.38 + Prepare a document using the given 'document_identifier'.
1.39 +
1.40 + Return the full path of the document for use either as the source
1.41 + document or as a reference with 'send_output' or 'get_result'.
1.42 + """
1.43 +
1.44 + filename = self.document_resources[document_identifier]
1.45 + return os.path.abspath(os.path.join(self.resource_dir, filename))
1.46 +
1.47 +class PyQtCommonResource(CommonResource):
1.48 +
1.49 + "Common PyQt-compatible resource methods."
1.50 +
1.51 + design_resources = {}
1.52 +
1.53 + def get_document(self, document_identifier):
1.54 + raise NotImplementedError, "get_document"
1.55 +
1.56 + def get_elements(self, document_identifier):
1.57 + doc = self.get_document(document_identifier)
1.58 + return doc.getElementsByTagName(document_identifier + "-enum")
1.59 +
1.60 + def prepare_design(self, design_identifier):
1.61 + filename = self.design_resources[design_identifier]
1.62 + return os.path.abspath(os.path.join(self.resource_dir, filename))
1.63 +
1.64 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- a/XSLForms/Resources/PyQtResources.py Wed Oct 26 00:07:09 2005 +0000
2.2 +++ b/XSLForms/Resources/PyQtResources.py Wed Oct 26 00:37:36 2005 +0000
2.3 @@ -1,42 +1,44 @@
2.4 #!/usr/bin/env python
2.5
2.6 +"""
2.7 +Resources for use with PyQt.
2.8 +
2.9 +Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
2.10 +
2.11 +This library is free software; you can redistribute it and/or
2.12 +modify it under the terms of the GNU Lesser General Public
2.13 +License as published by the Free Software Foundation; either
2.14 +version 2.1 of the License, or (at your option) any later version.
2.15 +
2.16 +This library is distributed in the hope that it will be useful,
2.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
2.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2.19 +Lesser General Public License for more details.
2.20 +
2.21 +You should have received a copy of the GNU Lesser General Public
2.22 +License along with this library; if not, write to the Free Software
2.23 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2.24 +"""
2.25 +
2.26 import XSLForms.Prepare
2.27 -import qt
2.28 -import qtui
2.29 -import qtxmldom
2.30 +import XSLForms.Resources.Common
2.31 +import qt, qtui, qtxmldom
2.32 import os
2.33
2.34 -class XSLFormsResource:
2.35 +class XSLFormsResource(XSLForms.Resources.Common.PyQtCommonResource):
2.36
2.37 "An XSLForms resource for use with PyQt."
2.38
2.39 - template_resources = {}
2.40 widget_resources = {}
2.41 - document_resources = {}
2.42 -
2.43 - # Helper methods.
2.44 - # NOTE: Should be moved to a superclass.
2.45 -
2.46 - def prepare_document(self, document_identifier):
2.47 - filename = self.document_resources[document_identifier]
2.48 - return os.path.abspath(os.path.join(self.resource_dir, filename))
2.49
2.50 def get_document(self, document_identifier):
2.51 return qtxmldom.parse(self.prepare_document(document_identifier))
2.52
2.53 - def get_elements(self, document_identifier):
2.54 - doc = self.get_document(document_identifier)
2.55 - return doc.getElementsByTagName(document_identifier + "-enum")
2.56 -
2.57 - def prepare_template(self, template_identifier):
2.58 - filename = self.template_resources[template_identifier]
2.59 - return os.path.abspath(os.path.join(self.resource_dir, filename))
2.60 -
2.61 - def prepare_widget(self, template_identifier, widget_identifier, parent=None):
2.62 - template_path = self.prepare_template(template_identifier)
2.63 + def prepare_widget(self, design_identifier, widget_identifier, parent=None):
2.64 + design_path = self.prepare_design(design_identifier)
2.65 fragment_name, widget_name = self.widget_resources[widget_identifier]
2.66 fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name))
2.67 - XSLForms.Prepare.ensure_qt_fragment(template_path, fragment_path, widget_name)
2.68 + XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name)
2.69 return qtui.QWidgetFactory.create(fragment_path, None, parent)
2.70
2.71 def populate_list(self, field, elements):
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/XSLForms/Resources/PyQtWebResources.py Wed Oct 26 00:37:36 2005 +0000
3.3 @@ -0,0 +1,95 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +PyQt-compatible resources for use with WebStack.
3.8 +
3.9 +Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk>
3.10 +
3.11 +This library is free software; you can redistribute it and/or
3.12 +modify it under the terms of the GNU Lesser General Public
3.13 +License as published by the Free Software Foundation; either
3.14 +version 2.1 of the License, or (at your option) any later version.
3.15 +
3.16 +This library is distributed in the hope that it will be useful,
3.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
3.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3.19 +Lesser General Public License for more details.
3.20 +
3.21 +You should have received a copy of the GNU Lesser General Public
3.22 +License along with this library; if not, write to the Free Software
3.23 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
3.24 +"""
3.25 +
3.26 +import XSLForms.Prepare
3.27 +import XSLForms.Resources.Common
3.28 +import XSLForms.Resources.WebResources
3.29 +import os
3.30 +import libxml2dom
3.31 +
3.32 +class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource):
3.33 +
3.34 + """
3.35 + An XSLForms resource supporting PyQt-compatible Web applications for use
3.36 + with WebStack.
3.37 + """
3.38 +
3.39 + widget_resources = {}
3.40 +
3.41 + def get_document(self, document_identifier):
3.42 + return libxml2dom.parse(self.prepare_document(document_identifier))
3.43 +
3.44 + def prepare_widget(self, design_identifier, widget_identifier, parent=None):
3.45 + design_path = self.prepare_design(design_identifier)
3.46 + fragment_name, widget_name = self.widget_resources[widget_identifier]
3.47 + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name))
3.48 + XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name)
3.49 + # NOTE: Implement the equivalent here!
3.50 + return qtui.QWidgetFactory.create(fragment_path, None, parent)
3.51 +
3.52 + def populate_list(self, field, elements):
3.53 + # NOTE: Support this!
3.54 + current_text = field.currentText()
3.55 + while field.count() > 0:
3.56 + field.removeItem(0)
3.57 + item = 0
3.58 + set = 0
3.59 + for element in elements:
3.60 + text = element.getAttribute("value")
3.61 + field.insertItem(text)
3.62 + if text == current_text:
3.63 + field.setCurrentItem(item)
3.64 + set = 1
3.65 + item += 1
3.66 + if not set:
3.67 + field.setCurrentItem(0)
3.68 +
3.69 + def reset_collection(self, field):
3.70 + # NOTE: Support this!
3.71 + layout = field.layout()
3.72 + for child in field.children():
3.73 + if child is not layout:
3.74 + layout.remove(child)
3.75 + child.deleteLater()
3.76 +
3.77 +class Factory:
3.78 +
3.79 + "A widget factory helper class."
3.80 +
3.81 + def __init__(self, ui_filename):
3.82 + self.ui_filename = ui_filename
3.83 + self.ui_doc = libxml2dom.parse(ui_filename)
3.84 +
3.85 + def connect(self, widget, obj):
3.86 + pass
3.87 +
3.88 + def find_widgets(self, widget, name):
3.89 + # NOTE: Support this!
3.90 + widgets = []
3.91 + found = widget.child(name)
3.92 + if found:
3.93 + widgets.append(found)
3.94 + for child in widget.children():
3.95 + widgets += self.find_widgets(child, name)
3.96 + return widgets
3.97 +
3.98 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/XSLForms/Resources/WebResources.py Wed Oct 26 00:07:09 2005 +0000
4.2 +++ b/XSLForms/Resources/WebResources.py Wed Oct 26 00:37:36 2005 +0000
4.3 @@ -24,10 +24,11 @@
4.4 import XSLForms.Fields
4.5 import XSLForms.Prepare
4.6 import XSLForms.Output
4.7 +import XSLForms.Resources.Common
4.8 from XSLTools import XSLOutput
4.9 import os
4.10
4.11 -class XSLFormsResource:
4.12 +class XSLFormsResource(XSLForms.Resources.Common.CommonResource):
4.13
4.14 """
4.15 A generic XSLForms resource for use with WebStack.
4.16 @@ -80,9 +81,8 @@
4.17 encoding = "utf-8"
4.18 template_resources = {}
4.19 in_page_resources = {}
4.20 + init_resources = {}
4.21 transform_resources = {}
4.22 - document_resources = {}
4.23 - resource_dir = None
4.24
4.25 def clean_parameters(self, parameters):
4.26
4.27 @@ -228,18 +228,6 @@
4.28 paths.append(os.path.abspath(os.path.join(self.resource_dir, filename)))
4.29 return paths
4.30
4.31 - def prepare_document(self, document_identifier):
4.32 -
4.33 - """
4.34 - Prepare a document using the given 'document_identifier'.
4.35 -
4.36 - Return the full path of the document for use either as the source
4.37 - document or as a reference with 'send_output' or 'get_result'.
4.38 - """
4.39 -
4.40 - filename = self.document_resources[document_identifier]
4.41 - return os.path.abspath(os.path.join(self.resource_dir, filename))
4.42 -
4.43 def get_in_page_resource(self, trans):
4.44
4.45 """