1.1 --- a/XSLForms/Resources/PyQtWebResources.py Tue Nov 01 18:56:33 2005 +0000
1.2 +++ b/XSLForms/Resources/PyQtWebResources.py Tue Nov 01 18:57:41 2005 +0000
1.3 @@ -41,7 +41,7 @@
1.4 self.factory = Factory()
1.5 self.default_design = design_identifier
1.6
1.7 - # NOTE: Filename extended by string concatenation.
1.8 + # NOTE: Filenames extended by string concatenation.
1.9
1.10 self.template_resources = {}
1.11 self.init_resources = {}
1.12 @@ -49,6 +49,27 @@
1.13 self.template_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_output.xsl")
1.14 self.init_resources[design_identifier] = (design_name + "_template.xhtml", design_name + "_input.xsl")
1.15
1.16 + # Initialisation of connections - just a mapping from field names to
1.17 + # methods in the Web version.
1.18 +
1.19 + self.method_resources = {}
1.20 + for design_identifier, design_name in self.design_resources.items():
1.21 + design_path = self.prepare_design(design_identifier)
1.22 + design_doc = libxml2dom.parse(design_path)
1.23 + connections = {}
1.24 + for connection in design_doc.xpath("UI/connections/connection"):
1.25 + receiver = "".join([n.nodeValue for n in connection.xpath("receiver/text()")])
1.26 + if receiver == design_identifier:
1.27 + sender = "".join([n.nodeValue for n in connection.xpath("sender/text()")])
1.28 + slot = "".join([n.nodeValue for n in connection.xpath("slot/text()")])
1.29 + slot = slot.split("(")[0]
1.30 + connections[sender] = slot
1.31 + self.method_resources[design_identifier] = connections
1.32 +
1.33 + # Refresh status - avoiding multiple refresh calls.
1.34 +
1.35 + self._refreshed = 0
1.36 +
1.37 # Resource methods.
1.38
1.39 def prepare_output(self, design_identifier):
1.40 @@ -79,16 +100,20 @@
1.41 return libxml2dom.parse(self.prepare_document(document_identifier))
1.42
1.43 def prepare_widget(self, design_identifier, widget_identifier, parent=None):
1.44 - design_path = self.prepare_design(design_identifier)
1.45 fragment_name, widget_name = self.widget_resources[widget_identifier]
1.46 - fragment_path = os.path.abspath(os.path.join(self.resource_dir, fragment_name))
1.47 - XSLForms.Prepare.ensure_qt_fragment(design_path, fragment_path, widget_name)
1.48 - # NOTE: Implement the equivalent here!
1.49 - return qtui.QWidgetFactory.create(fragment_path, None, parent)
1.50 + element = UINode(self.doc._node.ownerDocument.createElement(widget_name))
1.51 +
1.52 + # NOTE: Creating an element which may not be appropriate.
1.53 +
1.54 + element._node.appendChild(self.doc._node.ownerDocument.createElement(widget_name + "_value"))
1.55 + return element
1.56
1.57 def child(self, name):
1.58 return self.doc.child(name)
1.59
1.60 + def sender(self):
1.61 + return self._sender
1.62 +
1.63 # PyQt structural methods.
1.64
1.65 def form_init(self):
1.66 @@ -109,6 +134,14 @@
1.67
1.68 raise NotImplementedError, "form_refresh"
1.69
1.70 + def request_refresh(self, *args, **kw):
1.71 +
1.72 + "Request a refresh of the form."
1.73 +
1.74 + if not self._refreshed:
1.75 + self._refreshed = 1
1.76 + self.form_refresh(*args, **kw)
1.77 +
1.78 # Standard XSLFormsResource method, overridden to handle presentation.
1.79
1.80 def respond_to_form(self, trans, form):
1.81 @@ -120,6 +153,8 @@
1.82 documents).
1.83 """
1.84
1.85 + self._refreshed = 0
1.86 +
1.87 # Ensure the presence of the template.
1.88
1.89 self.prepare_output(self.default_design)
1.90 @@ -129,25 +164,45 @@
1.91 doc = form.get_document(self.default_design)
1.92 if doc is None:
1.93 doc = form.new_document(self.default_design)
1.94 - doc = self._form_init(doc)
1.95 + doc = self._get_initialised_form(doc)
1.96 self.doc = UINode(doc.xpath("*")[0])
1.97 self.form_init()
1.98 else:
1.99 - doc = self._form_init(doc)
1.100 + doc = self._get_initialised_form(doc)
1.101 self.doc = UINode(doc.xpath("*")[0])
1.102
1.103 self.form_populate()
1.104 +
1.105 + # Updates happen here.
1.106 +
1.107 + form.set_document(self.default_design, doc)
1.108 + selectors = form.get_selectors()
1.109 + connections = self.method_resources[self.default_design]
1.110 + for selector_name, selector_values in selectors.items():
1.111 + if connections.has_key(selector_name):
1.112 + slot = connections[selector_name]
1.113 + if hasattr(self, slot):
1.114 +
1.115 + # Initialise the sender.
1.116 +
1.117 + for selector_value in selector_values:
1.118 + # NOTE: Fake a special attribute to simulate the Qt widget hierarchy.
1.119 + selector_value.setAttribute("_sender", "")
1.120 + self._sender = UINode(selector_value.getAttributeNode("_sender"))
1.121 + getattr(self, slot)()
1.122 +
1.123 + # Consistency is ensured and filtering enforced.
1.124 +
1.125 + self.request_refresh()
1.126 #print self.doc._node.toString("iso-8859-1")
1.127
1.128 - # NOTE: Updates happen here.
1.129 -
1.130 - self.form_refresh()
1.131 + # Output is produced.
1.132
1.133 trans.set_content_type(WebStack.Generic.ContentType("application/xhtml+xml", self.encoding))
1.134 design_xsl = self.prepare_output(self.default_design)
1.135 self.send_output(trans, [design_xsl], doc._node)
1.136
1.137 - def _form_init(self, doc):
1.138 + def _get_initialised_form(self, doc):
1.139 input_xsl = self.prepare_initialiser(self.default_design, init_enumerations=0)
1.140 return self.get_result([input_xsl], doc)
1.141
1.142 @@ -158,6 +213,9 @@
1.143 def __init__(self, node):
1.144 self._node = node
1.145
1.146 + def add(self, node):
1.147 + self._node.appendChild(node._node)
1.148 +
1.149 def child(self, name):
1.150 nodes = self._node.xpath(name)
1.151 if len(nodes) > 0:
1.152 @@ -181,6 +239,9 @@
1.153 else:
1.154 return 0
1.155
1.156 + def deleteLater(self):
1.157 + pass
1.158 +
1.159 def insertItem(self, item, position=-1):
1.160 # NOTE: Names invented rather than being extracted from the schema.
1.161 new_element = self._node.ownerDocument.createElement(self._node.localName + "_enum")
1.162 @@ -194,29 +255,37 @@
1.163 else:
1.164 self._node.appendChild(new_element)
1.165
1.166 + def layout(self):
1.167 + return self
1.168 +
1.169 def parent(self):
1.170 return UINode(self._node.parentNode)
1.171
1.172 def removeItem(self, item):
1.173 - pass # NOTE: Not implemented yet!
1.174 + elements = self._node.xpath("*")
1.175 + if item < len(elements):
1.176 + self._node.removeChild(elements[item])
1.177
1.178 def remove(self, item):
1.179 - pass # NOTE: Not implemented yet!
1.180 -
1.181 - def layout(self):
1.182 - return self
1.183 + self._node.removeChild(item._node)
1.184
1.185 def setCurrentItem(self, index):
1.186 pass # NOTE: Not implemented yet!
1.187
1.188 - def deleteLater(self):
1.189 - self._node.parentNode.removeChild(self._node)
1.190 + def show(self):
1.191 + pass
1.192
1.193 class Factory:
1.194
1.195 "A widget factory helper class."
1.196
1.197 def connect(self, widget, obj):
1.198 +
1.199 + """
1.200 + Connection is done all at once by mapping field names to method names in
1.201 + the resource object.
1.202 + """
1.203 +
1.204 pass
1.205
1.206 def find_widgets(self, widget, name):