subiquity/subiquitycore/ui/buttons.py

54 lines
1.7 KiB
Python
Raw Normal View History

2017-09-15 20:47:12 +00:00
# Copyright 2017 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2017-09-15 20:47:12 +00:00
from urwid import AttrMap, Button, Text
def _stylized_button(left, right, style):
2017-09-15 20:47:12 +00:00
class Btn(Button):
button_left = Text(left)
button_right = Text(right)
2017-09-15 20:47:12 +00:00
class StyleAttrMap(AttrMap):
def __init__(self, label, on_press=None, user_arg=None):
btn = Btn(label, on_press=on_press, user_data=user_arg)
2018-06-25 22:19:57 +00:00
btn._w.contents[2] = (
btn._w.contents[2][0],
btn._w.options('given', len(right)))
2017-09-15 20:47:12 +00:00
super().__init__(btn, style + '_button', style + '_button focus')
return StyleAttrMap
def action_button(style):
return _stylized_button('[', ']', style)
2018-06-25 22:19:57 +00:00
_forward_rhs = "\N{BLACK RIGHT-POINTING SMALL TRIANGLE} ]"
menu_btn = _stylized_button("[", _forward_rhs, "menu")
forward_btn = _stylized_button("[", _forward_rhs, "done")
2017-11-22 00:28:08 +00:00
done_btn = action_button("done")
danger_btn = action_button("danger")
other_btn = action_button("other")
2017-09-14 23:04:38 +00:00
2017-11-22 00:28:08 +00:00
ok_btn = done_btn
2017-09-14 23:04:38 +00:00
2017-11-22 00:28:08 +00:00
delete_btn = danger_btn
back_btn = other_btn
cancel_btn = other_btn
reset_btn = other_btn