This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gregc
Recipients gregc, kbk, loewis
Date 2008-04-29.19:43:56
SpamBayes Score 6.5170616e-06
Marked as misclassified No
Message-id <1209498254.96.0.781952927448.issue2693@psf.upfronthosting.co.za>
In-reply-to
Content
Starting over:

The goal of this patch is to get Tk 8.5 to work with Python 2.5's Idle.
 It currently fails with a ValueError, "invalid literal for int() with
base 10: '(72,'" (the 72 changes depending on what was typed in).

The root cause of bug is due to an interaction between Tk 8.5 returning
more results as Tcl lists, instances of Idle's WidgetRedirector class
that wrap widget Tcl commands with the WidgetRedirector's dispatch
method, and _tkinter's internal PythonCmd function that stringifies
anything its gets from Python.  What happens is that when a Python
method is called on a redirected widget, the corresponding Tcl method is
called using the WidgetRedirector's imposter widget command, which calls
the WidgetRedirector's dispatch method from Tcl, which then invokes the
original widget Tcl command, and if that command returns a Tcl list,
_tkinter converts it to a Python tuple, the dispatch method returns the
tuple into _tkinter, _tkinter stringifies it so it looks like a Python
tuple representation instead of a Tcl list representation, returns it to
Tkinter which tries to parse it like a Tcl list representation, and
causes the ValueError.

The correct fix is already in Python 2.6a2, which is changing Text
class' index method in Tkinter.py to return a string, and changing
_tkinter's PythonCmd to convert Python objects to equivalent Tcl
objects.  Unfortunately backporting those simple changes to Python 2.5
cause a "SystemError: Objects/tupleobject.c:89: bad argument to internal
function".  While that is worth further investigation, Python 2.6a2
doesn't have that problem and a simple alternative fix is available for
Python 2.5, so that is for someone else to do.

The alternative fix that works in Python 2.5 is to make sure that the
Tcl list string representation is used for Python tuples that are
returned to _tkinter's PythonCmd.  Those changes are confined to the
WidgetRedirector's dispatch method.  Line 126 of WidgetRedirector.py:

    return self.tk.call((self.orig, operation) + args)

is replaced with:

    result = self.tk.call((self.orig, operation) + args)
    if isinstance(result, tuple):
        # convert to string ourselves so we get a Tcl list
        # that can be converted back into a tuple by Tkinter
        result = '{%s}' % '} {'.join(map(str, result))
    return result

For Tk 8.4, the if clause is never invoked because Idle does not use any
of the Tk 8.4 methods that return Tcl lists (luckily).  In Tk 8.5, the
additional quoting is only needed for the Tk text widget's tag names and
tag ranges commands when spaces are used for tag names (explicitly not
recommended), all other uses are lists of numbers.  Since none of Idle's
Text tags have spaces in them, that line can safely be replaced with:

        result = ' '.join(map(str, result))
History
Date User Action Args
2008-04-29 19:44:17gregcsetspambayes_score: 6.51706e-06 -> 6.5170616e-06
recipients: + gregc, loewis, kbk
2008-04-29 19:44:15gregcsetspambayes_score: 6.51706e-06 -> 6.51706e-06
messageid: <1209498254.96.0.781952927448.issue2693@psf.upfronthosting.co.za>
2008-04-29 19:44:12gregclinkissue2693 messages
2008-04-29 19:44:06gregccreate