Browse Source

Changes Project structure. Added doubleBuffering on panels to reduce flicker

pull/61/head
chriskiehl 10 years ago
parent
commit
a39924948c
21 changed files with 44 additions and 144 deletions
  1. 2
      gooey/__init__.py
  2. 8
      gooey/dev_utils/ast_inspector.py
  3. 3
      gooey/gui/client_app.py
  4. 1
      gooey/gui/lang/__init__.py
  5. 23
      gooey/gui/widgets/components2.py
  6. 1
      gooey/gui/widgets/widget_pack.py
  7. 4
      gooey/gui/windows/advanced_config.py
  8. 6
      gooey/gui/windows/base_window.py
  9. 2
      gooey/gui/windows/header.py
  10. 6
      gooey/mockapplications/example_argparse_souce_in_try.py
  11. 8
      gooey/mockapplications/mockapp.py
  12. 114
      gooey/monkey_parser.py
  13. 1
      gooey/python_bindings/__init__.py
  14. 0
      gooey/python_bindings/argparse_to_json.py
  15. 0
      gooey/python_bindings/code_prep.py
  16. 0
      gooey/python_bindings/codegen.py
  17. 4
      gooey/python_bindings/gooey_decorator.py
  18. 0
      gooey/python_bindings/modules.py
  19. 0
      gooey/python_bindings/parser_exceptions.py
  20. 3
      gooey/python_bindings/source_parser.py
  21. 2
      gooey/tests/modules_unittest.py

2
gooey/__init__.py

@ -1 +1 @@
from gooey_decorator import Gooey
from gooey.python_bindings.gooey_decorator import Gooey

8
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__

3
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):

1
gooey/gui/lang/__init__.py

@ -0,0 +1 @@
__author__ = 'Chris'

23
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):

1
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):

4
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:

6
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)

2
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

6
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())
sys.exit(main())

8
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()

114
gooey/monkey_parser.py

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

1
gooey/python_bindings/__init__.py

@ -0,0 +1 @@
__author__ = 'Chris'

gooey/argparse_to_json.py → gooey/python_bindings/argparse_to_json.py

gooey/code_prep.py → gooey/python_bindings/code_prep.py

gooey/codegen.py → gooey/python_bindings/codegen.py

gooey/gooey_decorator.py → 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,

gooey/modules.py → gooey/python_bindings/modules.py

gooey/parser_exceptions.py → gooey/python_bindings/parser_exceptions.py

gooey/source_parser.py → 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):

2
gooey/tests/modules_unittest.py

@ -1,4 +1,4 @@
from gooey import modules
from gooey.python_bindings import modules
__author__ = 'Chris'

Loading…
Cancel
Save