def __init__(self, function):
        """
        Construct the `TempFunctionCallCounter`.
        
        For `function`, you may pass in either a function object, or a
        `(parent_object, function_name)` pair, or a `(getter, setter)` pair.
        """

        if cute_iter_tools.is_iterable(function):
            first, second = function
            if isinstance(second, basestring):
                actual_function = getattr(first, second)
            else:
                assert callable(first) and callable(second)
                actual_function = first()  # `first` is the getter in this case.

        else:  # not cute_iter_tools.is_iterable(function)
            assert callable(function)
            actual_function = function
            try:
                address = address_tools.object_to_string.get_address(function)
                parent_object_address, function_name = address.rsplit(".", 1)
                parent_object = address_tools.resolve(parent_object_address)
            except Exception:
                raise Exception(
                    "Couldn't obtain parent/name pair from "
                    "function; supply one manually or "
                    "alternatively supply a getter/setter pair."
                )
            first, second = parent_object, function_name

        self.call_counting_function = count_calls(actual_function)

        TempValueSetter.__init__(self, (first, second), value=self.call_counting_function)
    def __init__(self, function):
        '''
        Construct the `TempFunctionCallCounter`.
        
        For `function`, you may pass in either a function object, or a
        `(parent_object, function_name)` pair, or a `(getter, setter)` pair.
        '''

        if cute_iter_tools.is_iterable(function):
            first, second = function
            if isinstance(second, str):
                actual_function = getattr(first, second)
            else:
                assert callable(first) and callable(second)
                actual_function = first(
                )  # `first` is the getter in this case.

        else:  # not cute_iter_tools.is_iterable(function)
            assert callable(function)
            actual_function = function
            try:
                address = address_tools.object_to_string.get_address(function)
                parent_object_address, function_name = address.rsplit('.', 1)
                parent_object = address_tools.resolve(parent_object_address)
            except Exception:
                raise Exception("Couldn't obtain parent/name pair from "
                                "function; supply one manually or "
                                "alternatively supply a getter/setter pair.")
            first, second = parent_object, function_name

        self.call_counting_function = count_calls(actual_function)

        TempValueSetter.__init__(self, (first, second),
                                 value=self.call_counting_function)
Пример #3
0
    def __init__(self, window, cursor):
        '''
        Construct the `CursorChanger`.

        `cursor` may be either a `wx.Cursor` object or a constant like
        `wx.CURSOR_BULLSEYE`.
        '''
        assert isinstance(window, wx.Window)
        self.window = window
        self.cursor = cursor if isinstance(cursor, wx.Cursor) \
                      else wx.StockCursor(cursor)
        TempValueSetter.__init__(self, (window.GetCursor, window.SetCursor),
                                 self.cursor,
                                 assert_no_fiddling=False)
Пример #4
0
 def __init__(self, window, cursor):
     '''
     Construct the `CursorChanger`.
     
     `cursor` may be either a `wx.Cursor` object or a constant like
     `wx.CURSOR_BULLSEYE`.
     '''
     assert isinstance(window, wx.Window)
     self.window = window
     self.cursor = cursor if isinstance(cursor, wx.Cursor) \
                   else wx.StockCursor(cursor)
     TempValueSetter.__init__(self,
                              (window.GetCursor, window.SetCursor),
                              self.cursor,
                              assert_no_fiddling=False)