connectors/PYRO/__init__.py
branch#2476
changeset 2006 c4ba142bf3fb
parent 2005 0d32b17f15b9
child 2010 bb9c28bd204f
equal deleted inserted replaced
2005:0d32b17f15b9 2006:c4ba142bf3fb
    34 import Pyro
    34 import Pyro
    35 import Pyro.core
    35 import Pyro.core
    36 import Pyro.util
    36 import Pyro.util
    37 from Pyro.errors import PyroError
    37 from Pyro.errors import PyroError
    38 
    38 
    39 try:
       
    40     import wx
       
    41     isWx = True
       
    42 except ImportError:
       
    43     isWx = False
       
    44 else:
       
    45     from controls.UriLocationEditor import IConnectorPanel
       
    46     from zope.interface import implementer
       
    47 
    39 
    48 service_type = '_PYRO._tcp.local.'
    40 service_type = '_PYRO._tcp.local.'
    49 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    41 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    50 # supported by this connector confnode.
    42 # supported by this connector confnode.
    51 #
    43 #
    52 # for connectors that do not support DNS-SD, this attribute can be omitted
    44 # for connectors that do not support DNS-SD, this attribute can be omitted
    53 # or set to an empty list.
    45 # or set to an empty list.
    54 
       
    55 URITypes = ["LOCAL", "PYRO", "PYROS"]
       
    56 
    46 
    57 
    47 
    58 def PYRO_connector_factory(uri, confnodesroot):
    48 def PYRO_connector_factory(uri, confnodesroot):
    59     """
    49     """
    60     This returns the connector to Pyro style PLCobject
    50     This returns the connector to Pyro style PLCobject
   212                 member = PyroCatcher(my_local_func, None)
   202                 member = PyroCatcher(my_local_func, None)
   213                 self.__dict__[attrName] = member
   203                 self.__dict__[attrName] = member
   214             return member
   204             return member
   215 
   205 
   216     return PyroProxyProxy()
   206     return PyroProxyProxy()
   217 
       
   218 if isWx:
       
   219     def PYRO_connector_dialog(confnodesroot):
       
   220         [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
       
   221 
       
   222 
       
   223         @implementer(IConnectorPanel)
       
   224         class PYROConnectorPanel(wx.Panel):
       
   225             def __init__(self, typeConnector, parrent, *args, **kwargs):
       
   226                 self.type = typeConnector
       
   227                 self.parrent = parrent
       
   228                 wx.Panel.__init__(self, parrent, *args, **kwargs)
       
   229                 self._init_ctrls()
       
   230                 self._init_sizers()
       
   231                 self.uri = None
       
   232 
       
   233             def _init_ctrls(self):
       
   234                 self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
       
   235                 self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
       
   236 
       
   237             def _init_sizers(self):
       
   238                 self.mainSizer = wx.BoxSizer(wx.VERTICAL)
       
   239                 self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
       
   240                 self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
       
   241 
       
   242                 self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
   243                 self.uriSizer.AddSpacer((0,0))
       
   244                 self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
       
   245                 self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
       
   246 
       
   247                 self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
       
   248                 self.portSizer.AddSpacer((0,0))
       
   249                 self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
       
   250                 self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
       
   251 
       
   252                 self.SetSizer(self.mainSizer)
       
   253 
       
   254             def SetURI(self, uri):
       
   255                 self.uri = uri
       
   256                 uri_list = uri.strip().split(":")
       
   257                 length = len(uri_list)
       
   258                 if length == 3:
       
   259                     self.IpText.SetValue(uri_list[1].strip("/"))
       
   260                     self.PortText.SetValue(uri_list[2])
       
   261                 elif length == 2:
       
   262                     self.IpText.SetValue(uri_list[1].strip("/"))
       
   263 
       
   264 
       
   265             def GetURI(self):
       
   266                 self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
       
   267                 return self.uri
       
   268 
       
   269         return PYROConnectorPanel("PYRO", confnodesroot)