Gentle elders of the village, I come here to ask your wise guidance.
I am trying to make a file manager kind of application. After a few headaches, I finally managed to upgrade tkdnd to the latest version,
and it's a game changer. Apparently, I can make any widget act as a drop-and-drop source or target, and receive data from the outside
world too.
tkdnd::drop_target register $::dropbutton *
bind $::dropbutton <<Drop>> {tk_messageBox -message "YES"}
Good.
The problem is, I need more than "any widget." I have a widget with
a file list and I want each file in that list to be a source and each directory to be both a source and a target.
I am trying to make a file manager kind of application.[snip]
I have made and am still working on two prototypes. One uses a text
widget to produce the file list. The other uses a treeview widget.
In the first case, each file or directory is in fact a line in a text
widget. In the second case, each file or directory is an "item" in a
tree that I don't know how to reference individually. So in either
case I don't know how to register or bind the individual file name,
which is a text widget's line or a treeview's item.
On Mon, 29 May 2023 22:00:09 -0000 (UTC), Rich wrote:
So much like with the treeview, you'd assign tags to passages of the text
widget, and bind to those tags (presumably tkdnd can bind to text
tags).
Sadly, no, it can't.
Remember this:
tkdnd::drop_target register $::dropbutton *
bind $::dropbutton <<Drop>> {tk_messageBox -message "YES"}
I suppose the second line would work if I could run the first one,
but I don't think I can. Do you?
I have tried, tkdnd will not accept a text widget tag as a "widget."
So much like with the treeview, you'd assign tags to passages of the text widget, and bind to those tags (presumably tkdnd can bind to text
tags).
On Mon, 29 May 2023 22:00:09 -0000 (UTC), Rich wrote:
So much like with the treeview, you'd assign tags to passages of the text
widget, and bind to those tags (presumably tkdnd can bind to text
tags).
Sadly, no, it can't.
Remember this:
tkdnd::drop_target register $::dropbutton *
bind $::dropbutton <<Drop>> {tk_messageBox -message "YES"}
I suppose the second line would work if I could run the first one,
but I don't think I can. Do you?
I have tried, tkdnd will not accept a text widget tag as a "widget."
But like most of this binary packages, they will probably die with Tcl
9.0 and no longer loadable.
First setup the window (the text or the treeview) as the "drop target"
(this satisifes the need for tkdnd::drop_target to register an actual widget).
Then setup bindings on the tkdnd events, attached to the window itself,
to trigger procs for each event. For <<DropPosition>> use the %X and
%Y expansions to obtain the x,y coordinate of the mouse over the
window. Then using the normal method calls for the widget (be it text
or treeview) convert the x,y mouse position into a text line number or
a treeview item id value (and decide if the drop "type" is appropriate
for this x,y value and return the appropriate return value).
Clever mechanism for targets.
Now, how would you turn a text line into a drag-and-drop source?
Presumably the same way you'd otherwise make a text line "active" for mousing, apply a text tag to the characters that should be "active" and
bind to the appropriate events to be a drag. Which most likely would
mean detecting the line on a button down event, then beginning the
"drop source" aspects upon motion (possibly upon sufficient motion
distance to avoid small mouse jitters of 2-3 pixels initiating a drag).
How would one be able to drag a text widget line onto something else?
Same way, apply tags, bind appropriate events to those tags to initiate
the drag -- then insert into the drag whatever is data appropriate for "dragging" of this text line.
On Tue, 30 May 2023 02:34:27 -0000 (UTC), Rich wrote:
First setup the window (the text or the treeview) as the "drop
target" (this satisifes the need for tkdnd::drop_target to register
an actual widget).
Then setup bindings on the tkdnd events, attached to the window
itself, to trigger procs for each event. For <<DropPosition>> use
the %X and %Y expansions to obtain the x,y coordinate of the mouse
over the window. Then using the normal method calls for the widget
(be it text or treeview) convert the x,y mouse position into a text
line number or a treeview item id value (and decide if the drop
"type" is appropriate for this x,y value and return the appropriate
return value).
Clever mechanism for targets.
Now, how would you turn a text line into a drag-and-drop source?
How would one be able to drag a text widget line onto something else?
On Tue, 30 May 2023 03:41:56 -0700 (PDT), Mole Cool wrote:
But like most of this binary packages, they will probably die with Tcl
9.0 and no longer loadable.
Then I will cling to Tcl 8.6 for at least 10 years before I jump to Tcl 9. Come and pry it away from my cold stiff dead hands.
On Wed, 31 May 2023 01:38:30 -0000 (UTC), Rich wrote:
Clever mechanism for targets.
Now, how would you turn a text line into a drag-and-drop source?
Presumably the same way you'd otherwise make a text line "active" for mousing, apply a text tag to the characters that should be "active" and bind to the appropriate events to be a drag. Which most likely would
mean detecting the line on a button down event, then beginning the
"drop source" aspects upon motion (possibly upon sufficient motion distance to avoid small mouse jitters of 2-3 pixels initiating a drag).
How would one be able to drag a text widget line onto something else?
Same way, apply tags, bind appropriate events to those tags to initiate the drag -- then insert into the drag whatever is data appropriate for "dragging" of this text line.You bring up tags again, but tags don't work with tkdnd. They don't work with the 'register' command that turns a widget into a source (or target) because a "tagged" line of text is not a widget.
I am having a busy week so I didn't have much time to code today, but
I have done some more prototyping and now I think that my best bet
will be labels in place of text lines. They can be fully referenced
as widgets. They *are* bona fide widgets. I'm just not too sure about
what parent widget I should use to contain them. Maybe a text widget,
but I guess I will have to experiment.
Hi Luc. I don't have time to experiment, so I don't know if this will
work, but you might give it a try: Use the textwidget dlineinfo call to
get the size information of the tagged text. Then use the textwidget peer call to create a peer textwidget. Resize the peer widget according to
the dlineinfo. Use this peer widget for the dragging. Afterwords,
destroy the peer widget.
-Brian
Maybe something more "simple" can be useful for you.
For example, take a look to "A simple DnD implementation by SES" (at end
of https://wiki.tcl-lang.org/page/Drag+and+Drop).
Or, in the same line
"simplednd" by Kevin Walzer (https://wiki.tcl-lang.org/page/SimpleDND).
This last isn't available but if you have interest i can paste the code
here.
Well, below i paste the code of simplednd by Kevin Walzer.
First, you must save this as "simplednd.tcl".
Now, how would you turn a text line into a drag-and-drop source?
How would one be able to drag a text widget line onto something else?
You indicated in a different thread that despite all the tips and hints**************************
you received, you still haven't managed to get this working. Then let me >spell it out for you.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 485 |
Nodes: | 16 (2 / 14) |
Uptime: | 131:28:35 |
Calls: | 9,655 |
Calls today: | 3 |
Files: | 13,707 |
Messages: | 6,166,553 |