1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/XSLForms/Resources/PyQtCommon.py Thu Nov 10 19:49:35 2005 +0000
1.3 @@ -0,0 +1,83 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Common resource class functionality for PyQt-related applications.
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 +from XSLForms.Resources.Common import CommonResource
1.28 +
1.29 +class PyQtCommonResource(CommonResource):
1.30 +
1.31 + "Common PyQt-compatible resource methods."
1.32 +
1.33 + design_resources = {}
1.34 +
1.35 + def get_document(self, document_identifier):
1.36 +
1.37 + """
1.38 + Return a DOM-style document retrieved using the given
1.39 + 'document_identifier'.
1.40 +
1.41 + Each implementation is free to choose its own DOM library.
1.42 + """
1.43 +
1.44 + raise NotImplementedError, "get_document"
1.45 +
1.46 + def get_elements(self, document_identifier):
1.47 + doc = self.get_document(document_identifier)
1.48 +
1.49 + # NOTE: Using special suffix.
1.50 +
1.51 + return doc.getElementsByTagName(document_identifier + "-enum")
1.52 +
1.53 + def prepare_design(self, design_identifier):
1.54 + filename = self.design_resources[design_identifier]
1.55 + return os.path.abspath(os.path.join(self.resource_dir, filename))
1.56 +
1.57 + def populate_list(self, field, elements):
1.58 +
1.59 + "Populate the given 'field' using a list of DOM 'elements'."
1.60 +
1.61 + current_text = field.currentText()
1.62 + while field.count() > 0:
1.63 + field.removeItem(0)
1.64 + item = 0
1.65 + set = 0
1.66 + for element in elements:
1.67 + text = element.getAttribute("value")
1.68 + field.insertItem(text)
1.69 + if text == current_text:
1.70 + field.setCurrentItem(item)
1.71 + set = 1
1.72 + item += 1
1.73 + if not set:
1.74 + field.setCurrentItem(0)
1.75 +
1.76 + def reset_collection(self, field):
1.77 +
1.78 + "Empty the given collection 'field'."
1.79 +
1.80 + layout = field.layout()
1.81 + for child in field.children():
1.82 + if child is not layout:
1.83 + layout.remove(child)
1.84 + child.deleteLater()
1.85 +
1.86 +# vim: tabstop=4 expandtab shiftwidth=4