diff --git a/gooey/__init__.py b/gooey/__init__.py index fff2c09..5815894 100644 --- a/gooey/__init__.py +++ b/gooey/__init__.py @@ -1 +1 @@ -from gooey_decorator import Gooey +from gooey.python_bindings.gooey_decorator import Gooey diff --git a/gooey/dev_utils/ast_inspector.py b/gooey/dev_utils/ast_inspector.py index e39596c..5fa7598 100644 --- a/gooey/dev_utils/ast_inspector.py +++ b/gooey/dev_utils/ast_inspector.py @@ -1,6 +1,5 @@ -import itertools -from gooey import source_parser, code_prep -import tempfile +from gooey.python_bindings import code_prep, source_parser + __author__ = 'Chris' """ @@ -8,7 +7,8 @@ Pretty Printing util for inspecting the various ast objects """ import ast -from _ast import Assign, Call +from _ast import Assign + def pretty_print(node, indent): d = node.__dict__ diff --git a/gooey/gui/client_app.py b/gooey/gui/client_app.py index 447060f..f4d2122 100644 --- a/gooey/gui/client_app.py +++ b/gooey/gui/client_app.py @@ -6,7 +6,6 @@ Created on Jan 23, 2014 import sys -from gooey.monkey_parser import ArgumentError from gooey.gui.action_sorter import ActionSorter @@ -32,7 +31,7 @@ class ClientApp(object): print self._parser.error self._parser.parse_args(arg_string.split()) return True - except ArgumentError as e: + except Exception as e: return str(e) def GetErrorMsg(self, arg_string): diff --git a/gooey/gui/lang/__init__.py b/gooey/gui/lang/__init__.py new file mode 100644 index 0000000..6bca6f6 --- /dev/null +++ b/gooey/gui/lang/__init__.py @@ -0,0 +1 @@ +__author__ = 'Chris' diff --git a/gooey/gui/widgets/components2.py b/gooey/gui/widgets/components2.py index 3682db6..f47b3ca 100644 --- a/gooey/gui/widgets/components2.py +++ b/gooey/gui/widgets/components2.py @@ -1,3 +1,4 @@ +import time from gooey.gui.widgets import widget_pack __author__ = 'Chris' @@ -20,6 +21,11 @@ class BaseGuiComponent(object): # Internal WidgetPack self.widget_pack = widget_pack + # used to throttle resizing (to avoid widget jiggle) + # TODO: figure out anti-jiggle technology + # self.last_update = time.time() + # self.event_stack = [] + def build(self, parent): return self.do_layout(parent) @@ -72,30 +78,33 @@ class BaseGuiComponent(object): def onResize(self, evt): # handle internal widgets + self.panel.Freeze() self._onResize(evt) # propagate event to child widgets self.widget_pack.onResize(evt) evt.Skip() + self.panel.Thaw() def _onResize(self, evt): if not self.help_msg: return self.panel.Size = evt.GetSize() - # print 'Component Panel Size:', self.panel.Size container_width, _ = self.panel.Size - # if 'filename' in self.data['display_name']: - # print 'Container Width:', container_width, '-', self.data['display_name'] text_width, _ = self.help_msg.Size - - # print 'container width:', container_width - # print 'text width', text_width + # if self.widget_pack.getValue() and '-c' in self.widget_pack.getValue(): + # print 'text width:', text_width + # print 'cont width:', container_width + # print if text_width != container_width: self.help_msg.SetLabel(self.help_msg.GetLabelText().replace('\n', ' ')) self.help_msg.Wrap(container_width) evt.Skip() def GetValue(self): - return self.widget_pack.getValue() + if self.widget_pack.getValue() and self.data['commands']: + return '{} {}'.format(self.data['commands'][0], self.widget_pack.getValue()) + else: + return self.widget_pack.getValue() class CheckBox(BaseGuiComponent): diff --git a/gooey/gui/widgets/widget_pack.py b/gooey/gui/widgets/widget_pack.py index 2eabb9c..c4eb9cf 100644 --- a/gooey/gui/widgets/widget_pack.py +++ b/gooey/gui/widgets/widget_pack.py @@ -104,6 +104,7 @@ class TextInputPayload(WidgetPack): def build(self, parent, data): self.widget = wx.TextCtrl(parent) self.widget.SetMinSize((0, -1)) + self.widget.SetDoubleBuffered(True) return self.widget def getValue(self): diff --git a/gooey/gui/windows/advanced_config.py b/gooey/gui/windows/advanced_config.py index 4c5a2f2..4d3e472 100644 --- a/gooey/gui/windows/advanced_config.py +++ b/gooey/gui/windows/advanced_config.py @@ -24,6 +24,8 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): ScrolledPanel.__init__(self, parent, **kwargs) self.SetupScrolling(scroll_x=False, scrollToTop=False) + self.SetDoubleBuffered(True) + self._action_groups = build_spec self._positionals = build_spec.get('required', None) self.components = component_builder.ComponentBuilder(build_spec) @@ -91,10 +93,12 @@ class AdvancedConfigPanel(ScrolledPanel, OptionReader): parent_sizer.AddSpacer(20) def OnResize(self, evt): + self.Freeze() for component in self.components: component.onResize(evt) self.SetupScrolling(scroll_x=False, scrollToTop=False) evt.Skip() + self.Thaw() def RegisterController(self, controller): if self._controller is None: diff --git a/gooey/gui/windows/base_window.py b/gooey/gui/windows/base_window.py index e3c0ee3..359f2d1 100644 --- a/gooey/gui/windows/base_window.py +++ b/gooey/gui/windows/base_window.py @@ -5,6 +5,8 @@ Created on Jan 19, 2014 import os import sys +import time +from collections import deque import wx @@ -107,10 +109,8 @@ class BaseWindow(wx.Frame): self._controller.ManualStart() def onResize(self, evt): - self.Freeze() - # print self.Size evt.Skip() - self.Thaw() + def PublishConsoleMsg(self, text): self.runtime_display.cmd_textbox.AppendText(text) diff --git a/gooey/gui/windows/header.py b/gooey/gui/windows/header.py index 998d6c9..5ef4849 100644 --- a/gooey/gui/windows/header.py +++ b/gooey/gui/windows/header.py @@ -19,7 +19,7 @@ class FrameHeader(wx.Panel): def __init__(self, heading, subheading, **kwargs): wx.Panel.__init__(self, **kwargs) - + self.SetDoubleBuffered(True) self._controller = None self._header = None diff --git a/gooey/mockapplications/example_argparse_souce_in_try.py b/gooey/mockapplications/example_argparse_souce_in_try.py index 3757982..7bc6e6b 100644 --- a/gooey/mockapplications/example_argparse_souce_in_try.py +++ b/gooey/mockapplications/example_argparse_souce_in_try.py @@ -19,11 +19,11 @@ It defines classes_and_methods import sys import os - from argparse import ArgumentParser from argparse import RawDescriptionHelpFormatter -from gooey.gooey_decorator import Gooey +from gooey.python_bindings.gooey_decorator import Gooey + __all__ = [] __version__ = 0.1 @@ -165,4 +165,4 @@ if __name__ == "__main__": stats.print_stats() statsfile.close() sys.exit(0) - sys.exit(main()) \ No newline at end of file + sys.exit(main()) diff --git a/gooey/mockapplications/mockapp.py b/gooey/mockapplications/mockapp.py index d008245..5373f88 100644 --- a/gooey/mockapplications/mockapp.py +++ b/gooey/mockapplications/mockapp.py @@ -23,13 +23,13 @@ def main(): my_cool_parser.add_argument("-s", "--showtime", action="store_true", help="display the countdown timer") my_cool_parser.add_argument("-d", "--delay", action="store_true", help="Delay execution for a bit") my_cool_parser.add_argument('-v', '--verbose', action='count') - # my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!") + my_cool_parser.add_argument("-o", "--obfuscate", action="store_true", help="obfuscate the countdown timer!") my_cool_parser.add_argument('-r', '--recursive', choices=['yes', 'no'], help='Recurse into subfolders') # my_cool_parser.add_argument("-w", "--writelog", default="No, NOT whatevs", help="write log to some file or something") # my_cool_parser.add_argument("-e", "--expandAll", action="store_true", help="expand all processes") - verbosity = my_cool_parser.add_mutually_exclusive_group() - verbosity.add_argument('-t', '--verbozze', dest='verbose', action="store_true", help="Show more details") - verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error") + # verbosity = my_cool_parser.add_mutually_exclusive_group() + # verbosity.add_argument('-t', '--verbozze', dest='verbose', action="store_true", help="Show more details") + # verbosity.add_argument('-q', '--quiet', dest='quiet', action="store_true", help="Only output on error") print 'inside of main(), my_cool_parser =', my_cool_parser args = my_cool_parser.parse_args() diff --git a/gooey/monkey_parser.py b/gooey/monkey_parser.py deleted file mode 100644 index 8b43499..0000000 --- a/gooey/monkey_parser.py +++ /dev/null @@ -1,114 +0,0 @@ -''' -Created on Feb 8, 2014 - -@author: Chris -''' - -import types - -from parser_exceptions import ArgumentError -from argparse import ArgumentParser -from argparse import RawDescriptionHelpFormatter -import code_prep - - -class MonkeyParser(object): - ''' - Builds a parser instance from the code - extracted from the client module. - - The instance is stored as a private variable in the - class and all methods are delagted to it so that the - user of the class can treat it just as a normal argparse - instance. - ''' - - def __init__(self, source_code): - self._parser_instance = self._build_argparser_from_client_source(source_code) - # Monkey patch parser's `error` method so that it raises an error - # rather than silently exiting - self._parser_instance.error = types.MethodType( - self._ErrorAsString, - self._parser_instance - ) - - def _build_argparser_from_client_source(self, source_code): - ''' - runs the client code by evaling each line. - - Example input Code: - parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter) - parser.add_argument("-r", "--recursive", dest="recurse", action="store_true", help="recurse into subfolders [default: %(default)s]") - parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %(default)s]") - - Method extracts the instance name (e.g. parser) from the first line, - and instantiates it in a local variable by evaling the rest of the lines. - Each subsequent line updates the local variable in turn. - ''' - imports = filter(lambda x: 'gooey' not in x, code_prep.take_imports(source_code)) - arg_code = code_prep.drop_imports(source_code) - updated_source_code = code_prep.update_parser_varname('clients_parser', arg_code) - - for _import in imports: - exec(_import) - - first_line = updated_source_code.pop(0) - clients_parser, assignment = code_prep.split_line(first_line) - clients_parser = eval(assignment) - - for line in updated_source_code: - eval(line) - return clients_parser - - def _format_source_with_new_varname(self, new_variable_name, source): - ''' - 'injects' the client code with a known variable name so that it - can be `eval`d and assigned to a variable in the local code. - - For example, if the client code was: - parser = ArgumentParser(descrip...) - parser.add_argument("-r", "--re...) - parser.add_argument("-v", "--ve...) - - The variable "parser" would be overwritten with a custom name. e.g. - my_parser = ArgumentParser(descrip...) - my_parser.add_argument("-r", "--re...) - ''' - source_code = source[:] - - first_line = source_code[0] - client_parser_variable, statement = self._split_line(first_line) - - client_parser_variable = client_parser_variable.strip() - - for index, line in enumerate(source_code): - source_code[index] = line.replace(client_parser_variable, new_variable_name) - source_code.append('{0}.parse_args()'.format(new_variable_name)) - return source_code - - def _split_line(self, line): - # Splits line at the first = sign, - # joins everything after the first = - # to account for additional = signs in - # parameters - components = line.split('=') - var = components.pop(0) - return var, '='.join(components) - - def __getattr__(self, attr): - ''' - Auto-delegates everything to the ArgumentParser instance''' - return getattr(self._parser_instance, attr) - - @staticmethod - def _ErrorAsString(self, msg): - ''' - Monkey patch for parser.error - Raises an error rather than - printing and silently exiting. - ''' - raise ArgumentError(msg) - - -if __name__ == '__main__': - pass \ No newline at end of file diff --git a/gooey/python_bindings/__init__.py b/gooey/python_bindings/__init__.py new file mode 100644 index 0000000..6bca6f6 --- /dev/null +++ b/gooey/python_bindings/__init__.py @@ -0,0 +1 @@ +__author__ = 'Chris' diff --git a/gooey/argparse_to_json.py b/gooey/python_bindings/argparse_to_json.py similarity index 100% rename from gooey/argparse_to_json.py rename to gooey/python_bindings/argparse_to_json.py diff --git a/gooey/code_prep.py b/gooey/python_bindings/code_prep.py similarity index 100% rename from gooey/code_prep.py rename to gooey/python_bindings/code_prep.py diff --git a/gooey/codegen.py b/gooey/python_bindings/codegen.py similarity index 100% rename from gooey/codegen.py rename to gooey/python_bindings/codegen.py diff --git a/gooey/gooey_decorator.py b/gooey/python_bindings/gooey_decorator.py similarity index 95% rename from gooey/gooey_decorator.py rename to gooey/python_bindings/gooey_decorator.py index 770536e..3359994 100644 --- a/gooey/gooey_decorator.py +++ b/gooey/python_bindings/gooey_decorator.py @@ -46,8 +46,8 @@ from functools import partial import wx -from gooey import argparse_to_json -import i18n +from gooey.python_bindings import argparse_to_json +from gooey import i18n import source_parser def Gooey(f=None, advanced=True, diff --git a/gooey/modules.py b/gooey/python_bindings/modules.py similarity index 100% rename from gooey/modules.py rename to gooey/python_bindings/modules.py diff --git a/gooey/parser_exceptions.py b/gooey/python_bindings/parser_exceptions.py similarity index 100% rename from gooey/parser_exceptions.py rename to gooey/python_bindings/parser_exceptions.py diff --git a/gooey/source_parser.py b/gooey/python_bindings/source_parser.py similarity index 95% rename from gooey/source_parser.py rename to gooey/python_bindings/source_parser.py index bdc58c6..ece7787 100644 --- a/gooey/source_parser.py +++ b/gooey/python_bindings/source_parser.py @@ -13,8 +13,7 @@ import ast import _ast from itertools import * -import codegen -from gooey import modules +from gooey.python_bindings import codegen, modules def parse_source_file(file_name): diff --git a/gooey/tests/modules_unittest.py b/gooey/tests/modules_unittest.py index 2b88c8f..9341bbe 100644 --- a/gooey/tests/modules_unittest.py +++ b/gooey/tests/modules_unittest.py @@ -1,4 +1,4 @@ -from gooey import modules +from gooey.python_bindings import modules __author__ = 'Chris'