# HG changeset patch # User paulb # Date 1131652175 0 # Node ID b77cac6d6fce3aee01e9768614214c206cc22bc9 # Parent b60c45cc4540d972cecd85ce261ea8d05323cd2e [project @ 2005-11-10 19:49:35 by paulb] Moved the PyQt common resource functionality into a separate module. diff -r b60c45cc4540 -r b77cac6d6fce XSLForms/Resources/Common.py --- a/XSLForms/Resources/Common.py Wed Nov 09 17:41:49 2005 +0000 +++ b/XSLForms/Resources/Common.py Thu Nov 10 19:49:35 2005 +0000 @@ -41,61 +41,4 @@ 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): - - """ - Return a DOM-style document retrieved using the given - 'document_identifier'. - - Each implementation is free to choose its own DOM library. - """ - - raise NotImplementedError, "get_document" - - def get_elements(self, document_identifier): - doc = self.get_document(document_identifier) - - # NOTE: Using special suffix. - - 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)) - - def populate_list(self, field, elements): - - "Populate the given 'field' using a list of DOM 'elements'." - - 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): - - "Empty the given collection 'field'." - - layout = field.layout() - for child in field.children(): - if child is not layout: - layout.remove(child) - child.deleteLater() - # vim: tabstop=4 expandtab shiftwidth=4 diff -r b60c45cc4540 -r b77cac6d6fce XSLForms/Resources/PyQtCommon.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XSLForms/Resources/PyQtCommon.py Thu Nov 10 19:49:35 2005 +0000 @@ -0,0 +1,83 @@ +#!/usr/bin/env python + +""" +Common resource class functionality for PyQt-related applications. + +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 +from XSLForms.Resources.Common import CommonResource + +class PyQtCommonResource(CommonResource): + + "Common PyQt-compatible resource methods." + + design_resources = {} + + def get_document(self, document_identifier): + + """ + Return a DOM-style document retrieved using the given + 'document_identifier'. + + Each implementation is free to choose its own DOM library. + """ + + raise NotImplementedError, "get_document" + + def get_elements(self, document_identifier): + doc = self.get_document(document_identifier) + + # NOTE: Using special suffix. + + 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)) + + def populate_list(self, field, elements): + + "Populate the given 'field' using a list of DOM 'elements'." + + 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): + + "Empty the given collection 'field'." + + layout = field.layout() + for child in field.children(): + if child is not layout: + layout.remove(child) + child.deleteLater() + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r b60c45cc4540 -r b77cac6d6fce XSLForms/Resources/PyQtResources.py --- a/XSLForms/Resources/PyQtResources.py Wed Nov 09 17:41:49 2005 +0000 +++ b/XSLForms/Resources/PyQtResources.py Thu Nov 10 19:49:35 2005 +0000 @@ -21,11 +21,11 @@ """ import XSLForms.Prepare -import XSLForms.Resources.Common +import XSLForms.Resources.PyQtCommon import qt, qtui, qtxmldom import os -class XSLFormsResource(XSLForms.Resources.Common.PyQtCommonResource): +class XSLFormsResource(XSLForms.Resources.PyQtCommon.PyQtCommonResource): "An XSLForms resource for use with PyQt." diff -r b60c45cc4540 -r b77cac6d6fce XSLForms/Resources/PyQtWebResources.py --- a/XSLForms/Resources/PyQtWebResources.py Wed Nov 09 17:41:49 2005 +0000 +++ b/XSLForms/Resources/PyQtWebResources.py Thu Nov 10 19:49:35 2005 +0000 @@ -21,14 +21,14 @@ """ import XSLForms.Prepare -import XSLForms.Resources.Common +import XSLForms.Resources.PyQtCommon import XSLForms.Resources.WebResources import WebStack.Generic import os import libxml2dom class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource, - XSLForms.Resources.Common.PyQtCommonResource): + XSLForms.Resources.PyQtCommon.PyQtCommonResource): """ An XSLForms resource supporting PyQt-compatible Web applications for use