Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Tk Drag and Drop Between Applications

by Ardemus (Beadle)
on Dec 15, 2004 at 00:29 UTC ( [id://414906]=perlquestion: print w/replies, xml ) Need Help??

Ardemus has asked for the wisdom of the Perl Monks concerning the following question:

Can I drag and drop a file *from* perl Tk into another windows app?

I haven't found *any* reference to this aspect of DND. I've spent 20+ hours on the web, Perl Monks, Safari, and in the few docs I found. I've read the ubiquitous stuff:

  1. http://www.perl.com/pub/a/2001/12/11/perltk.html
  2. http://www.perltk.org/articles/dnd/dnd.html
  3. http://www.perltk.org/articles/dnd/hlistdnd.pl

I changed 'Win32' to 'Local' in #3 above. While I can drag in and drag locally I can't drag out (not even to another instance of the same app). The OS and other apps don't respond in any way, and the token doesn't change to indicate a drop site.

Is this possible? Is there documentation? Thanks.

Ardemus - "This, right now, is our lives"


Resolution: This question has been answered: Yes, but only through the Tcl/Tk module (not Perl/Tk). Full details are available in this thread.

My Application: Search and aggregate data from multiple databases. I want to select and drag results into other apps (like Sound Forge or Pro Tools).


Replies are listed 'Best First'.
Re: Tk Drag and Drop Between Applications
by blueberryCoffee (Scribe) on Dec 15, 2004 at 10:40 UTC
    I don't know how this can be done but a simple workaround could be to use the clipboard to store what you want and then paste it into the other app. Make a popup window (or a button)that will grab your current selection and convert it (if it's a listbox or a set of widgets) into text usable by the other app. Then for windows use Win32::Clipboard to fill the clipboard.
      Breaking user's clipboard will frustrate them and sometimes make them mad.

      Also, there is an obvious place for race condition here: imagine two instances of same applications waiting for drag-drop from each other (using this d-n-d technique), clipboard will become invalid just on the half-way to a target.

      Best regards,
      Courage, the Cowardly Dog

Re: Tk Drag and Drop Between Applications
by fglock (Vicar) on Dec 15, 2004 at 12:24 UTC

    Tk::DragDrop has subclasses for Win32, KDE, Sun. It doesn't come with much documentation.

Re: Tk Drag and Drop Between Applications
by Anonymous Monk on Dec 15, 2004 at 03:01 UTC
    No, it is not possible. Its either a bug or it was never supposed to work, you'll have to ask the perltk mailing list.
Re: Tk Drag and Drop Between Applications
by paulbort (Hermit) on Dec 15, 2004 at 18:53 UTC

    Drag and drop between different apps is an OLE operation, IIRC. One app communicates to the other what is being offered, and the responding app accepts or declines. The OS indicates this to the user by fiddling the pointer and icon, but the apps can override the default appearances.

    There is a blog entry (part one of five) has some C code on doing drag and drop with the shell, and might be a good start.


    --
    Spring: Forces, Coiled Again!
Re: Tk Drag and Drop Between Applications
by Courage (Parson) on Dec 15, 2004 at 21:51 UTC
    Tcl/Tk's drag-and-drop is discussed at http://mini.net/tcl/571

    Please note this is not perlTk, but it is Tcl/Tk which is available for Perl programs with very similar syntax

    In order to go this way, you will need Tcl::Tk module from CPAN and will probably will face some difficulties, but those difficulties are solve-able and I will be happy to provide a bit of my knowledge in this way round...

    Best regards,
    Courage, the Cowardly Dog

      Fantastic Courage! Thanks.

      I've got a DnD proof of concept working in pure Tcl/Tk (just a tweak of the TkDnD 'dnddemo.tcl' file). I don't know Tcl, so that one tweak was a pain, but at this point I'm going to be learning *something* new.

      Do you know if I can work with my mySQL database from Tcl/Tk also? If so, I could create the entire tool in Tcl/Tk and create a single executable... what is it, Starkit?

      I'll post my progress here for anyone following my footsteps.

        Although Tcl/Tk allows mySQL database, there is no need to switch to Tcl for database access, because you can use it from Perl.

        For example, you can do GUI part (with DnD) in Tcl and remaining part using Perl.

        It's for you to decide.
        Let me know if you will have some difficulties, I'll help solving them.

        Best regards,
        Courage

Re: Tk Drag and Drop Between Applications
by zentara (Cardinal) on Dec 15, 2004 at 10:50 UTC
    You may have a shot at getting something to work, but only on Windows, then you may have to use MDI, or whatever windows calls it's standard. On linux, it would be impossible because all the apps are so different.

    My first try would be to make everything the "child" of a Tk app, and have a little Tk window open for dropping DnD objects into. You can use DND between Tk apps, so make a Tk wrapper around SoundForge and/or PrtTools, which starts up, and runs them thru IPC::Run, and creates a little 1 inch square canvas to drop onto. When the drop-recepticle gets an object dropped on it, it passes it on to the other apps thru IPC.

    All in all it sounds like it would get complicated and very "troubleprone" to deal with. Unless you are a "software pioneer", it would be best to think of other ways....like making a temp file and passing data that way.


    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://414906]
Approved by kvale
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2025-01-15 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (49 votes). Check out past polls.