discovery.py
changeset 399 77e23bf04c33
parent 392 6617d3fb43e2
child 644 b511cab580eb
equal deleted inserted replaced
398:31d08063b5d6 399:77e23bf04c33
    19 #
    19 #
    20 #You should have received a copy of the GNU General Public
    20 #You should have received a copy of the GNU General Public
    21 #License along with this library; if not, write to the Free Software
    21 #License along with this library; if not, write to the Free Software
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    22 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    23 
    23 
       
    24 import socket
    24 import wx
    25 import wx
       
    26 import  wx.lib.mixins.listctrl  as  listmix
    25 from Zeroconf import *
    27 from Zeroconf import *
    26 import socket
    28 
    27 import  wx.lib.mixins.listctrl  as  listmix
    29 import connectors
    28 
    30 
    29 class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
    31 class AutoWidthListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin):
    30     def __init__(self, parent, id, name, pos=wx.DefaultPosition,
    32     def __init__(self, parent, id, name, pos=wx.DefaultPosition,
    31                  size=wx.DefaultSize, style=0):
    33                  size=wx.DefaultSize, style=0):
    32         wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name)
    34         wx.ListCtrl.__init__(self, parent, id, pos, size, style, name=name)
   115         
   117         
   116         self.itemDataMap = {}
   118         self.itemDataMap = {}
   117         self.nextItemId = 0
   119         self.nextItemId = 0
   118         
   120         
   119         self.URI = None
   121         self.URI = None
   120         self.Browser = None
   122         self.Browsers = []
   121         
   123         
   122         self.ZeroConfInstance = Zeroconf()
   124         self.ZeroConfInstance = Zeroconf()
   123         self.RefreshList()
   125         self.RefreshList()
   124         
   126         
   125     def __del__(self):
   127     def __del__(self):
   126         self.Browser.cancel()
   128         for browser in self.Browsers:
       
   129             browser.cancel()
   127         self.ZeroConfInstance.close()
   130         self.ZeroConfInstance.close()
   128         
   131         
   129     def RefreshList(self):
   132     def RefreshList(self):
   130         self.Browser = ServiceBrowser(self.ZeroConfInstance, "_PYRO._tcp.local.", self)        
   133         for browser in self.Browsers:
       
   134             browser.cancel()
       
   135         
       
   136         self.Browsers = []
       
   137         for t in connectors.dnssd_connectors.keys():
       
   138             self.Browsers.append(ServiceBrowser(self.ZeroConfInstance, t, self))
   131 
   139 
   132     def OnRefreshButton(self, event):
   140     def OnRefreshButton(self, event):
   133         self.ServicesList.DeleteAllItems()
   141         self.ServicesList.DeleteAllItems()
   134         self.Browser.cancel()
       
   135         self.RefreshList()
   142         self.RefreshList()
   136 
   143 
   137     def OnLocalButton(self, event):
   144     def OnLocalButton(self, event):
   138         self.URI = "LOCAL://"
   145         self.URI = "LOCAL://"
   139         self.EndModal(wx.ID_OK)
   146         self.EndModal(wx.ID_OK)