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 from __future__ import print_function |
27 from __future__ import print_function |
28 import sys |
28 import wx |
|
29 from controls.UriLocationEditor import IConnectorPanel |
|
30 from zope.interface import implementer |
|
31 |
29 import traceback |
32 import traceback |
30 from threading import Thread, Event |
33 from threading import Thread, Event |
31 |
34 |
32 from twisted.internet import reactor, threads |
35 from twisted.internet import reactor, threads |
33 from autobahn.twisted import wamp |
36 from autobahn.twisted import wamp |
156 return WampPLCObjectProxy() |
160 return WampPLCObjectProxy() |
157 except Exception: |
161 except Exception: |
158 confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location) |
162 confnodesroot.logger.write_error(_("WAMP connection to '%s' failed.\n") % location) |
159 confnodesroot.logger.write_error(traceback.format_exc()) |
163 confnodesroot.logger.write_error(traceback.format_exc()) |
160 return None |
164 return None |
|
165 |
|
166 |
|
167 def WAMP_connector_dialog(confnodesroot): |
|
168 [ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)] |
|
169 |
|
170 |
|
171 @implementer(IConnectorPanel) |
|
172 class WAMPConnectorPanel(wx.Panel): |
|
173 def __init__(self, typeConnector, parrent, *args, **kwargs): |
|
174 self.type = typeConnector |
|
175 self.parrent = parrent |
|
176 wx.Panel.__init__(self, parrent, *args, **kwargs) |
|
177 self._init_ctrls() |
|
178 self._init_sizers() |
|
179 self.uri = None |
|
180 |
|
181 def _init_ctrls(self): |
|
182 self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1)) |
|
183 self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1)) |
|
184 self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size = wx.Size(200, -1)) |
|
185 self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size = wx.Size(200, -1)) |
|
186 self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?")) |
|
187 |
|
188 def _init_sizers(self): |
|
189 self.mainSizer = wx.BoxSizer(wx.VERTICAL) |
|
190 self.uriSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
191 self.portSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
192 self.realmSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
193 self.wampIDSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
194 |
|
195 self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI host:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
196 self.uriSizer.AddSpacer((0,0)) |
|
197 self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
198 self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL) |
|
199 |
|
200 self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI port:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
201 self.portSizer.AddSpacer((0,0)) |
|
202 self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
203 self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL) |
|
204 |
|
205 self.realmSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Realm:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
206 self.realmSizer.AddSpacer((0, 0)) |
|
207 self.realmSizer.Add(self.RealmText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
208 self.mainSizer.Add(self.realmSizer, border=2, flag=wx.ALL) |
|
209 |
|
210 self.wampIDSizer.Add(wx.StaticText(self, wx.ID_ANY, _("WAMP ID:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
211 self.wampIDSizer.AddSpacer((0, 0)) |
|
212 self.wampIDSizer.Add(self.WAMPIDText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
213 self.mainSizer.Add(self.wampIDSizer, border=2, flag=wx.ALL) |
|
214 |
|
215 self.mainSizer.Add(self.SecureCheckbox, proportion=1, flag=wx.ALIGN_LEFT) |
|
216 |
|
217 self.SetSizer(self.mainSizer) |
|
218 |
|
219 def SetURI(self, uri): |
|
220 self.uri = uri |
|
221 uri_list = uri.strip().split(":") |
|
222 length = len(uri_list) |
|
223 |
|
224 if length > 0: |
|
225 if uri_list[0] == URITypes[1]: |
|
226 self.SecureCheckbox.SetValue(True) |
|
227 |
|
228 if length > 2: |
|
229 self.IpText.SetValue(uri_list[1].strip("/")) |
|
230 wampSett = uri_list[2].split("#") |
|
231 length2 = len(wampSett) |
|
232 if length2 > 0: |
|
233 self.PortText.SetValue(wampSett[0]) |
|
234 if length2 > 1: |
|
235 self.RealmText.SetValue(wampSett[1]) |
|
236 if length2 > 2: |
|
237 self.WAMPIDText.SetValue(wampSett[2]) |
|
238 |
|
239 def GetURI(self): |
|
240 if self.IpText.Validate(): |
|
241 typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type |
|
242 self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue() |
|
243 return self.uri |
|
244 else: |
|
245 return "" |
|
246 |
|
247 return WAMPConnectorPanel("WAMP", confnodesroot) |