Skip to content

Commit

Permalink
further GUI usability improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
quiris11 committed Feb 7, 2016
1 parent ffc1bac commit ab94c5e
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
import tkFileDialog
import sys
import os
sentinel = object()


class ThreadedTask(threading.Thread):
"""Create threaded task.
"""
def __init__(self, queue, kindlepath, days, is_log,
def __init__(self, outqueue, kindlepath, days, is_log,
is_overwrite_pdoc_thumbs, is_overwrite_amzn_thumbs,
is_overwrite_apnx, skip_apnx, is_azw, is_fix_thumb,
status, run_button):
threading.Thread.__init__(self)
self.queue = queue
self.outqueue = outqueue
self.kindlepath = kindlepath
self.days = days
self.is_log = is_log
Expand Down Expand Up @@ -67,10 +68,9 @@ def run(self):
self.skip_apnx.get(), self.kindlepath.get(),
self.docs, self.is_azw, self.days.get(),
self.is_fix_thumb.get()

)
self.status.set(' Process finished...')
self.run_button['state'] = tk.NORMAL
self.outqueue.put(sentinel)


class StdoutRedirector(object):
"""Redirect output.
Expand Down Expand Up @@ -237,26 +237,33 @@ def askdirectory(self):
a = tkFileDialog.askdirectory(initialdir="/")
self.kindlepath.set(str(a.encode(sys.getfilesystemencoding())))

def process_queue(self):
"""
"""
self.master.after(100, self.process_queue)
return
def update(self, outqueue):
try:
msg = outqueue.get_nowait()
if msg is not sentinel:
root.after(250, self.update, outqueue)
else:
# By not calling root.after here, we allow update to
# truly end
self.status.set(' Process finished...')
self.run_button['state'] = tk.NORMAL
except Queue.Empty:
root.after(250, self.update, outqueue)

def createBtnCallback(self):
"""Create button event.
"""
self.run_button['state'] = tk.DISABLED
self.stext.delete(1.0, tk.END)
self.status.set(' Process started... Please wait...')
self.queue = Queue.Queue()
ThreadedTask(self.queue, self.kindlepath, self.days, self.is_log,
outqueue = Queue.Queue()
ThreadedTask(outqueue, self.kindlepath, self.days, self.is_log,
self.is_overwrite_pdoc_thumbs,
self.is_overwrite_amzn_thumbs,
self.is_overwrite_apnx, self.skip_apnx,
self.is_azw, self.is_fix_thumb,
self.status, self.run_button).start()
self.master.after(100, self.process_queue)
root.after(250, self.update, outqueue)

root = tk.Tk()
app = App(root)
Expand Down

0 comments on commit ab94c5e

Please sign in to comment.