Browse Source

closes #157 - fix unicode decode error in subparser

pull/160/head
chriskiehl 9 years ago
parent
commit
e9a6afe4db
4 changed files with 27 additions and 13 deletions
  1. 25
      gooey/gui/model.py
  2. 8
      gooey/gui/processor.py
  3. 5
      gooey/gui/util/quoting.py
  4. 2
      gooey/gui/widgets/components.py

25
gooey/gui/model.py

@ -11,7 +11,7 @@ ArgumentGroup = namedtuple('ArgumentGroup', 'name command required_args optional
class MyWidget(object):
# TODO: Undumbify damn
# TODO: Undumbify _value/value access
def __init__(self, type, title, help, default, nargs, commands, choices):
self.type = type
self.title = title
@ -35,7 +35,7 @@ class MyWidget(object):
if self.type == 'MultiFileChooser':
value = ' '.join(quote(x) for x in self._value.split(os.pathsep) if x)
if self.commands and value:
return '{} {}'.format(self.commands[0], value)
return u'{} {}'.format(self.commands[0], value)
return value or None
# if self.type == 'TextField':
# if self.commands and self._value:
@ -44,7 +44,7 @@ class MyWidget(object):
# return quote(self._value) if self._value else ''
if self.type == 'CommandField':
if self.commands and self._value:
return '{} {}'.format(self.commands[0], self._value)
return u'{} {}'.format(self.commands[0], self._value)
else:
return self._value or None
@ -65,14 +65,23 @@ class MyWidget(object):
if self._value == 'Select Option':
return None
elif self.commands and self._value:
return '{} {}'.format(self.commands[0], quote(self._value))
return u'{} {}'.format(self.commands[0], quote(self._value))
else:
return quote(self._value) if self._value else ''
else:
if self.commands and self._value:
return '{0} {1}'.format(self.commands[0], quote(self._value))
if not self.nargs:
v = quote(self._value)
else:
v = self._value
return u'{0} {1}'.format(self.commands[0], v)
else:
return quote(self._value) if self._value else None
if not self._value:
return None
elif not self.nargs:
return quote(self._value)
else:
return self._value
@value.setter
def value(self, val):
@ -206,8 +215,8 @@ class MyModel(object):
position_args.insert(0, "--")
cmd_string = ' '.join(filter(None, chain(required_args, optional_args, position_args)))
if self.layout_type == 'column':
cmd_string = '{} {}'.format(self.argument_groups[self.active_group].command, cmd_string)
return '{} --ignore-gooey {}'.format(self.build_spec['target'], cmd_string)
cmd_string = u'{} {}'.format(self.argument_groups[self.active_group].command, cmd_string)
return u'{} --ignore-gooey {}'.format(self.build_spec['target'], cmd_string)
def group_arguments(self, widget_list):
is_required = lambda widget: widget['required']

8
gooey/gui/processor.py

@ -5,6 +5,8 @@ import subprocess
from functools import partial
from multiprocessing.dummy import Pool
import sys
from gooey.gui.pubsub import pub
from gooey.gui.util.casting import safe_float
from gooey.gui.util.functional import unit, bind
@ -36,8 +38,10 @@ class ProcessController(object):
def run(self, command):
env = os.environ.copy()
env["GOOEY"] = "1"
self._process = subprocess.Popen(command, bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True, env=env)
self._process = subprocess.Popen(
command.encode(sys.getfilesystemencoding()),
bufsize=1, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=True, env=env)
Pool(1).apply_async(self._forward_stdout, (self._process,))
def _forward_stdout(self, process):

5
gooey/gui/util/quoting.py

@ -3,7 +3,8 @@ import sys
if sys.platform.startswith("win"):
def quote(value):
return '"{}"'.format('{}'.format(value).replace('"', '""'))
return u'"{}"'.format(u'{}'.format(value).replace(u'"', u'""'))
else: # POSIX shell
def quote(value):
return "'{}'".format('{}'.format(value).replace("'", "'\\''"))
return u"'{}'".format(u'{}'.format(value).replace(u"'", u"'\\''"))

2
gooey/gui/widgets/components.py

@ -104,7 +104,7 @@ class BaseGuiComponent(object):
def set_value(self, val):
if val:
self.widget_pack.widget.SetValue(str(val))
self.widget_pack.widget.SetValue(unicode(val))
def __repr__(self):
return self.__class__.__name__

Loading…
Cancel
Save