summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-06 11:00:04 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-06 11:00:04 (GMT)
commit645058d11a0ce6616d93cce692bb1378e61efb80 (patch)
tree16ce60bf4c02ce722c8873bcf8975d0aea1e2030 /Modules
parent008d88b46218ea618455c89cba74132be223c1a4 (diff)
downloadcpython-645058d11a0ce6616d93cce692bb1378e61efb80.zip
cpython-645058d11a0ce6616d93cce692bb1378e61efb80.tar.gz
cpython-645058d11a0ce6616d93cce692bb1378e61efb80.tar.bz2
Issue #23880: Tkinter's getint() and getdouble() now support Tcl_Obj.
Tkinter's getdouble() now supports any numbers (in particular int).
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_tkinter.c32
1 files changed, 25 insertions, 7 deletions
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 208ec47..b048a48 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -1934,12 +1934,18 @@ _tkinter_tkapp_getint(TkappObject *self, PyObject *arg)
return arg;
}
- if (!PyArg_Parse(arg, "s:getint", &s))
- return NULL;
- CHECK_STRING_LENGTH(s);
- value = Tcl_NewStringObj(s, -1);
- if (value == NULL)
- return Tkinter_Error((PyObject *)self);
+ if (PyTclObject_Check(arg)) {
+ value = ((PyTclObject*)arg)->value;
+ Tcl_IncrRefCount(value);
+ }
+ else {
+ if (!PyArg_Parse(arg, "s:getint", &s))
+ return NULL;
+ CHECK_STRING_LENGTH(s);
+ value = Tcl_NewStringObj(s, -1);
+ if (value == NULL)
+ return Tkinter_Error((PyObject *)self);
+ }
/* Don't use Tcl_GetInt() because it returns ambiguous result for value
in ranges -2**32..-2**31-1 and 2**31..2**32-1 (on 32-bit platform).
@@ -1977,12 +1983,24 @@ _tkinter_tkapp_getdouble(TkappObject *self, PyObject *arg)
return arg;
}
+ if (PyNumber_Check(arg)) {
+ return PyNumber_Float(arg);
+ }
+
+ if (PyTclObject_Check(arg)) {
+ if (Tcl_GetDoubleFromObj(Tkapp_Interp(self),
+ ((PyTclObject*)arg)->value,
+ &v) == TCL_ERROR)
+ return Tkinter_Error((PyObject *)self);
+ return PyFloat_FromDouble(v);
+ }
+
if (!PyArg_Parse(arg, "s:getdouble", &s))
return NULL;
CHECK_STRING_LENGTH(s);
if (Tcl_GetDouble(Tkapp_Interp(self), s, &v) == TCL_ERROR)
return Tkinter_Error((PyObject *)self);
- return Py_BuildValue("d", v);
+ return PyFloat_FromDouble(v);
}
/*[clinic input]