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 zope.interface import implementer |
|
14 |
|
15 from controls.UriLocationEditor import IConnectorPanel |
|
16 |
|
17 URITypes = ["LOCAL", "PYRO", "PYROS"] |
|
18 |
|
19 |
|
20 def PYRO_connector_dialog(confnodesroot): |
|
21 [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)] |
|
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.FlexGridSizer(cols=2, hgap=10, rows=5, vgap=10) |
|
39 self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI host:")), |
|
40 flag=wx.ALIGN_CENTER_VERTICAL) |
|
41 self.mainSizer.AddWindow(self.IpText, flag=wx.GROW) |
|
42 |
|
43 self.mainSizer.AddWindow(wx.StaticText(self, label=_("URI port:")), |
|
44 flag=wx.ALIGN_CENTER_VERTICAL) |
|
45 self.mainSizer.AddWindow(self.PortText, flag=wx.GROW) |
|
46 self.SetSizer(self.mainSizer) |
|
47 |
|
48 def SetURI(self, uri): |
|
49 self.uri = uri |
|
50 uri_list = uri.strip().split(":") |
|
51 length = len(uri_list) |
|
52 if length == 3: |
|
53 self.IpText.SetValue(uri_list[1].strip("/")) |
|
54 self.PortText.SetValue(uri_list[2]) |
|
55 elif length == 2: |
|
56 self.IpText.SetValue(uri_list[1].strip("/")) |
|
57 |
|
58 def GetURI(self): |
|
59 self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue() |
|
60 return self.uri |
|
61 |
|
62 return PYROConnectorPanel("PYRO", confnodesroot) |
|