connectors/PYRO/dialog.py
changeset 2010 bb9c28bd204f
parent 2008 1f31a2f61993
child 2179 84c4e56b38d6
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 
       
    12 import wx
       
    13 from controls.UriLocationEditor import IConnectorPanel
       
    14 from zope.interface import implementer
       
    15 
       
    16 URITypes = ["LOCAL", "PYRO", "PYROS"]
       
    17 
       
    18 
       
    19 def PYRO_connector_dialog(confnodesroot):
       
    20     [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
       
    21 
       
    22 
       
    23     @implementer(IConnectorPanel)
       
    24     class PYROConnectorPanel(wx.Panel):
       
    25         def __init__(self, typeConnector, parrent, *args, **kwargs):
       
    26             self.type = typeConnector
       
    27             self.parrent = parrent
       
    28             wx.Panel.__init__(self, parrent, *args, **kwargs)
       
    29             self._init_ctrls()
       
    30             self._init_sizers()
       
    31             self.uri = None
       
    32 
       
    33         def _init_ctrls(self):
       
    34             self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
       
    35             self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
       
    36 
       
    37         def _init_sizers(self):
       
    38             self.mainSizer = wx.BoxSizer(wx.VERTICAL)
       
    39             self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    40             self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    41 
       
    42             self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    43             self.uriSizer.AddSpacer((0,0))
       
    44             self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    45             self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
       
    46 
       
    47             self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    48             self.portSizer.AddSpacer((0,0))
       
    49             self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    50             self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
       
    51 
       
    52             self.SetSizer(self.mainSizer)
       
    53 
       
    54         def SetURI(self, uri):
       
    55             self.uri = uri
       
    56             uri_list = uri.strip().split(":")
       
    57             length = len(uri_list)
       
    58             if length == 3:
       
    59                 self.IpText.SetValue(uri_list[1].strip("/"))
       
    60                 self.PortText.SetValue(uri_list[2])
       
    61             elif length == 2:
       
    62                 self.IpText.SetValue(uri_list[1].strip("/"))
       
    63 
       
    64 
       
    65         def GetURI(self):
       
    66             self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
       
    67             return self.uri
       
    68 
       
    69     return PYROConnectorPanel("PYRO", confnodesroot)