mirror of https://github.com/chriskiehl/Gooey.git
22 changed files with 232 additions and 147 deletions
Unified View
Diff Options
-
5src/TODO.txt
-
1src/app/dialogs/advanced_config.py
-
BINsrc/app/dialogs/advanced_config.pyc
-
4src/app/dialogs/argparse_test_data.py
-
11src/app/dialogs/base_window.py
-
11src/app/dialogs/client_runner.py
-
2src/app/dialogs/components.py
-
32src/app/dialogs/controller.py
-
4src/app/dialogs/footer.py
-
BINsrc/app/dialogs/footer.pyc
-
165src/app/dialogs/model.py
-
4src/app/dialogs/window.py
-
BINsrc/app/images/image_store.pyc
-
0src/languages/__init__.py
-
1src/languages/english.json
-
7src/mockapplication/mockapp.py
-
BINsrc/model/codegen.pyc
-
4src/model/example_argparse_souce.py
-
70src/model/gooey.py
-
8src/model/integration_test.py
-
50src/model/source_parser.py
-
0src/parser/example.py
@ -0,0 +1,5 @@ |
|||||
|
|
||||
|
|
||||
|
1. Internationalization |
||||
|
|
||||
|
|
@ -0,0 +1,11 @@ |
|||||
|
''' |
||||
|
Created on Jan 24, 2014 |
||||
|
|
||||
|
@author: Chris |
||||
|
''' |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
pass |
@ -1,80 +1,85 @@ |
|||||
''' |
|
||||
Created on Jan 23, 2014 |
|
||||
|
|
||||
@author: Chris |
|
||||
''' |
|
||||
|
|
||||
import types |
|
||||
from app.dialogs.action_sorter import ActionSorter |
|
||||
|
|
||||
class ArgumentError(Exception): |
|
||||
pass |
|
||||
|
|
||||
class Model(object): |
|
||||
_instance = None |
|
||||
|
|
||||
def __init__(self, parser=None): |
|
||||
print parser |
|
||||
self._parser = parser |
|
||||
self.description = parser.description |
|
||||
|
|
||||
|
|
||||
self.action_groups = ActionSorter(self._parser._actions) |
|
||||
|
|
||||
# monkey patch |
|
||||
self._parser.error = types.MethodType( |
|
||||
self.ErrorAsString, |
|
||||
self._parser) |
|
||||
|
|
||||
Model._instance = self |
|
||||
|
|
||||
def HasPositionals(self): |
|
||||
if self.action_groups._positionals: |
|
||||
return True |
|
||||
return False |
|
||||
|
|
||||
def IsValidArgString(self, arg_string): |
|
||||
if isinstance(self._Parse(arg_string), str): |
|
||||
return False |
|
||||
return True |
|
||||
|
|
||||
def _Parse(self, arg_string): |
|
||||
try: |
|
||||
self._parser.parse_args(arg_string.split()) |
|
||||
return True |
|
||||
except ArgumentError as e: |
|
||||
return str(e) |
|
||||
|
|
||||
def GetErrorMsg(self, arg_string): |
|
||||
return self._FormatMsg(self._Parse(arg_string)) |
|
||||
|
|
||||
def _FormatMsg(self, msg): |
|
||||
output = list(msg) |
|
||||
if ':' in output: |
|
||||
output[output.index(':')] = ':\n ' |
|
||||
return ''.join(output) |
|
||||
|
|
||||
@staticmethod |
|
||||
def ErrorAsString(self, msg): |
|
||||
''' |
|
||||
Monkey patch for parser.error |
|
||||
Returns the error string rather than |
|
||||
printing and silently exiting. |
|
||||
''' |
|
||||
raise ArgumentError(msg) |
|
||||
|
|
||||
@classmethod |
|
||||
def GetInstance(cls): |
|
||||
return cls._instance |
|
||||
|
|
||||
|
|
||||
|
|
||||
if __name__ == '__main__': |
|
||||
pass |
|
||||
|
|
||||
|
|
||||
# print m2 |
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
''' |
||||
|
Created on Jan 23, 2014 |
||||
|
|
||||
|
@author: Chris |
||||
|
''' |
||||
|
|
||||
|
import sys |
||||
|
import types |
||||
|
from app.dialogs.action_sorter import ActionSorter |
||||
|
|
||||
|
class ArgumentError(Exception): |
||||
|
pass |
||||
|
|
||||
|
class Model(object): |
||||
|
_instance = None |
||||
|
|
||||
|
def __init__(self, parser=None): |
||||
|
self._parser = parser |
||||
|
self.description = parser.description |
||||
|
|
||||
|
self.action_groups = ActionSorter(self._parser._actions) |
||||
|
|
||||
|
# monkey patch |
||||
|
print self._parser.error |
||||
|
self._parser.error = types.MethodType( |
||||
|
self.ErrorAsString, |
||||
|
self._parser) |
||||
|
print self._parser.error |
||||
|
|
||||
|
Model._instance = self |
||||
|
|
||||
|
def HasPositionals(self): |
||||
|
if self.action_groups._positionals: |
||||
|
return True |
||||
|
return False |
||||
|
|
||||
|
def IsValidArgString(self, arg_string): |
||||
|
if isinstance(self._Parse(arg_string), str): |
||||
|
return False |
||||
|
return True |
||||
|
|
||||
|
def _Parse(self, arg_string): |
||||
|
try: |
||||
|
print self._parser.error |
||||
|
self._parser.parse_args(arg_string.split()) |
||||
|
return True |
||||
|
except ArgumentError as e: |
||||
|
return str(e) |
||||
|
|
||||
|
def GetErrorMsg(self, arg_string): |
||||
|
return self._FormatMsg(self._Parse(arg_string)) |
||||
|
|
||||
|
def _FormatMsg(self, msg): |
||||
|
output = list(msg) |
||||
|
if ':' in output: |
||||
|
output[output.index(':')] = ':\n ' |
||||
|
return ''.join(output) |
||||
|
|
||||
|
def AddToArgv(self, arg_string): |
||||
|
sys.argv.append(arg_string.split()) |
||||
|
|
||||
|
@staticmethod |
||||
|
def ErrorAsString(self, msg): |
||||
|
''' |
||||
|
Monkey patch for parser.error |
||||
|
Returns the error string rather than |
||||
|
printing and silently exiting. |
||||
|
''' |
||||
|
raise ArgumentError(msg) |
||||
|
|
||||
|
@classmethod |
||||
|
def GetInstance(cls): |
||||
|
return cls._instance |
||||
|
|
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
pass |
||||
|
|
||||
|
|
||||
|
# print m2 |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
@ -0,0 +1 @@ |
|||||
|
{ |
@ -0,0 +1,70 @@ |
|||||
|
''' |
||||
|
Created on Jan 24, 2014 |
||||
|
|
||||
|
@author: Chris |
||||
|
''' |
||||
|
|
||||
|
import os |
||||
|
import sys |
||||
|
import argparse |
||||
|
import source_parser |
||||
|
from app.dialogs import window |
||||
|
|
||||
|
|
||||
|
def Gooey(f=None, advanced=True, basic=False): |
||||
|
''' |
||||
|
Decorator for client code's main function. |
||||
|
Entry point for the GUI generator. |
||||
|
|
||||
|
Scans the client code for argparse data. |
||||
|
If found, extracts it and build the proper |
||||
|
configuration page (basic or advanced). |
||||
|
|
||||
|
Launched |
||||
|
|
||||
|
''' |
||||
|
|
||||
|
# Handles if the passed in object is instance |
||||
|
# of ArgumentParser. If so, it's being called as |
||||
|
# a function, rather than a decorator |
||||
|
# if isinstance(f, argparse.ArgumentParser): |
||||
|
# progname = sys.argv[0] |
||||
|
# |
||||
|
# build_doc_from_parser_obj( |
||||
|
# file_name=progname, |
||||
|
# parser_obj=f, |
||||
|
# format=format, |
||||
|
# noob=noob, |
||||
|
# success_msg=success_msg |
||||
|
# ) |
||||
|
# return |
||||
|
|
||||
|
# --------------------------------- # |
||||
|
# Below code is all decorator stuff # |
||||
|
# --------------------------------- # |
||||
|
def build(f): |
||||
|
def inner(): |
||||
|
module_path = get_caller_path() |
||||
|
prog_name = get_program_name(module_path) |
||||
|
parser = source_parser.pull_parser_from(module_path) |
||||
|
window.WithAdvancedOptions(parser, f) |
||||
|
inner.__name__ = f.__name__ |
||||
|
return inner |
||||
|
|
||||
|
if callable(f): |
||||
|
return build(f) |
||||
|
return build |
||||
|
|
||||
|
def get_program_name(path): |
||||
|
return '{}'.format(os.path.split(path)[-1]) |
||||
|
|
||||
|
|
||||
|
def get_caller_path(): |
||||
|
# utility func for decorator |
||||
|
# gets the name of the calling script |
||||
|
tmp_sys = __import__('sys') |
||||
|
return tmp_sys.argv[0] |
||||
|
|
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
pass |
@ -0,0 +1,8 @@ |
|||||
|
''' |
||||
|
Created on Jan 24, 2014 |
||||
|
|
||||
|
@author: Chris |
||||
|
''' |
||||
|
|
||||
|
if __name__ == '__main__': |
||||
|
pass |
Write
Preview
Loading…
Cancel
Save