# HG changeset patch # User paulb # Date 1130287056 0 # Node ID 38e9b24db220ab8534813a23cb0174c8f1efe908 # Parent 54af5279b35af9335d04660dd8eacedf9552dea8 [project @ 2005-10-26 00:37:36 by paulb] Made a Common module, moving various shared methods and attributes into classes within that module. Added the beginnings of PyQt-compatible Web application support. diff -r 54af5279b35a -r 38e9b24db220 XSLForms/Resources/Common.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/Common.py Wed Oct 26 00:37:36 2005 +0000 @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +""" +Common resource class functionality. + +Copyright (C) 2005 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import os + +class CommonResource: + + "Common resource methods." + + document_resources = {} + resource_dir = None + + def prepare_document(self, document_identifier): + + """ + Prepare a document using the given 'document_identifier'. + + Return the full path of the document for use either as the source + document or as a reference with 'send_output' or 'get_result'. + """ + + filename = self.document_resources[document_identifier] + return os.path.abspath(os.path.join(self.resource_dir, filename)) + +class PyQtCommonResource(CommonResource): + + "Common PyQt-compatible resource methods." + + design_resources = {} + + def get_document(self, document_identifier): + raise NotImplementedError, "get_document" + + def get_elements(self, document_identifier): + doc = self.get_document(document_identifier) + return doc.getElementsByTagName(document_identifier + "-enum") + + def prepare_design(self, design_identifier): + filename = self.design_resources[design_identifier] + return os.path.abspath(os.path.join(self.resource_dir, filename)) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 54af5279b35a -r 38e9b24db220 XSLForms/Resources/PyQtResources.py --- a/XSLForms/Resources/PyQtResources.py Wed Oct 26 00:07:09 2005 +0000 +++ b/XSLForms/Resources/PyQtResources.py Wed Oct 26 00:37:36 2005 +0000 @@ -1,42 +1,44 @@ #!/usr/bin/env python +""" +Resources for use with PyQt. + +Copyright (C) 2005 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + import XSLForms.Prepare -import qt -import qtui -import qtxmldom +import XSLForms.Resources.Common +import qt, qtui, qtxmldom import os -class XSLFormsResource: +class XSLFormsResource(XSLForms.Resources.Common.PyQtCommonResource): "An XSLForms resource for use with PyQt." - template_resources = {} widget_resources = {} - document_resources = {} - - # Helper methods. - # NOTE: Should be moved to a superclass. - - def prepare_document(self, document_identifier): - filename = self.document_resources[document_identifier] - return os.path.abspath(os.path.join(self.resource_dir, filename)) def get_document(self, document_identifier): return qtxmldom.parse(self.prepare_document(document_identifier)) - def get_elements(self, document_identifier): - doc = self.get_document(document_identifier) - return doc.getElementsByTagName(document_identifier + "-enum") - - def prepare_template(self, template_identifier): - filename = self.template_resources[template_identifier] - return os.path.abspath(os.path.join(self.resource_dir, filename)) - - def prepare_widget(self, template_identifier, widget_identifier, parent=None): - template_path = self.prepare_template(template_identifier) + def prepare_widget(self, design_identifier, widget_identifier, parent=None): + design_path = self.prepare_design(design_identifier) fragment_name, widget_name = self.widget_resources[widget_identifier] fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name)) - XSLForms.Prepare.ensure_qt_fragment(template_path, fragment_path, widget_name) + XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name) return qtui.QWidgetFactory.create(fragment_path, None, parent) def populate_list(self, field, elements): diff -r 54af5279b35a -r 38e9b24db220 XSLForms/Resources/PyQtWebResources.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/PyQtWebResources.py Wed Oct 26 00:37:36 2005 +0000 @@ -0,0 +1,95 @@ +#!/usr/bin/env python + +""" +PyQt-compatible resources for use with WebStack. + +Copyright (C) 2005 Paul Boddie + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +""" + +import XSLForms.Prepare +import XSLForms.Resources.Common +import XSLForms.Resources.WebResources +import os +import libxml2dom + +class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource): + + """ + An XSLForms resource supporting PyQt-compatible Web applications for use + with WebStack. + """ + + widget_resources = {} + + def get_document(self, document_identifier): + return libxml2dom.parse(self.prepare_document(document_identifier)) + + def prepare_widget(self, design_identifier, widget_identifier, parent=None): + design_path = self.prepare_design(design_identifier) + fragment_name, widget_name = self.widget_resources[widget_identifier] + fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name)) + XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name) + # NOTE: Implement the equivalent here! + return qtui.QWidgetFactory.create(fragment_path, None, parent) + + def populate_list(self, field, elements): + # NOTE: Support this! + current_text = field.currentText() + while field.count() > 0: + field.removeItem(0) + item = 0 + set = 0 + for element in elements: + text = element.getAttribute("value") + field.insertItem(text) + if text == current_text: + field.setCurrentItem(item) + set = 1 + item += 1 + if not set: + field.setCurrentItem(0) + + def reset_collection(self, field): + # NOTE: Support this! + layout = field.layout() + for child in field.children(): + if child is not layout: + layout.remove(child) + child.deleteLater() + +class Factory: + + "A widget factory helper class." + + def __init__(self, ui_filename): + self.ui_filename = ui_filename + self.ui_doc = libxml2dom.parse(ui_filename) + + def connect(self, widget, obj): + pass + + def find_widgets(self, widget, name): + # NOTE: Support this! + widgets = [] + found = widget.child(name) + if found: + widgets.append(found) + for child in widget.children(): + widgets += self.find_widgets(child, name) + return widgets + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 54af5279b35a -r 38e9b24db220 XSLForms/Resources/WebResources.py --- a/XSLForms/Resources/WebResources.py Wed Oct 26 00:07:09 2005 +0000 +++ b/XSLForms/Resources/WebResources.py Wed Oct 26 00:37:36 2005 +0000 @@ -24,10 +24,11 @@ import XSLForms.Fields import XSLForms.Prepare import XSLForms.Output +import XSLForms.Resources.Common from XSLTools import XSLOutput import os -class XSLFormsResource: +class XSLFormsResource(XSLForms.Resources.Common.CommonResource): """ A generic XSLForms resource for use with WebStack. @@ -80,9 +81,8 @@ encoding = "utf-8" template_resources = {} in_page_resources = {} + init_resources = {} transform_resources = {} - document_resources = {} - resource_dir = None def clean_parameters(self, parameters): @@ -228,18 +228,6 @@ paths.append(os.path.abspath(os.path.join(self.resource_dir, filename))) return paths - def prepare_document(self, document_identifier): - - """ - Prepare a document using the given 'document_identifier'. - - Return the full path of the document for use either as the source - document or as a reference with 'send_output' or 'get_result'. - """ - - filename = self.document_resources[document_identifier] - return os.path.abspath(os.path.join(self.resource_dir, filename)) - def get_in_page_resource(self, trans): """