| 42 | # UI agnostic way and then used with different toolkits. |
| 43 | # \ingroup python |
| 44 | class MenuDefinition( object ) : |
| 45 | |
| 46 | def __init__( self, items = None ) : |
| 47 | |
| 48 | self.__items = [] |
| 49 | |
| 50 | for path, item in items or []: |
| 51 | |
| 52 | self.append( path, item ) |
| 53 | |
| 54 | ## Prepends a menu item to the menu. The item will |
| 55 | # appear before all other items in its respective |
| 56 | # submenu. |
| 57 | def prepend( self, path, item ) : |
| 58 | |
| 59 | if isinstance( item, dict ) : |
| 60 | item = MenuItemDefinition( item ) |
| 61 | |
| 62 | self.remove( path, False ) |
| 63 | |
| 64 | self.__items.insert( 0, ( path, item ) ) |
| 65 | |
| 66 | ## Appends a menu item at the end. The item will |
| 67 | # appear after all other items in its respective |
| 68 | # submenu. |
| 69 | def append( self, path, item ) : |
| 70 | |
| 71 | if isinstance( item, dict ) : |
| 72 | item = MenuItemDefinition( item ) |
| 73 | |
| 74 | self.remove( path, False ) |
| 75 | |
| 76 | self.__items.append( ( path, item ) ) |
| 77 | |
| 78 | ## Insert a menu item before the specified menu item. |
| 79 | def insertBefore( self, path, item, beforePath ) : |
| 80 | |
| 81 | if isinstance( item, dict ) : |
| 82 | item = MenuItemDefinition( item ) |
| 83 | |
| 84 | self.remove( path, False ) |
| 85 | |
| 86 | i = self.__pathIndex( beforePath ) |
| 87 | self.__items.insert( i, ( path, item ) ) |
| 88 | |
| 89 | ## Insert a menu item after the specified menu item. |
| 90 | def insertAfter( self, path, item, afterPath ) : |
| 91 | |
| 92 | if isinstance( item, dict ) : |
| 93 | item = MenuItemDefinition( item ) |
| 94 | |
| 95 | self.remove( path, False ) |
| 96 | |
| 97 | i = self.__pathIndex( afterPath ) |
| 98 | self.__items.insert( i+1, ( path, item ) ) |
| 99 | |
| 100 | ## Removes the named menu item. Raises a KeyError if |
| 101 | # no such item exists and raiseIfMissing is True. |