# HG changeset patch # User paulb # Date 1130803169 0 # Node ID 4b1390c6a1c0a6ea67b6ce6fae6d4ea2303b22f7 # Parent 548e8ffa6ad83ba031a73d7113d843f2b290e7cf [project @ 2005-10-31 23:59:29 by paulb] Fixed template-related filenames and added initialisation resource mappings and usage of initialisation stylesheets. Introduced the form_populate method. Fixed various widget/factory wrapper methods. diff -r 548e8ffa6ad8 -r 4b1390c6a1c0 XSLForms/Resources/PyQtWebResources.py --- a/XSLForms/Resources/PyQtWebResources.py Mon Oct 31 23:57:57 2005 +0000 +++ b/XSLForms/Resources/PyQtWebResources.py Mon Oct 31 23:59:29 2005 +0000 @@ -27,7 +27,8 @@ import os import libxml2dom -class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource): +class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource, + XSLForms.Resources.Common.PyQtCommonResource): """ An XSLForms resource supporting PyQt-compatible Web applications for use @@ -43,8 +44,10 @@ # NOTE: Filename extended by string concatenation. self.template_resources = {} + self.init_resources = {} for design_identifier, design_name in self.design_resources.items(): - self.template_resources[design_identifier] = (design_name + ".xhtml", design_name + ".xsl") + self.template_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_output.xsl") + self.init_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_input.xsl") # Resource methods. @@ -63,7 +66,7 @@ """ design_path = self.prepare_design(design_identifier) - template_filename, output_filename = self.template_resources[output_identifier] + template_filename, output_filename = self.template_resources[design_identifier] output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename)) template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename)) XSLForms.Prepare.ensure_qt_template(design_path, template_path) @@ -89,9 +92,21 @@ # PyQt structural methods. def form_init(self): + + "Initialise a newly-created form." + raise NotImplementedError, "form_init" + def form_populate(self): + + "Populate the values in a form." + + raise NotImplementedError, "form_populate" + def form_refresh(self): + + "Refresh the form." + raise NotImplementedError, "form_refresh" # Standard XSLFormsResource method, overridden to handle presentation. @@ -105,15 +120,24 @@ documents). """ + # Ensure the presence of the template. + + self.prepare_output(self.default_design) + # Remember the document since it is accessed independently elsewhere. doc = form.get_document(self.default_design) if doc is None: - self.doc = UINode(form.new_document(self.default_design)) + doc = form.new_document(self.default_design) + doc = self._form_init(doc) + self.doc = UINode(doc.xpath("*")[0]) + self.form_init() else: - self.doc = UINode(doc) + doc = self._form_init(doc) + self.doc = UINode(doc.xpath("*")[0]) - self.form_init() + self.form_populate() + #print self.doc._node.toString("iso-8859-1") # NOTE: Updates happen here. @@ -123,6 +147,10 @@ design_xsl = self.prepare_output(self.default_design) self.send_output(trans, [design_xsl], doc._node) + def _form_init(self, doc): + input_xsl = self.prepare_initialiser(self.default_design, init_enumerations=0) + return self.get_result([input_xsl], doc) + class UINode: "A PyQt widget tree emulation node." @@ -144,7 +172,7 @@ return len(self._node.childNodes) def currentText(self): - return self.getAttribute("value") + return self._node.getAttribute("value") def currentItem(self): found = self._node.xpath("*[@value=current()/@value]") @@ -154,18 +182,32 @@ return 0 def insertItem(self, item, position=-1): + # NOTE: Names invented rather than being extracted from the schema. + new_element = self._node.ownerDocument.createElement(self._node.localName + "_enum") + new_element.setAttribute("value", item) + if position == -1: + self._node.appendChild(new_element) + else: + elements = self._node.xpath("*") + if position < len(elements) - 1: + self._node.insertBefore(new_element, elements[position]) + else: + self._node.appendChild(new_element) def parent(self): return UINode(self._node.parentNode) def removeItem(self, item): + pass # NOTE: Not implemented yet! def remove(self, item): + pass # NOTE: Not implemented yet! def layout(self): return self - def setCurrentItem(self): + def setCurrentItem(self, index): + pass # NOTE: Not implemented yet! def deleteLater(self): self._node.parentNode.removeChild(self._node) @@ -184,6 +226,6 @@ 'name'. """ - return widget.getElementsByTagName(name) + return [UINode(node) for node in widget.doc._node.getElementsByTagName(name)] # vim: tabstop=4 expandtab shiftwidth=4