Last active
November 10, 2016 13:05
-
-
Save dmpop/d5aaaa843badd0dc57aed036f9a15d79 to your computer and use it in GitHub Desktop.
Simple file drop palette in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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