-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControl_Menu.py
More file actions
110 lines (85 loc) · 2.58 KB
/
Control_Menu.py
File metadata and controls
110 lines (85 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
'''
Control Menu
Setups buttons on the menu
by Katie and Paulo
'''
import Tkinter as tk
from copy import deepcopy
from functools import partial
class Control_Menu():
def __init__(self):
# Number of buttons
self.num_btns = 16
# Initialize the buttons
self.buttons = [ tk.Button(text = "", command = "", state = "disabled") for i in range(self.num_btns) ]
# Last set of actions
self.last_actions = {}
# Action that is currently selected
self.selected_action = ''
'''
Updates the control menu
'''
def update(self,actions):
# Only update the buttons if the actions differ from the last_actions
if(set(actions) != set(self.last_actions)):
# Update local copy of available actions
self.last_actions = deepcopy(actions)
# # Get the base actions
# base_actions = [action.split('-')[0] for action in self.last_actions]
# If move is available, set it as default action
print self.last_actions
if 'move' in self.last_actions.keys():
self.selected_action = ('move',[])
# Update the buttons
self.update_buttons(self.last_actions.keys(), [])
'''
TODO: Add HERE!!
'''
def update_sub_buttons(self,action):
subactions = self.last_actions[action]
self.update_buttons([action],subactions)
'''
Updates the buttons to the currenlty available actions
'''
def update_buttons(self, actions, subactions):
# Subaction menu
if (len(subactions) > 0):
for i in range(self.num_btns):
if (len(subactions) > i):
self.buttons[i].config(text=subactions[i],state = "normal")
self.buttons[i].config(command=partial(self.set_current_action,(actions[0],subactions[i])))
else:
self.buttons[i].config(text = '', state = "disabled")
# Top level
else:
for i in range(self.num_btns):
if (len(actions) > i):
self.buttons[i].config(text=actions[i],state = "normal")
self.buttons[i].config(command=partial(self.set_current_action,(actions[i],'')))
else:
self.buttons[i].config(text = '', state = "disabled")
'''
Returns the buttons
'''
def get_buttons(self):
return self.buttons
'''
Returns the number of buttons
'''
def get_num_btns(self):
return self.num_btns
'''
Returns the action that is currently active
Defined as the button having been clicked or default
'''
def get_current_action(self):
return self.selected_action
'''
Sets the current action
'''
def set_current_action(self,action_tuple):
if action_tuple[0] == 'build' and action_tuple[1] == '':
self.update_sub_buttons(action_tuple[0])
self.selected_action = ('move',[])
return
self.selected_action = action_tuple