• Tk DND

    From saitology9@21:1/5 to All on Sat Feb 25 19:25:01 2023
    Hello,

    I am trying to follow the tutorial for TkDND on the wiki. I am using
    DND_Text. However, the dropped text is not what was dropped. It seems
    like it has all the other "control" type information in it as well.

    For example, this is the result of a text drop, not at all what I dropped:

    Version:0.9
    StartHTML:00000147
    EndHTML:00000274
    StartFragment:00000181
    EndFragment:00000238
    ....


    Is there another command/switch that lets you get the plain text
    instead? Or how do you interpret this result?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Tue Feb 28 09:21:07 2023
    On 2/25/2023 4:25 PM, saitology9 wrote:
    Hello,

    I am trying to follow the tutorial for TkDND on the wiki. I am using DND_Text. However, the dropped text is not what was dropped.  It seems like it has all the other "control" type information in it as well.

    For example, this is the result of a text drop, not at all what I dropped:

    Version:0.9
    StartHTML:00000147
    EndHTML:00000274
    StartFragment:00000181
    EndFragment:00000238
    ....


    Is there another command/switch that lets you get the plain text instead?  Or how do you interpret this result?


    what os system
    what tkdnd version (is that the .9 you output)
    what tutorial website

    I use tkdnd on windows and my version in magicsplat
    8.6.13 distro, is 2.9.2

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

    I can take the 2 code blocks (that say complete), and
    copy/paste them into a windows console and I then see
    3 buttons, the first of which says "drop target (i can
    accept anything)?"

    I can then drag the text and file type drag
    sources and get,

    Dropped text: "{Some nice dropped text!}"
    Dropped files: ""
    Drop action: {copy}

    And the text, as one can see in the code, came from the
    %D in the binding. Same with the file drop. The {copy}
    comes from the %A

    Or here's what I get if I d/d a file from my a: drive

    Dropped files: "A:/IMG_20230226_103951606_HDR.jpg"

    When I added d/d to one of my programs, I just took
    those example code blocks less the code I didn't need
    and just used what was left.

    But I don't see anything like what you posted, so I
    suggest you either start with those 2 code blocks, or
    compare them to your own code. And get a later version
    if you are using .9

    However, I only tested it on windows.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to All on Tue Feb 28 15:45:52 2023
    On 2/28/2023 12:21 PM, et99 wrote:
    On 2/25/2023 4:25 PM, saitology9 wrote:

    what os system
    what tkdnd version (is that the .9 you output)
    what tutorial website


    Thank you for the feedback.

    Quick answers: MS Windows 11, The "0.9" comes from tkdnd itself, and the
    same tutorial website and the same version of tkdnd as yours.

    I dragged some text from my browser. I can only guess that it is because
    the source is html. I am pretty sure you will see the same thing if you
    use your browser as the source.

    I looked at the output. There is some control stuff like I mentioned,
    but then comes the html version of the text being dragged; it is there.
    You just have to extract it I suppose. I was expecting to see plain
    text as when I do with notepad.

    I came across it on the wiki and thought it was interesting. Maybe I
    will come back to it in the future if I find time.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Tue Feb 28 21:19:08 2023
    On 2/28/2023 9:16 PM, et99 wrote:
    On 2/28/2023 12:45 PM, saitology9 wrote:
    On 2/28/2023 12:21 PM, et99 wrote:
    On 2/25/2023 4:25 PM, saitology9 wrote:

    what os system
    what tkdnd version (is that the .9 you output)
    what tutorial website


    Thank you for the feedback.

    Quick answers: MS Windows 11, The "0.9" comes from tkdnd itself, and the same tutorial website and the same version of tkdnd as yours.

    I dragged some text from my browser. I can only guess that it is because the source is html. I am pretty sure you will see the same thing if you use your browser as the source.

    I looked at the output.  There is some control stuff like I mentioned, but then comes the html version of the text being dragged; it is there. You  just have to extract it I suppose. I was expecting to see plain text as when I do with notepad.

    I came across it on the wiki and thought it was interesting. Maybe I will come back to it in the future if I find time.


    I tried it from my text editor, and it works correctly.

    If you're doing a drag/drop from a webpage, there's
    no telling what it will drop. However, I did a d/d from
    firefox and also chrome, and I only got the selected text.

    So, I'm stumped :)


    Wait, how did you get that 0.9? If you just type in "package require tkdnd" what do you get?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Tue Feb 28 21:16:33 2023
    On 2/28/2023 12:45 PM, saitology9 wrote:
    On 2/28/2023 12:21 PM, et99 wrote:
    On 2/25/2023 4:25 PM, saitology9 wrote:

    what os system
    what tkdnd version (is that the .9 you output)
    what tutorial website


    Thank you for the feedback.

    Quick answers: MS Windows 11, The "0.9" comes from tkdnd itself, and the same tutorial website and the same version of tkdnd as yours.

    I dragged some text from my browser. I can only guess that it is because the source is html. I am pretty sure you will see the same thing if you use your browser as the source.

    I looked at the output.  There is some control stuff like I mentioned, but then comes the html version of the text being dragged; it is there. You  just have to extract it I suppose. I was expecting to see plain text as when I do with notepad.

    I came across it on the wiki and thought it was interesting. Maybe I will come back to it in the future if I find time.


    I tried it from my text editor, and it works correctly.

    If you're doing a drag/drop from a webpage, there's
    no telling what it will drop. However, I did a d/d from
    firefox and also chrome, and I only got the selected text.

    So, I'm stumped :)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to All on Wed Mar 1 11:03:39 2023
    On 3/1/2023 12:19 AM, et99 wrote:
    I tried it from my text editor, and it works correctly.

    If you're doing a drag/drop from a webpage, there's
    no telling what it will drop. However, I did a d/d from
    firefox and also chrome, and I only got the selected text.

    So, I'm stumped :)


    Wait, how did you get that 0.9? If you just type in "package require tkdnd" what do you get?


    That is wild! I am stumped too. There is a lot to say on this now :-)

    This is close to what I was doing the other day:

    package req Tk
    package req tkdnd
    frame .f
    tkdnd::drop_target register .f *
    bind .f <<Drop:DND_Text>> {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_HTML>> {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_Files>> {puts "Dropped: \"%D\""; return %A}


    Now, open your Firefox or Chrome and go to https://wiki.tcl-lang.org/page/TkDND+Tutorial and locate the title that
    says "Creating a drop target" and just select/highlight the word "Creating".



    Now drop this into the widget above. I get an error message and I
    click on "details" button and this is what I see:


    First time, I get an error message:
    ---------------------
    extra characters after close-quote
    couldn't open "C:/Tcl/Tcl8612/lib/tclIndex": no such file or directory
    while executing
    "open [file join $dir tclIndex]"
    ------------------------


    After trying again, the message changes to this. I don't recall getting
    error messages like this but I may be wrong. But you can see that where
    it says "Version:0.9, ..."


    With firefox:
    ----------------
    extra characters after close-quote
    extra characters after close-quote
    while executing
    "puts "Dropped: {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:00000285

    SourceURL:chrome://browser/content/br..."
    ("uplevel" body line 1)
    invoked from within
    "uplevel \#0 $cmd"
    (procedure "::tkdnd::generic::HandleDrop" line 36)
    invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {} $pressedkeys $rootX $rootY 0"
    (procedure "::tkdnd::olednd::HandleDrop" line 3)
    invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 223 240 {HTML Format} {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:000002..."
    -----------------



    With Chrome, you get mixed results. Sometimes it is OK and just prints
    out the text you selected. Other times, it gives a similar error message:

    ----------
    extra characters after close-quote
    extra characters after close-quote
    while executing
    "puts "Dropped: {Creating a drop target
    A "d"
    ("uplevel" body line 1)
    invoked from within
    "uplevel \#0 $cmd"
    (procedure "::tkdnd::generic::HandleDrop" line 36)
    invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {} $pressedkeys $rootX $rootY 0"
    (procedure "::tkdnd::olednd::HandleDrop" line 3)
    invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 288 288 CF_UNICODETEXT {Creating a
    drop target
    A "drop target" is a widget that can accept drops. What we must speci..." ------------------

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Griffiths@21:1/5 to All on Wed Mar 1 13:03:57 2023
    On Wednesday, 1 March 2023 at 16:03:45 UTC, saitology9 wrote:
    On 3/1/2023 12:19 AM, et99 wrote:
    I tried it from my text editor, and it works correctly.

    If you're doing a drag/drop from a webpage, there's
    no telling what it will drop. However, I did a d/d from
    firefox and also chrome, and I only got the selected text.

    So, I'm stumped :)


    Wait, how did you get that 0.9? If you just type in "package require tkdnd"
    what do you get?
    That is wild! I am stumped too. There is a lot to say on this now :-)

    This is close to what I was doing the other day:

    package req Tk
    package req tkdnd
    frame .f
    tkdnd::drop_target register .f *
    bind .f <<Drop:DND_Text>> {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_HTML>> {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_Files>> {puts "Dropped: \"%D\""; return %A}


    Now, open your Firefox or Chrome and go to https://wiki.tcl-lang.org/page/TkDND+Tutorial and locate the title that
    says "Creating a drop target" and just select/highlight the word "Creating".



    Now drop this into the widget above. I get an error message and I
    click on "details" button and this is what I see:


    First time, I get an error message:
    ---------------------
    extra characters after close-quote
    couldn't open "C:/Tcl/Tcl8612/lib/tclIndex": no such file or directory
    while executing
    "open [file join $dir tclIndex]"
    ------------------------


    After trying again, the message changes to this. I don't recall getting error messages like this but I may be wrong. But you can see that where
    it says "Version:0.9, ..."


    With firefox:
    ----------------
    extra characters after close-quote
    extra characters after close-quote
    while executing
    "puts "Dropped: {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:00000285

    SourceURL:chrome://browser/content/br..."
    ("uplevel" body line 1)
    invoked from within
    "uplevel \#0 $cmd"
    (procedure "::tkdnd::generic::HandleDrop" line 36)
    invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {} $pressedkeys $rootX $rootY 0" (procedure "::tkdnd::olednd::HandleDrop" line 3)
    invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 223 240 {HTML Format} {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:000002..."
    -----------------



    With Chrome, you get mixed results. Sometimes it is OK and just prints
    out the text you selected. Other times, it gives a similar error message:

    ----------
    extra characters after close-quote
    extra characters after close-quote
    while executing
    "puts "Dropped: {Creating a drop target
    A "d"
    ("uplevel" body line 1)
    invoked from within
    "uplevel \#0 $cmd"
    (procedure "::tkdnd::generic::HandleDrop" line 36)
    invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {} $pressedkeys $rootX $rootY 0" (procedure "::tkdnd::olednd::HandleDrop" line 3)
    invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 288 288 CF_UNICODETEXT {Creating a
    drop target
    A "drop target" is a widget that can accept drops. What we must speci..." ------------------

    I suspect the substitution where %D is replaced with a string of text containing quotes, braces, and other special characters is causing the command list to not be properly formed resulting in Tcl errors; in the test with simple inputs it probably works
    OK but fails on real-world usage. You may need to build the command in the [bind] more programatically so that you aren't getting code injection errors. The simplest way to do this is to use a proc for the fuller actions and use a simple [list] to
    construct the command.

    proc dndHandler {type str action} {
    if { $type eq } {
    puts "Generic data drop: \"$str\""
    } else {
    puts "Dropped $type: \"$str\""
    }
    return $action;
    }

    bind .drop_target <<Drop>> [list dndHandler "" %D %A]
    bind .drop_target <<Drop:DND_Text>> [list dndHandler "text" %D %A]
    ... etc

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Wed Mar 1 14:10:32 2023
    On 3/1/2023 8:03 AM, saitology9 wrote:
    On 3/1/2023 12:19 AM, et99 wrote:
    I tried it from my text editor, and it works correctly.

    If you're doing a drag/drop from a webpage, there's
    no telling what it will drop. However, I did a d/d from
    firefox and also chrome, and I only got the selected text.

    So, I'm stumped :)


    Wait, how did you get that 0.9? If you just type in "package require tkdnd" >> what do you get?


    That is wild! I am stumped too. There is a lot to say on this now :-)

    This is close to what I was doing the other day:

    package req Tk
    package req tkdnd
    frame .f
    tkdnd::drop_target register .f *
    bind .f <<Drop:DND_Text>>  {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_HTML>>  {puts "Dropped: \"%D\""; return %A}
    bind .f <<Drop:DND_Files>>  {puts "Dropped: \"%D\""; return %A}


    Now, open your Firefox or Chrome and go to https://wiki.tcl-lang.org/page/TkDND+Tutorial and locate the title that says "Creating a drop target" and just select/highlight the word "Creating".



    Now drop this into the widget above.  I get an error message  and I click on "details" button and this is what I see:


    First time, I get an error message:
    ---------------------
    extra characters after close-quote
    couldn't open "C:/Tcl/Tcl8612/lib/tclIndex": no such file or directory
        while executing
    "open [file join $dir tclIndex]"
    ------------------------


    After trying again, the message changes to this. I don't recall getting error messages like this but I may be wrong. But you can see that where it says "Version:0.9, ..."


    With firefox:
    ----------------
    extra characters after close-quote
    extra characters after close-quote
        while executing
    "puts "Dropped: {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:00000285

    SourceURL:chrome://browser/content/br..."
        ("uplevel" body line 1)
        invoked from within
    "uplevel \#0 $cmd"
        (procedure "::tkdnd::generic::HandleDrop" line 36)
        invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {}  $pressedkeys $rootX $rootY 0"
        (procedure "::tkdnd::olednd::HandleDrop" line 3)
        invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 223 240 {HTML Format} {Version:0.9

    StartHTML:00000147

    EndHTML:00000321

    StartFragment:00000181

    EndFragment:000002..."
    -----------------



    With Chrome, you get mixed results.  Sometimes it is OK and just prints out the text you selected.  Other times, it gives a similar error message:

    ----------
    extra characters after close-quote
    extra characters after close-quote
        while executing
    "puts "Dropped: {Creating a drop target
    A "d"
        ("uplevel" body line 1)
        invoked from within
    "uplevel \#0 $cmd"
        (procedure "::tkdnd::generic::HandleDrop" line 36)
        invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {}  $pressedkeys $rootX $rootY 0"
        (procedure "::tkdnd::olednd::HandleDrop" line 3)
        invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 288 288 CF_UNICODETEXT {Creating a drop target
    A "drop target" is a widget that can accept drops. What we must speci..." ------------------





    I'm still not sure you are running a recent version. What does a

    package require tkdnd

    return to you if you type that into a console window? Is it 0.9
    where I'm running version 2.x depending on which tcl version I use.

    % package require tkdnd
    2.2

    I also had to add a pack of .f and then add a button .f.b with text "hello".
    to get a drop target.

    % pack .f
    % button .f.b -text hello
    .f.b
    % pack .f.b -fill both -expand 1


    Then I dragged what you mentioned, and got this:

    Dropped: "{Creating }"
    Dropped: "{Creating a drop target}"


    Notice that my version adds the braces since I dragged some spaces.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to Mike Griffiths on Wed Mar 1 17:52:21 2023
    On 3/1/2023 4:03 PM, Mike Griffiths wrote:

    I suspect the substitution where %D is replaced with a string of text containing
    quotes, braces, and other special characters

    Yes, it definitely looks like it. Its pkgIndex file is also different
    than what you find for other packages in its syntax. I was following its tutorial page on the wiki, so if the examples are causing trouble, it
    could be something internal to the package.

    I should also emphasize that I was just playing with it. I was not
    aware of the package before last weekend, and I suspect my use
    (vis-a-vis with a browser as the source) may not have been the intended functionality at all.


    Your code prevents error message dialogs. It still generates the same
    output I saw originally:

    Dropped text: "Version:0.9
    StartHTML:00000147
    EndHTML:00000321
    StartFragment:00000181
    EndFragment:00000285
    SourceURL:chrome://browser/content/browser.xhtml
    <html><body>
    <!--StartFragment--><h2 id="3bc024451a44757459cf4c87e16e637b17dd1fb295b2ee51924acd7edaf62743" class="mkup_h1">Creating </h2><!--EndFragment-->
    </body>
    </html>

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From saitology9@21:1/5 to All on Wed Mar 1 17:37:40 2023
    On 3/1/2023 5:10 PM, et99 wrote:

    I'm still not sure you are running a recent version. What does a

    package require tkdnd

    return to you if you type that into a console window? Is it 0.9
    where I'm running version 2.x depending on which tcl version I use.

    % package require tkdnd
    2.2


    It seems more recent than yours:

    % package req tkdnd
    2.9.2



    I also had to add a pack of .f and then add a button .f.b with text
    "hello".
    to get a drop target.

    % pack .f
    % button .f.b -text hello
    .f.b
    % pack .f.b -fill both -expand 1



    Sorry - I must not have copied it fully. I had three more lines as follows:

    wm geometry . 300x300
    pack .f -fill both -expand 1
    .f config -bg blue

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From et99@21:1/5 to All on Wed Mar 1 16:51:25 2023
    On 3/1/2023 2:37 PM, saitology9 wrote:
    On 3/1/2023 5:10 PM, et99 wrote:

    I'm still not sure you are running a recent version. What does a

    package require tkdnd

    return to you if you type that into a console window? Is it 0.9
    where I'm running version 2.x depending on which tcl version I use.

    % package require tkdnd
    2.2


    It seems more recent than yours:

    % package req tkdnd
    2.9.2



    I also had to add a pack of .f and then add a button .f.b with text "hello". >> to get a drop target.

    % pack .f
    % button .f.b -text hello
    .f.b
    % pack .f.b -fill both -expand 1



    Sorry - I must not have copied it fully.  I had three more lines as follows:

    wm geometry . 300x300
    pack .f -fill both -expand 1
    .f config -bg blue




    Ok, I fired up 2.9.2 (from magicsplat's 8.6.13) and I can repeat it!!!
    So, looks like an issue in the *newer* version. :(

    Since tkdnd includes a binary .dll, I can't compare versions. I think
    a ticket is needed (if tkdnd is not part of the core, not sure where to post).


    extra characters after close-quote
    extra characters after close-quote
    while executing
    "puts "Dropped: \"{Version:0.9

    StartHTML:00000147

    EndHTML:00000320

    StartFragment:00000181

    EndFragment:00000284

    SourceURL:chrome://browser/content/..."
    ("uplevel" body line 1)
    invoked from within
    "uplevel \#0 $cmd"
    (procedure "::tkdnd::generic::HandleDrop" line 36)
    invoked from within
    "::tkdnd::generic::HandleDrop $drop_target {} $pressedkeys $rootX $rootY 0"
    (procedure "::tkdnd::olednd::HandleDrop" line 3)
    invoked from within
    "::tkdnd::olednd::HandleDrop .f {} 212 179 {HTML Format} {Version:0.9

    StartHTML:00000147

    EndHTML:00000320

    StartFragment:00000181

    EndFragment:000002..."

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Mike Griffiths@21:1/5 to All on Thu Mar 2 15:36:47 2023
    On Wednesday, 1 March 2023 at 22:52:27 UTC, saitology9 wrote:
    On 3/1/2023 4:03 PM, Mike Griffiths wrote:

    I suspect the substitution where %D is replaced with a string of text containing
    quotes, braces, and other special characters
    Yes, it definitely looks like it. Its pkgIndex file is also different
    than what you find for other packages in its syntax. I was following its tutorial page on the wiki, so if the examples are causing trouble, it
    could be something internal to the package.

    I should also emphasize that I was just playing with it. I was not
    aware of the package before last weekend, and I suspect my use
    (vis-a-vis with a browser as the source) may not have been the intended functionality at all.


    Your code prevents error message dialogs. It still generates the same
    output I saw originally:

    Dropped text: "Version:0.9
    StartHTML:00000147
    EndHTML:00000321
    StartFragment:00000181
    EndFragment:00000285
    SourceURL:chrome://browser/content/browser.xhtml
    <html><body>
    <!--StartFragment--><h2 id="3bc024451a44757459cf4c87e16e637b17dd1fb295b2ee51924acd7edaf62743" class="mkup_h1">Creating </h2><!--EndFragment-->
    </body>
    </html>

    See https://learn.microsoft.com/en-us/windows/win32/dataxchg/html-clipboard-format for a description of the format.

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