classification
Title: tk_focusNext() fails
Type: behavior Stage:
Components: Tkinter Versions: Python 3.0, Python 2.6, Python 2.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: loewis Nosy List: douardda, gpolo, jepler, lither, loewis, perrygreenfield, reowen
Priority: normal Keywords: patch

Created on 2003-09-02 21:58 by perrygreenfield, last changed 2008-08-02 07:25 by loewis. This issue is now closed.

Files
File name Uploaded Description Edit
Tkinter_patch.txt reowen, 2008-02-21 18:10 Path for Tkinter.py based on current svn
bugfix_and_revamp_nametowidget.diff gpolo, 2008-04-24 20:40
Messages (10)
msg18049 - (view) Author: Perry Greenfield (perrygreenfield) Date: 2003-09-02 21:58
Calls to the widget method tk_focusNext() fail with
"unsubscriptable object" error. Looking at the Tkinter.py 
code for the routine shows this statement:

name = self.tk.call('tk_focusNext', self._w)

(line 433)

which used to return a string in 2.2 but now returns
a "cmdName object". When this is passed to 
self._nametowidget(name), it fails when it tries to
subscript name (line 1006) since the object does
not support indexing. Perhaps str(name) or
name.string is more appropriate now? (when
that change is made, it works--well, I tested
name.string and that worked)

Perry Greenfield (perry@stsci.edu)
msg18050 - (view) Author: Perry Greenfield (perrygreenfield) Date: 2003-09-03 13:29
Logged In: YES 
user_id=252130

Presumably the same problem exists with tk_focusPrev.
msg18051 - (view) Author: Jeff Epler (jepler) Date: 2003-09-07 15:23
Logged In: YES 
user_id=2772

Presumably, _nametowidget() should be modified to work properly with a "cmdName object", rather than modifying each site that gets a widget path from a tk command.  
msg18052 - (view) Author: David Douard (douardda) Date: 2005-11-09 15:03
Logged In: YES 
user_id=692511

The problem is still not resolved for now (AFAIK).

Here is a very simple patch for Tkinter.py:

*** 432,442 ****
--- 432,446 ----
          to 0."""
          name = self.tk.call('tk_focusNext', self._w)
          if not name: return None
+         try: name=name.string
+         except: pass
          return self._nametowidget(name)
      def tk_focusPrev(self):
          """Return previous widget in the focus order. See
tk_focusNext for details."""
          name = self.tk.call('tk_focusPrev', self._w)
          if not name: return None
+         try: name=name.string
+         except: pass
          return self._nametowidget(name)
      def after(self, ms, func=None, *args):
          """Call function once after given time.

Note: I have made this (try/except) cause I have encountered
cases where "name" was still a string (well, at least with
Python 2.3.1).

David (david.douard*gmail.com)
msg18053 - (view) Author: Rick Litherland (lither) Date: 2007-06-07 17:44
This problem still persists, at least in Python 2.4. As noted by Perry Greenfield, the same problem occurs in tk_focusPrev, and some other methods as well. Rather than track down all such calls it would be easier to add the line
    name = str(name)
at the top of the nametowidget method.

Rick Litherand.
lither@math.lsu.edu
msg62637 - (view) Author: Russell Owen (reowen) Date: 2008-02-21 18:10
The bug still exists. Please assign this bug and patch to Martin Loewis if 
possible (I don't have privileges for that).
msg64929 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-04-04 12:43
While we are at it, can't we revamp nametowidget too ?
Patch attached
msg65747 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-04-24 20:38
There was a problem with my previous patch if the widget name was just '.'
New patch attached
msg65748 - (view) Author: Guilherme Polo (gpolo) * (Python committer) Date: 2008-04-24 20:40
Sorry for the previous patch, correct one attached now
msg70621 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-08-02 07:24
Thanks for the patch, committed as r65399, r65400, and r65401.
History
Date User Action Args
2008-08-02 07:25:12loewissetstatus: open -> closed
resolution: fixed
versions: + Python 2.6, Python 3.0
2008-08-02 07:24:55loewissetmessages: + msg70621
2008-04-24 20:40:35gpolosetfiles: + bugfix_and_revamp_nametowidget.diff
messages: + msg65748
2008-04-24 20:40:06gpolosetfiles: - bugfix_and_revamp_nametowidget.diff
2008-04-24 20:38:38gpolosetfiles: + bugfix_and_revamp_nametowidget.diff
messages: + msg65747
2008-04-24 20:38:24gpolosetfiles: - bugfix_and_revamp_nametowidget.diff
2008-04-04 12:43:55gpolosetfiles: + bugfix_and_revamp_nametowidget.diff
nosy: + gpolo
messages: + msg64929
2008-03-21 22:07:33gvanrossumsetassignee: loewis
nosy: + loewis
2008-02-21 20:11:16loewissetkeywords: + patch
2008-02-21 18:10:20reowensetfiles: + Tkinter_patch.txt
nosy: + reowen
type: behavior
messages: + msg62637
versions: + Python 2.5, - Python 2.3
2003-09-02 21:58:36perrygreenfieldcreate