Greg Couch <[EMAIL PROTECTED]> added the comment: 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)) __________________________________ Tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue2693> __________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com