denis@2007: #!/usr/bin/env python
denis@2007: # -*- coding: utf-8 -*-
denis@2007: 
denis@2008: # Copyright (C) 2018: Smarteh
denis@2007: #
denis@2007: # See COPYING file for copyrights details.
denis@2007: 
denis@2007: 
denis@2007: from __future__ import absolute_import
denis@2007: from __future__ import print_function
denis@2007: 
denis@2007: import wx
andrej@2182: from zope.interface import implementer
andrej@2182: 
denis@2007: from controls.UriLocationEditor import IConnectorPanel
denis@2007: 
denis@2007: URITypes = ["LOCAL", "PYRO", "PYROS"]
denis@2007: 
denis@2007: 
denis@2007: def PYRO_connector_dialog(confnodesroot):
denis@2007:     [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
denis@2007: 
denis@2007:     @implementer(IConnectorPanel)
denis@2007:     class PYROConnectorPanel(wx.Panel):
denis@2007:         def __init__(self, typeConnector, parrent, *args, **kwargs):
denis@2007:             self.type = typeConnector
denis@2007:             self.parrent = parrent
denis@2007:             wx.Panel.__init__(self, parrent, *args, **kwargs)
denis@2007:             self._init_ctrls()
denis@2007:             self._init_sizers()
denis@2007:             self.uri = None
denis@2007: 
denis@2007:         def _init_ctrls(self):
andrej@2182:             self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size=wx.Size(200, -1))
andrej@2182:             self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size=wx.Size(200, -1))
denis@2007: 
denis@2007:         def _init_sizers(self):
andrej@2180:             self.mainSizer = wx.FlexGridSizer(cols=2, hgap=10, rows=5, vgap=10)
andrej@2180:             self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI host:")),
andrej@2180:                                      flag=wx.ALIGN_CENTER_VERTICAL)
andrej@2180:             self.mainSizer.AddWindow(self.IpText, flag=wx.GROW)
denis@2007: 
andrej@2180:             self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI port:")),
andrej@2180:                                      flag=wx.ALIGN_CENTER_VERTICAL)
andrej@2180:             self.mainSizer.AddWindow(self.PortText, flag=wx.GROW)
denis@2007:             self.SetSizer(self.mainSizer)
denis@2007: 
denis@2007:         def SetURI(self, uri):
denis@2007:             self.uri = uri
denis@2007:             uri_list = uri.strip().split(":")
denis@2007:             length = len(uri_list)
denis@2007:             if length == 3:
denis@2007:                 self.IpText.SetValue(uri_list[1].strip("/"))
denis@2007:                 self.PortText.SetValue(uri_list[2])
denis@2007:             elif length == 2:
denis@2007:                 self.IpText.SetValue(uri_list[1].strip("/"))
denis@2007: 
denis@2007:         def GetURI(self):
denis@2007:             self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
denis@2007:             return self.uri
denis@2007: 
denis@2007:     return PYROConnectorPanel("PYRO", confnodesroot)