Issue46666
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.
Created on 2022-02-06 21:52 by primexx, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Files | ||||
---|---|---|---|---|
File name | Uploaded | Description | Edit | |
npp-indent-guide.png | primexx, 2022-02-07 01:44 | screenshot of indent guide in notepad++ |
Messages (9) | |||
---|---|---|---|
msg412672 - (view) | Author: primexx (primexx) | Date: 2022-02-06 21:52 | |
Request: support indent guide for IDLE in editor window (i.e. not interactive shell) there appears to not be currently support for indent guides in idle one take is that idle is meant for small scripts and one should seek out a more complex IDE if it gets to the point of needing indent lines https://stackoverflow.com/q/66231105 i think that there would still be value in indent lines even in IDLE. it is a popular IDE for beginners and even in short scripts there can still be sufficiently large indented blocks, relatively speaking. it doesn't take that much code for indent guides to become helpful. |
|||
msg412698 - (view) | Author: Terry J. Reedy (terry.reedy) * | Date: 2022-02-07 00:50 | |
[Please just select the current development version. Others can be marked if and when backported. 3.8 and before only get security fixes. Same for 3.9 after about next May 31.] Please explain exactly what you want and rewrite something like the following. if a: if b: if c: pass if d: pass IDLE's code context feature (Options menu) could be considered an indent guide. In some ways, it is better. What you see in the editor is what is saved (including when running), so any non-code additions have to be removed first. |
|||
msg412702 - (view) | Author: primexx (primexx) | Date: 2022-02-07 01:44 | |
> Please just select the current development version. Others can be marked if and when backported oh sorry about that! > Please explain exactly what you want these dotted lines in the attached screenshot > What you see in the editor is what is saved (including when running), so any non-code additions have to be removed first. yes, this would be a pure visual element in the editor, not modifying the actual code > IDLE's code context feature (Options menu) could be considered an indent guide. In some ways, it is better. it is very useful indeed, but not quite the same as a persistent visual indicator imho thanks! |
|||
msg412706 - (view) | Author: Terry J. Reedy (terry.reedy) * | Date: 2022-02-07 03:14 | |
I loaded a .py file into N++ and see them. Under 3 x, there are clearly separate minidots. Under 10x, the dots are hardly visible. They are not characters in the text (cannot be copied) but a special manipulation of the column of pixels 'between' spaces. This must be a built-in feature of to the text widget. I suspect it involves special subpixel manipulation, perhaps requiring information from the monitor. AFAIK, Tk widgets do not have this feature. Unless there is a unicode char consisting of light dots on the very edge, we cannot even simulate this. |
|||
msg412707 - (view) | Author: Raymond Hettinger (rhettinger) * | Date: 2022-02-07 03:34 | |
If this were possible, it would be really nice to have. FWIW, the rich¹ project was able to pull this off in regular text terminal window: $ python3.10 -m pip install rich $ python3.10 -m rich.pretty { │ 'foo': [1, 'Hello World!', 100.123, 323.232, 432324.0, {(1, 2, 3, 4), 5, 6, 7, 8}, ...], │ 'bar': frozenset({1, 2, 3}), │ 'defaultdict': defaultdict(<class 'list'>, {'crumble': ['apple', 'rhubarb', 'butter', 'sugar', 'flour']}), │ 'counter': Counter({'apple': 1, 'orange': 1, 'pear': 1, 'kumquat': 2, 'duriandurianduriandu'+580: 1}), │ 'atomic': (False, True, None), │ 'Broken': <repr-error 'division by zero'> } ¹ https://rich.readthedocs.io/en/stable/index.html |
|||
msg412708 - (view) | Author: Terry J. Reedy (terry.reedy) * | Date: 2022-02-07 04:53 | |
'│' is a bit taller that ascii bar '|'; hex(ord('│')) = '0x2502'. It is a bit heavy. In this Windows Firefox box it is slightly lighter than | but in IDLE with Source Code Pro, it is slightly darder. Worse is being centered instead of on one edge. We would have to check it with multiple fixed-ascii-pitch fonts on multiple systems before using any non-ascii char. Does it always have the exact width of ascii ' ' or easier to check, ascii '|', so that is does not change the indent? This is easily tested in the Settings dialog Font tab sample box. Paste the following │││││││││││││││ ||||||||||||||| It passes with all but one of the Windows mono fonts I tried. I may ask a tk/tkinter question on SO about other possible options. Testing this one in code: if a: # Put 1st bar on 4th space. if b: │ if c: │ │ pass if d: │ pass if a: # Put 1st bar on 5th space. if b: │ if c: │ │ pass if d: │ pass if a: # Put 1st bar on 1st space. │ if b: │ │ if c: │ │ │ pass │ if d: │ │ pass The 2nd option looks best to me. The 3rd would be easier to program, as default tab indent would always be '│ '. In any case, copied code would not be runnable code. I would add this on the Option menu between Code Context and Line Numbers. I believe only updating the markers on demand would be much easier to program than dynamically updating them with each keystroke (checking key and whether whitespace in indent area). Before merging a PR (writen by someone else), someone other than me, such as Raymond, must test it in real use both for correctness, usefulness, and aesthetics. (I anticipate that I would fail it on the latter two.) |
|||
msg413105 - (view) | Author: primexx (primexx) | Date: 2022-02-11 23:27 | |
very informative discussion. i'll just say that if it's not possible to do purely visually, and it can only be done by modifying the textual content, then it probably should not be done at all. preserving the code (and copy+paste integrity) is more important. maybe this is actually something to raise with Tk first? |
|||
msg413114 - (view) | Author: Terry J. Reedy (terry.reedy) * | Date: 2022-02-12 02:42 | |
I am guessing that N++ or its GUI framework uses a transparent overlay. For tkinter, that would mean a transparent Canvas on which one could draw vertical dotted gray lines 1-pixel wide. However, Serhiy Storchaka in msg213643 of #20920 said: "Tk supports alpha only for photo images and as an attribute of top-level window. It doesn't support alpha component in colors." I searched 'tkinter transparent canvas'. For pixel positioning, photos with transparent backgrounds can only be used on a canvas. This was one of the answers to https://stackoverflow.com/questions/53021603/how-to-make-a-tkinter-canvas-background-transparent More details, using pil(low) to make images, are in the following: https://www.tutorialspoint.com/how-to-make-a-tkinter-canvas-rectangle-transparent https://www.javaer101.com/en/article/921105.html Another answer to the SO question, for Windows only, was to pip install pywin32 and use various calls to make a canvas layered with a transparent colorkey. Perhaps the same could be done, at least on Windows, with ctypes. A top-level background is made (partially) transparent with "top.attributes('-alpha', d)" where d in [0.0-1.0]. On Windows, 'top.wm_attributes('-transparentcolor', keycolor) makes that keycolor actually be transparent, like the green/blue screen used in television and movies. But any keycolor pixel in the toplevel exposes the screen beneath the toplevel, not the widget in the toplevel. This detail is not clear in the tk docs. https://www.youtube.com/watch?v=75jbNpc8vN4 What also is not clear is whether the keycolor applies only to the one toplevel or all toplevels, nor what happens when one toplevel is over another. I summarized the above so I or anyone else can find the information. I am closing this issue for now, but someone can reopen if the situation changes. |
|||
msg413991 - (view) | Author: Aivar Annamaa (aivarannamaa) | Date: 2022-02-25 12:25 | |
The guides could be implemented by tagging the indentation characters in the Text widget with tags configured with suitable bgstipple (https://www.tcl.tk/man/tcl/TkCmd/text.html#M45) bitmaps. I had some success with this in Thonny IDE, but abandoned the plan because bstipple is not supported on macOS (for some reason). |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:59:55 | admin | set | github: 90824 |
2022-02-25 12:25:33 | aivarannamaa | set | nosy:
+ aivarannamaa messages: + msg413991 |
2022-02-12 02:42:44 | terry.reedy | set | status: open -> closed resolution: third party messages: + msg413114 stage: test needed -> resolved |
2022-02-11 23:27:20 | primexx | set | messages: + msg413105 |
2022-02-07 04:53:27 | terry.reedy | set | messages: + msg412708 |
2022-02-07 03:34:28 | rhettinger | set | nosy:
+ rhettinger messages: + msg412707 |
2022-02-07 03:14:19 | terry.reedy | set | messages: + msg412706 |
2022-02-07 01:44:46 | primexx | set | files:
+ npp-indent-guide.png messages: + msg412702 |
2022-02-07 00:50:02 | terry.reedy | set | versions:
- Python 3.7, Python 3.8, Python 3.9, Python 3.10 title: IDLE indent guide -> IDLE Add indent guide messages: + msg412698 type: enhancement stage: test needed |
2022-02-06 21:52:47 | primexx | create |