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
8 __all__
= ["ActionList",
9 "ActionListIcons", "ActionListIcon",
10 "ActionListDescriptions", "ActionListDescription"]
12 class ActionList(RelativeLayout
):
13 action_title
= StringProperty("")
14 action_list
= ListProperty([])
16 def update_list(self
, key
, action_descriptions
):
17 self
.action_title
= "actions linked to key {}:".format(key
.key_sym
)
20 for [action
, status
] in action_descriptions
:
23 elif status
== "current":
27 action_list
.append([icon
, action
])
28 self
.action_list
= action_list
30 class ActionListIcons(StackLayout
):
31 def __init__(self
, **kwargs
):
32 super(ActionListIcons
, self
).__init
__(**kwargs
)
35 def on_parent(self
, instance
, parent
):
36 parent
.bind(action_list
=self
.update_actionlist_icons
)
38 def update_actionlist_icons(self
, instance
, actionlist
):
39 for icon
in self
.icons
:
40 self
.remove_widget(icon
)
42 for icon
, description
in actionlist
:
43 icon_label
= ActionListIcon(text
=icon
)
44 self
.add_widget(icon_label
)
45 self
.icons
.append(icon_label
)
47 class ActionListIcon(Label
):
48 def __init__(self
, text
='', **kwargs
):
49 super(ActionListIcon
, self
).__init
__(**kwargs
)
52 def on_parent(self
, instance
, parent
):
53 if parent
is not None:
54 self
.font_size
= math
.ceil(2 * math
.sqrt(parent
.parent
.parent
.key_size
))
55 self
.height
= parent
.parent
.labels_height
57 class ActionListDescriptions(StackLayout
):
58 def __init__(self
, **kwargs
):
59 super(ActionListDescriptions
, self
).__init
__(**kwargs
)
60 self
.descriptions
= []
62 def on_parent(self
, instance
, parent
):
63 parent
.bind(action_list
=self
.update_actionlist_descriptions
)
65 def update_actionlist_descriptions(self
, instance
, actionlist
):
66 for description
in self
.descriptions
:
67 self
.remove_widget(description
)
68 self
.descriptions
= []
69 for icon
, description
in actionlist
:
70 description_label
= ActionListDescription(text
=description
)
71 self
.add_widget(description_label
)
72 self
.descriptions
.append(description_label
)
74 class ActionListDescription(Label
):
75 def __init__(self
, text
='', **kwargs
):
76 super(ActionListDescription
, self
).__init
__(**kwargs
)
79 def on_parent(self
, instance
, parent
):
80 if parent
is not None:
81 self
.font_size
= math
.ceil(2 * math
.sqrt(parent
.parent
.parent
.key_size
))
82 self
.height
= parent
.parent
.labels_height