Permalink
Browse files

Added some more kludgy fixes for encoding issues. Should be a bit mor…

…e stable, but likely imperfect.
  • Loading branch information...
1 parent 495f077 commit 66ee2c5fd157e43c4050ed2ab2636b708ec7e1a1 @Vultaire committed Jun 15, 2012
Showing with 20 additions and 5 deletions.
  1. +1 −1 r21buddy/logger.py
  2. +6 −1 r21buddy/r21buddy.py
  3. +13 −3 r21buddy/r21buddy_gui.py
View
@@ -34,7 +34,7 @@ def read(self):
output.append(self.q.get(False) + "\n")
except Queue.Empty:
break
- return "".join(output)
+ return u"".join(output)
logger = StdoutStderrLogger()
View
@@ -126,7 +126,12 @@ def run(target_dir, input_paths, length_patch=True, verbose=False, ext_logger=No
if length_patch:
patch_length(target_dir, verbose=verbose)
except:
- logger.error(traceback.format_exc())
+ msg = traceback.format_exc()
+ try:
+ enc_msg = msg.decode()
+ except UnicodeDecodeError:
+ enc_msg = repr(msg).decode()
+ logger.error(enc_msg)
def main():
options = parse_args()
View
@@ -10,6 +10,14 @@
POLL_INTERVAL = 100 # milliseconds
+def askdirectory(*args, **kwargs):
+ """Workaround for Tkinter-related encoding oddities."""
+ result = tkFileDialog.askdirectory(*args, **kwargs)
+ if isinstance(result, unicode):
+ result = eval(repr(result)[1:])
+ return result
+
+
class CompositeControl(object):
def configure(self, **kwargs):
@@ -42,7 +50,7 @@ def on_browse(self):
initialdir = self.str_var.get()
if len(initialdir) > 0:
dialog_args["initialdir"] = initialdir
- path = tkFileDialog.askdirectory(**dialog_args)
+ path = askdirectory(**dialog_args)
path = path.replace("/", os.sep)
if len(path) > 0:
self.str_var.set(path)
@@ -175,7 +183,7 @@ def on_inputdir_add(self):
dialog_kwargs = {"mustexist": True}
if self.last_dir is not None:
dialog_kwargs["initialdir"] = self.last_dir
- path = tkFileDialog.askdirectory(**dialog_kwargs)
+ path = askdirectory(**dialog_kwargs)
path = path.replace("/", os.sep)
if len(path) == 0:
return
@@ -222,12 +230,14 @@ def on_delete(self):
self.input_dirs.delete(i)
def on_run(self):
- target_dir = self.target_dir.get()
+ target_dir = self.target_dir.get().decode(sys.getfilesystemencoding())
if len(target_dir) == 0:
tkMessageBox.showinfo(title="No target directory",
message="No target directory selected.")
return
input_paths = self.input_dirs.get(0, Tkinter.END)
+ input_paths = [ip.decode(sys.getfilesystemencoding())
+ for ip in input_paths]
no_length_patch = bool(self.skip_ogg_patch.get())
# Disable GUI

0 comments on commit 66ee2c5

Please sign in to comment.