-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenamerViews.py
More file actions
299 lines (247 loc) · 10 KB
/
RenamerViews.py
File metadata and controls
299 lines (247 loc) · 10 KB
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
import logging
import tkinter as tk
from tkinter import ttk
from tkinter import scrolledtext
from tkinter import filedialog
# Mod 1. Made filepath non editable & proper class var
# https://github.com/chezhj/sbRenamer/issues/1
#
class SettingView(ttk.Frame):
def __init__(self, parent):
parent_width = parent.winfo_width()
# parent_height = parent.winfo_height()
super().__init__(
parent,
padding=10,
width=parent_width - 22,
height=160,
relief="ridge",
borderwidth=3,
)
self.grid_propagate(0)
# FlightPlanPath widgets
self.lblFlightPlanPath = tk.Label(self, text="Flight Plan directory:", pady="5")
self.lblFlightPlanPath.grid(row="0", column="0", sticky="W")
self.strDirectory = tk.StringVar()
# Mod 1
self.entFlightPlanPath = tk.Entry(
self, textvariable=self.strDirectory, width=62
)
self.entFlightPlanPath.config(state="readonly")
self.entFlightPlanPath.grid(
row="0", column="1", columnspan=3, sticky="W", padx=5
)
# Browse for dir button
self.btnBrowser = ttk.Button(self, text="browse", command=self.getDirectory)
self.btnBrowser.grid(row=0, column=4)
# Renamer settings widgets
self.lblFilenameFormat = tk.Label(self, text="Filename Format:", pady="5")
self.lblFilenameFormat.grid(row="1", column="0", sticky="W")
self.strFileFormat = tk.StringVar()
self.ddFilenameFormat = ttk.Combobox(self, textvariable=self.strFileFormat)
self.ddFilenameFormat.config(state="readonly")
self.ddFilenameFormat.grid(row="1", column="1", sticky="W", padx=5)
self.ddFilenameFormat.bind("<<ComboboxSelected>>", self.comboSelected)
self.lblAutoStart = tk.Label(self, text="Auto start:")
self.lblAutoStart.grid(row="1", column="2", sticky="W")
self.boolAutoStart = tk.BooleanVar()
self.cbAutoStart = tk.Checkbutton(
self,
onvalue=True,
offvalue=False,
variable=self.boolAutoStart,
command=self.update_model,
)
self.cbAutoStart.grid(row=1, column=3, sticky="W")
self.lblAutoHide = tk.Label(self, text="Auto hide:")
self.lblAutoHide.grid(row="1", column="3")
self.boolAutoHide = tk.BooleanVar()
self.cbAutoHide = tk.Checkbutton(
self,
onvalue=True,
offvalue=False,
variable=self.boolAutoHide,
command=self.update_model,
)
self.cbAutoHide.grid(row=1, column=3, sticky="E")
# Delete setting
delete_row = 2
self.lbl_save_xml = tk.Label(self, text="Save original XML:")
self.lbl_save_xml.grid(row=delete_row, column="0", sticky="W")
self.bool_save_xml = tk.BooleanVar()
self.cb_save_xml = tk.Checkbutton(
self,
onvalue=True,
offvalue=False,
variable=self.bool_save_xml,
command=self.update_model,
)
self.cb_save_xml.grid(row=delete_row, column=1, sticky="W")
self.lbl_delete_files = tk.Label(self, text="Delete files older then (days):")
self.lbl_delete_files.grid(row=delete_row, column="2", columnspan=2, sticky="W")
self.nof_days = tk.StringVar()
self.nof_days.trace_add("write", self.update_model)
# Register validation function so only numbers can be set
validation = self.register(self.only_numbers)
self.ent_nof_days = tk.Entry(
self,
validate="key",
validatecommand=(validation, "%S"),
textvariable=self.nof_days,
width=5,
)
self.ent_nof_days.grid(row=delete_row, column=3, sticky="E", padx=8)
# fms widget Mod 13
# Renamer settings widgets
self.lbl_fms_format = tk.Label(self, text="Flightplan Rename:", pady="5")
self.lbl_fms_format.grid(row="3", column="0", sticky="W")
self.str_fms_format = tk.StringVar()
self.dd_fms_format = ttk.Combobox(self, textvariable=self.str_fms_format)
self.dd_fms_format.config(state="readonly")
self.dd_fms_format.grid(row="3", column="1", sticky="W", padx=5)
self.dd_fms_format.bind("<<ComboboxSelected>>", self.comboSelected)
# Log settings widgets
log_row = 4
self.lblLogToFile = tk.Label(self, text="Log to file:")
self.lblLogToFile.grid(row=log_row, column="0", sticky="W")
self.boolLogToFile = tk.BooleanVar()
self.cbLog2File = tk.Checkbutton(
self,
text="Active",
onvalue=1,
offvalue=0,
variable=self.boolLogToFile,
command=self.update_model,
)
self.cbLog2File.grid(row=log_row, column=1, sticky="W")
self.lblLogLevel = tk.Label(self, text="Log level:", pady="5")
self.lblLogLevel.grid(row=log_row, column="2", sticky="W")
self.strLogLevel = tk.StringVar()
self.lstLoglevels = []
self.ddLogLevel = ttk.Combobox(self, textvariable=self.strLogLevel, width=22)
self.ddLogLevel.config(state="readonly")
self.ddLogLevel.grid(row=log_row, column="3", sticky="W", padx=5)
self.ddLogLevel.bind("<<ComboboxSelected>>", self.comboSelected)
# Save button
self.btnSave = ttk.Button(
self, text="Save", state="disabled", command=self.save
)
self.btnSave.grid(row=1, column=4)
self._controller = None
def only_numbers(self, char):
if char:
return char.isdigit()
return True
def set_widgets(
self,
flighplan_path,
file_format,
file_formats_list,
auto_start: bool,
auto_hide: bool,
fms_format,
fms_formats_list,
):
"""should be called to updated the settings widgets"""
self.strDirectory.set(flighplan_path)
self.strFileFormat.set(file_format)
self.ddFilenameFormat["values"] = file_formats_list
self.boolAutoStart.set(auto_start)
self.boolAutoHide.set(auto_hide)
self.str_fms_format.set(fms_format)
self.dd_fms_format["values"] = fms_formats_list
def set_delete_widgets(self, save_xml, nof_days):
"""update delete widgets"""
self.bool_save_xml.set(save_xml)
self.nof_days.set(nof_days)
def setLogWidgets(self, logLevel, logLevelsList, logToFile):
self.lstLoglevels = logLevelsList
self.ddLogLevel["values"] = self.lstLoglevels
self.strLogLevel.set(logLevel.upper())
self.update_loglevelwidget(logToFile)
self.ddLogLevel.current(self.lstLoglevels.index(self.strLogLevel.get()))
self.boolLogToFile.set(logToFile)
def update_loglevelwidget(self, logToFile):
if logToFile:
self.ddLogLevel.config(state="readonly")
else:
self.ddLogLevel.config(state="disabled")
def getDirectory(self):
# get a directory path by user
selected = filedialog.askdirectory(
initialdir=self.strDirectory.get(), title="Dialog box"
)
if selected != "":
self.strDirectory.set(selected)
self.update_model()
logging.info("New directory is set to: %s", self.strDirectory.get())
def set_controller(self, controller):
self._controller = controller
def update_model(self, *args):
"""Interface to call the controller update method"""
if self._controller:
self._controller.update_model(
self.strDirectory.get(),
self.strFileFormat.get(),
self.strLogLevel.get(),
self.boolLogToFile.get(),
self.boolAutoStart.get(),
self.boolAutoHide.get(),
self.bool_save_xml.get(),
self.nof_days.get(),
self.str_fms_format.get(),
)
self.update_loglevelwidget(self.boolLogToFile.get())
def comboSelected(self, *args):
self.update_model()
def save(self):
if self._controller:
self._controller.save()
def updateSaveBtn(self, dirty):
if dirty:
self.btnSave["state"] = tk.NORMAL
else:
self.btnSave["state"] = tk.DISABLED
class RenamerView(ttk.Frame):
def __init__(self, parent):
parent_width = parent.winfo_width()
parent_height = parent.winfo_height()
super().__init__(
parent,
padding=10,
width=parent_width - 22,
height=parent_height - 180,
relief="ridge",
borderwidth=3,
)
self.__parent = parent
self.grid_propagate(0)
self.grid(column=0, row=1, sticky="NW")
self.strState = tk.StringVar()
self.strState.set("Start")
self.btnStart = ttk.Button(
self, textvariable=self.strState, command=self.startStop
)
self.btnStart.grid(row=1, column=3, pady=3, sticky="E")
self.logWidget = scrolledtext.ScrolledText(self, font=("Courier", 8), height=26)
self.logWidget.config(state="disabled")
self.logWidget.grid(row=2, column=0, columnspan=4, sticky="NE")
self._controller = None
def startStop(self):
if self._controller:
newState = self._controller.switch_monitoring(self.strState.get())
self.strState.set(newState)
def set_controller(self, controller):
self._controller = controller
def addLine(self, value):
# Enable the widget to allow new text to be inserted
self.logWidget.config(state="normal")
# Append log message to the widget
self.logWidget.insert(tk.END, value)
# Scroll down to the bottom of the ScrolledText box to ensure the latest log message
# is visible
self.logWidget.see("end")
# Re-disable the widget to prevent users from entering text
self.logWidget.config(state="disabled")
def minimize(self):
self.__parent.iconify()