Skip to content

Instantly share code, notes, and snippets.

@dmpop
Last active November 10, 2016 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmpop/d5aaaa843badd0dc57aed036f9a15d79 to your computer and use it in GitHub Desktop.
Save dmpop/d5aaaa843badd0dc57aed036f9a15d79 to your computer and use it in GitHub Desktop.
Simple file drop palette in Python
#!/usr/bin/python
# filedrop.py
# http://zetcode.com/wxpython/draganddrop/
import wx, os, shutil, ntpath
dest_dir = '/home/user/backup/'
if not os.path.exists(dest_dir):
os.makedirs(dest_dir)
class FileDrop(wx.FileDropTarget):
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
for name in filenames:
try:
file = os.path.abspath(name)
self.window.WriteText('Copying ' + file + '\n')
shutil.copy2(file, dest_dir)
os.system("exiftool -d %Y%m%d-%H%M%S.%%e '-FileName<DateTimeOriginal' " + dest_dir + ntpath.basename(file))
except IOError, error:
dlg = wx.MessageDialog(None, 'Error opening file\n' + str(error))
dlg.ShowModal()
class DropFile(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size = (450, 400))
self.text = wx.TextCtrl(self, -1, style = wx.TE_MULTILINE)
dt = FileDrop(self.text)
self.text.SetDropTarget(dt)
self.Centre()
self.Show(True)
app = wx.App()
DropFile(None, -1, 'FileDrop')
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment