close ZeroConf object when exiting the Service Discovery window.
authorbtaylor@grond.willowglen.ab.ca
Mon, 06 Jul 2009 11:27:06 -0600
changeset 357 19db1076e93c
parent 356 e9698d0ee5f3
child 358 855b6fd21416
child 373 a7f26d9f214f
child 376 53b00ff1b2d6
close ZeroConf object when exiting the Service Discovery window.
(otherwise pythonw.exe does not exit when closing Beremiz on Windows)
discovery.py
--- a/discovery.py	Tue Jun 09 10:10:34 2009 +0200
+++ b/discovery.py	Mon Jul 06 11:27:06 2009 -0600
@@ -23,7 +23,7 @@
 #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 import wx
-from Zeroconf import *
+from Zeroconf import *
 import socket
 import  wx.lib.mixins.listctrl  as  listmix
 
@@ -77,11 +77,11 @@
         btsizer.AddGrowableCol(3)
 
         b = wx.Button(self, wx.ID_CANCEL, "Cancel")
-        #self.Bind(wx.EVT_BUTTON, self.OnClose, b)
+        self.Bind(wx.EVT_BUTTON, self.OnCancel, b)
         btsizer.Add(b)
 
         b = wx.Button(self, wx.ID_OK, "OK")
-        #self.Bind(wx.EVT_BUTTON, self.OnConnect, b)
+        self.Bind(wx.EVT_BUTTON, self.OnOk, b)
         b.SetDefault()
         btsizer.Add(b)
 
@@ -94,6 +94,8 @@
         self.zConfInstance = Zeroconf()
         self.RefreshList()
 
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
+
     def RefreshList(self):
         type = "_PYRO._tcp.local."
         self.browser = ServiceBrowser(self.zConfInstance, type, self)        
@@ -103,6 +105,18 @@
         self.browser.cancel()
         self.RefreshList()
 
+    def OnClose(self, event):
+        self.zConfInstance.close()
+        event.Skip()
+
+    def OnCancel(self, event):
+        self.zConfInstance.close()
+        event.Skip()
+
+    def OnOk(self, event):
+        self.zConfInstance.close()
+        event.Skip()
+
     # Used by the ColumnSorterMixin, see wx/lib/mixins/listctrl.py
     def GetListCtrl(self):
         return self.list
@@ -143,11 +157,11 @@
     def GetResult(self):
         return self.my_result
         
-    def removeService(self, zeroconf, type, name):
+    def removeService(self, zeroconf, type, name):
         pass
-	
+
     def addService(self, zeroconf, type, name):
-        info = self.zConfInstance.getServiceInfo(type, name)
+        info = self.zConfInstance.getServiceInfo(type, name)
         typename = type.split(".")[0][1:]
         num_items = self.list.GetItemCount()
         self.list.InsertStringItem(num_items, name.split(".")[0])