1.1 --- a/XSLForms/Resources/Common.py Thu Oct 27 16:31:26 2005 +0000
1.2 +++ b/XSLForms/Resources/Common.py Thu Oct 27 16:33:53 2005 +0000
1.3 @@ -48,6 +48,14 @@
1.4 design_resources = {}
1.5
1.6 def get_document(self, document_identifier):
1.7 +
1.8 + """
1.9 + Return a DOM-style document retrieved using the given
1.10 + 'document_identifier'.
1.11 +
1.12 + Each implementation is free to choose its own DOM library.
1.13 + """
1.14 +
1.15 raise NotImplementedError, "get_document"
1.16
1.17 def get_elements(self, document_identifier):
1.18 @@ -58,4 +66,33 @@
1.19 filename = self.design_resources[design_identifier]
1.20 return os.path.abspath(os.path.join(self.resource_dir, filename))
1.21
1.22 + def populate_list(self, field, elements):
1.23 +
1.24 + "Populate the given 'field' using a list of DOM 'elements'."
1.25 +
1.26 + current_text = field.currentText()
1.27 + while field.count() > 0:
1.28 + field.removeItem(0)
1.29 + item = 0
1.30 + set = 0
1.31 + for element in elements:
1.32 + text = element.getAttribute("value")
1.33 + field.insertItem(text)
1.34 + if text == current_text:
1.35 + field.setCurrentItem(item)
1.36 + set = 1
1.37 + item += 1
1.38 + if not set:
1.39 + field.setCurrentItem(0)
1.40 +
1.41 + def reset_collection(self, field):
1.42 +
1.43 + "Empty the given collection 'field'."
1.44 +
1.45 + layout = field.layout()
1.46 + for child in field.children():
1.47 + if child is not layout:
1.48 + layout.remove(child)
1.49 + child.deleteLater()
1.50 +
1.51 # vim: tabstop=4 expandtab shiftwidth=4