1
1
Menus
2
2
======
3
3
4
- This page contains tutorials about the :mod: `menus.radio ` package.
4
+ This page contains tutorials about the :mod: `menus ` package.
5
5
6
6
7
7
Creating PagedMenu
@@ -11,6 +11,8 @@ This is a simple example to create paged menu
11
11
12
12
.. code-block :: python
13
13
14
+ import random
15
+
14
16
from commands.say import SayCommand
15
17
16
18
from menus import PagedMenu
@@ -23,23 +25,25 @@ This is a simple example to create paged menu
23
25
@SayCommand ([' menu' , ' /menu' , ' !menu' ])
24
26
def say_command (command , index , teamonly ):
25
27
# Send the menu
26
- build_paged_menu (index)
28
+ menu.send (index)
27
29
return False
28
30
29
- def build_paged_menu (index ):
30
- # Create the Paged Menu and set title to My Menu
31
- menu = PagedMenu(title = ' My Menu' )
32
- # Add options from 1 to 20
33
- for i in range (1 , 20 ):
34
- menu.append(PagedOption(f ' { i} ' , i))
35
- menu.select_callback= my_select_callback
36
- menu.send(index)
31
+ menu = PagedMenu(title = ' Welcome menu' , description = ' Choose an option:' , select_callback = my_select_callback)
32
+
33
+ # Add options from 1 to 20
34
+ for i in range (1 , 20 ):
35
+ menu.append(PagedOption(f ' { i} ' , i))
37
36
38
37
def my_select_callback (menu , index , option ):
39
- # Create player object from index
40
- player = Player(index)
41
- # Print the player name who have selected a menu option
42
- print (f ' { player.name} have selected a menu option! ' )
38
+ '''
39
+ Called whenever a selection was made.
40
+ '''
41
+
42
+ # Shuffle the menu : D
43
+ random.shuffle(menu)
44
+
45
+ # Make it sticky
46
+ return menu
43
47
44
48
45
49
Creating SimpleMenu
@@ -49,6 +53,8 @@ This is a simple example to create simple menu
49
53
50
54
.. code-block :: python
51
55
56
+ import time
57
+
52
58
from commands.say import SayCommand
53
59
54
60
from menus import SimpleMenu
@@ -63,31 +69,29 @@ This is a simple example to create simple menu
63
69
@SayCommand ([' menus' , ' /menus' , ' !menus' ])
64
70
def say_menus_command (command , index , teamonly ):
65
71
# Send the menu
66
- build_simple_menu (index)
72
+ menu.send (index)
67
73
return False
68
74
69
- def build_simple_menu (index ):
70
- # Create the SimpleMenu
71
- menu = SimpleMenu
72
- # Add in menu text
73
- menu.append(Text(' Do you accept the rules?' ))
74
- menu.append(Text(' ' ))
75
- # Add in menu options
76
- menu.append(SimpleOption(1 , ' Yes' , ' yes' ))
77
- menu.append(SimpleOption(2 , ' No' , ' no' ))
78
- menu.select_callback= my_menu_select_callback
79
- menu.send(index)
75
+
76
+ menu = SimpleMenu()
77
+ # Tell the current time
78
+ menu.append(Text(f " Current Time: { time.strftime(' %H:%M:%S' )} " ))
79
+ # Add empty line
80
+ menu.append(Text(' ' ))
81
+ menu.append(Text(' Do you accept the rules?' ))
82
+ menu.append(Text(' ' ))
83
+ # Add in menu options
84
+ menu.append(SimpleOption(1 , ' Yes' , ' yes' ))
85
+ menu.append(SimpleOption(2 , ' No' , ' no' ))
86
+ menu.select_callback= my_menu_select_callback
87
+
80
88
81
89
def my_menu_select_callback (menu , index , option ):
82
- choice = option.value
83
- # Create player object from index
84
- player = Player(index)
85
- # Player did select yes option
86
- if choice == ' yes' :
90
+ if option.value == ' yes' :
87
91
SayText2(' Thank you for accepting the rules!' ).send(index)
88
92
# Player selected no option
89
93
else :
90
- player .kick(' You have to accept the rules!' )
94
+ Player(index) .kick(' You have to accept the rules!' )
91
95
92
96
Creating ListMenu
93
97
--------------------------
@@ -105,12 +109,9 @@ This is a simple example to create list menu
105
109
@SayCommand ([' menus' , ' /menus' , ' !menus' ])
106
110
def say_menus_command (command , index , teamonly ):
107
111
# Send the menu
108
- build_list_menu (index)
112
+ menu.send (index)
109
113
return False
110
114
111
- def build_simple_menu (index ):
112
- # Create the ListMenu
113
- menu = ListMenu()
114
- # Add in menu text
115
- menu.append(Text(' This is a example text' ))
116
- menu.send(index)
115
+ menu = ListMenu()
116
+ # Add in menu text
117
+ menu.append(Text(' This is a example text' ))
0 commit comments