]>
Commit | Line | Data |
---|---|---|
60aa2bed IB |
1 | from kivy.uix.label import Label |
2 | from kivy.uix.stacklayout import StackLayout | |
3 | from kivy.uix.relativelayout import RelativeLayout | |
4 | from kivy.properties import ListProperty, StringProperty | |
4d1dfc89 | 5 | from ..lock import Lock |
60aa2bed IB |
6 | |
7 | __all__ = ["ActionList", | |
8 | "ActionListIcons", "ActionListIcon", | |
9 | "ActionListDescriptions", "ActionListDescription"] | |
10 | ||
4d1dfc89 IB |
11 | actionlist_lock = Lock("playlist") |
12 | ||
60aa2bed IB |
13 | class ActionList(RelativeLayout): |
14 | action_title = StringProperty("") | |
15 | action_list = ListProperty([]) | |
16 | ||
17 | def update_list(self, key, action_descriptions): | |
814c30c6 IB |
18 | if key.repeat_delay > 0: |
19 | self.action_title = _( | |
20 | "actions linked to key {} (repeat protection {}s):" | |
21 | ).format(key.key_sym, key.repeat_delay) | |
22 | else: | |
23 | self.action_title = _( | |
24 | "actions linked to key {}:" | |
25 | ).format(key.key_sym) | |
26 | ||
60aa2bed IB |
27 | action_list = [] |
28 | ||
29 | for [action, status] in action_descriptions: | |
30 | if status == "done": | |
31 | icon = "✓" | |
32 | elif status == "current": | |
33 | icon = "✅" | |
34 | else: | |
35 | icon = " " | |
36 | action_list.append([icon, action]) | |
4d1dfc89 IB |
37 | with actionlist_lock: |
38 | self.action_list = action_list | |
60aa2bed IB |
39 | |
40 | class ActionListIcons(StackLayout): | |
41 | def __init__(self, **kwargs): | |
42 | super(ActionListIcons, self).__init__(**kwargs) | |
43 | self.icons = [] | |
44 | ||
45 | def on_parent(self, instance, parent): | |
46 | parent.bind(action_list=self.update_actionlist_icons) | |
47 | ||
48 | def update_actionlist_icons(self, instance, actionlist): | |
4d1dfc89 IB |
49 | icons_length = len(self.icons) |
50 | index = -1 | |
51 | for index, [icon, description] in enumerate(actionlist): | |
52 | if index >= icons_length: | |
53 | icon_label = ActionListIcon(text=icon) | |
54 | self.add_widget(icon_label) | |
55 | self.icons.append(icon_label) | |
56 | else: | |
57 | self.icons[index].text = icon | |
58 | ||
59 | if index+1 < icons_length: | |
60 | self.clear_widgets(children=self.icons[index+1:icons_length]) | |
61 | del(self.icons[index+1:icons_length]) | |
60aa2bed IB |
62 | |
63 | class ActionListIcon(Label): | |
64 | def __init__(self, text='', **kwargs): | |
65 | super(ActionListIcon, self).__init__(**kwargs) | |
66 | self.text = text | |
67 | ||
68 | def on_parent(self, instance, parent): | |
69 | if parent is not None: | |
4d1dfc89 IB |
70 | parent.bind(font_size=self.update_font_size) |
71 | parent.bind(labels_height=self.update_height) | |
72 | ||
73 | def update_height(self, instance, height): | |
74 | self.height = height | |
75 | ||
76 | def update_font_size(self, instance, font_size): | |
77 | self.font_size = font_size | |
60aa2bed IB |
78 | |
79 | class ActionListDescriptions(StackLayout): | |
80 | def __init__(self, **kwargs): | |
81 | super(ActionListDescriptions, self).__init__(**kwargs) | |
82 | self.descriptions = [] | |
83 | ||
84 | def on_parent(self, instance, parent): | |
85 | parent.bind(action_list=self.update_actionlist_descriptions) | |
86 | ||
87 | def update_actionlist_descriptions(self, instance, actionlist): | |
4d1dfc89 IB |
88 | descriptions_length = len(self.descriptions) |
89 | index = -1 | |
90 | for index, [icon, description] in enumerate(actionlist): | |
91 | if index >= descriptions_length: | |
92 | description_label = ActionListDescription(text=description) | |
93 | self.add_widget(description_label) | |
94 | self.descriptions.append(description_label) | |
95 | else: | |
96 | self.descriptions[index].text = description | |
97 | ||
98 | if index+1 < descriptions_length: | |
99 | self.clear_widgets( | |
100 | children=self.descriptions[index+1:descriptions_length]) | |
101 | del(self.descriptions[index+1:descriptions_length]) | |
60aa2bed IB |
102 | |
103 | class ActionListDescription(Label): | |
104 | def __init__(self, text='', **kwargs): | |
105 | super(ActionListDescription, self).__init__(**kwargs) | |
106 | self.text = text | |
107 | ||
108 | def on_parent(self, instance, parent): | |
109 | if parent is not None: | |
4d1dfc89 IB |
110 | parent.bind(font_size=self.update_font_size) |
111 | parent.bind(labels_height=self.update_height) | |
112 | ||
113 | def update_height(self, instance, height): | |
114 | self.height = height | |
60aa2bed | 115 | |
4d1dfc89 IB |
116 | def update_font_size(self, instance, font_size): |
117 | self.font_size = font_size | |
60aa2bed | 118 |