-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathAttachFolderBox.py
232 lines (183 loc) · 8.81 KB
/
AttachFolderBox.py
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# All works in this code have been curated by ECCC and licensed under the GNU General Public License v3.0.
# Read more: https://www.gnu.org/licenses/gpl-3.0.en.html
import wx
import os
import sys
import wx.lib.scrolledpanel as scrolled
class AttachFolderBox(wx.Panel):
def __init__(self, parent, func, *args, **kwargs):
super(AttachFolderBox, self).__init__(*args, **kwargs)
self.parent = parent
self.func = func
self.manager = None
self.barSize = (610, -1)
self.buttonSize = (30, 24)
self.browseSize = (-1, 24)
self.labelSize = (190, -1)
self.buttonList = []
self.addrList = []
self.labelList = []
self.browseList = []
self.columnList = []
self.pathList = []
self.count = 0
self.InitUI()
def InitUI(self):
self.layoutSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.layoutSizer)
self.tableSizer = wx.BoxSizer(wx.VERTICAL)
self.column = wx.BoxSizer(wx.HORIZONTAL)
self.pathPanel = scrolled.ScrolledPanel(self, style = wx.NO_BORDER)
self.pathSizer = wx.BoxSizer(wx.VERTICAL)
self.pathPanel.SetSizer(self.pathSizer)
self.columnList.append(wx.BoxSizer(wx.HORIZONTAL))
self.buttonList.append(wx.Button(self.pathPanel, label="-", size=self.buttonSize))
self.addrList.append(wx.TextCtrl(self.pathPanel, size=self.barSize))
self.browseList.append(wx.Button(self.pathPanel, label="Browse", size=self.browseSize))
self.labelList.append(wx.TextCtrl(self.pathPanel, size=self.labelSize, style=wx.TE_READONLY))
self.pathList.append("")
self.buttonList[-1].Bind(wx.EVT_BUTTON, self.add_remove)
self.browseList[-1].Bind(wx.EVT_BUTTON, self.Browse)
self.columnList[-1].Add(self.buttonList[-1])
self.columnList[-1].Add(self.addrList[-1])
self.columnList[-1].Add(self.browseList[-1])
self.columnList[-1].Add(self.labelList[-1])
self.tableSizer.Add(self.columnList[-1])
self.addButton = wx.Button(self.pathPanel, label="+", size=self.buttonSize)
self.addButton.Bind(wx.EVT_BUTTON, self.add_remove)
self.column.Add(self.addButton)
self.pathSizer.Add(self.tableSizer)
self.pathSizer.Add(self.column)
self.layoutSizer.Add(self.pathPanel, 1, wx.EXPAND)
self.spit = wx.Panel(self, style = wx.SIMPLE_BORDER, size = (-1, 1))
self.layoutSizer.Add(self.spit, 0, wx.EXPAND)
self.layoutSizer.Add((-1, 4))
self.includePanel = wx.Panel(self, size = (-1, 20))
self.inlcudeRow = wx.BoxSizer(wx.HORIZONTAL)
self.includePanel.SetSizer(self.inlcudeRow)
contentLabel = wx.StaticText(self.includePanel, label = "Content of Logger Folder:")
self.dataCheck = wx.CheckBox(self.includePanel)
self.dataCheck.Bind(wx.EVT_CHECKBOX, self.notEmpty)
dataLabel = wx.StaticText(self.includePanel, label = "Data Files")
self.diagnosticCheck = wx.CheckBox(self.includePanel)
self.diagnosticCheck.Bind(wx.EVT_CHECKBOX, self.notEmpty)
diagnosticLabel = wx.StaticText(self.includePanel, label="Diagnostic Files")
self.programCheck = wx.CheckBox(self.includePanel)
self.programCheck.Bind(wx.EVT_CHECKBOX, self.notEmpty)
programLabel = wx.StaticText(self.includePanel, label="Program Files")
self.inlcudeRow.Add((5, -1))
self.inlcudeRow.Add(contentLabel)
self.inlcudeRow.Add((60,-1))
self.inlcudeRow.Add(self.dataCheck)
self.inlcudeRow.Add(dataLabel)
self.inlcudeRow.Add((80, -1))
self.inlcudeRow.Add(self.diagnosticCheck)
self.inlcudeRow.Add(diagnosticLabel)
self.inlcudeRow.Add((80, -1))
self.inlcudeRow.Add(self.programCheck)
self.inlcudeRow.Add(programLabel)
self.layoutSizer.Add(self.includePanel, 0, wx.EXPAND)
self.pathPanel.SetupScrolling()
self.pathPanel.ShowScrollbars(wx.SHOW_SB_NEVER, wx.SHOW_SB_DEFAULT)
def notEmpty(self, evt):
if len(self.returnPath()) == 0:
evt.GetEventObject().SetValue(False)
evt.Skip()
def add(self):
self.columnList.append(wx.BoxSizer(wx.HORIZONTAL))
self.buttonList.append(wx.Button(self.pathPanel, label="-", size=self.buttonSize))
self.addrList.append(wx.TextCtrl(self.pathPanel, size=self.barSize))
self.browseList.append(wx.Button(self.pathPanel, label="Browse", size=self.browseSize))
self.labelList.append(wx.TextCtrl(self.pathPanel, size=self.labelSize, style=wx.TE_READONLY))
self.pathList.append("")
self.buttonList[-1].Bind(wx.EVT_BUTTON, self.add_remove)
self.browseList[-1].Bind(wx.EVT_BUTTON, self.Browse)
self.columnList[-1].Add(self.buttonList[-1])
self.columnList[-1].Add(self.addrList[-1])
self.columnList[-1].Add(self.browseList[-1])
self.columnList[-1].Add(self.labelList[-1])
self.tableSizer.Add(self.columnList[-1])
self.layoutSizer.Layout()
self.Update()
def add_remove(self, evt):
if evt.GetEventObject().GetLabel() == "+":
self.columnList.append(wx.BoxSizer(wx.HORIZONTAL))
self.buttonList.append(wx.Button(self.pathPanel, label="-", size=self.buttonSize))
self.addrList.append(wx.TextCtrl(self.pathPanel, size=self.barSize))
self.browseList.append(wx.Button(self.pathPanel, label="Browse", size=self.browseSize))
self.labelList.append(wx.TextCtrl(self.pathPanel, size=self.labelSize, style=wx.TE_READONLY))
self.pathList.append("")
self.buttonList[-1].Bind(wx.EVT_BUTTON, self.add_remove)
self.browseList[-1].Bind(wx.EVT_BUTTON, self.Browse)
self.columnList[-1].Add(self.buttonList[-1])
self.columnList[-1].Add(self.addrList[-1])
self.columnList[-1].Add(self.browseList[-1])
self.columnList[-1].Add(self.labelList[-1])
self.tableSizer.Add(self.columnList[-1])
self.updateLabels()
self.layoutSizer.Layout()
self.Update()
elif evt.GetEventObject().GetLabel() == "-":
id = self.buttonList.index(evt.GetEventObject())
self.buttonList[id].Destroy()
self.addrList[id].Destroy()
self.browseList[id].Destroy()
self.labelList[id].Destroy()
del self.columnList[id]
del self.buttonList[id]
del self.addrList[id]
del self.browseList[id]
del self.labelList[id]
del self.pathList[id]
if len(self.returnPath()) == 0:
self.dataCheck.SetValue(False)
self.diagnosticCheck.SetValue(False)
self.programCheck.SetValue(False)
self.updateLabels()
self.layoutSizer.Layout()
self.Update()
self.parent.Layout()
# Update the displayed file labels for the window
def updateLabels(self):
# Set the count back to zero
self.count = 0
# Get the station number
stnNum = self.parent.parent.genInfo.stnNumCmbo.GetValue()
if stnNum.isspace():
stnNum = ''
# Get the date
dateVal = self.parent.parent.genInfo.datePicker.GetValue().Format(self.parent.fm)
# Iterate over every entered path
# And increment the count and set the label
for id in range(len(self.addrList)):
if self.addrList[id].GetValue() != "":
self.count += 1
self.labelList[id].ChangeValue(stnNum + "_" + dateVal + "_LG" + str(self.count))
def Browse(self, evt):
id = self.browseList.index(evt.GetEventObject())
folderOpenDialog = wx.DirDialog(self, "Select the File", self.parent.getRootPath(),
style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
if folderOpenDialog.ShowModal() == wx.ID_CANCEL:
folderOpenDialog.Destroy()
return
# Set the root path of the parent to be the new root path
self.parent.setRootPath(os.path.dirname(folderOpenDialog.GetPath()))
self.pathList[id] = folderOpenDialog.GetPath()
self.addrList[id].ChangeValue(self.pathList[id])
folderOpenDialog.Destroy()
self.updateLabels()
# return none empty path
def returnPath(self):
pathList = []
for x in range(len(self.addrList)):
if self.addrList[x].GetValue() != "":
pathList.append(self.addrList[x].GetValue())
return pathList
def main():
app = wx.App()
frame = wx.Frame(None, size=(850, 600))
AttachFolderBox(wx.Frame, "DEBUG", frame)
frame.Show()
app.MainLoop()
if __name__ == "__main__":
main()