Browse Source

Plane edits

pull/1/head
unknown 11 years ago
parent
commit
0ed061a44e
22 changed files with 232 additions and 147 deletions
  1. 5
      src/TODO.txt
  2. 1
      src/app/dialogs/advanced_config.py
  3. BIN
      src/app/dialogs/advanced_config.pyc
  4. 4
      src/app/dialogs/argparse_test_data.py
  5. 11
      src/app/dialogs/base_window.py
  6. 11
      src/app/dialogs/client_runner.py
  7. 2
      src/app/dialogs/components.py
  8. 32
      src/app/dialogs/controller.py
  9. 4
      src/app/dialogs/footer.py
  10. BIN
      src/app/dialogs/footer.pyc
  11. 165
      src/app/dialogs/model.py
  12. 4
      src/app/dialogs/window.py
  13. BIN
      src/app/images/image_store.pyc
  14. 0
      src/languages/__init__.py
  15. 1
      src/languages/english.json
  16. 7
      src/mockapplication/mockapp.py
  17. BIN
      src/model/codegen.pyc
  18. 4
      src/model/example_argparse_souce.py
  19. 70
      src/model/gooey.py
  20. 8
      src/model/integration_test.py
  21. 50
      src/model/source_parser.py
  22. 0
      src/parser/example.py

5
src/TODO.txt

@ -0,0 +1,5 @@
1. Internationalization

1
src/app/dialogs/advanced_config.py

@ -91,7 +91,6 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader):
return line
def OnResize(self, evt):
print 'SIZEEEE:', evt.m_size
for component in self.components:
component.Update(evt.m_size)
evt.Skip()

BIN
src/app/dialogs/advanced_config.pyc

4
src/app/dialogs/argparse_test_data.py

@ -3,10 +3,9 @@ Created on Jan 16, 2014
@author: Chris
'''
import sys
from argparse import ArgumentParser
parser = ArgumentParser(description='Example Argparse Program')
parser.add_argument("filename", help="Name of the file you want to read") # positional
parser.add_argument("outfile", help="Name of the file where you'll save the output") # positional
@ -19,5 +18,4 @@ parser.add_argument('-c', '--constoption', action="store_const", const="myconsta
parser.add_argument('-t', '--truify', action="store_true", help='Ensure the store_true actions are sorted') # Flag
parser.add_argument('-f', '--falsificle', action="store_false", help='Ensure the store_false actions are sorted') # Flag
print parser.parse_args('fname oname -T yes'.split())

11
src/app/dialogs/base_window.py

@ -31,6 +31,7 @@ class BaseWindow(wx.Frame):
)
self._model = Model.GetInstance()
self._payload = None
self._controller = None
self._init_properties()
@ -39,6 +40,8 @@ class BaseWindow(wx.Frame):
self._init_controller()
self.registerControllers()
# self.Bind(wx.EVT_CLOSE, self.OnXClose)
def _init_properties(self):
self.SetMinSize((400,300))
self.icon = wx.Icon(image_store.icon, wx.BITMAP_TYPE_ICO)
@ -84,8 +87,12 @@ class BaseWindow(wx.Frame):
for panel in self.panels:
panel.RegisterController(self._controller)
def AttachPayload(self, payload):
self._payload = payload
# def OnXClose(self, event):
# print 'adsfasdfadsf'
if __name__ == '__main__':
pass

11
src/app/dialogs/client_runner.py

@ -0,0 +1,11 @@
'''
Created on Jan 24, 2014
@author: Chris
'''
if __name__ == '__main__':
pass

2
src/app/dialogs/components.py

@ -276,9 +276,7 @@ class Flag(AbstractComponent):
width, height = size
content_area = int((width/3)*.70)
print 'wiget size', help_msg.Size[0]
wiggle_room = range(int(content_area - content_area * .05), int(content_area + content_area * .05))
print '(',int(content_area - content_area * .05), int(content_area + content_area * .05),')'
if help_msg.Size[0] not in wiggle_room:
self._msg.SetLabel(self._msg.GetLabelText().replace('\n',' '))
self._msg.Wrap(content_area)

32
src/app/dialogs/controller.py

@ -5,9 +5,12 @@ Created on Dec 22, 2013
'''
import wx
import msg_dialog
import sys
from app.dialogs.model import Model
YES = 5103
NO = 5104
class Controller(object):
'''
Main controller for the gui.
@ -35,17 +38,32 @@ class Controller(object):
self._model = Model.GetInstance()
def OnConfigCancel(self, event):
print 'OnCongigCancel pressed!'
msg = "Are you sure you want to exit?"
dlg = wx.MessageDialog(None, msg, "Close Program?", wx.YES_NO)
result = dlg.ShowModal()
print result
if result == YES:
dlg.Destroy()
self._base.Destroy()
sys.exit()
def OnConfigNext(self, event):
cmd_line_args = self._body.GetOptions()
if not self._model.IsValidArgString(cmd_line_args):
error_msg = self._model.GetErrorMsg(cmd_line_args)
print error_msg
self.ShowArgumentErrorDlg(error_msg)
else:
print 'All args passed.'
print cmd_line_args
return
self._model.AddToArgv(cmd_line_args)
self._base.NextPage()
self.RunClientCode()
def RunClientCode(self):
pass
def AddPayload(self, payload):
pass
def OnMainCancel(self, event):

4
src/app/dialogs/footer.py

@ -65,9 +65,11 @@ class ConfigFooter(AbstractFooter):
def OnConfigCancel(self, event):
self._controller.OnConfigCancel(event)
event.Skip()
def OnConfigNext(self, event):
self._controller.OnConfigNext(event)
event.Skip()
class MainFooter(AbstractFooter):
@ -87,9 +89,11 @@ class MainFooter(AbstractFooter):
def OnMainCancel(self, event):
self._controller.OnMainCancel(event)
# event.Skip()
def OnMainNext(self, event):
self._controller.OnMainNext(event)
event.Skip()

BIN
src/app/dialogs/footer.pyc

165
src/app/dialogs/model.py

@ -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

4
src/app/dialogs/window.py

@ -27,17 +27,17 @@ import wx
import base_window
import advanced_config
from app.dialogs import argparse_test_data
from app.dialogs.action_sorter import ActionSorter
from app.dialogs.model import Model
def WithNoOptions(): pass
def WithBasicOptions(): pass
def WithAdvancedOptions(parser):
def WithAdvancedOptions(parser, payload):
app = wx.App(False)
model = Model(parser)
frame = base_window.BaseWindow(advanced_config.AdvancedConfigPanel)
frame.AttachPayload(payload)
frame.Show(True) # Show the frame.
app.MainLoop()

BIN
src/app/images/image_store.pyc

src/parser/asdfasdf.py → src/languages/__init__.py

1
src/languages/english.json

@ -0,0 +1 @@
{

7
src/mockapplication/mockapp.py

@ -4,14 +4,17 @@ Created on Dec 21, 2013
@author: Chris
'''
import sys
import hashlib
from time import time as _time
from time import sleep as _sleep
from argparse import ArgumentParser
import hashlib
from model.gooey import Gooey
@Gooey
def main():
my_cool_parser = ArgumentParser(description="Mock application to test @Gui's functionality")
my_cool_parser.add_argument('filename', help="bla bla bla")
my_cool_parser.add_argument('-c', '--countdown', default=10, type=int, help='sets the time to count down from')
my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer")
my_cool_parser.add_argument("-w", "--whatevs", default="No, NOT whatevs", help="...")
@ -28,5 +31,5 @@ def main():
print 'Finished running the program. Byeeeeesss!'
if __name__ == '__main__':
sys.argv.append('-sc 5')
# sys.argv.extend('-c 5'.split())
main()

BIN
src/model/codegen.pyc

4
src/model/example_argparse_souce.py

@ -82,8 +82,8 @@ USAGE
parser.add_argument('-T', '--tester', choices=['yes','no'])
parser.add_argument(dest="paths", help="paths to folder(s) with source file(s) [default: %(default)s]", metavar="path", nargs='+')
for i in parser._actions:
print i
# for i in parser._actions:
# print i
# Process arguments
args = parser.parse_args()

70
src/model/gooey.py

@ -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

8
src/model/integration_test.py

@ -0,0 +1,8 @@
'''
Created on Jan 24, 2014
@author: Chris
'''
if __name__ == '__main__':
pass

50
src/model/source_parser.py

@ -19,7 +19,6 @@ import argparse
import cStringIO
from itertools import chain
from functools import partial
from numpy.lib.utils import _split_line
from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter
from app.dialogs.action_sorter import ActionSorter
@ -217,52 +216,11 @@ def find_argparse_location(locations):
def convert_to_python(ast_source):
return map(codegen.to_source, ast_source)
def generate_doc(f=None, format='html', noob=1, success_msg=1):
'''
Decorator for client code's main function.
It gets the name of the calling script, loads it
into parse_pyfile(), and generates the documentation,
before finally calling the main() function to resume
execution as normal.
'''
# 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):
filename = sys.argv[0]
build_doc_from_parser_obj(
file_name=filename,
parser_obj=f,
format=format,
noob=noob,
success_msg=success_msg
)
return
# --------------------------------- #
# Below code is all decorator stuff #
# --------------------------------- #
def get_caller_path():
# utility func for decorator
# gets the name of the calling script
tmp_sys = __import__('sys')
return tmp_sys.argv[0]
def generate_docs(f):
def inner():
module_path = get_caller_path()
path = os.path.join(*os.path.split(module_path)[:-1])
filename = '{}'.format(os.path.split(module_path)[-1])
parse_pyfile(filename, format=format, noob=noob, success_msg=success_msg)
inner.__name__ = f.__name__
return inner
if callable(f):
return generate_docs(f)
return generate_docs
def pull_parser_from(modulepath):
ast_source = parse_source_file(modulepath)
python_code = convert_to_python(ast_source)
return ParserFromSource(python_code)
if __name__ == '__main__':

0
src/parser/example.py

Loading…
Cancel
Save