• tkdnd (drag and drop) not working as expected

    From Luc@21:1/5 to All on Thu May 25 22:39:18 2023
    This code works:

    ------------------------
    package require Tk
    package require tkdnd

    proc p.playwav {argWavFile} {
    package require sound
    snack::sound s -file $argWavFile; s play -block 1
    }

    pack [ttk::button .drop_target -text " Drop Target (I can accept anything!) "] -fill x -padx 20 -pady 20
    tkdnd::drop_target register .drop_target *
    bind .drop_target <<Drop>> {puts %D; return %A}
    ------------------------



    This code also works:

    ------------------------
    package require Tk
    package require tkdnd
    package require tile
    wm withdraw .
    set ::w [toplevel .dnd -background #c0c0c0]
    wm resizable $::w 1 1

    set ::outerframe $::w.outerframe
    set ::dropbutton $::w.dropbutton

    frame $::outerframe
    $::outerframe configure -background #ADD8E6
    pack $::outerframe -fill both -expand 1

    button $::dropbutton
    $::dropbutton configure -background #d9d9d9 -foreground #000000
    $::dropbutton configure -font "Freesans 12" -text "DROP"
    $::dropbutton configure -borderwidth 1 -relief raised -overrelief ridge
    pack $::dropbutton -side right

    tkdnd::drop_target register $::dropbutton *
    bind .drop_target <<Drop>> {puts %D; return %A}
    ------------------------


    But this code doesn't work:

    ------------------------
    package require Tk
    package require tkdnd
    package require tile
    wm withdraw .
    set ::w [toplevel .dnd -background #c0c0c0]
    wm resizable $::w 1 1

    proc p.playwav {argWavFile} {
    package require sound
    snack::sound s -file $argWavFile; s play -block 1
    }


    set ::outerframe $::w.outerframe
    set ::dropbutton $::outerframe.dropbutton

    frame $::outerframe
    $::outerframe configure -background #ADD8E6
    pack $::outerframe -fill both -expand 1

    button $::dropbutton
    $::dropbutton configure -background #d9d9d9 -foreground #000000
    $::dropbutton configure -font "Freesans 12" -text "DROP"
    $::dropbutton configure -borderwidth 1 -relief raised -overrelief ridge
    pack $::dropbutton -side right

    tkdnd::drop_target register $::dropbutton *
    bind .drop_target <<Drop>> {puts %D; return %A}
    ------------------------


    In other words, the "drop target" only works if it's not inside a frame? [shrug]

    Looks like a bug to me. Can someone please have a look to make sure
    I am not doing something wrong before I attempt to file a bug report
    or something?

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to All on Thu May 25 22:42:12 2023
    Note:

    The p.playwav proc should not have been included in my previous code.
    I use sounds for testing the drag and drop action, but the code also
    provides for puts statements. Please disregard the additional proc.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From [email protected]@21:1/5 to All on Fri May 26 03:37:42 2023
    bind .drop_target ...

    should probably be

    bind $::dropbutton ,,,

    The examples use of .drop_target is confusing when used with the tkdnd::drop_target command

    Daved B

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Luc@21:1/5 to [email protected] on Fri May 26 10:52:36 2023
    On Fri, 26 May 23 03:37:42 GMT, [email protected] wrote:

    bind .drop_target ...

    should probably be

    bind $::dropbutton ,,,

    The examples use of .drop_target is confusing when used with the tkdnd::drop_target command

    Daved B


    Thanks. But that is a typo from my use of sounds. My actual code
    is this:

    #bind .drop_target <<Drop>> {puts %D; return %A}
    bind $::dropbutton <<Drop>> {p.playwav /path/to/sound/file.wav}

    I deleted the line that uses sound from my example and uncommented
    the line that uses puts, but forgot to adjust the bind statement.
    But I already use bind $::dropbutton.

    And it doesn't work.

    --
    Luc


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to Luc on Fri May 26 11:32:58 2023
    On 5/26/2023 6:52 AM, Luc wrote:
    On Fri, 26 May 23 03:37:42 GMT, [email protected] wrote:

    bind .drop_target ...

    should probably be

    bind $::dropbutton ,,,

    The examples use of .drop_target is confusing when used with the
    tkdnd::drop_target command

    Daved B


    Thanks. But that is a typo from my use of sounds. My actual code
    is this:

    #bind .drop_target <<Drop>> {puts %D; return %A}
    bind $::dropbutton <<Drop>> {p.playwav /path/to/sound/file.wav}

    I deleted the line that uses sound from my example and uncommented
    the line that uses puts, but forgot to adjust the bind statement.
    But I already use bind $::dropbutton.

    And it doesn't work.




    Is your code returning an action inside p.playwav like
    it does with the return %A in the commented out bind?

    If you don't then refuse drop is assumed, though to be
    honest, I don't know what that does.

    But maybe it messes things up if you don't do a return of
    some kind. In my usage, I always just return "copy".

    Have you looked at:

    https://wiki.tcl-lang.org/page/TkDND+Tutorial

    Especially look at the Q&A at the bottom.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Fri May 26 21:57:20 2023
    On 5/26/2023 11:32 AM, et99 wrote:
    On 5/26/2023 6:52 AM, Luc wrote:
    On Fri, 26 May 23 03:37:42 GMT, [email protected] wrote:

    bind .drop_target ...

    should probably be

    bind $::dropbutton ,,,

    The examples use of .drop_target is confusing when used with the
    tkdnd::drop_target command

    Daved B


    Thanks. But that is a typo from my use of sounds. My actual code
    is this:

    #bind .drop_target <<Drop>> {puts %D; return %A}
    bind $::dropbutton <<Drop>> {p.playwav /path/to/sound/file.wav}

    I deleted the line that uses sound from my example and uncommented
    the line that uses puts, but forgot to adjust the bind statement.
    But I already use bind $::dropbutton.

    And it doesn't work.




    Is your code returning an action inside p.playwav like
    it does with the return %A in the commented out bind?

    If you don't then refuse drop is assumed, though to be
    honest, I don't know what that does.

    But maybe it messes things up if you don't do a return of
    some kind. In my usage, I always just return "copy".

    Have you looked at:

    https://wiki.tcl-lang.org/page/TkDND+Tutorial

    Especially look at the Q&A at the bottom.




    Actually, when I changed it to:

    bind $::dropbutton <<Drop>> {p.playwav %D}

    and dragged a .wav file onto DROP it works for me
    on my windows system.

    I didn't bother to return an action. So, that's not
    a problem here.

    How are you dragging, I'm just using windows explorer.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)