connectors/WAMP/dialog.py
changeset 2010 bb9c28bd204f
parent 2008 1f31a2f61993
child 2180 017ad9cc20b9
equal deleted inserted replaced
2004:28af541d776b 2010:bb9c28bd204f
       
     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 import wx
       
    12 from controls.UriLocationEditor import IConnectorPanel
       
    13 from zope.interface import implementer
       
    14 
       
    15 URITypes = ["WAMP", "WAMPS"]
       
    16 
       
    17 
       
    18 def WAMP_connector_dialog(confnodesroot):
       
    19     [ID_IPTEXT, ID_PORTTEXT, ID_REALMTEXT, ID_WAMPIDTEXT, ID_SECURECHECKBOX] = [wx.NewId() for _init_ctrls in range(5)]
       
    20 
       
    21 
       
    22     @implementer(IConnectorPanel)
       
    23     class WAMPConnectorPanel(wx.Panel):
       
    24         def __init__(self, typeConnector, parrent, *args, **kwargs):
       
    25             self.type = typeConnector
       
    26             self.parrent = parrent
       
    27             wx.Panel.__init__(self, parrent, *args, **kwargs)
       
    28             self._init_ctrls()
       
    29             self._init_sizers()
       
    30             self.uri = None
       
    31 
       
    32         def _init_ctrls(self):
       
    33             self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
       
    34             self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
       
    35             self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size = wx.Size(200, -1))
       
    36             self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size = wx.Size(200, -1))
       
    37             self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?"))
       
    38 
       
    39         def _init_sizers(self):
       
    40             self.mainSizer = wx.BoxSizer(wx.VERTICAL)
       
    41             self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    42             self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    43             self.realmSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    44             self.wampIDSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    45 
       
    46             self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI host:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    47             self.uriSizer.AddSpacer((0,0))
       
    48             self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    49             self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
       
    50 
       
    51             self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, _("URI port:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    52             self.portSizer.AddSpacer((0,0))
       
    53             self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    54             self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
       
    55 
       
    56             self.realmSizer.Add(wx.StaticText(self, wx.ID_ANY, _("Realm:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    57             self.realmSizer.AddSpacer((0, 0))
       
    58             self.realmSizer.Add(self.RealmText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    59             self.mainSizer.Add(self.realmSizer, border=2, flag=wx.ALL)
       
    60 
       
    61             self.wampIDSizer.Add(wx.StaticText(self, wx.ID_ANY, _("WAMP ID:"), size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    62             self.wampIDSizer.AddSpacer((0, 0))
       
    63             self.wampIDSizer.Add(self.WAMPIDText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    64             self.mainSizer.Add(self.wampIDSizer, border=2, flag=wx.ALL)
       
    65 
       
    66             self.mainSizer.Add(self.SecureCheckbox, proportion=1, flag=wx.ALIGN_LEFT)
       
    67 
       
    68             self.SetSizer(self.mainSizer)
       
    69 
       
    70         def SetURI(self, uri):
       
    71             self.uri = uri
       
    72             uri_list = uri.strip().split(":")
       
    73             length = len(uri_list)
       
    74 
       
    75             if length > 0:
       
    76                 if uri_list[0] == URITypes[1]:
       
    77                     self.SecureCheckbox.SetValue(True)
       
    78 
       
    79                 if length > 2:
       
    80                     self.IpText.SetValue(uri_list[1].strip("/"))
       
    81                     wampSett = uri_list[2].split("#")
       
    82                     length2 = len(wampSett)
       
    83                     if length2 > 0:
       
    84                         self.PortText.SetValue(wampSett[0])
       
    85                         if length2 > 1:
       
    86                             self.RealmText.SetValue(wampSett[1])
       
    87                             if length2 > 2:
       
    88                                 self.WAMPIDText.SetValue(wampSett[2])
       
    89 
       
    90         def GetURI(self):
       
    91             if self.IpText.Validate():
       
    92                 typeForURI = self.type + "S" if self.SecureCheckbox.GetValue() else self.type
       
    93                 self.uri = typeForURI + "://" + self.IpText.GetValue() + ":" + self.PortText.GetValue() + "#" + self.RealmText.GetValue() + "#" + self.WAMPIDText.GetValue()
       
    94                 return self.uri
       
    95             else:
       
    96                 return ""
       
    97 
       
    98     return WAMPConnectorPanel("WAMP", confnodesroot)