Update welcome model to list a few languages

Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
Adam Stokes 2015-06-17 12:47:15 -04:00
parent 1e253a7759
commit f6634c5e4f
3 changed files with 116 additions and 4 deletions

View File

@ -15,6 +15,7 @@
from subiquity.controllers import BaseController
from subiquity.views.welcome import WelcomeView
from subiquity.models.welcome import WelcomeModel
class WelcomeController(BaseController):
@ -22,7 +23,8 @@ class WelcomeController(BaseController):
controller_name = "Welcome to Ubuntu"
def show(self):
return WelcomeView(self.finish)
model = WelcomeModel()
return WelcomeView(model, self.finish)
def finish(self, code, val):
raise SystemExit("Saw res: {}, val: {}".format(code, val))

View File

@ -15,7 +15,7 @@
""" Welcome Model
Welcome model provides user with installation options
Welcome model provides user with language selection
"""
@ -23,7 +23,8 @@ from subiquity import models
class WelcomeModel(models.Model):
""" Model representing installation type
""" Model representing language selection
"""
install_type = None
supported_languages = ['English', 'Belgian', 'German', 'Italian']
selected_language = None

109
subiquity/ui/lists.py Normal file
View File

@ -0,0 +1,109 @@
# 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/>.
from urwid import ListBox, SimpleListWalker, WidgetWrap
class Scrollable:
"""A interface that makes widgets *scrollable*."""
def scroll_up(self):
raise NotImplementedError
def scroll_down(self):
raise NotImplementedError
def scroll_top(self):
raise NotImplementedError
def scroll_bottom(self):
raise NotImplementedError
class ScrollableListBox(ListBox, Scrollable):
"""
A ``urwid.ListBox`` subclass that implements the
:class:`~subiquity.ui.Scrollable` interface.
"""
def __init__(self,
contents,
offset=1):
"""
Arguments:
`contents` is a list with the elements contained in the
`ScrollableListBox`.
`offset` is the number of position that `scroll_up` and `scroll_down`
shift the cursor.
"""
self.offset = offset
ListBox.__init__(self,
SimpleListWalker(contents))
def scroll_up(self):
focus_status, pos = self.get_focus()
if pos is None:
return
new_pos = pos - self.offset
if new_pos < 0:
new_pos = 0
self.set_focus(new_pos)
def scroll_down(self):
focus_status, pos = self.get_focus()
if pos is None:
return
new_pos = pos + self.offset
if new_pos >= len(self.body):
new_pos = len(self.body) - 1
self.set_focus(new_pos)
def scroll_top(self):
if len(self.body):
self.set_focus(0)
def scroll_bottom(self):
last = len(self.body) - 1
if last:
self.set_focus(last)
class ScrollableWidgetWrap(WidgetWrap, Scrollable):
"""
A ``urwid.WidgetWrap`` for :class:`~subiquity.ui.Scrollable`, list-like
widgets.
"""
def __init__(self, contents=None):
columns = [] if contents is None else contents
WidgetWrap.__init__(self, columns)
def scroll_up(self):
self._w.scroll_up()
def scroll_down(self):
self._w.scroll_down()
def scroll_top(self):
self._w.scroll_top()
def scroll_bottom(self):
self._w.scroll_bottom()