GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Public Member Functions | Properties
python-bindings.function_class.ClassFromFunctions Class Reference
Inheritance diagram for python-bindings.function_class.ClassFromFunctions:

Public Member Functions

def __new__
 
def __init__
 
def get_instance
 
def add_method
 
def ya_add_classmethod
 
def ya_add_method
 
def add_methods_with_prefix
 
def add_constructor_and_methods_with_prefix
 
def decorate_functions
 

Properties

 instance = property(get_instance)
 

Detailed Description

Inherit this class to give yourself a python class that wraps a set of
functions that together constitute the methods of the class.

The method functions must all have as a first argument an object
holding the instance data. There must also be a function that
returns a new instance of the class, the constructor.

Your subclass must define
_module - The module where the method functions, including the
constructor can be found
_new_instance - The name of a function that serves as a constructor,
returning the instance data.

To access the instance data, use the read-only property instance.

To add some functions from _module as methods, call classmethods like
add_method and add_methods_with_prefix.

Definition at line 31 of file function_class.py.

Constructor & Destructor Documentation

def python-bindings.function_class.ClassFromFunctions.__init__ (   self,
  args,
  kargs 
)
Construct a new instance, using either the function
self._module[self._new_instance] or using existing instance
data. (specified with the keyword argument, instance)

Pass the arguments that should be passed on to
self._module[self._new_instance] . Any arguments of that
are instances of ClassFromFunctions will be switched with the instance
data. (by calling the .instance property)

Definition at line 57 of file function_class.py.

57 
58  def __init__(self, *args, **kargs):
59  """Construct a new instance, using either the function
60  self._module[self._new_instance] or using existing instance
61  data. (specified with the keyword argument, instance)
62 
63  Pass the arguments that should be passed on to
64  self._module[self._new_instance] . Any arguments of that
65  are instances of ClassFromFunctions will be switched with the instance
66  data. (by calling the .instance property)
67  """
68  if INSTANCE_ARGUMENT in kargs:
69  self.__instance = kargs[INSTANCE_ARGUMENT]
70  else:
71  self.__instance = getattr(self._module, self._new_instance)(
72  *process_list_convert_to_instance(args) )

Member Function Documentation

def python-bindings.function_class.ClassFromFunctions.add_constructor_and_methods_with_prefix (   cls,
  prefix,
  constructor 
)
Add a group of functions with the same prefix, and set the
_new_instance attribute to prefix + constructor

Definition at line 136 of file function_class.py.

137  def add_constructor_and_methods_with_prefix(cls, prefix, constructor):
138  """Add a group of functions with the same prefix, and set the
139  _new_instance attribute to prefix + constructor
140  """
141  cls.add_methods_with_prefix(prefix)
142  cls._new_instance = prefix + constructor
def python-bindings.function_class.ClassFromFunctions.add_method (   cls,
  function_name,
  method_name 
)
Add the function, method_name to this class as a method named name

Definition at line 85 of file function_class.py.

85 
86  def add_method(cls, function_name, method_name):
87  """Add the function, method_name to this class as a method named name
88  """
89  def method_function(self, *meth_func_args):
90  return getattr(self._module, function_name)(
91  self.instance,
92  *process_list_convert_to_instance(meth_func_args) )
93 
94  setattr(cls, method_name, method_function)
95  setattr(method_function, "__name__", method_name)
96  return method_function
def python-bindings.function_class.ClassFromFunctions.add_methods_with_prefix (   cls,
  prefix 
)
Add a group of functions with the same prefix 

Definition at line 128 of file function_class.py.

129  def add_methods_with_prefix(cls, prefix):
130  """Add a group of functions with the same prefix
131  """
132  for function_name, function_value, after_prefix in \
133  extract_attributes_with_prefix(cls._module, prefix):
134  cls.add_method(function_name, after_prefix)
def python-bindings.function_class.ClassFromFunctions.get_instance (   self)
Get the instance data.

You can also call the instance property

Definition at line 73 of file function_class.py.

73 
74  def get_instance(self):
75  """Get the instance data.
76 
77  You can also call the instance property
78  """
79  return self.__instance
def python-bindings.function_class.ClassFromFunctions.ya_add_classmethod (   cls,
  function_name,
  method_name 
)
Add the function, method_name to this class as a classmethod named name

Taken from function_class and slightly modified.

Definition at line 98 of file function_class.py.

98 
99  def ya_add_classmethod(cls, function_name, method_name):
100  """Add the function, method_name to this class as a classmethod named name
101 
102  Taken from function_class and slightly modified.
103  """
104  def method_function(self, *meth_func_args):
105  return getattr(self._module, function_name)(
106  self,
107  *process_list_convert_to_instance(meth_func_args) )
108 
109  setattr(cls, method_name, classmethod(method_function))
110  setattr(method_function, "__name__", method_name)
111  return method_function
def python-bindings.function_class.ClassFromFunctions.ya_add_method (   cls,
  function_name,
  method_name 
)
Add the function, method_name to this class as a method named name

Taken from function_class and slightly modified.

Definition at line 113 of file function_class.py.

114  def ya_add_method(cls, function_name, method_name):
115  """Add the function, method_name to this class as a method named name
116 
117  Taken from function_class and slightly modified.
118  """
119  def method_function(self, *meth_func_args):
120  return getattr(self._module, function_name)(
121  self,
122  *process_list_convert_to_instance(meth_func_args) )
123 
124  setattr(cls, method_name, method_function)
125  setattr(method_function, "__name__", method_name)
126  return method_function

The documentation for this class was generated from the following file: