2015-06-10 20:59:55 +00:00
|
|
|
# Copyright 2015 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/>.
|
|
|
|
|
2015-07-21 15:55:02 +00:00
|
|
|
""" Welcome
|
|
|
|
|
|
|
|
Welcome provides user with language selection
|
|
|
|
|
|
|
|
"""
|
|
|
|
import logging
|
2015-10-29 20:58:51 +00:00
|
|
|
from urwid import (ListBox, Pile, BoxAdapter)
|
2016-06-30 18:17:01 +00:00
|
|
|
from subiquitycore.ui.lists import SimpleList
|
|
|
|
from subiquitycore.ui.buttons import menu_btn, ok_btn, cancel_btn
|
|
|
|
from subiquitycore.ui.utils import Padding, Color
|
|
|
|
from subiquitycore.view import ViewPolicy
|
2015-06-10 20:59:55 +00:00
|
|
|
|
2016-06-30 18:17:01 +00:00
|
|
|
log = logging.getLogger("subiquitycore.views.welcome")
|
2015-07-21 15:55:02 +00:00
|
|
|
|
2015-06-10 20:59:55 +00:00
|
|
|
|
2015-07-23 02:31:21 +00:00
|
|
|
class WelcomeView(ViewPolicy):
|
2015-07-21 15:55:02 +00:00
|
|
|
def __init__(self, model, signal):
|
2015-06-17 16:48:32 +00:00
|
|
|
self.model = model
|
2015-07-21 15:55:02 +00:00
|
|
|
self.signal = signal
|
2015-06-17 16:48:32 +00:00
|
|
|
self.items = []
|
2016-06-22 19:19:54 +00:00
|
|
|
#Padding.center_50(self._build_model_inputs()),
|
2015-06-23 16:40:10 +00:00
|
|
|
self.body = [
|
2015-06-23 16:48:37 +00:00
|
|
|
Padding.line_break(""),
|
2015-11-19 21:24:40 +00:00
|
|
|
Padding.fixed_10(self._build_buttons())
|
2015-06-10 20:59:55 +00:00
|
|
|
]
|
2015-06-23 16:40:10 +00:00
|
|
|
super().__init__(ListBox(self.body))
|
2015-06-10 20:59:55 +00:00
|
|
|
|
|
|
|
def _build_buttons(self):
|
|
|
|
self.buttons = [
|
2016-06-22 19:19:54 +00:00
|
|
|
Color.button(ok_btn(on_press=self.confirm),
|
2015-08-24 15:51:10 +00:00
|
|
|
focus_map='button focus'),
|
2015-06-10 20:59:55 +00:00
|
|
|
]
|
2015-06-16 23:17:04 +00:00
|
|
|
return Pile(self.buttons)
|
2015-06-10 20:59:55 +00:00
|
|
|
|
2015-06-17 16:48:32 +00:00
|
|
|
def _build_model_inputs(self):
|
2015-06-22 15:15:44 +00:00
|
|
|
sl = []
|
2015-07-22 01:34:46 +00:00
|
|
|
for lang in self.model.get_menu():
|
2015-08-24 15:51:10 +00:00
|
|
|
sl.append(Color.menu_button(
|
|
|
|
menu_btn(label=lang, on_press=self.confirm),
|
|
|
|
focus_map="menu_button focus"))
|
2015-06-22 15:15:44 +00:00
|
|
|
|
|
|
|
return BoxAdapter(SimpleList(sl),
|
|
|
|
height=len(sl))
|
2015-06-17 16:48:32 +00:00
|
|
|
|
2015-07-21 21:04:28 +00:00
|
|
|
def confirm(self, result):
|
|
|
|
self.model.selected_language = result.label
|
2016-06-23 20:27:09 +00:00
|
|
|
log.debug('calling installpath')
|
|
|
|
self.signal.emit_signal('menu:installpath:main')
|
2015-10-29 20:58:51 +00:00
|
|
|
|
2015-06-10 20:59:55 +00:00
|
|
|
def cancel(self, button):
|
2015-07-21 21:04:28 +00:00
|
|
|
raise SystemExit("No language selected, exiting as there are no "
|
|
|
|
"more previous controllers to render.")
|