Skip to content

Commit

Permalink
Add status bar to main UI
Browse files Browse the repository at this point in the history
searching and converting status added
fix minor bugs in UI
  • Loading branch information
xenups committed Nov 25, 2019
1 parent eee5c4b commit 0c9663c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
7 changes: 6 additions & 1 deletion SRTWalker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ def __init__(self, cb, path):
self.path = path

def run(self):
status = "Searching"
files_list = []
path = " "
logging.info("Thread %s: starting", 'started')
for root, dirs, files in os.walk(self.path):
for file in files:
if file.endswith(".srt"):
files_list.append(os.path.join(root, file))
self.callback(os.path.join(root, file))
path = os.path.join(root, file)
self.callback(path, status)
status = "Finished"
self.callback(path, status)
19 changes: 11 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def __init__(self, *args, **kwargs):
container = tk.Frame(self)
self.center()
self.list_file_address = []
self.statusbar = tk.Label(self, text="Ready", bd=1, relief=tk.SUNKEN, anchor=tk.W)
self.statusbar.pack(side=tk.BOTTOM, fill="x")
container.pack(side="top", fill="both", expand=True)

self.store_button = Button(self, text='Select Folder', command=self.open_dialogue, bd=2, width=10,
compound=tk.TOP, activebackground='lightgrey').pack(side="right")
compound=tk.TOP, activebackground='lightgrey').pack(side="right",padx=5, pady=5)
self.convert_button = Button(self, text='Convert', command=self.convert_action, bd=2, width=10, compound=tk.TOP,
activebackground='lightgrey').pack(side="right")

self.path_label = Label(self, compound=tk.TOP, text=" path ")
self.path_label.pack(side="bottom")
# self.path_label.grid()

self.last_search_label = Label(self, compound=tk.CENTER, text=" search ")
self.last_search_label.pack(side="top")
self.last_search_label = Label(self, compound=tk.CENTER, text=" ... ")
self.last_search_label.pack(side="left")

self.listbox = Listbox(container, width=100, height=10)
vertical_scrollbar = Scrollbar(container, orient="vertical", command=self.listbox.yview)
Expand All @@ -54,20 +54,23 @@ def __init__(self, *args, **kwargs):
self.listbox.pack(side="top", fill="both", expand=True)
self.listbox.insert(END, "found subtitles: ")

def add_subtitle_to_listbox(self, names):
def add_subtitle_to_listbox(self, names, search_status):
self.listbox.insert(END, names)
self.last_search_label.config(text=names)
self.statusbar.config(text=search_status)

self.list_file_address.append(names)

def notify_subtitle_converted(self, names):
def notify_subtitle_converted(self, names, convert_status):
self.listbox.insert(END, names)
self.last_search_label.config(text=names)
self.statusbar.config(text=convert_status)

def open_dialogue(self):
# try:
self.list_file_address = []
folder_name = filedialog.askdirectory()
self.path_label.configure(text="Path : "+folder_name)
self.statusbar.configure(text="Path : " + folder_name)
# self.path_label["text"] = folder_name
if folder_name:
self.listbox.delete(0, tk.END)
Expand Down
9 changes: 7 additions & 2 deletions subtitleConvertor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, cb, list_file_address):
threading.Thread.__init__(self)
self.files_path = list_file_address
self.callback = cb
self.status = " "

def get_file_encoding(self, path):
print(path)
Expand All @@ -31,18 +32,22 @@ def get_file_encoding(self, path):
return e

def convert_format(self, path, source_encoding):
self.callback('Trying to convert from ' + source_encoding)
status = "Converting"
self.callback('Trying to convert from ' + source_encoding,self.status)
with codecs.open(path, 'r', encoding=source_encoding, errors='ignore') as file:
lines = file.read()
# print(lines)
# write output file
converted_name = os.path.splitext(path)[0] + ' converted.srt'
with codecs.open(converted_name, 'w', encoding='utf-8') as file:
file.write(lines)
self.callback(path + ' converted')
self.callback(path + ' converted', status)

def run(self):
for path in self.files_path:
source_format = self.get_file_encoding(path)
if source_format != "utf-8":
self.convert_format(path, source_format)
self.status = "Finished"
self.callback(' ', self.status)

0 comments on commit 0c9663c

Please sign in to comment.