connectors/WAMP/dialog.py
author Andrey Skvortsov <andrej.skvortzov@gmail.com>
Sat, 09 Jun 2018 17:14:56 +0300
changeset 2182 eeca1aff0691
parent 2180 017ad9cc20b9
permissions -rw-r--r--
Fix linter errors
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
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    11
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    12
import wx
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    13
from zope.interface import implementer
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    14
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    15
from controls.UriLocationEditor import IConnectorPanel
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
URITypes = ["WAMP", "WAMPS"]
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    18
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    19
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    20
def WAMP_connector_dialog(confnodesroot):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    21
    [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
    22
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    23
    @implementer(IConnectorPanel)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    24
    class WAMPConnectorPanel(wx.Panel):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    25
        def __init__(self, typeConnector, parrent, *args, **kwargs):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    26
            self.type = typeConnector
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    27
            self.parrent = parrent
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    28
            wx.Panel.__init__(self, parrent, *args, **kwargs)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    29
            self._init_ctrls()
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    30
            self._init_sizers()
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    31
            self.uri = None
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    32
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    33
        def _init_ctrls(self):
2182
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    34
            self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size=wx.Size(200, -1))
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    35
            self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size=wx.Size(200, -1))
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    36
            self.RealmText = wx.TextCtrl(parent=self, id=ID_REALMTEXT, size=wx.Size(200, -1))
eeca1aff0691 Fix linter errors
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2180
diff changeset
    37
            self.WAMPIDText = wx.TextCtrl(parent=self, id=ID_WAMPIDTEXT, size=wx.Size(200, -1))
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    38
            self.SecureCheckbox = wx.CheckBox(self, ID_SECURECHECKBOX, _("Is connection secure?"))
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    39
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    40
        def _init_sizers(self):
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    41
            self.mainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=5, vgap=10)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    42
            self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI host:")),
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    43
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    44
            self.mainSizer.AddWindow(self.IpText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    45
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    46
            self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI port:")),
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    47
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    48
            self.mainSizer.AddWindow(self.PortText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    49
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    50
            self.mainSizer.AddWindow(wx.StaticText(self, label=_("Realm:")),
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    51
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    52
            self.mainSizer.AddWindow(self.RealmText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    53
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    54
            self.mainSizer.AddWindow(wx.StaticText(self, label=_("WAMP ID:")),
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    55
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    56
            self.mainSizer.AddWindow(self.WAMPIDText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    57
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    58
            self.mainSizer.AddWindow(wx.StaticText(self, label=""), flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2008
diff changeset
    59
            self.mainSizer.AddWindow(self.SecureCheckbox, flag=wx.GROW)
2007
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.SetSizer(self.mainSizer)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    62
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    63
        def SetURI(self, uri):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    64
            self.uri = uri
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    65
            uri_list = uri.strip().split(":")
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    66
            length = len(uri_list)
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
            if length > 0:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    69
                if uri_list[0] == URITypes[1]:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    70
                    self.SecureCheckbox.SetValue(True)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    71
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    72
                if length > 2:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    73
                    self.IpText.SetValue(uri_list[1].strip("/"))
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    74
                    wampSett = uri_list[2].split("#")
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    75
                    length2 = len(wampSett)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    76
                    if length2 > 0:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    77
                        self.PortText.SetValue(wampSett[0])
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    78
                        if length2 > 1:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    79
                            self.RealmText.SetValue(wampSett[1])
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    80
                            if length2 > 2:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    81
                                self.WAMPIDText.SetValue(wampSett[2])
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    82
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    83
        def GetURI(self):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    84
            if self.IpText.Validate():
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    85
                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
    86
                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
    87
                return self.uri
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    88
            else:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    89
                return ""
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    90
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    91
    return WAMPConnectorPanel("WAMP", confnodesroot)