* Trying to bring in line a lot more with some of the other Python Projects
authorepage <eopage@byu.net>
Sat, 14 Feb 2009 21:52:10 +0000 (21:52 +0000)
committerepage <eopage@byu.net>
Sat, 14 Feb 2009 21:52:10 +0000 (21:52 +0000)
* Some profiling leading to some hopeful optimizations

git-svn-id: file:///svnroot/ejpi/trunk@16 df6cc7de-23d0-4ae0-bb86-c17aa67b2a9d

Makefile
src/libraries/gtkpie.py
src/libraries/recipes/gtk_utils.py
src/libraries/recipes/test_utils.py
support/builddeb.py
support/pylint.rc

index c74571f..0f22b6b 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,36 +1,41 @@
 PROJECT_NAME=ejpi
 SOURCE_PATH=src
 SOURCE=$(shell find $(SOURCE_PATH) -iname *.py)
+PROGRAM=$(SOURCE_PATH)/$(PROJECT_NAME).py
 DATA_TYPES=*.ini *.map *.glade *.png
 DATA=$(foreach type, $(DATA_TYPES), $(shell find $(SOURCE_PATH) -iname $(type)))
 OBJ=$(SOURCE:.py=.pyc)
-TAG_FILE=~/.ctags/$(PROJECT_NAME).tags
 BUILD_PATH=./build/
 BUILD_SOURCE=$(foreach file, $(SOURCE), $(BUILD_PATH)/$(subst /,-,$(file)))
+TAG_FILE=~/.ctags/$(PROJECT_NAME).tags
 TODO_FILE=./TODO
 
 DEBUGGER=winpdb
-UNIT_TEST=nosetests -w $(TEST_PATH)
-STYLE_TEST=../../Python/tools/pep8.py --ignore=W191
+UNIT_TEST=nosetests --with-doctest -w $(TEST_PATH)
+STYLE_TEST=../../Python/tools/pep8.py --ignore=W191,E501
 LINT_RC=./support/pylint.rc
 LINT=pylint --rcfile=$(LINT_RC)
-COVERAGE_TEST=figleaf
-PROFILER=pyprofiler
-CTAGS=ctags-exuberant
 TODO_FINDER=support/todo.py
+PROFILE_GEN=python -m cProfile -o .profile
+PROFILE_VIEW=python -m pstats .profile
+CTAGS=ctags-exuberant
 
-.PHONY: all run debug test lint tags todo package clean distclean
+.PHONY: all run profile debug test lint tags todo package clean distclean
 
 all: test package
 
 run: $(SOURCE)
        $(SOURCE_PATH)/ejpi_glade.py
 
+profile: $(SOURCE)
+       $(PROFILE_GEN) $(PROGRAM)
+       $(PROFILE_VIEW)
+
 debug: $(SOURCE)
-       $(DEBUGGER) $(SOURCE_PATH)/ejpi_glade.py
+       $(DEBUGGER) $(PROGRAM)
 
 test: $(SOURCE)
-       $(SOURCE_PATH)/ejpi_glade.py -t
+       $(UNIT_TEST)
 
 package:
        rm -Rf $(BUILD_PATH)
@@ -41,7 +46,7 @@ package:
        cp support/$(PROJECT_NAME).desktop $(BUILD_PATH)
        cp support/builddeb.py $(BUILD_PATH)
 
-lint:
+lint: $(SOURCE)
        $(foreach file, $(SOURCE), $(LINT) $(file) ; )
 
 tags: $(TAG_FILE) 
@@ -56,6 +61,10 @@ distclean:
        rm -Rf $(OBJ)
        rm -Rf $(BUILD_PATH)
        rm -Rf $(TAG_FILE)
+       find $(SOURCE_PATH) -name "*.*~" | xargs rm -f
+       find $(SOURCE_PATH) -name "*.swp" | xargs rm -f
+       find $(SOURCE_PATH) -name "*.bak" | xargs rm -f
+       find $(SOURCE_PATH) -name ".*.swp" | xargs rm -f
 
 $(TAG_FILE): $(SOURCE)
        mkdir -p $(dir $(TAG_FILE))
index 672c383..a383628 100755 (executable)
@@ -648,13 +648,14 @@ class PiePopup(gtk.DrawingArea):
                self.__clickPosition = 0, 0
                self.__popupTimeDelay = None
 
-               self.__popupWindow = gtk.Window(type = gtk.WINDOW_POPUP)
-               self.__popupWindow.set_title("")
-
                self.__pie = None
                self.__pie = PieMenu(self.sliceStyle)
-               self.__popupWindow.add(self.__pie)
                self.__pie.connect("button_release_event", self._on_button_release)
+               self.__pie.show()
+
+               self.__popupWindow = gtk.Window(type = gtk.WINDOW_POPUP)
+               self.__popupWindow.set_title("")
+               self.__popupWindow.add(self.__pie)
 
                for direction in PieSlice.SLICE_DIRECTIONS:
                        self.add_slice(NullPieSlice(), direction)
@@ -760,7 +761,7 @@ class PiePopup(gtk.DrawingArea):
 
        def _on_motion_notify(self, widget, event):
                self.__update_state(event.get_coords())
-               if self.__pie is None:
+               if not self.__popped:
                        return
 
                mousePosition = event.get_root_coords()
@@ -817,13 +818,15 @@ class PiePopup(gtk.DrawingArea):
                self.__pie._on_button_press(self.__pie, pieClick)
                self.__pie.grab_focus()
 
-               self.__popupWindow.show_all()
+               self.__popupWindow.show()
 
        def __unpop(self):
                assert self.__popped
                self.__popped = False
+
                piePosition = self.__popupWindow.get_position()
                self.grab_focus()
+
                self.__popupWindow.hide()
 
 
index 7f83aec..01f86db 100644 (file)
@@ -3,9 +3,9 @@
 
 from __future__ import with_statement
 
+import threading
 import contextlib
 import functools
-import math
 
 import gobject
 import gtk
@@ -27,7 +27,8 @@ def make_idler(func):
                if not a:
                        a.append(func(*args, **kwds))
                try:
-                       a[0].next()
+                       shouldBeNone = a[0].next()
+                       assert shouldBeNone is None, "The idle only task yield a value, %r" % shouldBeNone
                        return True
                except StopIteration:
                        del a[:]
@@ -40,8 +41,10 @@ def make_idler(func):
 def gtk_critical_section():
        #The API changed and I hope these are the right calls
        gtk.gdk.threads_enter()
-       yield
-       gtk.gdk.threads_leave()
+       try:
+               yield
+       finally:
+               gtk.gdk.threads_leave()
 
 
 if __name__ == "__main__":
index 349eded..d238bfa 100644 (file)
@@ -82,11 +82,12 @@ def CheckReferences(func):
        return wrapper
 
 
-class expected(object):
+@contextlib.contextmanager
+def expected(exception):
        """
-       >>> with expected(ZeroDivisionError):
+       >>> with expected2(ZeroDivisionError):
        ...     1 / 0
-       >>> with expected(AssertionError("expected ZeroDivisionError to have been thrown")):
+       >>> with expected2(AssertionError("expected ZeroDivisionError to have been thrown")):
        ...     with expected(ZeroDivisionError):
        ...             1 / 2
        Traceback (most recent call last):
@@ -97,33 +98,33 @@ class expected(object):
                File "/media/data/Personal/Development/bzr/Recollection-trunk/src/libraries/recipes/context.py", line 139, in __exit__
                        assert t is not None, ("expected {0:%s} to have been thrown" % (self._t.__name__))
        AssertionError: expected {0:ZeroDivisionError} to have been thrown
-       >>> with expected(Exception("foo")):
+       >>> with expected2(Exception("foo")):
        ...     raise Exception("foo")
-       >>> with expected(Exception("bar")):
+       >>> with expected2(Exception("bar")):
        ...     with expected(Exception("foo")): # this won't catch it
        ...             raise Exception("bar")
        ...     assert False, "should not see me"
-       >>> with expected(Exception("can specify")):
+       >>> with expected2(Exception("can specify")):
        ...     raise Exception("can specify prefixes")
-       >>> with expected(Exception("Base class fun")):
-       ...     raise IndexError("Base class fun")
+       >>> with expected2(Exception("Base class fun")):
+       True
+       >>> True
+       False
        """
-
-       def __init__(self, e):
-               if isinstance(e, Exception):
-                       self._t, self._v = type(e), str(e)
-               elif isinstance(e, type):
-                       self._t, self._v = e, ""
-               else:
-                       raise Exception("usage: with expected(Exception): ... or "
-                                                       "with expected(Exception(\"text\")): ...")
-
-       def __enter__(self):
-               try:
-                       pass
-               except:
-                       pass # this is a Python 3000 way of saying sys.exc_clear()
-
-       def __exit__(self, t, v, tb):
-               assert t is not None, ("expected {0:%s} to have been thrown" % (self._t.__name__))
-               return self._t in inspect.getmro(t) and str(v).startswith(self._v)
+       if isinstance(exception, Exception):
+               excType, excValue = type(exception), str(exception)
+       elif isinstance(e, type):
+               excType, excValue = e, ""
+
+       try:
+               yield
+       except Exception, e:
+               if not (excType in inspect.getmro(type(e)) and str(e).startswith(excValue)):
+                       raise
+       else:
+               raise AssertionError("expected {0:%s} to have been thrown" % excType.__name__)
+
+
+if __name__ == "__main__":
+       import doctest
+       doctest.testmod()
\ No newline at end of file
index c4fe9b0..f6afdc9 100755 (executable)
@@ -7,9 +7,12 @@ __appname__ = "ejpi"
 __description__ = "RPN Calculator"
 __author__ = "Ed Page"
 __email__ = "eopage@byu.net"
-__version__ = "0.9.0"
-__build__ = 4
+__version__ = "0.9.1"
+__build__ = 0
 __changelog__ = '''\
+0.9.1 - "Laziness doesn't always pay off"
+* Modified the pie menus a bit to try and optimize popup time
+
 0.9.0 - "Feed is for horses, so what about feedback?"
 * Initial public release
 * Pie menus for keys
index b9a1464..3b73f77 100644 (file)
@@ -1,11 +1,11 @@
 # lint Python modules using external checkers.
-# 
+#
 # This is the main checker controling the other ones and the reports
 # generation. It is itself both a raw checker and an astng checker in order
 # to:
 # * handle message activation / deactivation at the module level
 # * handle some basic but necessary stats'data (number of classes, methods...)
-# 
+#
 [MASTER]
 
 # Specify a configuration file.
@@ -53,16 +53,16 @@ load-plugins=
 #enable-msg=
 
 # Disable the message(s) with the given id(s).
-disable-msg=W0403,W0612,W0613,C0103,C0111,C0301
+disable-msg=W0403,W0612,W0613,C0103,C0111,C0301,R0903,W0142,W0603,R0904
 
 [REPORTS]
 
 # set the output format. Available formats are text, parseable, colorized, msvs
 # (visual studio) and html
-output-format=text
+output-format=colorized
 
 # Include message's id in output
-include-ids=no
+include-ids=yes
 
 # Put messages in a separate file for each module / package specified on the
 # command line instead of printing them on stdout. Reports (if any) will be
@@ -70,7 +70,7 @@ include-ids=no
 files-output=no
 
 # Tells wether to display a full report or only the messages
-reports=yes
+reports=no
 
 # Python expression which should return a note less than 10 (10 is the highest
 # note).You have access to the variables errors warning, statement which
@@ -95,7 +95,7 @@ comment=no
 # * undefined variables
 # * redefinition of variable from builtins or from an outer scope
 # * use of variable before assigment
-# 
+#
 [VARIABLES]
 
 # Tells wether we should check for unused import in __init__ files.
@@ -118,7 +118,7 @@ additional-builtins=
 # * dangerous default values as arguments
 # * redefinition of function / method / class
 # * uses of the global statement
-# 
+#
 [BASIC]
 
 # Required attributes for module, separated by a comma
@@ -186,7 +186,7 @@ acquired-members=REQUEST,acl_users,aq_parent
 # checks for sign of poor/misdesign:
 # * number of methods, attributes, local variables...
 # * size, complexity of functions, methods
-# 
+#
 [DESIGN]
 
 # Maximum number of arguments for function / method
@@ -224,7 +224,7 @@ max-public-methods=20
 # * attributes not defined in the __init__ method
 # * supported interfaces implementation
 # * unreachable code
-# 
+#
 [CLASSES]
 
 # List of interface methods to ignore, separated by a comma. This is used for
@@ -240,7 +240,7 @@ defining-attr-methods=__init__,__new__,setUp
 # * relative / wildcard imports
 # * cyclic imports
 # * uses of deprecated modules
-# 
+#
 [IMPORTS]
 
 # Deprecated modules which should not be used, separated by a comma
@@ -262,7 +262,7 @@ int-import-graph=
 # checks for similarities and duplicated code. This computation may be
 # memory / CPU intensive, so you should disable it if you experiments some
 # problems.
-# 
+#
 [SIMILARITIES]
 
 # Minimum lines number of a similarity.
@@ -278,7 +278,7 @@ ignore-docstrings=yes
 # checks for:
 # * warning notes in the code like FIXME, XXX
 # * PEP 263: source code with non ascii character but no encoding declaration
-# 
+#
 [MISCELLANEOUS]
 
 # List of note tags to take in consideration, separated by a comma.
@@ -290,7 +290,7 @@ notes=FIXME,XXX,TODO
 # * strict indentation
 # * line length
 # * use of <> instead of !=
-# 
+#
 [FORMAT]
 
 # Maximum number of characters on a single line.