44 | | |
45 | | You can use the call-method later to append more items: |
46 | | |
47 | | {{{ |
48 | | # Append another item to the menu |
49 | | my_menu(MyMenuLayout("Third Item")) |
50 | | }}} |
51 | | |
52 | | If you want to insert an item at a particular position, use the insert method: |
53 | | |
54 | | {{{ |
55 | | my_menu.insert(0, MyMenuLayout("New First Item")) |
56 | | }}} |
57 | | |
58 | | You can also remove items from a certain position: |
59 | | |
60 | | {{{ |
61 | | my_menu.pop(0) # Remove "New First Item" again |
62 | | }}} |
63 | | |
64 | | Note that every item can only ever belong to exactly one parent item. If you append or insert the same item to a different parent item, it will automatically be removed from the original parent: |
65 | | |
66 | | {{{ |
67 | | # CLI example |
68 | | >>> menu_1 = M("Menu 1") # define menu 1 |
69 | | >>> menu_2 = M("Menu 2") # define menu 2 |
70 | | >>> item_1 = M("Item 1") # define a menu item |
71 | | >>> menu_1.append(item_1) # append the menu item to menu 1 |
72 | | <S3OptionsMenuLayout:Menu 1 {<S3OptionsMenuLayout:Item 1>}> |
73 | | >>> menu_2 |
74 | | <S3OptionsMenuLayout:Menu 2> |
75 | | >>> menu_2.append(item_1) # append the menu item to menu 2 |
76 | | <S3OptionsMenuLayout:Menu 2 {<S3OptionsMenuLayout:Item 1>}> |
77 | | >>> menu_1 |
78 | | <S3OptionsMenuLayout:Menu 1> # => menu item no longer component of menu 1 |
79 | | }}} |
80 | | |
81 | | Thus, if you want to re-use a sequence of menu items, make their definition a function and call it at each place you need the sequence. |