1.1 --- a/XSLForms/Resources/PyQtCommon.py Sun Oct 12 19:28:30 2008 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,82 +0,0 @@
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 program is free software; you can redistribute it and/or modify it under
1.12 -the terms of the GNU Lesser General Public License as published by the Free
1.13 -Software Foundation; either version 3 of the License, or (at your option) any
1.14 -later version.
1.15 -
1.16 -This program is distributed in the hope that it will be useful, but WITHOUT
1.17 -ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 -FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
1.19 -details.
1.20 -
1.21 -You should have received a copy of the GNU Lesser General Public License along
1.22 -with this program. If not, see <http://www.gnu.org/licenses/>.
1.23 -"""
1.24 -
1.25 -import os
1.26 -from XSLForms.Resources.Common import CommonResource
1.27 -
1.28 -class PyQtCommonResource(CommonResource):
1.29 -
1.30 - "Common PyQt-compatible resource methods."
1.31 -
1.32 - design_resources = {}
1.33 -
1.34 - def get_document(self, document_identifier):
1.35 -
1.36 - """
1.37 - Return a DOM-style document retrieved using the given
1.38 - 'document_identifier'.
1.39 -
1.40 - Each implementation is free to choose its own DOM library.
1.41 - """
1.42 -
1.43 - raise NotImplementedError, "get_document"
1.44 -
1.45 - def get_elements(self, document_identifier):
1.46 - doc = self.get_document(document_identifier)
1.47 -
1.48 - # NOTE: Using special suffix.
1.49 -
1.50 - return doc.getElementsByTagName(document_identifier + "-enum")
1.51 -
1.52 - def prepare_design(self, design_identifier):
1.53 - filename = self.design_resources[design_identifier]
1.54 - return os.path.abspath(os.path.join(self.resource_dir, filename))
1.55 -
1.56 - def populate_list(self, field, elements):
1.57 -
1.58 - "Populate the given 'field' using a list of DOM 'elements'."
1.59 -
1.60 - current_text = field.currentText()
1.61 - while field.count() > 0:
1.62 - field.removeItem(0)
1.63 - item = 0
1.64 - set = 0
1.65 - for element in elements:
1.66 - text = element.getAttribute("value")
1.67 - field.insertItem(text)
1.68 - if text == current_text:
1.69 - field.setCurrentItem(item)
1.70 - set = 1
1.71 - item += 1
1.72 - if not set:
1.73 - field.setCurrentItem(0)
1.74 -
1.75 - def reset_collection(self, field):
1.76 -
1.77 - "Empty the given collection 'field'."
1.78 -
1.79 - layout = field.layout()
1.80 - for child in field.children():
1.81 - if child is not layout:
1.82 - layout.remove(child)
1.83 - child.deleteLater()
1.84 -
1.85 -# vim: tabstop=4 expandtab shiftwidth=4