Some improvements to visibility and file input
This commit is contained in:
parent
e31f7b2163
commit
0149bb8ed0
1 changed files with 23 additions and 11 deletions
34
main.py
34
main.py
|
@ -1,4 +1,5 @@
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
|
import tkinter.ttk as ttk
|
||||||
from tkinter import filedialog
|
from tkinter import filedialog
|
||||||
from tk_tooltip import CreateToolTip
|
from tk_tooltip import CreateToolTip
|
||||||
import re
|
import re
|
||||||
|
@ -64,7 +65,7 @@ def get_input_filepath():
|
||||||
global input_filepath
|
global input_filepath
|
||||||
filepath = filedialog.askopenfilename(
|
filepath = filedialog.askopenfilename(
|
||||||
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")],
|
filetypes=[("Text Files", "*.txt"), ("All Files", "*.*")],
|
||||||
# initialdir='/'.join(ent_input.get().split('/')[:-1])
|
initialdir='/'.join(ent_input.get().split('/')[:-1 if '.' in ent_input.get() else len(ent_input.get())])
|
||||||
)
|
)
|
||||||
if not filepath:
|
if not filepath:
|
||||||
return
|
return
|
||||||
|
@ -87,24 +88,24 @@ def get_output_filepath():
|
||||||
def toggle_channel(index):
|
def toggle_channel(index):
|
||||||
def tgl_chan():
|
def tgl_chan():
|
||||||
if chan_toggle[index]:
|
if chan_toggle[index]:
|
||||||
btn_chan_toggle[index].config(relief="raised")
|
btn_chan_toggle[index].config(relief="raised", bg="#ffcccb")
|
||||||
chan_toggle[index] = False
|
chan_toggle[index] = False
|
||||||
if index == 11:
|
if channel_names[index] == "SYSTEM":
|
||||||
frm_btn_sys.grid_remove()
|
frm_btn_sys.grid_remove()
|
||||||
else:
|
else:
|
||||||
btn_chan_toggle[index].config(relief="sunken")
|
btn_chan_toggle[index].config(relief="sunken", bg="#99e599")
|
||||||
chan_toggle[index] = True
|
chan_toggle[index] = True
|
||||||
if index == 11:
|
if channel_names[index] == "SYSTEM":
|
||||||
frm_btn_sys.grid()
|
frm_btn_sys.grid()
|
||||||
return tgl_chan
|
return tgl_chan
|
||||||
|
|
||||||
def toggle_system(index):
|
def toggle_system(index):
|
||||||
def tgl_sys():
|
def tgl_sys():
|
||||||
if sys_toggle[index]:
|
if sys_toggle[index]:
|
||||||
btn_sys_toggle[index].config(relief="raised")
|
btn_sys_toggle[index].config(relief="raised", bg="#ffcccb")
|
||||||
sys_toggle[index] = False
|
sys_toggle[index] = False
|
||||||
else:
|
else:
|
||||||
btn_sys_toggle[index].config(relief="sunken")
|
btn_sys_toggle[index].config(relief="sunken", bg="#99e599")
|
||||||
sys_toggle[index] = True
|
sys_toggle[index] = True
|
||||||
return tgl_sys
|
return tgl_sys
|
||||||
|
|
||||||
|
@ -119,6 +120,8 @@ ent_input = None
|
||||||
ent_output = None
|
ent_output = None
|
||||||
ent_outfile = None
|
ent_outfile = None
|
||||||
frm_btn_sys = None
|
frm_btn_sys = None
|
||||||
|
btn_process = None
|
||||||
|
window = None
|
||||||
|
|
||||||
def create_ui():
|
def create_ui():
|
||||||
global btn_chan_toggle
|
global btn_chan_toggle
|
||||||
|
@ -129,6 +132,9 @@ def create_ui():
|
||||||
global ent_output
|
global ent_output
|
||||||
global ent_outfile
|
global ent_outfile
|
||||||
global frm_btn_sys
|
global frm_btn_sys
|
||||||
|
global window
|
||||||
|
global btn_process
|
||||||
|
|
||||||
window = tk.Tk()
|
window = tk.Tk()
|
||||||
window.title("Ryzom Log Cleaner")
|
window.title("Ryzom Log Cleaner")
|
||||||
|
|
||||||
|
@ -169,7 +175,7 @@ def create_ui():
|
||||||
frm_btn_channel.columnconfigure([0,1,2,3], weight=1)
|
frm_btn_channel.columnconfigure([0,1,2,3], weight=1)
|
||||||
frm_btn_channel.rowconfigure([0,1,2], weight=1)
|
frm_btn_channel.rowconfigure([0,1,2], weight=1)
|
||||||
for i,name in enumerate(channel_names):
|
for i,name in enumerate(channel_names):
|
||||||
btn_chan_toggle.append(tk.Button(frm_btn_channel, text=name, command=toggle_channel(i)))
|
btn_chan_toggle.append(tk.Button(frm_btn_channel, text=name, command=toggle_channel(i), bg="#ffcccb"))
|
||||||
btn_chan_toggle[i].grid(row=int(i/4), column=i%4, sticky='ew')
|
btn_chan_toggle[i].grid(row=int(i/4), column=i%4, sticky='ew')
|
||||||
|
|
||||||
btn_sys_toggle = []
|
btn_sys_toggle = []
|
||||||
|
@ -179,7 +185,7 @@ def create_ui():
|
||||||
frm_btn_sys.columnconfigure([0,1,2,3,4,5,6], weight=1)
|
frm_btn_sys.columnconfigure([0,1,2,3,4,5,6], weight=1)
|
||||||
frm_btn_sys.rowconfigure([0,1,2,3,4], weight=1)
|
frm_btn_sys.rowconfigure([0,1,2,3,4], weight=1)
|
||||||
for i,(name,tooltip) in enumerate(system_info_categories):
|
for i,(name,tooltip) in enumerate(system_info_categories):
|
||||||
btn_sys_toggle.append(tk.Button(frm_btn_sys, text=name, command=toggle_system(i)))
|
btn_sys_toggle.append(tk.Button(frm_btn_sys, text=name, command=toggle_system(i), bg="#ffcccb"))
|
||||||
btn_sys_toggle[i].grid(row=int(i/7), column=i%7, sticky='ew')
|
btn_sys_toggle[i].grid(row=int(i/7), column=i%7, sticky='ew')
|
||||||
ttp_sys = CreateToolTip(btn_sys_toggle[i], tooltip)
|
ttp_sys = CreateToolTip(btn_sys_toggle[i], tooltip)
|
||||||
|
|
||||||
|
@ -215,8 +221,12 @@ def process_file():
|
||||||
if sys_toggle[i+1]:
|
if sys_toggle[i+1]:
|
||||||
chan_pattern += '|\(SYSTEM/' + name + '\)'
|
chan_pattern += '|\(SYSTEM/' + name + '\)'
|
||||||
chan_regex = re.compile(chan_pattern)
|
chan_regex = re.compile(chan_pattern)
|
||||||
with open(input_filepath, 'rb') as in_file, open(output_filepath + '/' + ent_outfile.get(), 'w') as out_file:
|
with open(ent_input.get(), 'r', errors='surrogateescape') as in_file, open(ent_output.get() + '/' + ent_outfile.get(), 'w', errors='surrogateescape') as out_file:
|
||||||
|
orig_lines = 0
|
||||||
|
filtered_lines = 0
|
||||||
|
btn_process["text"] = "Started Processing..."
|
||||||
for line in in_file:
|
for line in in_file:
|
||||||
|
orig_lines += 1
|
||||||
if chan_regex.search(line) == None:
|
if chan_regex.search(line) == None:
|
||||||
continue
|
continue
|
||||||
if not keep_color:
|
if not keep_color:
|
||||||
|
@ -234,7 +244,9 @@ def process_file():
|
||||||
# if char_name[0] == '[' and char_name[2] == ']':
|
# if char_name[0] == '[' and char_name[2] == ']':
|
||||||
# char_name = char_name[3:]
|
# char_name = char_name[3:]
|
||||||
# channel_name = line[21:line.find(')')]
|
# channel_name = line[21:line.find(')')]
|
||||||
out_file.write(line + '\n')
|
out_file.write(line.lstrip())
|
||||||
|
filtered_lines += 1
|
||||||
|
btn_process["text"]="Processing done! (" + str(filtered_lines) + " lines kept out of " + str(orig_lines) + " original lines)"
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue