connectors/PYRO/__init__.py
branch#2476
changeset 2005 0d32b17f15b9
parent 2001 bcbd41efd846
child 2006 c4ba142bf3fb
equal deleted inserted replaced
2001:bcbd41efd846 2005:0d32b17f15b9
    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 import wx
    39 try:
    40 from controls.UriLocationEditor import IConnectorPanel
    40     import wx
    41 from zope.interface import implementer
    41     isWx = True
       
    42 except ImportError:
       
    43     isWx = False
       
    44 else:
       
    45     from controls.UriLocationEditor import IConnectorPanel
       
    46     from zope.interface import implementer
    42 
    47 
    43 service_type = '_PYRO._tcp.local.'
    48 service_type = '_PYRO._tcp.local.'
    44 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    49 # this module attribute contains a list of DNS-SD (Zeroconf) service types
    45 # supported by this connector confnode.
    50 # supported by this connector confnode.
    46 #
    51 #
   208                 self.__dict__[attrName] = member
   213                 self.__dict__[attrName] = member
   209             return member
   214             return member
   210 
   215 
   211     return PyroProxyProxy()
   216     return PyroProxyProxy()
   212 
   217 
   213 
   218 if isWx:
   214 def PYRO_connector_dialog(confnodesroot):
   219     def PYRO_connector_dialog(confnodesroot):
   215     [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
   220         [ID_IPTEXT, ID_PORTTEXT] = [wx.NewId() for _init_ctrls in range(2)]
   216 
   221 
   217 
   222 
   218     @implementer(IConnectorPanel)
   223         @implementer(IConnectorPanel)
   219     class PYROConnectorPanel(wx.Panel):
   224         class PYROConnectorPanel(wx.Panel):
   220         def __init__(self, typeConnector, parrent, *args, **kwargs):
   225             def __init__(self, typeConnector, parrent, *args, **kwargs):
   221             self.type = typeConnector
   226                 self.type = typeConnector
   222             self.parrent = parrent
   227                 self.parrent = parrent
   223             wx.Panel.__init__(self, parrent, *args, **kwargs)
   228                 wx.Panel.__init__(self, parrent, *args, **kwargs)
   224             self._init_ctrls()
   229                 self._init_ctrls()
   225             self._init_sizers()
   230                 self._init_sizers()
   226             self.uri = None
   231                 self.uri = None
   227 
   232 
   228         def _init_ctrls(self):
   233             def _init_ctrls(self):
   229             self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
   234                 self.IpText = wx.TextCtrl(parent=self, id=ID_IPTEXT, size = wx.Size(200, -1))
   230             self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
   235                 self.PortText = wx.TextCtrl(parent=self, id=ID_PORTTEXT, size = wx.Size(200, -1))
   231 
   236 
   232         def _init_sizers(self):
   237             def _init_sizers(self):
   233             self.mainSizer = wx.BoxSizer(wx.VERTICAL)
   238                 self.mainSizer = wx.BoxSizer(wx.VERTICAL)
   234             self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
   239                 self.uriSizer = wx.BoxSizer(wx.HORIZONTAL)
   235             self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
   240                 self.portSizer = wx.BoxSizer(wx.HORIZONTAL)
   236 
   241 
   237             self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
   242                 self.uriSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI host:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
   238             self.uriSizer.AddSpacer((0,0))
   243                 self.uriSizer.AddSpacer((0,0))
   239             self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
   244                 self.uriSizer.Add(self.IpText, proportion=1, flag=wx.ALIGN_RIGHT)
   240             self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
   245                 self.mainSizer.Add(self.uriSizer, border=2, flag=wx.ALL)
   241 
   246 
   242             self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
   247                 self.portSizer.Add(wx.StaticText(self, wx.ID_ANY, "URI port:", size = wx.Size(70, -1)), proportion=0, flag=wx.ALIGN_CENTER_VERTICAL)
   243             self.portSizer.AddSpacer((0,0))
   248                 self.portSizer.AddSpacer((0,0))
   244             self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
   249                 self.portSizer.Add(self.PortText, proportion=1, flag=wx.ALIGN_RIGHT)
   245             self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
   250                 self.mainSizer.Add(self.portSizer, border=2, flag=wx.ALL)
   246 
   251 
   247             self.SetSizer(self.mainSizer)
   252                 self.SetSizer(self.mainSizer)
   248 
   253 
   249         def SetURI(self, uri):
   254             def SetURI(self, uri):
   250             self.uri = uri
   255                 self.uri = uri
   251             uri_list = uri.strip().split(":")
   256                 uri_list = uri.strip().split(":")
   252             length = len(uri_list)
   257                 length = len(uri_list)
   253             if length == 3:
   258                 if length == 3:
   254                 self.IpText.SetValue(uri_list[1].strip("/"))
   259                     self.IpText.SetValue(uri_list[1].strip("/"))
   255                 self.PortText.SetValue(uri_list[2])
   260                     self.PortText.SetValue(uri_list[2])
   256             elif length == 2:
   261                 elif length == 2:
   257                 self.IpText.SetValue(uri_list[1].strip("/"))
   262                     self.IpText.SetValue(uri_list[1].strip("/"))
   258 
   263 
   259 
   264 
   260         def GetURI(self):
   265             def GetURI(self):
   261             self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
   266                 self.uri = self.type+"://"+self.IpText.GetValue()+":"+self.PortText.GetValue()
   262             return self.uri
   267                 return self.uri
   263 
   268 
   264     return PYROConnectorPanel("PYRO", confnodesroot)
   269         return PYROConnectorPanel("PYRO", confnodesroot)