Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

text widget: drag and drop

8 views
Skip to first unread message

Ihug

unread,
Nov 28, 2005, 11:08:03 PM11/28/05
to
I am trying to get drag and drop to work.

One thing I am trying to understand is when events get triggered - this
differs once the mouse button is depressed.

When the user moves the mouse over the various tags they are highlighted (as
per the Motion binding below).
When the user presses button-1 the drag gets initiated.
When the user releases button-1 the drop gets initiated.

The problem is once the button is pressed no more motion events get
triggered, hence nullifying the "drag" effect.
Can the text widget ($tw) be configured to activate motion events while the
buttons are pressed?


$tw tag bind $tag <Motion> "highlight_bar $t $tag_no"
$tw tag bind $tag <1> [list select_list_1 $t $tag_no "drag"]
$tw tag bind $tag <ButtonRelease-1> [list select_list_1 $t $tag_no "drop"]


Bryan Oakley

unread,
Nov 28, 2005, 11:32:23 PM11/28/05
to
Ihug wrote:
> I am trying to get drag and drop to work.
>
> One thing I am trying to understand is when events get triggered - this
> differs once the mouse button is depressed.
>
> When the user moves the mouse over the various tags they are highlighted (as
> per the Motion binding below).
> When the user presses button-1 the drag gets initiated.
> When the user releases button-1 the drop gets initiated.
>
> The problem is once the button is pressed no more motion events get
> triggered, hence nullifying the "drag" effect.
> Can the text widget ($tw) be configured to activate motion events while the
> buttons are pressed?
>

Short answer: no.

What you do is put a <Motion> binding on the thing being clicked on.
Then, use the winfo command to determine the window below the mouse as
it is being dragged. Use this information to know what to highlight. If
it is a text widget, you can get the index of the character under the
pointer, determine any bindings on that character, and Do The Right Thing.

This behavior of the widget handling the ButtonPress event also getting
all the Motion events is documented briefly in the bind man page.

A rudimentary drag and drop example can be found at this wiki page:
http://wiki.tcl.tk/416

The example doesn't explicitly address text widgets, but it shows how as
the drag occurs, the widget that was clicked on gets the motion events
and can highlight the item under the pointer.

Ihug

unread,
Nov 29, 2005, 2:50:28 PM11/29/05
to
Thanks Bryan.
I found that I was binding the text "tags" directly when it was far simpler
to bind the text widget with "%x %y" and then use "$text tag names @%x,%y" -
it amazes me that I never realised it could be so much simpler (and more
efficient).

I am only dragging items within the same text widget so the dragging is
working perfectly for me now.

"Bryan Oakley" <oak...@bardo.clearlight.com> wrote in message
news:rRQif.26316$Zv5....@newssvr25.news.prodigy.net...

0 new messages