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
5 from ..lock
import Lock
7 __all__
= ["ActionList",
8 "ActionListIcons", "ActionListIcon",
9 "ActionListDescriptions", "ActionListDescription"]
11 actionlist_lock
= Lock("playlist")
13 class ActionList(RelativeLayout
):
14 action_title
= StringProperty("")
15 action_list
= ListProperty([])
17 def update_list(self
, key
, action_descriptions
):
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
)
23 self
.action_title
= _(
24 "actions linked to key {}:"
29 for [action
, status
] in action_descriptions
:
32 elif status
== "current":
36 action_list
.append([icon
, action
])
38 self
.action_list
= action_list
40 class ActionListIcons(StackLayout
):
41 def __init__(self
, **kwargs
):
42 super(ActionListIcons
, self
).__init
__(**kwargs
)
45 def on_parent(self
, instance
, parent
):
46 parent
.bind(action_list
=self
.update_actionlist_icons
)
48 def update_actionlist_icons(self
, instance
, actionlist
):
49 icons_length
= len(self
.icons
)
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
)
57 self
.icons
[index
].text
= icon
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
])
63 class ActionListIcon(Label
):
64 def __init__(self
, text
='', **kwargs
):
65 super(ActionListIcon
, self
).__init
__(**kwargs
)
68 def on_parent(self
, instance
, parent
):
69 if parent
is not None:
70 parent
.bind(font_size
=self
.update_font_size
)
71 parent
.bind(labels_height
=self
.update_height
)
73 def update_height(self
, instance
, height
):
76 def update_font_size(self
, instance
, font_size
):
77 self
.font_size
= font_size
79 class ActionListDescriptions(StackLayout
):
80 def __init__(self
, **kwargs
):
81 super(ActionListDescriptions
, self
).__init
__(**kwargs
)
82 self
.descriptions
= []
84 def on_parent(self
, instance
, parent
):
85 parent
.bind(action_list
=self
.update_actionlist_descriptions
)
87 def update_actionlist_descriptions(self
, instance
, actionlist
):
88 descriptions_length
= len(self
.descriptions
)
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
)
96 self
.descriptions
[index
].text
= description
98 if index
+1 < descriptions_length
:
100 children
=self
.descriptions
[index
+1:descriptions_length
])
101 del(self
.descriptions
[index
+1:descriptions_length
])
103 class ActionListDescription(Label
):
104 def __init__(self
, text
='', **kwargs
):
105 super(ActionListDescription
, self
).__init
__(**kwargs
)
108 def on_parent(self
, instance
, parent
):
109 if parent
is not None:
110 parent
.bind(font_size
=self
.update_font_size
)
111 parent
.bind(labels_height
=self
.update_height
)
113 def update_height(self
, instance
, height
):
116 def update_font_size(self
, instance
, font_size
):
117 self
.font_size
= font_size