Questions about event handling with Ttk::treeview
- From: Steve <fake@xxxxxxxxxxx>
- Date: Mon, 27 Apr 2009 00:03:49 -0400
Pardon the newbie-level from which I ask this question. I used Tcl/Tk pretty extensively back in the 90's, but am YEARS out of practice. I got excited after reading about the advances in the Tk toolkit over the past few years, and have been playing around trying to ramp back up...
I'm trying to write a small Tcl/Tk app with a treeview widget for selecting multiple files and directories in the filesystem. I'm needing to implement the following behavior with the widget:
1) When a directory is selected, it causes all the files and subdirectories beneath that directory to be selected also.
2) Selecting another item, even without holding down the Shift or Ctrl key, does NOT deselect the currently item(s). Once a file or directory has been selected, it is only deselected if explicitly clicked a second time (or maybe if its parent is deselected).
Some other GUI toolkits have a "checkbox tree" kind of widget that behaves this way (typically with a checkbox to the left of each item for selecting). I'm gathering that Ttk::treeview doesn't exactly offer this out-of-the-box (if I'm wrong please stop me at this point so I save time!). However, maybe I can roll my own functionality through event handling? That is, I can keep track of the currently selected items in a variable... and when the tree is clicked, I can process what the currently selected items SHOULD be based on what was clicked.
The problem is that I'm having a hard time grasping the event handling model for the treeview widget. Items of confusion (so far):
1) The treeview man page (http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_treeview.htm) talks about the relevant events being <KeyPress> or <ButtonPress>. However, the TkDocs tutorial site (http://www.tkdocs.com/tutorial/tree.html) references <TreeviewSelect>. I'm not sure what event I'm looking for.
2) I'm also not sure how to get the event. The Event Handling page on that TkDocs site (http://www.tkdocs.com/tutorial/concepts.html#events) talks about using the "bind" command. However, the bottom of treeview page on that site (http://www.tkdocs.com/tutorial/tree.html) talks about using the "tag bind" command off the treeview object itself. The example given is a little too bare-bones for my intellect, unfortunately.
3) Finally, even once I DO capture the event I'm not sure what to do with it. The "treeview selection" command returns a list of the currently selected items, but I'm not sure how to translate that into a tree structure so my code can process it correctly (i.e. recognizing that a directory has been selected and therefore all the children should be selected as well). I suppose the brute force approach would be to start with my own data structure representing the filesystem tree, and write functions that can export the initial tree as well as a list of id's to later pass to "treeview selection set". If anyone has an idea for a more elegant approach I would love to hear it!
Anyway, if you've read this far then thanks alot. I realize this post is a mouthful of a question, and I don't really need someone to write the app for me. However, if you can point me in the right direction on any of these sub-questions raised I would deeply appreciate it. Thanks!
.
- Follow-Ups:
- Prev by Date: Re: Questions regarding tcl's value semantics
- Next by Date: Re: Questions regarding tcl's value semantics
- Previous by thread: Questions regarding tcl's value semantics
- Next by thread: Re: Questions about event handling with Ttk::treeview
- Index(es):