Drag and drop in Windows

Robert Flintham Robert.Flintham at uhb.nhs.uk
Mon Apr 29 06:25:51 EDT 2013


Hello all,

Sorry to post such a generic question, but after searching the interwebs I'm not really any wiser about how to start with this.

I'm currently on:
Windows XP
Python 2.7

I'm trying to create a small window in Python 2.7, that when you drop a file onto it from Windows explorer returns the file's path so that I can then go on to open the file and do whatever with it.  I was planning on using Tkinter because that's what I've used before for GUI's, but I can be swayed from this if needs be.

I've found this (TkDND):
http://wiki.tcl.tk/2768

But I don't know how to implement this in Python.  The Windows binary for it comes as a set of ".tcl" files and a single ".dll" file.

The two options I've stumbled across seem to be

1.  a Python wrapper for the DLL (I think to wrap C code??), which can then be imported like you'd import a Python package

2.  direct implementation of the Tcl file [tk.eval('source ...')], but I don't reallu understand what's going on with this - can you only execute a "main" bit of Tcl files rather than implementing individual functions?

Any input (however minimal) is definitely appreciated!  I've included what I think are probably the relevant functions from the Tcl files at the bottom of the email, but I don't really understand the nuts and bolts of the code.

All the best,
Rob

[From "tkdnd.tcl"...]

# ----------------------------------------------------------------------------
#  Command tkdnd::drag_source
# ----------------------------------------------------------------------------
proc tkdnd::drag_source { mode path { types {} } { event 1 } } {
  set tags [bindtags $path]
  set idx  [lsearch $tags "TkDND_Drag*"]
  switch -- $mode {
    register {
      if { $idx != -1 } {
        bindtags $path [lreplace $tags $idx $idx TkDND_Drag$event]
      } else {
        bindtags $path [concat $tags TkDND_Drag$event]
      }
      set types [platform_specific_types $types]
      set old_types [bind $path <<DragSourceTypes>>]
      foreach type $types {
        if {[lsearch $old_types $type] < 0} {lappend old_types $type}
      }
      bind $path <<DragSourceTypes>> $old_types
    }
    unregister {
      if { $idx != -1 } {
        bindtags $path [lreplace $tags $idx $idx]
      }
    }
  }
};# tkdnd::drag_source


[From "tkdnd_windows.tcl"...]

# ----------------------------------------------------------------------------
#  Command olednd::_GetDragSource
# ----------------------------------------------------------------------------
proc olednd::_GetDragSource {  } {
  variable _drag_source
  return $_drag_source
};# olednd::_GetDragSource
DISCLAIMER:
This email and any attachments hereto contains proprietary information, some or all of which may be confidential or legally privileged. It is for the exclusive use of the intended recipient(s) only. If an addressing or transmission error has misdirected this e-mail and you are not the intended recipient(s), please notify the author by replying to this e-mail. If you are not the intended recipient you must not use, disclose, distribute, copy, print, or rely on this e-mail or any attachments, as this may be unlawful.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130429/ad17e59e/attachment.html>


More information about the Python-list mailing list