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: Convert browsers to use ttk.Treeview
Type: behavior Stage: test needed
Components: IDLE Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: aroberge, terry.reedy
Priority: normal Keywords:

Created on 2017-09-22 15:18 by terry.reedy, last changed 2022-04-11 14:58 by admin.

Messages (8)
msg302747 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-22 15:18
ttk.Treeview should look as good as idlelib.tree, but will check.  It is more flexible.  Note that Treeview is low-level, need to add higher level functions or classes.  See if can more or less duplicate API of tree Items.
msg302749 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-22 15:24
From #31461: Browsers currently use idlelib.tree.TreeWidget.  Treeview is not a drop-in replacement because TreeWidget has some of the higher-level app-specific functions that users are expected to add to Treeview.  But could Treeview replace the low-level parts of TreeWidget that actually display stuff on the screen?
msg303189 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-28 04:07
Two concrete reasons to make the conversion: two issues are stymied by current tree.TreeNode.

1. #25090 tree.TreeNode requires an icon for every line.  Hence functions and classes get python file and director icons and they are difficult to remove.  By default, Treeview items do not get an image beside the text.

2. #20827 tree.TreeNode hardcodes single click behavior (in multiple places). TreeItems can only override or augment double clicks.  So it would be hard to keep hilites synchronized in browser and editor.  Treeview generates '<<TreeviewSelect>>' when a line is clicked on; setting the editor line can be done in a select handler.
msg303190 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2017-09-28 04:22
The main issue for conversion is expanding nodes.  tree.py does not define a widget class.  Rather, is uses a used a canvas and places images and text thereupon.  The latter is done with instances of TreeNode.  Each instance thereof is initialized with an instance of a subclass of TreeItem.  TreeItems can tell their TreeNode whether they can generate children without actually doing so.

Treeview *is* a widget which manages internal column and line structures.  Clicking a [+] or [-] icon generates a '<<TreeviwOpen>>' or '<<TreeviewClose>>' event.  Double clicking a line generates both a select and flip event.  The catch is that there is no [+] unless the node already has at least one child.

One solution would be to initially generate the whole tree of Treeview items from the pyclbr tree.  Another is to give items with children a dummy child and replace it on demand.  The item could be given its line number (as a string) as its id.  A subclass of Treeview (or a Frame containing one) could have a dict mapping ids to child dicts).

Since the browser TreeItem subclasses are used by pathbrowser, I would initially move them to that module rather than delete them.  Or I would combine the two modules.
msg343533 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-05-26 04:41
I changed the type to behavior because the hard-coded pixel heights prevent the browsers form being usable on at least one HiDPI monitor.  I closed #37041 in favor of this on the presumption that ttk.Treeview will work on such monitors, at least after fix_scaling(root) is called.  I posted a quick test there.
msg395060 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-06-04 00:56
Concrete reason 3. Treewidget does not work on high-res monitors.  The #37041 quick Treeview test worked for Andre Roberge
msg415506 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-03-18 15:19
3. continued. As noted in #22628, idlelib.tree has line spacing and other stuff hardcoded so it will not work properly on all monitors.
msg415532 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-03-19 01:20
ttk.Treeview also has problems, at least on some systems and versions.

https://mail.python.org/pipermail/tkinter-discuss/2022-March/004226.html
HiDPI displays and tkinter [cont]
https://mail.python.org/pipermail/tkinter-discuss/attachments/20220316/843e7076/attachment-0001.png
Apparently on linux.

https://mail.python.org/pipermail/tkinter-discuss/2022-March/004228.html
https://www.tcl.tk/man/tcl/TkCmd/ttk_treeview.html

under "Styling Options'
there is parameter to set the -rowheight
that needs to be defined as

ttk::style configure Treeview \
     -rowheight [expr {[font metrics font -linespace] + 2}]

however I could not find how to call this command, and when
If I do the following

style = ttk.Style()
style.configure("Treeview", rowheight="30")

it works, but it is not dynamic with the font size/dpi

Response has suggestion.
History
Date User Action Args
2022-04-11 14:58:52adminsetgithub: 75733
2022-03-19 08:43:15AlexWaygoodsettitle: IDLE: Convert browswers to use ttk.Treeview -> IDLE: Convert browsers to use ttk.Treeview
2022-03-19 01:20:28terry.reedysetmessages: + msg415532
2022-03-18 15:44:13terry.reedylinkissue22628 superseder
2022-03-18 15:19:14terry.reedysetmessages: + msg415506
2021-06-04 00:56:10terry.reedysetnosy: + aroberge

messages: + msg395060
versions: + Python 3.11, - Python 3.7, Python 3.8
2019-05-26 04:41:01terry.reedysettype: enhancement -> behavior
messages: + msg343533
versions: + Python 3.8, - Python 3.6
2019-05-26 04:37:25terry.reedylinkissue37041 superseder
2017-09-28 04:22:43terry.reedysetmessages: + msg303190
2017-09-28 04:07:47terry.reedysetmessages: + msg303189
2017-09-22 15:24:32terry.reedysetmessages: + msg302749
2017-09-22 15:23:27terry.reedylinkissue31461 dependencies
2017-09-22 15:18:50terry.reedycreate