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.

classification
Title: IDLE: Make multiple improvements to CodeContext
Type: enhancement Stage: patch review
Components: IDLE Versions: Python 3.10
process
Status: open Resolution:
Dependencies: 22703 31493 32831 33628 33642 33664 33763 35521 35555 37530 Superseder:
Assigned To: terry.reedy Nosy List: cheryl.sabella, miss-islington, taleinat, terry.reedy
Priority: normal Keywords: 3.5regression, patch

Created on 2018-05-23 05:18 by terry.reedy, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 7597 merged terry.reedy, 2018-06-10 19:07
PR 7598 merged miss-islington, 2018-06-10 19:49
PR 7599 merged miss-islington, 2018-06-10 19:50
PR 14821 merged taleinat, 2019-07-17 18:46
PR 14822 merged taleinat, 2019-07-17 19:30
PR 14846 merged miss-islington, 2019-07-18 20:03
PR 14847 merged miss-islington, 2019-07-18 20:03
PR 14913 merged miss-islington, 2019-07-23 10:02
PR 14914 merged miss-islington, 2019-07-23 10:02
PR 23773 merged terry.reedy, 2020-12-15 04:29
PR 23774 merged miss-islington, 2020-12-15 05:24
PR 23775 merged miss-islington, 2020-12-15 05:25
Messages (39)
msg317357 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-05-23 05:18
There are a number of possible improvements to CodeContext.  They be separate issues (and PRs) that are dependencies of this master index issue. Some should be fairly easy now that we have the new tests.

1. #32831 added docstrings and tests.  Review has notes.
2. Follow-up may revise and do some user-invisible code cleanups.
3. #31493 cancelled the event loops when instances are deleted.
4. Spinoff from above: 1 or 2 events loops for class, not each instance.
5. #22703: separate initial context state of new window from toggling the state of current windows.  Current behavior is buggy.
6. Gray-out Options => Code Context on non-editor windows. (This would have to be revised again if windows became panes in master window.)
7. Change fixed # of lines to variable # of lines as needed, up to limit.  About 15 is limit for 4-space indents in 80 char lines. 
8. Click on context line jumps to line. Show it at top of window.
9. Reenable user config of context colors?
10. Somehow mark blocks in editor.  Subtle background color change?
Or tag just the indents, or, if add line numbers, the line numbers?
msg317364 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-05-23 07:45
11. Use read-only Text instead of Label for context. Text.index(f'@{e.x},{e.y}', where e is event, converts mouse click to line number.  That can be mapped to text line number for 8. above.  Text also enables

12. If context box is too short for all lines, add scrollbar.

13. When horizontal scrollbars are added to editor, scroll context along with text scroll.
msg317480 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-05-23 23:53
For item 2 - #33628
msg317599 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-05-24 18:20
With #33628 merged, I consider the next priorities to be 5. #22703 (overt bug, highest), 7, and 8, to make the feature more usable.

10. is a vague speculative feature that would use get_indent_firstword but would actually be for the editor.  Update problem: It requires a representation of the structure of the entire code, and any edit could change that.  The saving grace of code context is that it only maintains information about the invisible lines above the cursor.

More feasible than item 10 would be

14. Block structure navigation: As near as I can tell, Alt-arrowkey is currently the same as arrowkey.  Have Alt-Up and Alt-Down move to the next block line above or below with the same indent and Alt-Left, Alt-Right move up and out (smaller indent) or down and in (larger indent).

15. (Instead of 4b. One font loop for class.) Replace font loop with font-change notification by the editor when the editor gets such a notification (which is very rare).

16. (Instead of 4a. One font loop for class.)  The current loops update every window 10 times a second, which is about the upper limit for a great typist or normal scroller.  But only an active editor window needs updating, and there is at most 1.  Most checks are wasted.

16A. Replace update loop with notification of visible display changes.  Pro: We already monitor key and mouse actions.  Anti: the event loop is simple.

16B. Only run update loop in active window.  Anti: I don't think we currently monitor window focus.  Pro: if we don't, we will need to for a multipane, multitab IDLE.  (Stopping should be easy: check status before after call in callback.  This automatically does a last update after focus gone.)
msg317601 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-05-24 18:27
I've started looking at #22703, more specifically, I've been trying to recreate it.  Since the config changes in 3.6/3.7 where the flag was removed from config dialog, the code context needs to be turned on explicitly for each editor.  3.5 has the old behavior.

So, I think the current change would be to add it back to config but with the behavior defined in #22703.  

I hope to have a PR within the next few days.
msg317651 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-05-25 00:47
For item 7 - #33642.
msg317822 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-05-28 02:28
While trying out variable lines, #33642, I encounter two related issues.

First is the context colors.  Black on gray is a variant of black on white.  I am using the dark theme, white on dark blue.  For fixed sized context, the high contrast is okay.  For variable context, having lines flip from light on dark to dark on light and back is distracting to obnoxious. So I want to change
9. Reenable user config of context colors?
to 
9. Reenable user config of context colors!
Add the current black on gray to the light theme and appropriate values, to be determined, to the dark theme.

Second is getting partial lines at the top of the text box as a result of scrolling with the mousewheel or scrollbar slider.  I never liked this but tolerated it.  With complete text lines above, it looks awful to me.  Hence, I consider the following to be a dependency of this issue.  
17. #33664 Scroll by lines instead of sometimes by pixels.

Following the implementation notes for #33664, once the label is changes to text, to get the target topline, 8. can be implemented with
text.xview_scroll(target_topline - current_topline, 'units')

I would like to release multiple user visible improvements at once, at least 7, 9, and 17, so the new code context looks good from the start.   8, menu changes, and 14 could come later.
msg318012 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-05-29 11:42
For item 9 - #33679
msg318351 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-01 00:46
The release candidate has been re-scheduled for June 11.  So we should be able to merge the minimal upgrade before that and get it in 3.7.0 and 3.6.6.  (The latter will come out at the same time as the former.)

Variable lines is about ready.  Colors looks like it should be, with a final test needed after variable lines is merged (or maybe I will reverse the order).  That leaves line alignment.  If you are working on it, but don't have a PR ready yet, please say so.
msg318355 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-01 01:10
5, reformulated. Now that 'Code Context' on the Options menu only toggles a feature for the current window, like 'Zoom Height' on the Window menu, both should appear together on the same menu.  My current inclination is to move 'Code Context' to Window because a) it is the feature be that will be changed and discussed in What's New, and b) 'Window' otherwise lists individual windows so it more clearly implies that toggles are for the current window without adding a fake menu entry.  Agree?
msg318357 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-01 02:04
18. Error or bounds checking for maxlines entry.  I believe this really a config dialog issue that applies to everything, but maxlines should be at least 1, with some reasonable max.  In the meanwhile, we could check whether crazy entries (text, negatives, super high) can crash IDLE.
msg318358 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-01 02:55
19. idle.rst doc change
20. What's New for 3.6.6 and 3.7.0
These could be patches on this issue.
21. idlelib/NEWS.txt entries
msg318466 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-06-01 21:40
> That leaves line alignment.  If you are working on it, but don't have a PR ready yet, please say so.

I was going to work on it this weekend, but haven't started yet.

I agree that moving Code Context to the Windows menu makes sense.
msg318476 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-02 00:10
I merged 'variable lines' and edited 'colors' to fix the resulting conflicts.  Travis passed the latter so I expect to merge it also.  To avoid more conflicts, you should wait to create the 'alignment' branch until 'colors' is merged and pulled into your clone.  (We should continue to keep having two pending patches for the same file rare.)

Counter-argument for menu location.  Window has 1 to n top-level window items.  Options will have just one item without Code Context.  So moving Zoom would make things more balanced.
msg318562 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-03 15:48
After writing the above, I realized that line scroll only touches editor.py, not codecontext.py.  On the other hand, the next item, 8. jump to context line did have to wait.  Replacing Label with Text will require explicit height setting with each context change.  The click handler will be a simplified version of the scroll handler you just wrote.  Jumping to a line will look much better when it jumps to a whole rather than a fractional line.  Again, one of us should say something before starting.
msg318589 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-06-04 00:16
For item 11 - #33763
msg318791 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-06-06 00:00
Menu location:

If Code Context is moved under Windows, maybe Configure IDLE should be moved as well?  

- VS Code has Preferences under the File menu.
- Spyder has a menu option called Tools which contains Preferences, Update PYTHONPATH manager, and Reset Spyder to defaults
- Atom has Preferences under the Edit menu.
- Sublime Text has a menu called Preferences.
- Notepad++ has a menu called Settings, which includes Preferences.
msg319240 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-10 19:48
New changeset af4b0130d44bf8a1ff4f7b46195d1dc79add444a by Terry Jan Reedy in branch 'master':
 bpo-33610: Update IDLE Code Context doc entry (GH-7597)
https://github.com/python/cpython/commit/af4b0130d44bf8a1ff4f7b46195d1dc79add444a
msg319241 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2018-06-10 19:54
General Update: We have done 1, 3, 7, 8, 9, 11, 17, 21.  Very nice.  A re-organized list of the remainder (with old numbers).

Docs:
D1: idle.rst subsection on Code Context (19, see #33642).
D2: What's New in 3.6.6 and 3.7.0 (20).

Menu
M1: put Code Context and Zoom Height on same menu (5).
M2: Add Show/Hide Code Context (5).
M3. Gray out menu entry when not applicable (6).
M3: Shortcut for CC? (new),

Code Context Display
C1. Add vertical scrollbar if lines > maxlines (12).
C2. Add horizontal scrollbar if add to text (13).

Internal Changes
I1. Unspecified code cleanups for codecontext.py (2)
I2. Reduce events (4). Font change notification (15). Text active or text changed notification (16).

External Changes
E1. Mark blocks in editor (10, unlikely).
E2. Navigate by blocks in editor (14).
E3. Error check maxlines in configdialog (18).

D1 is PR 7579 and backports.  D2 was done on #33820 and #33821.

For M1, I would still like to move Zoom Height to Options with a separate bar after IDLE settings.
msg319242 - (view) Author: miss-islington (miss-islington) Date: 2018-06-10 20:07
New changeset 2adfeef1853262b207a1993e523f0f3ba708dd9f by Miss Islington (bot) in branch '3.7':
bpo-33610: Update IDLE Code Context doc entry (GH-7597)
https://github.com/python/cpython/commit/2adfeef1853262b207a1993e523f0f3ba708dd9f
msg319243 - (view) Author: miss-islington (miss-islington) Date: 2018-06-10 20:11
New changeset 08a1b133925f50903691c77fa9c23b618abc89f2 by Miss Islington (bot) in branch '3.6':
bpo-33610: Update IDLE Code Context doc entry (GH-7597)
https://github.com/python/cpython/commit/08a1b133925f50903691c77fa9c23b618abc89f2
msg332034 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-12-18 00:48
D1 in issue35521.
msg332105 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-12-19 01:19
For M1 and M2 - #22703.
msg332312 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2018-12-21 23:55
For M3 - #35555.
msg347571 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-07-09 18:03
#37530 addresses I2, events (Tal, see msg319241 above).  I considered this to be about next in priority.  It also does some I1 cleanup.

In that list, the 2nd M3 should be M4.  The comment "D1 is PR 7579" should have referred to PR 7597, merged thereafter.
msg348001 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-07-16 05:10
I2: replace font/hightlight loop with notification and immediate change instead of a delay is a bugfix.

In testing PR 14675 for #37530 I discovered a bug.  'Show' always shows a single blank line, as if the top visible line were the top line of the file.  One should not have to scroll to trigger the context calculation.  This exists now, prior to the new PR. If/when we add a hotkey (M4), once should be able to show, see context, and hide just by hitting hotkey twice.  Add

C3: Make 'Show' show the context for the current top visible line.
msg348078 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-07-17 18:47
Terry, on latest master (with the aforementioned PR merged), the context is updated quickly after the code-context is shown.  This happens after a delay of up to 100ms due to the update loop.

I've created PR GH-14821 with a fix.
msg348081 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-07-17 19:31
Regarding validating integer inputs in the configuration dialog (E3), see my new PR GH-14822.
msg348125 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-07-18 20:03
New changeset e0a1f8fb5c60886dbddf1a3ccb5d47576bdd43e2 by Terry Jan Reedy (Tal Einat) in branch 'master':
bpo-33610: IDLE's code-context always shows current context immediately (GH-14821)
https://github.com/python/cpython/commit/e0a1f8fb5c60886dbddf1a3ccb5d47576bdd43e2
msg348126 - (view) Author: miss-islington (miss-islington) Date: 2019-07-18 20:46
New changeset db2957c8ebbe1c4609b3fc730c6e682cb8ccfeb0 by Miss Islington (bot) in branch '3.7':
bpo-33610: IDLE's code-context always shows current context immediately (GH-14821)
https://github.com/python/cpython/commit/db2957c8ebbe1c4609b3fc730c6e682cb8ccfeb0
msg348127 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-07-18 20:47
New changeset 86eb5daaf31860da479e034d69e9a6d4f47a8eb6 by Terry Jan Reedy (Miss Islington (bot)) in branch '3.8':
bpo-33610: IDLE's code-context always shows current context immediately (GH-14821) (#14846)
https://github.com/python/cpython/commit/86eb5daaf31860da479e034d69e9a6d4f47a8eb6
msg348324 - (view) Author: Tal Einat (taleinat) * (Python committer) Date: 2019-07-23 10:02
New changeset 1ebee37dde5c2aabc8e2d2c7bbe2a69b293133bb by Tal Einat in branch 'master':
bpo-33610: validate non-negative integer inputs in IDLE's config (GH-14822)
https://github.com/python/cpython/commit/1ebee37dde5c2aabc8e2d2c7bbe2a69b293133bb
msg348325 - (view) Author: miss-islington (miss-islington) Date: 2019-07-23 10:18
New changeset 5dab5e7d24c790d54b8d1eca0568e798bfda2c68 by Miss Islington (bot) in branch '3.8':
bpo-33610: validate non-negative integer inputs in IDLE's config (GH-14822)
https://github.com/python/cpython/commit/5dab5e7d24c790d54b8d1eca0568e798bfda2c68
msg348326 - (view) Author: miss-islington (miss-islington) Date: 2019-07-23 10:21
New changeset 28815e0e2c904644660d29995cdfbb65f67e4a1d by Miss Islington (bot) in branch '3.7':
bpo-33610: validate non-negative integer inputs in IDLE's config (GH-14822)
https://github.com/python/cpython/commit/28815e0e2c904644660d29995cdfbb65f67e4a1d
msg383031 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-15 04:03
E4. Max context lines = 0 is treated as infinity.  For depth 0, "self.info[-self.context_depth:]" is whole slice.  I don't remember if this is intended (if one does not want context, don't toggle it on), but it is not documented in settings help or doc section.  In any case,
  offset = max(1, lines - self.context_depth) - 1
fails with depth 0.

E5. test_codecontext is affected by user customization, but should not be.

E6. Bad bug make CC useless.  See #42638.
msg383033 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-15 04:17
Delete E6.  No bug.  I do have a couple of internal edits.
msg383035 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-15 05:24
New changeset 6f79e60b66dacefca147bdaa80eb37f936a72991 by Terry Jan Reedy in branch 'master':
bpo-33610: Edit idlelib.codecontext (GH-23773)
https://github.com/python/cpython/commit/6f79e60b66dacefca147bdaa80eb37f936a72991
msg383036 - (view) Author: miss-islington (miss-islington) Date: 2020-12-15 05:45
New changeset 925f9987866703b0e7cfde341d23f19b832603cb by Miss Islington (bot) in branch '3.8':
bpo-33610: Edit idlelib.codecontext (GH-23773)
https://github.com/python/cpython/commit/925f9987866703b0e7cfde341d23f19b832603cb
msg383048 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-12-15 12:52
New changeset 99d37a0ee82c16f30a874c9b583d59a3844dc9c9 by Miss Islington (bot) in branch '3.9':
bpo-33610: Edit idlelib.codecontext (GH-23773) (GH-23775)
https://github.com/python/cpython/commit/99d37a0ee82c16f30a874c9b583d59a3844dc9c9
History
Date User Action Args
2022-04-11 14:59:00adminsetgithub: 77791
2020-12-15 12:52:04terry.reedysetmessages: + msg383048
2020-12-15 05:45:52miss-islingtonsetmessages: + msg383036
2020-12-15 05:25:37miss-islingtonsetpull_requests: + pull_request22631
2020-12-15 05:24:24miss-islingtonsetpull_requests: + pull_request22630
2020-12-15 05:24:10terry.reedysetmessages: + msg383035
2020-12-15 04:29:51terry.reedysetpull_requests: + pull_request22629
2020-12-15 04:17:35terry.reedysetdependencies: - IDLE: Context lines not working correctly
messages: + msg383033
2020-12-15 04:03:27terry.reedysetdependencies: + IDLE: Context lines not working correctly
messages: + msg383031
versions: + Python 3.10, - Python 3.7, Python 3.8
2019-07-23 10:21:55miss-islingtonsetmessages: + msg348326
2019-07-23 10:18:47miss-islingtonsetmessages: + msg348325
2019-07-23 10:02:46miss-islingtonsetpull_requests: + pull_request14690
2019-07-23 10:02:35miss-islingtonsetpull_requests: + pull_request14689
2019-07-23 10:02:22taleinatsetmessages: + msg348324
2019-07-18 20:47:29terry.reedysetmessages: + msg348127
2019-07-18 20:46:40miss-islingtonsetmessages: + msg348126
2019-07-18 20:03:43miss-islingtonsetpull_requests: + pull_request14638
2019-07-18 20:03:34miss-islingtonsetpull_requests: + pull_request14637
2019-07-18 20:03:24terry.reedysetmessages: + msg348125
2019-07-17 19:31:55taleinatsetmessages: + msg348081
2019-07-17 19:30:22taleinatsetpull_requests: + pull_request14616
2019-07-17 18:47:55taleinatsetmessages: + msg348078
2019-07-17 18:46:51taleinatsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14615
2019-07-16 05:10:25terry.reedysetmessages: + msg348001
2019-07-09 18:03:11terry.reedysetnosy: + taleinat
dependencies: + IDLE: simplify, optimize, and clean up code context
messages: + msg347571
2018-12-21 23:55:48cheryl.sabellasetdependencies: + IDLE: Gray out Code Context on non-editor windows
messages: + msg332312
2018-12-19 01:19:55cheryl.sabellasetmessages: + msg332105
2018-12-18 00:48:07cheryl.sabellasetdependencies: + IDLE: Add doc section for Code Context and ref links.
messages: + msg332034
2018-12-12 02:48:30terry.reedysetversions: - Python 3.6
2018-06-10 20:11:23miss-islingtonsetmessages: + msg319243
2018-06-10 20:07:27miss-islingtonsetnosy: + miss-islington
messages: + msg319242
2018-06-10 19:54:34terry.reedysetkeywords: + 3.5regression, - patch

messages: + msg319241
stage: patch review -> (no value)
2018-06-10 19:50:51miss-islingtonsetpull_requests: + pull_request7221
2018-06-10 19:49:56miss-islingtonsetpull_requests: + pull_request7220
2018-06-10 19:48:44terry.reedysetmessages: + msg319240
2018-06-10 19:07:31terry.reedysetkeywords: + patch
stage: patch review
pull_requests: + pull_request7219
2018-06-06 00:00:13cheryl.sabellasetmessages: + msg318791
2018-06-04 00:17:45cheryl.sabellasetdependencies: + IDLE: Use text widget for code context instead of label widget
2018-06-04 00:16:07cheryl.sabellasetmessages: + msg318589
2018-06-03 15:48:54terry.reedysetmessages: + msg318562
2018-06-02 00:10:39terry.reedysetmessages: + msg318476
2018-06-01 21:40:55cheryl.sabellasetmessages: + msg318466
2018-06-01 02:55:09terry.reedysetmessages: + msg318358
2018-06-01 02:04:32terry.reedysetmessages: + msg318357
2018-06-01 01:10:58terry.reedysetmessages: + msg318355
2018-06-01 00:46:20terry.reedysetdependencies: - IDLE: Enable theme-specific color configuration for code context
messages: + msg318351
2018-05-29 11:42:09cheryl.sabellasetdependencies: + IDLE: Enable theme-specific color configuration for code context
messages: + msg318012
2018-05-28 02:28:02terry.reedysetdependencies: + IDLE: scroll text by lines, not pixels.
messages: + msg317822
2018-05-25 00:47:56cheryl.sabellasetdependencies: + IDLE: Display up to maxlines non-blank lines for Code Context
messages: + msg317651
2018-05-24 18:27:32cheryl.sabellasetmessages: + msg317601
2018-05-24 18:20:18terry.reedysetmessages: + msg317599
2018-05-23 23:53:14cheryl.sabellasetdependencies: + IDLE: Code cleanup on codecontext
messages: + msg317480
2018-05-23 07:45:36terry.reedysetmessages: + msg317364
2018-05-23 05:20:38terry.reedysettitle: IDLE: Improve CodeContext (various issues) -> IDLE: Make multiple improvements to CodeContext
dependencies: + Idle Code Context menu entrie(s), IDLE cond context: fix code update and font update timers, IDLE: Add docstrings and tests for codecontext
stage: test needed -> (no value)
versions: + Python 3.6, Python 3.7, Python 3.8
2018-05-23 05:18:12terry.reedycreate