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