summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-04-04 09:43:01 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-04-04 09:43:01 (GMT)
commit9a6e201f7d5f147b776274c1598089fc68859e98 (patch)
treee0daed0ebec9426b48936bb37e2dc91ef74e0c79 /Modules
parentc9ba38c21c9a7ba9e26cdfaee7f6e201f561222e (diff)
downloadcpython-9a6e201f7d5f147b776274c1598089fc68859e98.zip
cpython-9a6e201f7d5f147b776274c1598089fc68859e98.tar.gz
cpython-9a6e201f7d5f147b776274c1598089fc68859e98.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_tkinter.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 6599564..e31afae 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -1929,19 +1929,24 @@ Tkapp_GetDouble(PyObject *self, PyObject *args)
}
static PyObject *
-Tkapp_GetBoolean(PyObject *self, PyObject *args)
+Tkapp_GetBoolean(PyObject *self, PyObject *arg)
{
char *s;
int v;
- if (PyTuple_Size(args) == 1) {
- PyObject *o = PyTuple_GetItem(args, 0);
- if (PyLong_Check(o)) {
- Py_INCREF(o);
- return o;
- }
+ if (PyLong_Check(arg)) { /* int or bool */
+ return PyBool_FromLong(Py_SIZE(arg) != 0);
}
- if (!PyArg_ParseTuple(args, "s:getboolean", &s))
+
+ if (PyTclObject_Check(arg)) {
+ if (Tcl_GetBooleanFromObj(Tkapp_Interp(self),
+ ((PyTclObject*)arg)->value,
+ &v) == TCL_ERROR)
+ return Tkinter_Error(self);
+ return PyBool_FromLong(v);
+ }
+
+ if (!PyArg_Parse(arg, "s:getboolean", &s))
return NULL;
CHECK_STRING_LENGTH(s);
if (Tcl_GetBoolean(Tkapp_Interp(self), s, &v) == TCL_ERROR)
@@ -2854,7 +2859,7 @@ static PyMethodDef Tkapp_methods[] =
{"globalunsetvar", Tkapp_GlobalUnsetVar, METH_VARARGS},
{"getint", Tkapp_GetInt, METH_VARARGS},
{"getdouble", Tkapp_GetDouble, METH_VARARGS},
- {"getboolean", Tkapp_GetBoolean, METH_VARARGS},
+ {"getboolean", Tkapp_GetBoolean, METH_O},
{"exprstring", Tkapp_ExprString, METH_VARARGS},
{"exprlong", Tkapp_ExprLong, METH_VARARGS},
{"exprdouble", Tkapp_ExprDouble, METH_VARARGS},