Browse Source

add cx_freeze support

pull/118/head
Alexander Gordeyev 9 years ago
parent
commit
f6aee1463b
5 changed files with 40 additions and 18 deletions
  1. 4
      gooey/gui/image_repository.py
  2. 13
      gooey/gui/lang/i18n.py
  3. 20
      gooey/gui/util/freeze.py
  4. 10
      gooey/gui/util/quoting.py
  5. 11
      gooey/python_bindings/config_generator.py

4
gooey/gui/image_repository.py

@ -1,10 +1,10 @@
import os
from gooey.gui.util.freeze import get_resource_path
__author__ = 'Chris'
base_path = os.path.dirname(__file__)
image_dir = os.path.join(base_path, '../images')
image_dir = get_resource_path('images')
alessandro_rei_checkmark = os.path.join(image_dir, "alessandro_rei_checkmark.png")
computer = os.path.join(image_dir, "computer.png")

13
gooey/gui/lang/i18n.py

@ -11,12 +11,13 @@ import os
import json
from gooey.gui.lang import i18n_config
from gooey.gui.util.freeze import get_resource_path
__all__ = ['translate']
_LANG = i18n_config.LANG
_DEFAULT_DIR = os.path.join(os.path.dirname(__file__), '../../languages')
_DEFAULT_DIR = get_resource_path("languages")
_DICTIONARY = None
@ -41,13 +42,7 @@ def load(filename):
'translation file is in the languages directory, ')
def translate(key):
return _DICTIONARY[key]
return _DICTIONARY.get(key, key)
def _(key):
return _DICTIONARY[key]
if __name__ == '__main__':
pass
return translate(key)

20
gooey/gui/util/freeze.py

@ -0,0 +1,20 @@
import sys
import os
def is_frozen():
return getattr(sys, 'frozen', False)
def get_resource_path(*args):
if is_frozen():
resource_dir = os.path.join(os.path.dirname(sys.executable), 'gooey')
if not os.path.isdir(resource_dir):
raise IOError(("cannot locate Gooey resources. It seems that the program "
"was frozen, but resource files were not copied to "
"directory of the executable file. Please copy "
"`languages` and `images` folders from gooey module "
"directory into `{}{}` directory.".format(resource_dir, os.sep)))
else:
resource_dir = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', '..'))
return os.path.join(resource_dir, *args)

10
gooey/gui/util/quoting.py

@ -1,4 +1,12 @@
import re
import sys
if sys.platform.startswith("win"):
def quote(value):
return '"{}"'.format('{}'.format(value).replace('"', '""'))
else: # POSIX shell
def quote(value):
return "'{}'".format('{}'.format(value).replace("'", "'\\''"))
def maybe_quote(string):

11
gooey/python_bindings/config_generator.py

@ -1,18 +1,17 @@
import os
import sys
import argparse_to_json
from gooey.gui.windows import layouts
from gooey.python_bindings import source_parser
from gooey.python_bindings import argparse_to_json
from gooey.gui.util.quoting import quote
def create_from_parser(parser, source_path, **kwargs):
show_config = kwargs.get('show_config', False)
#If script has been frozen execute it straight
if hasattr(sys, 'frozen'):
run_cmd = source_path
if source_path.endswith(".py"):
run_cmd = '{} {}'.format(quote(sys.executable), quote(source_path))
else:
run_cmd = 'python -u {}'.format(source_path)
run_cmd = quote(source_path)
build_spec = {
'language': kwargs.get('language', 'english'),

Loading…
Cancel
Save