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 from kivy
.clock
import mainthread
9 __all__
= ["ActionList",
10 "ActionListIcons", "ActionListIcon",
11 "ActionListDescriptions", "ActionListDescription"]
13 actionlist_lock
= Lock("playlist")
15 class ActionList(RelativeLayout
):
16 action_title
= StringProperty("")
17 action_list
= ListProperty([])
20 def update_list(self
, key
, action_descriptions
):
21 if key
.repeat_delay
> 0:
22 self
.action_title
= _(
23 "actions linked to key {} (repeat protection {}s):"
24 ).format(key
.key_sym
, key
.repeat_delay
)
26 self
.action_title
= _(
27 "actions linked to key {}:"
32 for [action
, status
] in action_descriptions
:
35 elif status
== "current":
39 action_list
.append([icon
, action
])
41 self
.action_list
= action_list
43 class ActionListIcons(StackLayout
):
44 def __init__(self
, **kwargs
):
45 super(ActionListIcons
, self
).__init
__(**kwargs
)
48 def on_parent(self
, instance
, parent
):
49 parent
.bind(action_list
=self
.update_actionlist_icons
)
51 def update_actionlist_icons(self
, instance
, actionlist
):
52 icons_length
= len(self
.icons
)
54 for index
, [icon
, description
] in enumerate(actionlist
):
55 if index
>= icons_length
:
56 icon_label
= ActionListIcon(text
=icon
)
57 self
.add_widget(icon_label
)
58 self
.icons
.append(icon_label
)
60 self
.icons
[index
].text
= icon
62 if index
+1 < icons_length
:
63 self
.clear_widgets(children
=self
.icons
[index
+1:icons_length
])
64 del(self
.icons
[index
+1:icons_length
])
66 class ActionListIcon(Label
):
67 def __init__(self
, text
='', **kwargs
):
68 super(ActionListIcon
, self
).__init
__(**kwargs
)
71 def on_parent(self
, instance
, parent
):
72 if parent
is not None:
73 parent
.bind(font_size
=self
.update_font_size
)
74 parent
.bind(labels_height
=self
.update_height
)
76 def update_height(self
, instance
, height
):
79 def update_font_size(self
, instance
, font_size
):
80 self
.font_size
= font_size
82 class ActionListDescriptions(StackLayout
):
83 def __init__(self
, **kwargs
):
84 super(ActionListDescriptions
, self
).__init
__(**kwargs
)
85 self
.descriptions
= []
87 def on_parent(self
, instance
, parent
):
88 parent
.bind(action_list
=self
.update_actionlist_descriptions
)
90 def update_actionlist_descriptions(self
, instance
, actionlist
):
91 descriptions_length
= len(self
.descriptions
)
93 for index
, [icon
, description
] in enumerate(actionlist
):
94 if index
>= descriptions_length
:
95 description_label
= ActionListDescription(text
=description
)
96 self
.add_widget(description_label
)
97 self
.descriptions
.append(description_label
)
99 self
.descriptions
[index
].text
= description
101 if index
+1 < descriptions_length
:
103 children
=self
.descriptions
[index
+1:descriptions_length
])
104 del(self
.descriptions
[index
+1:descriptions_length
])
106 class ActionListDescription(Label
):
107 def __init__(self
, text
='', **kwargs
):
108 super(ActionListDescription
, self
).__init
__(**kwargs
)
111 def on_parent(self
, instance
, parent
):
112 if parent
is not None:
113 parent
.bind(font_size
=self
.update_font_size
)
114 parent
.bind(labels_height
=self
.update_height
)
116 def update_height(self
, instance
, height
):
119 def update_font_size(self
, instance
, font_size
):
120 self
.font_size
= font_size