1.1 --- a/XSLForms/Resources/PyQtWebResources.py Mon Oct 31 23:57:57 2005 +0000
1.2 +++ b/XSLForms/Resources/PyQtWebResources.py Mon Oct 31 23:59:29 2005 +0000
1.3 @@ -27,7 +27,8 @@
1.4 import os
1.5 import libxml2dom
1.6
1.7 -class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource):
1.8 +class XSLFormsResource(XSLForms.Resources.WebResources.XSLFormsResource,
1.9 + XSLForms.Resources.Common.PyQtCommonResource):
1.10
1.11 """
1.12 An XSLForms resource supporting PyQt-compatible Web applications for use
1.13 @@ -43,8 +44,10 @@
1.14 # NOTE: Filename extended by string concatenation.
1.15
1.16 self.template_resources = {}
1.17 + self.init_resources = {}
1.18 for design_identifier, design_name in self.design_resources.items():
1.19 - self.template_resources[design_identifier] = (design_name + ".xhtml", design_name + ".xsl")
1.20 + self.template_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_output.xsl")
1.21 + self.init_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_input.xsl")
1.22
1.23 # Resource methods.
1.24
1.25 @@ -63,7 +66,7 @@
1.26 """
1.27
1.28 design_path = self.prepare_design(design_identifier)
1.29 - template_filename, output_filename = self.template_resources[output_identifier]
1.30 + template_filename, output_filename = self.template_resources[design_identifier]
1.31 output_path = os.path.abspath(os.path.join(self.resource_dir, output_filename))
1.32 template_path = os.path.abspath(os.path.join(self.resource_dir, template_filename))
1.33 XSLForms.Prepare.ensure_qt_template(design_path, template_path)
1.34 @@ -89,9 +92,21 @@
1.35 # PyQt structural methods.
1.36
1.37 def form_init(self):
1.38 +
1.39 + "Initialise a newly-created form."
1.40 +
1.41 raise NotImplementedError, "form_init"
1.42
1.43 + def form_populate(self):
1.44 +
1.45 + "Populate the values in a form."
1.46 +
1.47 + raise NotImplementedError, "form_populate"
1.48 +
1.49 def form_refresh(self):
1.50 +
1.51 + "Refresh the form."
1.52 +
1.53 raise NotImplementedError, "form_refresh"
1.54
1.55 # Standard XSLFormsResource method, overridden to handle presentation.
1.56 @@ -105,15 +120,24 @@
1.57 documents).
1.58 """
1.59
1.60 + # Ensure the presence of the template.
1.61 +
1.62 + self.prepare_output(self.default_design)
1.63 +
1.64 # Remember the document since it is accessed independently elsewhere.
1.65
1.66 doc = form.get_document(self.default_design)
1.67 if doc is None:
1.68 - self.doc = UINode(form.new_document(self.default_design))
1.69 + doc = form.new_document(self.default_design)
1.70 + doc = self._form_init(doc)
1.71 + self.doc = UINode(doc.xpath("*")[0])
1.72 + self.form_init()
1.73 else:
1.74 - self.doc = UINode(doc)
1.75 + doc = self._form_init(doc)
1.76 + self.doc = UINode(doc.xpath("*")[0])
1.77
1.78 - self.form_init()
1.79 + self.form_populate()
1.80 + #print self.doc._node.toString("iso-8859-1")
1.81
1.82 # NOTE: Updates happen here.
1.83
1.84 @@ -123,6 +147,10 @@
1.85 design_xsl = self.prepare_output(self.default_design)
1.86 self.send_output(trans, [design_xsl], doc._node)
1.87
1.88 + def _form_init(self, doc):
1.89 + input_xsl = self.prepare_initialiser(self.default_design, init_enumerations=0)
1.90 + return self.get_result([input_xsl], doc)
1.91 +
1.92 class UINode:
1.93
1.94 "A PyQt widget tree emulation node."
1.95 @@ -144,7 +172,7 @@
1.96 return len(self._node.childNodes)
1.97
1.98 def currentText(self):
1.99 - return self.getAttribute("value")
1.100 + return self._node.getAttribute("value")
1.101
1.102 def currentItem(self):
1.103 found = self._node.xpath("*[@value=current()/@value]")
1.104 @@ -154,18 +182,32 @@
1.105 return 0
1.106
1.107 def insertItem(self, item, position=-1):
1.108 + # NOTE: Names invented rather than being extracted from the schema.
1.109 + new_element = self._node.ownerDocument.createElement(self._node.localName + "_enum")
1.110 + new_element.setAttribute("value", item)
1.111 + if position == -1:
1.112 + self._node.appendChild(new_element)
1.113 + else:
1.114 + elements = self._node.xpath("*")
1.115 + if position < len(elements) - 1:
1.116 + self._node.insertBefore(new_element, elements[position])
1.117 + else:
1.118 + self._node.appendChild(new_element)
1.119
1.120 def parent(self):
1.121 return UINode(self._node.parentNode)
1.122
1.123 def removeItem(self, item):
1.124 + pass # NOTE: Not implemented yet!
1.125
1.126 def remove(self, item):
1.127 + pass # NOTE: Not implemented yet!
1.128
1.129 def layout(self):
1.130 return self
1.131
1.132 - def setCurrentItem(self):
1.133 + def setCurrentItem(self, index):
1.134 + pass # NOTE: Not implemented yet!
1.135
1.136 def deleteLater(self):
1.137 self._node.parentNode.removeChild(self._node)
1.138 @@ -184,6 +226,6 @@
1.139 'name'.
1.140 """
1.141
1.142 - return widget.getElementsByTagName(name)
1.143 + return [UINode(node) for node in widget.doc._node.getElementsByTagName(name)]
1.144
1.145 # vim: tabstop=4 expandtab shiftwidth=4