1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # Copyright (C) 2018: Smarteh |
|
5 # |
|
6 # See COPYING file for copyrights details. |
|
7 |
|
8 |
|
9 from __future__ import absolute_import |
|
10 from __future__ import print_function |
|
11 |
|
12 import wx |
|
13 from zope.interface import implementer |
|
14 |
|
15 from controls.UriLocationEditor import IConnectorPanel |
|
16 |
|
17 URITypes = ["WAMP", "WAMPS"] |
|
18 |
|
19 |
|
20 def WAMP_connector_dialog(confnodesroot): |
|
21 [ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)] |
|
22 |
|
23 @implementer(IConnectorPanel) |
|
24 class WAMPConnectorPanel(wx.Panel): |
|
25 def __init__(self, typeConnector, parrent, *args, **kwargs): |
|
26 self.type = typeConnector |
|
27 self.parrent = parrent |
|
28 wx.Panel.__init__(self, parrent, *args, **kwargs) |
|
29 self._init_ctrls() |
|
30 self._init_sizers() |
|
31 self.uri = None |
|
32 |
|
33 def _init_ctrls(self): |
|
34 self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size=wx.Size(200, -1)) |
|
35 self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size=wx.Size(200, -1)) |
|
36 self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size=wx.Size(200, -1)) |
|
37 self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size=wx.Size(200, -1)) |
|
38 self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?")) |
|
39 |
|
40 def _init_sizers(self): |
|
41 self.mainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=5, vgap=10) |
|
42 self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI host:")), |
|
43 flag=wx.ALIGN_CENTER_VERTICAL) |
|
44 self.mainSizer.AddWindow(self.IpText, flag=wx.GROW) |
|
45 |
|
46 self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI port:")), |
|
47 flag=wx.ALIGN_CENTER_VERTICAL) |
|
48 self.mainSizer.AddWindow(self.PortText, flag=wx.GROW) |
|
49 |
|
50 self.mainSizer.AddWindow(wx.StaticText(self, label=_("Realm:")), |
|
51 flag=wx.ALIGN_CENTER_VERTICAL) |
|
52 self.mainSizer.AddWindow(self.RealmText, flag=wx.GROW) |
|
53 |
|
54 self.mainSizer.AddWindow(wx.StaticText(self, label=_("WAMP ID:")), |
|
55 flag=wx.ALIGN_CENTER_VERTICAL) |
|
56 self.mainSizer.AddWindow(self.WAMPIDText, flag=wx.GROW) |
|
57 |
|
58 self.mainSizer.AddWindow(wx.StaticText(self, label=""), flag=wx.ALIGN_CENTER_VERTICAL) |
|
59 self.mainSizer.AddWindow(self.SecureCheckbox, flag=wx.GROW) |
|
60 |
|
61 self.SetSizer(self.mainSizer) |
|
62 |
|
63 def SetURI(self, uri): |
|
64 self.uri = uri |
|
65 uri_list = uri.strip().split(":") |
|
66 length = len(uri_list) |
|
67 |
|
68 if length > 0: |
|
69 if uri_list[0] == URITypes[1]: |
|
70 self.SecureCheckbox.SetValue(True) |
|
71 |
|
72 if length > 2: |
|
73 self.IpText.SetValue(uri_list[1].strip("/")) |
|
74 wampSett = uri_list[2].split("#") |
|
75 length2 = len(wampSett) |
|
76 if length2 > 0: |
|
77 self.PortText.SetValue(wampSett[0]) |
|
78 if length2 > 1: |
|
79 self.RealmText.SetValue(wampSett[1]) |
|
80 if length2 > 2: |
|
81 self.WAMPIDText.SetValue(wampSett[2]) |
|
82 |
|
83 def GetURI(self): |
|
84 if self.IpText.Validate(): |
|
85 typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type |
|
86 self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue() |
|
87 return self.uri |
|
88 else: |
|
89 return "" |
|
90 |
|
91 return WAMPConnectorPanel("WAMP", confnodesroot) |
|