1 #!/usr/bin/env python |
|
2 # -*- coding: utf-8 -*- |
|
3 |
|
4 # This file is part of Beremiz, a Integrated Development Environment for |
|
5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival. |
|
6 # |
|
7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD |
|
8 # |
|
9 # See COPYING file for copyrights details. |
|
10 # |
|
11 # This program is free software; you can redistribute it and/or |
|
12 # modify it under the terms of the GNU General Public License |
|
13 # as published by the Free Software Foundation; either version 2 |
|
14 # of the License, or (at your option) any later version. |
|
15 # |
|
16 # This program is distributed in the hope that it will be useful, |
|
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
19 # GNU General Public License for more details. |
|
20 # |
|
21 # You should have received a copy of the GNU General Public License |
|
22 # along with this program; if not, write to the Free Software |
|
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
24 |
|
25 |
|
26 from __future__ import absolute_import |
|
27 from __future__ import print_function |
|
28 import wx |
|
29 from controls.UriLocationEditor import IConnectorPanel |
|
30 from zope.interface import implementer |
|
31 |
|
32 URITypes = ["WAMP", "WAMPS"] |
|
33 |
|
34 |
|
35 def WAMP_connector_dialog(confnodesroot): |
|
36 [ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)] |
|
37 |
|
38 |
|
39 @implementer(IConnectorPanel) |
|
40 class WAMPConnectorPanel(wx.Panel): |
|
41 def __init__(self, typeConnector, parrent, *args, **kwargs): |
|
42 self.type = typeConnector |
|
43 self.parrent = parrent |
|
44 wx.Panel.__init__(self, parrent, *args, **kwargs) |
|
45 self._init_ctrls() |
|
46 self._init_sizers() |
|
47 self.uri = None |
|
48 |
|
49 def _init_ctrls(self): |
|
50 self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1)) |
|
51 self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1)) |
|
52 self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size = wx.Size(200, -1)) |
|
53 self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size = wx.Size(200, -1)) |
|
54 self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?")) |
|
55 |
|
56 def _init_sizers(self): |
|
57 self.mainSizer = wx.BoxSizer(wx.VERTICAL) |
|
58 self.uriSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
59 self.portSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
60 self.realmSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
61 self.wampIDSizer = wx.BoxSizer(wx.HORIZONTAL) |
|
62 |
|
63 self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI host:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
64 self.uriSizer.AddSpacer((0,0)) |
|
65 self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
66 self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL) |
|
67 |
|
68 self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI port:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
69 self.portSizer.AddSpacer((0,0)) |
|
70 self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
71 self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL) |
|
72 |
|
73 self.realmSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Realm:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
74 self.realmSizer.AddSpacer((0, 0)) |
|
75 self.realmSizer.Add(self.RealmText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
76 self.mainSizer.Add(self.realmSizer, border=2, flag=wx.ALL) |
|
77 |
|
78 self.wampIDSizer.Add(wx.StaticText(self, wx.ID_ANY, _("WAMP ID:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
|
79 self.wampIDSizer.AddSpacer((0, 0)) |
|
80 self.wampIDSizer.Add(self.WAMPIDText, proportion=1, flag=wx.ALIGN_RIGHT) |
|
81 self.mainSizer.Add(self.wampIDSizer, border=2, flag=wx.ALL) |
|
82 |
|
83 self.mainSizer.Add(self.SecureCheckbox, proportion=1, flag=wx.ALIGN_LEFT) |
|
84 |
|
85 self.SetSizer(self.mainSizer) |
|
86 |
|
87 def SetURI(self, uri): |
|
88 self.uri = uri |
|
89 uri_list = uri.strip().split(":") |
|
90 length = len(uri_list) |
|
91 |
|
92 if length > 0: |
|
93 if uri_list[0] == URITypes[1]: |
|
94 self.SecureCheckbox.SetValue(True) |
|
95 |
|
96 if length > 2: |
|
97 self.IpText.SetValue(uri_list[1].strip("/")) |
|
98 wampSett = uri_list[2].split("#") |
|
99 length2 = len(wampSett) |
|
100 if length2 > 0: |
|
101 self.PortText.SetValue(wampSett[0]) |
|
102 if length2 > 1: |
|
103 self.RealmText.SetValue(wampSett[1]) |
|
104 if length2 > 2: |
|
105 self.WAMPIDText.SetValue(wampSett[2]) |
|
106 |
|
107 def GetURI(self): |
|
108 if self.IpText.Validate(): |
|
109 typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type |
|
110 self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue() |
|
111 return self.uri |
|
112 else: |
|
113 return "" |
|
114 |
|
115 return WAMPConnectorPanel("WAMP", confnodesroot) |
|