Repository navigation
IDLE goto should use query.Query subclass #71302
Description
Activity
On Win 10, Python 3.5 or 3.6, IDLE Shell or Editor with at least a few lines of text: hit Alt-G to open 'Goto' window. Enter a line # other than the current one. Hit <Return>. Cursor moves to line enter, though it shrinks to one pixel wide from two pixels. Line:col in status bar is updated.
Instead of hitting return, click [OK] button. Same thing happens except that status bar line:col is NOT updated. Here is relevant code in EditorWindow, about line 610
def goto_line_event(self, event): text = self.text lineno = tkSimpleDialog.askinteger("Goto", "Go to line number:",parent=text) text.mark_set("insert", "%d.0" % lineno) text.see("insert")
Changing parent=text to parent=self.root makes no difference. I have not yet tried simulating the interaction with button.invoke and event_generate('<Key-Return>.
My guess is that one of the last two tk methods is supposed to generate a cursor moved event that is bound to a reset status bar function. But somehow the previous click instead of keypress inhibits the event. So this seems a tk bug. Sethiy, what do you think?
The workaround for IDLE is to manually invoke a status bar update.
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on May 24, 2016 This is not Tkinter issue, but IDLE issue.
Other similar cases:
Open search dialog and find something. The status bar is not updated. It is updated only if you close the search dialog.
Select a text and delete it by a mouse. The status bar is not updated. Choice the Edit|Redo action by a mouse. The status bar is not updated.
Okay, will take a look at the status bar code and update mechanism.
If you close the Goto dialog by pressing <Return>, the KeyRelease event is sent to the editor window. This triggers the <<set-line-and-column>> event.
We can solve this problem by two ways.
One is to add set_line_and_column() to the end of goto_line_event(), but this will make Return trigger set_line_and_column twice.
Another is to change the bind event in simpledialog from "<Return>" to "<KeyRelease-Return>" to prevent editor use the KeyRelease event. But I think this will have some backward-compatibility problem, maybe we should add a parameter to control buttonbox bind on "<Return>" or "<KeyRelease-Return>".
Then we can add set_line_and_column() to the end of the goto_line_event(), and have no problem about trigging twice.
We should not change simpledialog.py, but we could change bindings after import.
However, since last summer, we can instead replace simpledialog.py with subclasses of ttk-using query.Query, with custom validators. editor.py uses askinterger for indent width, columns/tab, and goto line number. Iomenu uses askstring for encoding. I have already planned to use Query for the line# box.
- changed the title
[-]IDLE/tkinter: in simpledialog, <Return> != [OK] click[/-][+]IDLE: replace used of tkinter simpledialog with query.Query[/+]on May 30, 2017 - changed the title
[-]IDLE: replace used of tkinter simpledialog with query.Query[/-][+]IDLE: replace uses of tkinter simpledialog with query.Query[/+]on May 30, 2017 Ok, changed to query.Query will be good. But the problem still exist, query.Query use "<Key-Return>" to bind at button ok, should it re-bind to "<KeyRelease-Return>" at subclass such as AskInteger(Query) ?
2 remaining items
Terry, on the original issue about goto dialog, I would like to propose another approach, instead of using query.Query or simpledialog, how about to make it as a single-window application like sublime text: http://docs.sublimetext.info/en/latest/file_management/file_navigation.html#goto-anything
I'm now doing some experience on this, and it will push forward for what bpo-30422 want to do.
I changed the title to reflect the intended user-visible behavior, which was always the real issue. The original title proposed a solution that would not work. The revised title gave an alternate solution that should not work.
The discrepancy between clicking [Ok] and and pressing <Return> arises because pressing Enter in the query box leaks <KeyRelease-Return> to the text, which happens to trigger a status bar update. I regard this somewhat accidental side-effect to be a bug to be fixed. Changing the text and status bar are the responsibility of the event handler.
The line number query box should just return a positive int or None, without side-effect. So we should make sure that Query boxes do not leak key events and create a subclass to get a positive int. But such a replacement is somewhat independent of triggering <<set-line-and-column>>.
A related issue is that goto does not clear selections. bpo-39844. I may fix that and this with one PR.
- changed the title
[-]IDLE: replace uses of tkinter simpledialog with query.Query[/-][+]IDLE goto should always update status bar line & column[/+]on Mar 6, 2020 Since PR-18801 fixed the status issue, I am returning this to the box replacement issue.
- changed the title
[-]IDLE goto should always update status bar line & column[/-][+]IDLE goto should use query.Query subclass[/+]on Mar 8, 2020
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: