connectors/PYRO/dialog.py
branch#2476
changeset 2007 ef2d479f564f
child 2008 1f31a2f61993
equal deleted inserted replaced
2006:c4ba142bf3fb 2007:ef2d479f564f
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # This file is part of Beremiz, a Integrated Development Environment for
       
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
       
     6 #
       
     7 # Copyright (C) 2007: Edouard TISSERANT and Laurent BESSARD
       
     8 #
       
     9 # See COPYING file for copyrights details.
       
    10 #
       
    11 # This program is free software; you can redistribute it and/or
       
    12 # modify it under the terms of the GNU General Public License
       
    13 # as published by the Free Software Foundation; either version 2
       
    14 # of the License, or (at your option) any later version.
       
    15 #
       
    16 # This program is distributed in the hope that it will be useful,
       
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    19 # GNU General Public License for more details.
       
    20 #
       
    21 # You should have received a copy of the GNU General Public License
       
    22 # along with this program; if not, write to the Free Software
       
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    24 
       
    25 
       
    26 from __future__ import absolute_import
       
    27 from __future__ import print_function
       
    28 
       
    29 import wx
       
    30 from controls.UriLocationEditor import IConnectorPanel
       
    31 from zope.interface import implementer
       
    32 
       
    33 URITypes = ["LOCAL", "PYRO", "PYROS"]
       
    34 
       
    35 
       
    36 def PYRO_connector_dialog(confnodesroot):
       
    37     [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
       
    38 
       
    39 
       
    40     @implementer(IConnectorPanel)
       
    41     class PYROConnectorPanel(wx.Panel):
       
    42         def __init__(self, typeConnector, parrent, *args, **kwargs):
       
    43             self.type = typeConnector
       
    44             self.parrent = parrent
       
    45             wx.Panel.__init__(self, parrent, *args, **kwargs)
       
    46             self._init_ctrls()
       
    47             self._init_sizers()
       
    48             self.uri = None
       
    49 
       
    50         def _init_ctrls(self):
       
    51             self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
       
    52             self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
       
    53 
       
    54         def _init_sizers(self):
       
    55             self.mainSizer = wx.BoxSizer(wx.VERTICAL)
       
    56             self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    57             self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
       
    58 
       
    59             self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    60             self.uriSizer.AddSpacer((0,0))
       
    61             self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    62             self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
       
    63 
       
    64             self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
    65             self.portSizer.AddSpacer((0,0))
       
    66             self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
       
    67             self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
       
    68 
       
    69             self.SetSizer(self.mainSizer)
       
    70 
       
    71         def SetURI(self, uri):
       
    72             self.uri = uri
       
    73             uri_list = uri.strip().split(":")
       
    74             length = len(uri_list)
       
    75             if length == 3:
       
    76                 self.IpText.SetValue(uri_list[1].strip("/"))
       
    77                 self.PortText.SetValue(uri_list[2])
       
    78             elif length == 2:
       
    79                 self.IpText.SetValue(uri_list[1].strip("/"))
       
    80 
       
    81 
       
    82         def GetURI(self):
       
    83             self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
       
    84             return self.uri
       
    85 
       
    86     return PYROConnectorPanel("PYRO", confnodesroot)