wmllint GUI: fixed a bug on Python 2.7.7 that froze the application on Windows

This commit is contained in:
Elvish_Hunter 2014-06-20 22:49:09 +02:00
parent 7e84df7f6c
commit ebb4a80f46

View file

@ -71,22 +71,16 @@ def run_tool(tool,queue,command):
output=subprocess.check_output(' '.join(wrapped_line),stderr=subprocess.STDOUT,startupinfo=si)
queue.put_nowait(output)
except subprocess.CalledProcessError as error:
# post the precise message
showerror("Error","""There was an error while executing {0}.
Error code: {1}""".format(tool,error.returncode))
queue.put_nowait(error.output)
# post the precise message and the remaining output as a tuple
queue.put_nowait((tool,error.returncode,error.output))
else: # STARTUPINFO is not available, nor needed, outside of Windows
queue.put_nowait(' '.join(command)+"\n")
try:
output=subprocess.check_output(command,stderr=subprocess.STDOUT)
queue.put_nowait(output)
except subprocess.CalledProcessError as error:
# post the precise message
showerror("Error","""There was an error while executing {0}.
Error code: {1}""".format(tool,error.returncode))
queue.put_nowait(error.output)
# post the precise message and the remaining output as a tuple
queue.put_nowait((tool,error.returncode,error.output))
def is_wesnoth_tools_path(path):
"""Checks if the supplied path may be a wesnoth/data/tools directory"""
@ -982,13 +976,25 @@ wmlindent will be run on the Wesnoth core directory""")
dialog=Popup(self.parent,"wmlindent",wmlindent_thread)
def update_text(self):
"""Checks periodically if the queue is empty, and pushes its content in the Text widget if it isn't"""
"""Checks periodically if the queue is empty.
If it contains a string, pushes it into the Text widget.
If it contains an error in form of a tuple, displays a message and pushes the remaining output in the Text widget"""
if not self.queue.empty():
text_to_push=self.queue.get_nowait()
self.text.configure(state=NORMAL)
self.text.insert(END,text_to_push)
self.text.configure(state=DISABLED)
self.text.after(100,self.update_text)
queue_item=self.queue.get_nowait()
# I tried posting directly the error in the queue, but for some reason
# isinstance(queue_item,subprocess.CalledProcessError) is ignored
if isinstance(queue_item,tuple):
showerror("Error","""There was an error while executing {0}.
Error code: {1}""".format(queue_item[0],queue_item[1]))
self.text.configure(state=NORMAL)
self.text.insert(END,queue_item[2])
self.text.configure(state=DISABLED)
elif isinstance(queue_item,str):
self.text.configure(state=NORMAL)
self.text.insert(END,queue_item)
self.text.configure(state=DISABLED)
self.after(100,self.update_text)
def on_save(self):
fn=asksaveasfilename(defaultextension=".txt",filetypes=[("Text file","*.txt")],initialdir=".")