cpython: 38747f32fa7b (original) (raw)

Mercurial > cpython

changeset 95439:38747f32fa7b

Issue #15133: _tkinter.tkapp.getboolean() now supports Tcl_Obj and always returns bool. tkinter.BooleanVar now validates input values (accepted bool, int, str, and Tcl_Obj). tkinter.BooleanVar.get() now always returns bool. [#15133]

Serhiy Storchaka storchaka@gmail.com
date Sat, 04 Apr 2015 12:44:30 +0300
parents ea94f6c87f5d(current diff)117f45749359(diff)
children 47a61a1c97b3
files Lib/test/test_tcl.py Lib/tkinter/__init__.py Misc/NEWS Modules/_tkinter.c
diffstat 6 files changed, 58 insertions(+), 17 deletions(-)[+] [-] Lib/test/test_tcl.py 3 Lib/tkinter/__init__.py 5 Lib/tkinter/test/test_tkinter/test_variables.py 34 Lib/tkinter/ttk.py 6 Misc/NEWS 4 Modules/_tkinter.c 23

line wrap: on

line diff

--- a/Lib/test/test_tcl.py +++ b/Lib/test/test_tcl.py @@ -179,7 +179,8 @@ class TclTest(unittest.TestCase): tcl = self.interp.tk self.assertIs(tcl.getboolean('on'), True) self.assertIs(tcl.getboolean('1'), True)

--- a/Lib/tkinter/init.py +++ b/Lib/tkinter/init.py @@ -391,6 +391,11 @@ class BooleanVar(Variable): """ Variable.init(self, master, value, name)

+ def get(self): """Return the value of the variable as a bool.""" try:

--- a/Lib/tkinter/test/test_tkinter/test_variables.py +++ b/Lib/tkinter/test/test_tkinter/test_variables.py @@ -1,6 +1,7 @@ import unittest -from tkinter import Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl +from tkinter import (Variable, StringVar, IntVar, DoubleVar, BooleanVar, Tcl,

class Var(Variable): @@ -159,16 +160,41 @@ class TestBooleanVar(TestBase): def test_default(self): v = BooleanVar(self.root)

def test_get(self): v = BooleanVar(self.root, True, "name")

+

def test_invalid_value_domain(self):

--- a/Lib/tkinter/ttk.py +++ b/Lib/tkinter/ttk.py @@ -573,7 +573,7 @@ class Widget(tkinter.Widget): if ret and callback: return callback(*args, **kw)

def state(self, statespec=None): @@ -681,7 +681,7 @@ class Entry(Widget, tkinter.Entry): """Force revalidation, independent of the conditions specified by the validate option. Returns False if validation fails, True if it succeeds. Sets or clears the invalid state accordingly."""

class Combobox(Entry): @@ -1231,7 +1231,7 @@ class Treeview(Widget, tkinter.XView, tk def exists(self, item): """Returns True if the specified item is present in the tree, False otherwise."""

def focus(self, item=None):

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -19,6 +19,10 @@ Core and Builtins Library ------- +- Issue #15133: _tkinter.tkapp.getboolean() now supports Tcl_Obj and always

--- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -1934,19 +1934,24 @@ Tkapp_GetDouble(PyObject *self, PyObject } static PyObject * -Tkapp_GetBoolean(PyObject *self, PyObject *args) +Tkapp_GetBoolean(PyObject *self, PyObject *arg) { char *s; int v;

+

+