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 self
.action_title
= _("actions linked to key {}:").format(key
.key_sym
)
21 for [action
, status
] in action_descriptions
:
24 elif status
== "current":
28 action_list
.append([icon
, action
])
30 self
.action_list
= action_list
32 class ActionListIcons(StackLayout
):
33 def __init__(self
, **kwargs
):
34 super(ActionListIcons
, self
).__init
__(**kwargs
)
37 def on_parent(self
, instance
, parent
):
38 parent
.bind(action_list
=self
.update_actionlist_icons
)
40 def update_actionlist_icons(self
, instance
, actionlist
):
41 icons_length
= len(self
.icons
)
43 for index
, [icon
, description
] in enumerate(actionlist
):
44 if index
>= icons_length
:
45 icon_label
= ActionListIcon(text
=icon
)
46 self
.add_widget(icon_label
)
47 self
.icons
.append(icon_label
)
49 self
.icons
[index
].text
= icon
51 if index
+1 < icons_length
:
52 self
.clear_widgets(children
=self
.icons
[index
+1:icons_length
])
53 del(self
.icons
[index
+1:icons_length
])
55 class ActionListIcon(Label
):
56 def __init__(self
, text
='', **kwargs
):
57 super(ActionListIcon
, self
).__init
__(**kwargs
)
60 def on_parent(self
, instance
, parent
):
61 if parent
is not None:
62 parent
.bind(font_size
=self
.update_font_size
)
63 parent
.bind(labels_height
=self
.update_height
)
65 def update_height(self
, instance
, height
):
68 def update_font_size(self
, instance
, font_size
):
69 self
.font_size
= font_size
71 class ActionListDescriptions(StackLayout
):
72 def __init__(self
, **kwargs
):
73 super(ActionListDescriptions
, self
).__init
__(**kwargs
)
74 self
.descriptions
= []
76 def on_parent(self
, instance
, parent
):
77 parent
.bind(action_list
=self
.update_actionlist_descriptions
)
79 def update_actionlist_descriptions(self
, instance
, actionlist
):
80 descriptions_length
= len(self
.descriptions
)
82 for index
, [icon
, description
] in enumerate(actionlist
):
83 if index
>= descriptions_length
:
84 description_label
= ActionListDescription(text
=description
)
85 self
.add_widget(description_label
)
86 self
.descriptions
.append(description_label
)
88 self
.descriptions
[index
].text
= description
90 if index
+1 < descriptions_length
:
92 children
=self
.descriptions
[index
+1:descriptions_length
])
93 del(self
.descriptions
[index
+1:descriptions_length
])
95 class ActionListDescription(Label
):
96 def __init__(self
, text
='', **kwargs
):
97 super(ActionListDescription
, self
).__init
__(**kwargs
)
100 def on_parent(self
, instance
, parent
):
101 if parent
is not None:
102 parent
.bind(font_size
=self
.update_font_size
)
103 parent
.bind(labels_height
=self
.update_height
)
105 def update_height(self
, instance
, height
):
108 def update_font_size(self
, instance
, font_size
):
109 self
.font_size
= font_size