| |
- menu_cl
class menu_cl |
|
Members:
--------------------------------------------------------
1. menu_item:<dict>: menu chain
2. attr_dict:<dict>: attributes
Functions:
--------------------------------------------------------
1. __getitem__: overriding index function ('[]') to check dictionary entry of self.menu_item
2. delete_menu: remove item from self.menu_item
3. update_menu: Add or update menu item
4. get_attr: get attribute
5. set_attr: set attribute
6. print_menu: print out what is in the menu chain
Notes:
-------------------------------------------------------------
1. menu_cl is designed to be a container for dictionary trees so it can have a nested structure like:
Menu P---->Menu C1
---->Menu C2
etc
Consquently item under sub-menu (for example menu C1) will be accessed using the
full name of menu chain separated by '.' (for example P.C1.itemname)
2. special words: __load; __dict; __list;
---> __load: If an item value is given as a string in form of '__load:module_name:module_member' ,
self.update_menu will try to import this module, and then assign its corresponding member to the menu item.
---> __dict: if an item value is given as a string in form of '__dict:a=x, b=y, ...,
self.update_menu will create a dictionary as {'a':x, 'b':y,,.} under the item's name
---> __list: if an item value is given as a string in form of '__list:a, b, ...,
self.update_menu will create a list as [a, b, c] under the item's name |
|
Methods defined here:
- __getitem__(self, itemname)
- Overriding index function
Inputs:
----------------------------------------------------
1. itemname: <str>: name of the menu item to be checked
Outputs:
--------------------------------------------------
1. value: the menu value if found
Notes:
--------------------------------------
1. if itemname contains '.' (for example M1.M2.M3), the value will be searched down through chain
of menu classes (such as M1-->M2--M3)
- __init__(self, **menu_dict)
- initialization
Inputs:
----------------------------------
1. menu_dict:<dict>: menu
- delete_menu(self, menu_name)
- remove item from self.menu_item
Inputs:
------------------------------------
1. menu_name:<str>: name of the menu to be deleted
- get_attr(self, attr_name)
- get attribute of the object
Inputs:
------------------------------------------
1.attr_name:<str>: attribut name
Returns:
------------------------------------------
1. val:<obj>: attribute
- print_menu(self, parentname='')
- print out what is in the menu chain
- set_attr(self, attr_name, attr_value)
- set attribute of the object
Inputs:
------------------------------------------
1.attr_name:<str>: attribute name
2.attr_value:<obj>: attribute value
- update_menu(self, menu_name, menu_val)
- Add or update menu item
Inputs:
--------------------------------------------
1. menu_name:<str>: name of the menu
2. menu_val: <obj>: value
Notes:
--------------------------------------
1. if itemname contains '.' (for example M1.M2.M3), the value will be added or updated down through
the chain of menu classes (such as M1-->M2--M3)
2. special words: __load; __dict; __list;
---> __load: If an item value is given as a string in form of '__load:module_name:module_member' ,
self.update_menu will try to import this module, and then assign its corresponding member to the menu item.
---> __dict: if an item value is given as a string in form of '__dict:a=x, b=y, ...,
self.update_menu will create a dictionary as {'a':x, 'b':y,,.} under the item's name
---> __list: if an item value is given as a string in form of '__list:a, b, ...,
self.update_menu will create a list as [a, b, c] under the item's name
---> __range: if an item value is given as a string in form of '__range:a, b, c,
self.update_menu will create a array as arange(a, b, c) under the item's name
| |