23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 |
24 |
25 |
25 |
26 from __future__ import absolute_import |
26 from __future__ import absolute_import |
27 import os |
27 import os |
|
28 from builtins import str as text |
28 |
29 |
29 from nevow import tags, loaders |
30 from nevow import tags, loaders |
30 import simplejson as json # pylint: disable=import-error |
31 import simplejson as json # pylint: disable=import-error |
31 import runtime.NevowServer as NS |
32 import runtime.NevowServer as NS |
32 |
33 |
120 ]) |
121 ]) |
121 |
122 |
122 def HMIinitialisation(self): |
123 def HMIinitialisation(self): |
123 gadgets = [] |
124 gadgets = [] |
124 for gadget in svguiWidgets.values(): |
125 for gadget in svguiWidgets.values(): |
125 gadgets.append(unicode(json.dumps(gadget, default=get_object_init_state, indent=2), 'ascii')) |
126 gadgets.append(text(json.dumps(gadget, default=get_object_init_state, indent=2), 'ascii')) |
126 d = self.callRemote('init', gadgets) |
127 d = self.callRemote('init', gadgets) |
127 d.addCallback(self.HMIinitialised) |
128 d.addCallback(self.HMIinitialised) |
128 |
129 |
129 def sendData(self, data): |
130 def sendData(self, data): |
130 if self.initialised: |
131 if self.initialised: |
131 return self.callRemote('receiveData', unicode(json.dumps(data, default=get_object_current_state, indent=2), 'ascii')) |
132 return self.callRemote('receiveData', text(json.dumps(data, default=get_object_current_state, indent=2), 'ascii')) |
132 return None |
133 return None |
133 |
134 |
134 def setattr(self, id, attrname, value): |
135 def setattr(self, id, attrname, value): |
135 svguiWidgets[id].setinput(attrname, value) |
136 svguiWidgets[id].setinput(attrname, value) |
136 |
137 |
137 |
138 |
138 def createSVGUIControl(*args, **kwargs): |
139 def createSVGUIControl(*args, **kwargs): |
139 id = getNewId() |
140 id = getNewId() |
140 gad = SvguiWidget(args[0], id, **kwargs) |
141 gad = SvguiWidget(args[0], id, **kwargs) |
141 svguiWidgets[id] = gad |
142 svguiWidgets[id] = gad |
142 gadget = [unicode(json.dumps(gad, default=get_object_init_state, indent=2), 'ascii')] |
143 gadget = [text(json.dumps(gad, default=get_object_init_state, indent=2), 'ascii')] |
143 interface = website.getHMI() |
144 interface = website.getHMI() |
144 if isinstance(interface, SVGUI_HMI) and interface.initialised: |
145 if isinstance(interface, SVGUI_HMI) and interface.initialised: |
145 interface.callRemote('init', gadget) |
146 interface.callRemote('init', gadget) |
146 return id |
147 return id |
147 |
148 |