1.1 --- a/XSLForms/Resources/Common.py Wed Nov 09 17:41:49 2005 +0000
1.2 +++ b/XSLForms/Resources/Common.py Thu Nov 10 19:49:35 2005 +0000
1.3 @@ -41,61 +41,4 @@
1.4 filename = self.document_resources[document_identifier]
1.5 return os.path.abspath(os.path.join(self.resource_dir, filename))
1.6
1.7 -class PyQtCommonResource(CommonResource):
1.8 -
1.9 - "Common PyQt-compatible resource methods."
1.10 -
1.11 - design_resources = {}
1.12 -
1.13 - def get_document(self, document_identifier):
1.14 -
1.15 - """
1.16 - Return a DOM-style document retrieved using the given
1.17 - 'document_identifier'.
1.18 -
1.19 - Each implementation is free to choose its own DOM library.
1.20 - """
1.21 -
1.22 - raise NotImplementedError, "get_document"
1.23 -
1.24 - def get_elements(self, document_identifier):
1.25 - doc = self.get_document(document_identifier)
1.26 -
1.27 - # NOTE: Using special suffix.
1.28 -
1.29 - return doc.getElementsByTagName(document_identifier + "-enum")
1.30 -
1.31 - def prepare_design(self, design_identifier):
1.32 - filename = self.design_resources[design_identifier]
1.33 - return os.path.abspath(os.path.join(self.resource_dir, filename))
1.34 -
1.35 - def populate_list(self, field, elements):
1.36 -
1.37 - "Populate the given 'field' using a list of DOM 'elements'."
1.38 -
1.39 - current_text = field.currentText()
1.40 - while field.count() > 0:
1.41 - field.removeItem(0)
1.42 - item = 0
1.43 - set = 0
1.44 - for element in elements:
1.45 - text = element.getAttribute("value")
1.46 - field.insertItem(text)
1.47 - if text == current_text:
1.48 - field.setCurrentItem(item)
1.49 - set = 1
1.50 - item += 1
1.51 - if not set:
1.52 - field.setCurrentItem(0)
1.53 -
1.54 - def reset_collection(self, field):
1.55 -
1.56 - "Empty the given collection 'field'."
1.57 -
1.58 - layout = field.layout()
1.59 - for child in field.children():
1.60 - if child is not layout:
1.61 - layout.remove(child)
1.62 - child.deleteLater()
1.63 -
1.64 # vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/XSLForms/Resources/PyQtCommon.py Thu Nov 10 19:49:35 2005 +0000
2.3 @@ -0,0 +1,83 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +Common resource class functionality for PyQt-related applications.
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 os
2.27 +from XSLForms.Resources.Common import CommonResource
2.28 +
2.29 +class PyQtCommonResource(CommonResource):
2.30 +
2.31 + "Common PyQt-compatible resource methods."
2.32 +
2.33 + design_resources = {}
2.34 +
2.35 + def get_document(self, document_identifier):
2.36 +
2.37 + """
2.38 + Return a DOM-style document retrieved using the given
2.39 + 'document_identifier'.
2.40 +
2.41 + Each implementation is free to choose its own DOM library.
2.42 + """
2.43 +
2.44 + raise NotImplementedError, "get_document"
2.45 +
2.46 + def get_elements(self, document_identifier):
2.47 + doc = self.get_document(document_identifier)
2.48 +
2.49 + # NOTE: Using special suffix.
2.50 +
2.51 + return doc.getElementsByTagName(document_identifier + "-enum")
2.52 +
2.53 + def prepare_design(self, design_identifier):
2.54 + filename = self.design_resources[design_identifier]
2.55 + return os.path.abspath(os.path.join(self.resource_dir, filename))
2.56 +
2.57 + def populate_list(self, field, elements):
2.58 +
2.59 + "Populate the given 'field' using a list of DOM 'elements'."
2.60 +
2.61 + current_text = field.currentText()
2.62 + while field.count() > 0:
2.63 + field.removeItem(0)
2.64 + item = 0
2.65 + set = 0
2.66 + for element in elements:
2.67 + text = element.getAttribute("value")
2.68 + field.insertItem(text)
2.69 + if text == current_text:
2.70 + field.setCurrentItem(item)
2.71 + set = 1
2.72 + item += 1
2.73 + if not set:
2.74 + field.setCurrentItem(0)
2.75 +
2.76 + def reset_collection(self, field):
2.77 +
2.78 + "Empty the given collection 'field'."
2.79 +
2.80 + layout = field.layout()
2.81 + for child in field.children():
2.82 + if child is not layout:
2.83 + layout.remove(child)
2.84 + child.deleteLater()
2.85 +
2.86 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- a/XSLForms/Resources/PyQtResources.py Wed Nov 09 17:41:49 2005 +0000
3.2 +++ b/XSLForms/Resources/PyQtResources.py Thu Nov 10 19:49:35 2005 +0000
3.3 @@ -21,11 +21,11 @@
3.4 """
3.5
3.6 import XSLForms.Prepare
3.7 -import XSLForms.Resources.Common
3.8 +import XSLForms.Resources.PyQtCommon
3.9 import qt, qtui, qtxmldom
3.10 import os
3.11
3.12 -class XSLFormsResource(XSLForms.Resources.Common.PyQtCommonResource):
3.13 +class XSLFormsResource(XSLForms.Resources.PyQtCommon.PyQtCommonResource):
3.14
3.15 "An XSLForms resource for use with PyQt."
3.16
4.1 --- a/XSLForms/Resources/PyQtWebResources.py Wed Nov 09 17:41:49 2005 +0000
4.2 +++ b/XSLForms/Resources/PyQtWebResources.py Thu Nov 10 19:49:35 2005 +0000
4.3 @@ -21,14 +21,14 @@
4.4 """
4.5
4.6 import XSLForms.Prepare
4.7 -import XSLForms.Resources.Common
4.8 +import XSLForms.Resources.PyQtCommon
4.9 import XSLForms.Resources.WebResources
4.10 import WebStack.Generic
4.11 import os
4.12 import libxml2dom
4.13
4.14 class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource,
4.15 - XSLForms.Resources.Common.PyQtCommonResource):
4.16 + XSLForms.Resources.PyQtCommon.PyQtCommonResource):
4.17
4.18 """
4.19 An XSLForms resource supporting PyQt-compatible Web applications for use