[Python-checkins] r66032 - in sandbox/trunk/ttk-gsoc/src: 2.x/test/test_extensions.py 2.x/ttk.py 3.x/test/test_extensions.py 3.x/ttk.py

guilherme.polo python-checkins at python.org
Mon Aug 25 18:38:53 CEST 2008


Author: guilherme.polo
Date: Mon Aug 25 18:38:53 2008
New Revision: 66032

Log:
Fixed OptionMenu destroy so the variable doesn't live "forever".


Modified:
   sandbox/trunk/ttk-gsoc/src/2.x/test/test_extensions.py
   sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
   sandbox/trunk/ttk-gsoc/src/3.x/test/test_extensions.py
   sandbox/trunk/ttk-gsoc/src/3.x/ttk.py

Modified: sandbox/trunk/ttk-gsoc/src/2.x/test/test_extensions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/test/test_extensions.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/test/test_extensions.py	Mon Aug 25 18:38:53 2008
@@ -74,17 +74,26 @@
 
 
 class OptionMenuTest(unittest.TestCase):
-    # XXX
 
     def setUp(self):
         self.root = Tkinter.Tk()
-        self.textvar = Tkinter.StringVar()
+        self.textvar = Tkinter.StringVar(self.root)
 
     def tearDown(self):
         del self.textvar
         del self.root
 
 
+    def test_widget_destroy(self):
+        var = Tkinter.StringVar(self.root)
+        optmenu = ttk.OptionMenu(self.root, var)
+        name = var._name
+        optmenu.destroy()
+        self.failUnlessEqual(optmenu.tk.globalgetvar(name), var.get())
+        del var
+        self.failUnlessRaises(Tkinter.TclError, optmenu.tk.globalgetvar, name)
+
+
     def test_initialization(self):
         self.failUnlessRaises(Tkinter.TclError,
             ttk.OptionMenu, self.root, self.textvar, invalid='thing')

Modified: sandbox/trunk/ttk-gsoc/src/2.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/2.x/ttk.py	Mon Aug 25 18:38:53 2008
@@ -1560,5 +1560,6 @@
 
 
     def destroy(self):
-        """Destroy this widget."""
+        """Destroy this widget and its associated variable."""
+        del self._variable
         Menubutton.destroy(self)

Modified: sandbox/trunk/ttk-gsoc/src/3.x/test/test_extensions.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/test/test_extensions.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/test/test_extensions.py	Mon Aug 25 18:38:53 2008
@@ -74,17 +74,26 @@
 
 
 class OptionMenuTest(unittest.TestCase):
-    # XXX
 
     def setUp(self):
         self.root = tkinter.Tk()
-        self.textvar = tkinter.StringVar()
+        self.textvar = tkinter.StringVar(self.root)
 
     def tearDown(self):
         del self.textvar
         del self.root
 
 
+    def test_widget_destroy(self):
+        var = tkinter.StringVar(self.root)
+        optmenu = ttk.OptionMenu(self.root, var)
+        name = var._name
+        optmenu.destroy()
+        self.failUnlessEqual(optmenu.tk.globalgetvar(name), var.get())
+        del var
+        self.failUnlessRaises(tkinter.TclError, optmenu.tk.globalgetvar, name)
+
+
     def test_initialization(self):
         self.failUnlessRaises(tkinter.TclError,
             ttk.OptionMenu, self.root, self.textvar, invalid='thing')

Modified: sandbox/trunk/ttk-gsoc/src/3.x/ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/src/3.x/ttk.py	Mon Aug 25 18:38:53 2008
@@ -1560,5 +1560,6 @@
 
 
     def destroy(self):
-        """Destroy this widget."""
+        """Destroy this widget and its associated variable."""
+        del self._variable
         Menubutton.destroy(self)


More information about the Python-checkins mailing list