| 43 | }}} |
| 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 | >>> menu_1 = M("Menu 1") |
| 68 | >>> menu_2 = M("Menu 2") |
| 69 | >>> item_1 = M("Item 1") |
| 70 | >>> menu_1.append(item_1) |
| 71 | <S3OptionsMenuLayout:Menu 1 {<S3OptionsMenuLayout:Item 1>}> |
| 72 | >>> menu_2 |
| 73 | <S3OptionsMenuLayout:Menu 2> |
| 74 | >>> menu_2.append(item_1) |
| 75 | <S3OptionsMenuLayout:Menu 2 {<S3OptionsMenuLayout:Item 1>}> |
| 76 | >>> menu_1 |
| 77 | <S3OptionsMenuLayout:Menu 1> |