author | Edouard Tisserant |
Wed, 23 May 2018 10:53:57 +0200 | |
changeset 2011 | 64268e87613e |
parent 2008 | 1f31a2f61993 |
child 2180 | 017ad9cc20b9 |
permissions | -rw-r--r-- |
2007
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
1 |
#!/usr/bin/env python |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
2 |
# -*- coding: utf-8 -*- |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
3 |
|
2008
1f31a2f61993
#2476 Changes to the comment.
dporopat <denis.poropat@smarteh.si>
parents:
2007
diff
changeset
|
4 |
# Copyright (C) 2018: Smarteh |
2007
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
5 |
# |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
6 |
# See COPYING file for copyrights details. |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
7 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
8 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
9 |
from __future__ import absolute_import |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
10 |
from __future__ import print_function |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
11 |
import wx |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
12 |
from controls.UriLocationEditor import IConnectorPanel |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
13 |
from zope.interface import implementer |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
14 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
15 |
URITypes = ["WAMP", "WAMPS"] |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
16 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
17 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
18 |
def WAMP_connector_dialog(confnodesroot): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
19 |
[ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)] |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
20 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
21 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
22 |
@implementer(IConnectorPanel) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
23 |
class WAMPConnectorPanel(wx.Panel): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
24 |
def __init__(self, typeConnector, parrent, *args, **kwargs): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
25 |
self.type = typeConnector |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
26 |
self.parrent = parrent |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
27 |
wx.Panel.__init__(self, parrent, *args, **kwargs) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
28 |
self._init_ctrls() |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
29 |
self._init_sizers() |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
30 |
self.uri = None |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
31 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
32 |
def _init_ctrls(self): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
33 |
self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
34 |
self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
35 |
self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size = wx.Size(200, -1)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
36 |
self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size = wx.Size(200, -1)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
37 |
self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?")) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
38 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
39 |
def _init_sizers(self): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
40 |
self.mainSizer = wx.BoxSizer(wx.VERTICAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
41 |
self.uriSizer = wx.BoxSizer(wx.HORIZONTAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
42 |
self.portSizer = wx.BoxSizer(wx.HORIZONTAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
43 |
self.realmSizer = wx.BoxSizer(wx.HORIZONTAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
44 |
self.wampIDSizer = wx.BoxSizer(wx.HORIZONTAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
45 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
46 |
self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI host:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
47 |
self.uriSizer.AddSpacer((0,0)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
48 |
self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
49 |
self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
50 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
51 |
self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI port:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
52 |
self.portSizer.AddSpacer((0,0)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
53 |
self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
54 |
self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
55 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
56 |
self.realmSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Realm:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
57 |
self.realmSizer.AddSpacer((0, 0)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
58 |
self.realmSizer.Add(self.RealmText, proportion=1, flag=wx.ALIGN_RIGHT) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
59 |
self.mainSizer.Add(self.realmSizer, border=2, flag=wx.ALL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
60 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
61 |
self.wampIDSizer.Add(wx.StaticText(self, wx.ID_ANY, _("WAMP ID:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
62 |
self.wampIDSizer.AddSpacer((0, 0)) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
63 |
self.wampIDSizer.Add(self.WAMPIDText, proportion=1, flag=wx.ALIGN_RIGHT) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
64 |
self.mainSizer.Add(self.wampIDSizer, border=2, flag=wx.ALL) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
65 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
66 |
self.mainSizer.Add(self.SecureCheckbox, proportion=1, flag=wx.ALIGN_LEFT) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
67 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
68 |
self.SetSizer(self.mainSizer) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
69 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
70 |
def SetURI(self, uri): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
71 |
self.uri = uri |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
72 |
uri_list = uri.strip().split(":") |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
73 |
length = len(uri_list) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
74 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
75 |
if length > 0: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
76 |
if uri_list[0] == URITypes[1]: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
77 |
self.SecureCheckbox.SetValue(True) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
78 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
79 |
if length > 2: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
80 |
self.IpText.SetValue(uri_list[1].strip("/")) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
81 |
wampSett = uri_list[2].split("#") |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
82 |
length2 = len(wampSett) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
83 |
if length2 > 0: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
84 |
self.PortText.SetValue(wampSett[0]) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
85 |
if length2 > 1: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
86 |
self.RealmText.SetValue(wampSett[1]) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
87 |
if length2 > 2: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
88 |
self.WAMPIDText.SetValue(wampSett[2]) |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
89 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
90 |
def GetURI(self): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
91 |
if self.IpText.Validate(): |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
92 |
typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
93 |
self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue() |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
94 |
return self.uri |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
95 |
else: |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
96 |
return "" |
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
97 |
|
ef2d479f564f
#2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff
changeset
|
98 |
return WAMPConnectorPanel("WAMP", confnodesroot) |