connectors/PYRO/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
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    11
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 = ["LOCAL", "PYRO", "PYROS"]
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 PYRO_connector_dialog(confnodesroot):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    21
    [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
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 PYROConnectorPanel(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))
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    36
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    37
        def _init_sizers(self):
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    38
            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: 2179
diff changeset
    39
            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: 2179
diff changeset
    40
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    41
            self.mainSizer.AddWindow(self.IpText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    42
2180
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    43
            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: 2179
diff changeset
    44
                                     flag=wx.ALIGN_CENTER_VERTICAL)
017ad9cc20b9 Don't use fixed width labels in WAMP and PYRO dialogs
Andrey Skvortsov <andrej.skvortzov@gmail.com>
parents: 2179
diff changeset
    45
            self.mainSizer.AddWindow(self.PortText, flag=wx.GROW)
2007
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    46
            self.SetSizer(self.mainSizer)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    47
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    48
        def SetURI(self, uri):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    49
            self.uri = uri
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    50
            uri_list = uri.strip().split(":")
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    51
            length = len(uri_list)
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    52
            if length == 3:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    53
                self.IpText.SetValue(uri_list[1].strip("/"))
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    54
                self.PortText.SetValue(uri_list[2])
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    55
            elif length == 2:
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    56
                self.IpText.SetValue(uri_list[1].strip("/"))
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    57
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    58
        def GetURI(self):
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    59
            self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    60
            return self.uri
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    61
ef2d479f564f #2476 Connectors dialog module added.
dporopat <denis.poropat@smarteh.si>
parents:
diff changeset
    62
    return PYROConnectorPanel("PYRO", confnodesroot)