-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwxDropboxImporter.pyw
executable file
·158 lines (126 loc) · 5.24 KB
/
wxDropboxImporter.pyw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/usr/bin/env python
"""
Rename images as Dropbox "Camera Upload" feature does.
File name format is "year-month-day hours.minutes.seconds".
Tries to extract creation date from EXIF or video metadata,
if not available uses file modification time from file system.
Does not support video metadata earlier than Epoch time 0
(earlier than 1970-01-01 00:00:00 UTC).
"""
import sys
import wx
import dropboximport
class FileListDropTarget(wx.FileDropTarget):
""" This object implements Drop Target functionality
for Files droped to ListBox
(and in fact any subclass of wx.ItemContainer
"""
def __init__(self, obj):
""" Initialize the Drop Target, passing in the Object Reference to
indicate what should receive the dropped files """
# Initialize the wsFileDropTarget Object
wx.FileDropTarget.__init__(self)
# Store the Object Reference for dropped files
self.obj = obj
def OnDropFiles(self, x, y, filenames):
""" Implement File Drop """
# append a list of the file names to ListBox items
self.obj.AppendItems(filenames)
class GatherFilesPanel(wx.Panel):
"""Panel that displays a list of files
and allows adding and removing files or groups of files
"""
def __init__(self, parent, id, filenames, wildcard="All files (*.*)|*.*"):
wx.Panel.__init__(self, parent, id)
self.wildcard = wildcard
vsizer = wx.BoxSizer(wx.VERTICAL)
btnsizer = wx.BoxSizer(wx.HORIZONTAL)
addfilebtn = wx.Button(self, -1, 'Add files',
style=wx.ID_OPEN |
wx.BU_EXACTFIT |
wx.BU_LEFT |
wx.BU_RIGHT)
self.Bind(wx.EVT_BUTTON, self.OnAddFiles, addfilebtn)
btnsizer.Add(addfilebtn, 1, wx.GROW)
rmfilebtn = wx.Button(self, -1, 'Remove files',
style=wx.ID_CLOSE |
wx.BU_EXACTFIT |
wx.BU_LEFT |
wx.BU_RIGHT)
self.Bind(wx.EVT_BUTTON, self.OnRmFiles, rmfilebtn)
btnsizer.Add(rmfilebtn, 1, wx.GROW)
vsizer.Add(btnsizer, 0, wx.GROW)
self.filelist = wx.ListBox(self, -1, size=(300, 200),
choices=filenames,
style=wx.LB_EXTENDED |
wx.LB_HSCROLL |
wx.LB_NEEDED_SB |
wx.LB_SORT)
vsizer.Add(self.filelist, 1, wx.GROW)
self.SetSizer(vsizer)
self.Fit()
# Create a File Drop Target object
droptarget = FileListDropTarget(self.filelist)
# Link the Drop Target Object to the ListBox
self.filelist.SetDropTarget(droptarget)
def OnAddFiles(self, evt):
fileDlg = wx.FileDialog(self, 'Choose files',
style=wx.OPEN |
wx.FD_MULTIPLE |
wx.FD_CHANGE_DIR,
wildcard=self.wildcard)
if fileDlg.ShowModal() == wx.ID_OK:
self.filelist.AppendItems(fileDlg.GetPaths())
## self.fileslist.Set(self.filenames)
fileDlg.Destroy()
evt.Skip()
def RemoveFile(self, index):
self.filelist.Delete(index)
def OnRmFiles(self, evt):
selected = sorted(self.filelist.GetSelections())
selected.reverse()
for index in selected:
self.RemoveFile(index)
evt.Skip()
pass
def GetFiles(self):
return self.filelist.GetItems()
def SetWildcard(self, wildcard):
self.wildcard = wildcard
class RenamerFrame(wx.Frame):
def __init__(self, parent, id, filenames, title='Rename Camera Files'):
wx.Frame.__init__(self, parent, id, title)
panel = wx.Panel(self, -1)
sizer = wx.BoxSizer(wx.VERTICAL)
self.filelist = GatherFilesPanel(panel, -1, filenames)
## self.filelist.SetWildcard = 'jpeg, mp4, avi, mov'
sizer.Add(self.filelist, 1, wx.GROW)
self.rnmbtn = wx.Button(panel, -1, 'Rename',
style=wx.ID_OPEN |
wx.BU_EXACTFIT |
wx.BU_LEFT |
wx.BU_RIGHT)
self.Bind(wx.EVT_BUTTON, self.OnRename, self.rnmbtn)
sizer.Add(self.rnmbtn, 0, wx.GROW)
panel.SetSizer(sizer)
panel.Fit()
self.Fit()
def OnRename(self, evt):
filenames = self.filelist.GetFiles()
filenames.reverse()
for index, filename in enumerate(filenames):
status = dropboximport.import_file(filename)
if not status:
self.filelist.RemoveFile(len(filenames) - index - 1)
if len(self.filelist.GetFiles()) > 0:
icon = wx.ICON_ERROR
text = 'Could not rename some files:\n'
text += 'see files remained in the list'
else:
icon = wx.ICON_INFORMATION
text = 'Processing complete.\nNo errors occured.'
wx.MessageDialog(self, text, 'Report', wx.OK | icon).ShowModal()
app = wx.App()
frame = RenamerFrame(None, -1, sys.argv[1:])
frame.Show()
app.MainLoop()