Skip to content

Commit

Permalink
add cx_freeze support
Browse files Browse the repository at this point in the history
  • Loading branch information
Shura1oplot committed Oct 23, 2015
1 parent 837f871 commit f6aee14
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
4 changes: 2 additions & 2 deletions gooey/gui/image_repository.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
13 changes: 4 additions & 9 deletions gooey/gui/lang/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
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

Expand All @@ -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 changes: 20 additions & 0 deletions gooey/gui/util/freeze.py
Original file line number Diff line number Diff line change
@@ -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 changes: 9 additions & 1 deletion gooey/gui/util/quoting.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
11 changes: 5 additions & 6 deletions gooey/python_bindings/config_generator.py
Original file line number Diff line number Diff line change
@@ -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'),
Expand Down

0 comments on commit f6aee14

Please # to comment.