Skip to content

bpo-17535: IDLE editor line numbers #14030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Jul 23, 2019

Conversation

taleinat
Copy link
Contributor

@taleinat taleinat commented Jun 12, 2019

Line numbers for IDLE editor windows!

This is based on Saimadhav Heblikar's last patch posted to the related issue.

https://bugs.python.org/issue17535

@tebeka
Copy link

tebeka commented Jul 4, 2019

I'd love to see line number finally landing in IDLE. I use it a lot for teaching and it'll be a great help referencing parts of the code.

taleinat added 4 commits July 6, 2019 00:00
* avoid duplicate scrolling events which degrade performance
* reorganize event forwarding code
* dragging on line numbers now selects entire lines
* work around difficult to handle drag-scrolling
@taleinat
Copy link
Contributor Author

taleinat commented Jul 5, 2019

I've made some significant improvements in several aspects:

  1. Scrolling: performance and behavior
  2. Selection entire lines by dragging over line numbers
  3. Color config: a separate highlighting setting for line numbers, which takes effect immediately

taleinat added 3 commits July 6, 2019 01:38
Taking advantage of the tighter integration with EditorWindow,
each window now directly updates its line numbers sidebar upon
font changes.
There is apparently a minor inconsistency in Tk's Text widget.
@taleinat taleinat force-pushed the bpo-17535/IDLE-line-numbers branch from 1893bf2 to b7faf1f Compare July 7, 2019 08:19
@terryjreedy
Copy link
Member

terryjreedy commented Jul 8, 2019

Tal, thank you for reviving the improving the old patch. This seems to work better than the 2014 version, enough so I want to get this into b3 (scheduled in 3 weeks, 7/29). If we can coordinate, I will help with the needed changes. (I believe some of them amount to fixing parts of the old patch that are now obsolete.)

I would like to immediately follow up with a shell sidebar, which will, among other things, separate prompt and code and allow properly spaced indents instead of the wonky tabbing. (we might do something else immediately, but I want it eventually.) I will try to post something for discussion tomorrow.

Issues (couple of which would be separate).

  1. New names: Because the sidebar is not just about line numbers, the new file should be sidebar.py and the highlights sidebar-foreground and -background.

  2. Startup

>>> import idlelib.idle

 Warning: config.IdleConf.GetThemeDict -
 problem retrieving theme element 'linenumber-foreground'
 from theme 'Custom Dark'.
 returning default color: '#000000'

 Warning: config.IdleConf.GetThemeDict -
 problem retrieving theme element 'linenumber-background'
 from theme 'Custom Dark'.
 returning default color: '#ffffff'

This happens with custom themes every time we add theme elements. We immediately need to extend previous workaround, but should do a more permanent fix that adds elements, with default values, to custom themes.

  1. Default status: When I opened the editor, line numbers appeared. I believe the consensus on the issue is that the default should be off.

  2. Menu: Location good, but as I said on the issue, I want to copy the code context solution, which works, instead of keeping the check mark. Besides aesthetics and consistency, the line number mark is buggy in a way similar to the way that the old code context check was: changing the mark in one window affects the mark in other windows, possibly resulting in the menu checkmark for a window becoming out of sync with the window state. When a window with a check does not have line numbers, they sometimes cannot be added.

  3. Scrolling. While working on code context, Cheryl and I fixed scrolling to be by lines, and intended that there should always be an even line at the top. I wonder if this helped this patch work better.

The default size of a Text widget with all lines the same height (as in IDLE) is an even number of lines, and when this is true, there are no partial lines to worry about. When a user changes the window height to have a fractional size, IDLE (without this patch) puts a whole line at the top and the fractional line at the bottom. I intend that this remain true.

While using the patch, I discovered that when one scrolls to the bottom of the file, the fractional line moves to the top. It stays there until one scrolls to the top or until the widget just switches back. This looks even worse with line numbers, so a fix would be good if it can be done without making scrolling on macOS worse. (1? adjust window size to an integral number of line after a resize? 2? display a partial unnumbered blank line, like Notepad++.)

  1. Selection: With Notepad++, one can select a whole line by clicking on a line number. To select multiple lines, one drags the cursor to the last line one wants to include. Very intuitive to me. With this patch, clicking does nothing and one must drag to the first line to be excluded. Much worse. This slice-like behavior would look better if the cursor were a horizontal line, so one could click between line numbers and drag to another slice position, between numbers. But even then, click -- select would be more useful, and eventually I would like to be able to select a multiline statement with a double click. (And in Shell, double click select an entire traceback, where the sidebar might have 'ERR' opposite the 'Traceback...' line.)

  2. Font resizing: This seems to now work the same as without line numbers, with none of the vertical jumps I remember. The main issue now is that with 4 windows, at least 1 with a few 1000 lines, resizing takes about a second to complete, mostly because of re-colorizing the files. It naively seems that changing the font attribute should be enough. Do you know whether it is tk or IDLE that removes the tags?

  3. Implementation: Implementing builtin features as extensions is obsolete since Sept 2017. Issue 27099.

@terryjreedy
Copy link
Member

  1. Code Context. The CC box extends over the side bar. Result is displayed lines offset from text below. Not good. If we grid, which we should, row 0, column 0 should be blank. Whether and how color background to be worked out.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See separate comments. Will look at code later.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@terryjreedy
Copy link
Member

The doc looks even better.

@taleinat taleinat merged commit 7123ea0 into python:master Jul 23, 2019
@miss-islington
Copy link
Contributor

Thanks @taleinat for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

I'm having trouble backporting to 3.8. Reason: 'Error 110 while writing to socket. Connection timed out.'. Please retry by removing and re-adding the needs backport to 3.8 label.

@miss-islington
Copy link
Contributor

Sorry, @taleinat, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 7123ea009b0b004062d91f69859bddf422c34ab4 3.7

@taleinat taleinat deleted the bpo-17535/IDLE-line-numbers branch July 23, 2019 12:22
@taleinat taleinat restored the bpo-17535/IDLE-line-numbers branch July 23, 2019 12:22
@miss-islington
Copy link
Contributor

Thanks @taleinat for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Thanks @taleinat for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry @taleinat, I had trouble checking out the 3.7 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 7123ea009b0b004062d91f69859bddf422c34ab4 3.7

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 23, 2019
(cherry picked from commit 7123ea0)

Co-authored-by: Tal Einat <taleinat@gmail.com>
@bedevere-bot
Copy link

GH-14916 is a backport of this pull request to the 3.8 branch.

miss-islington added a commit that referenced this pull request Jul 23, 2019
(cherry picked from commit 7123ea0)

Co-authored-by: Tal Einat <taleinat@gmail.com>
taleinat added a commit to taleinat/cpython that referenced this pull request Jul 23, 2019
(cherry picked from commit 7123ea0)

Co-authored-by: Tal Einat <taleinat@gmail.com>
@bedevere-bot
Copy link

GH-14917 is a backport of this pull request to the 3.7 branch.

@taleinat taleinat deleted the bpo-17535/IDLE-line-numbers branch July 23, 2019 13:08
taleinat added a commit that referenced this pull request Jul 23, 2019
lisroach pushed a commit to lisroach/cpython that referenced this pull request Sep 10, 2019
DinoV pushed a commit to DinoV/cpython that referenced this pull request Jan 14, 2020
websurfer5 pushed a commit to websurfer5/cpython that referenced this pull request Jul 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants