Add initial start view, buttons, and utilities

Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
This commit is contained in:
Adam Stokes 2015-06-10 16:59:55 -04:00
parent 9f78c2a775
commit 389fdf17cb
14 changed files with 304 additions and 15 deletions

6
Makefile Normal file
View File

@ -0,0 +1,6 @@
#
# Makefile for subiquity
#
ui-view:
PYTHONPATH=$(shell pwd):$(PYTHONPATH) bin/subiquity

34
bin/subiquity Executable file
View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# 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/>.
import urwid
from subiquity.palette import STYLES
from subiquity.views import StartView
def main():
screen = urwid.raw_display.Screen()
screen.set_terminal_properties(256)
screen.register_palette(STYLES)
def unhandled_input(key):
if key in ('Q', 'q', 'esc'):
raise urwid.ExitMainLoop()
urwid.MainLoop(StartView(), screen=screen,
unhandled_input=unhandled_input).run()
if __name__ == '__main__':
main()

18
subiquity/__init__.py Normal file
View File

@ -0,0 +1,18 @@
# 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/>.
""" Subiquity """
__version__ = "0.0.1"

View File

@ -1,4 +1,17 @@
# 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/>.
""" Model Classes

View File

@ -1,4 +1,17 @@
# 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/>.
""" Identity Model

View File

@ -1,4 +1,17 @@
# 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/>.
""" Welcome Model

53
subiquity/palette.py Normal file
View File

@ -0,0 +1,53 @@
# 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/>.
""" Palette Loader """
def apply_default_colors(cls):
color_map = {'orange': '#d51',
'light_orange': '#d81',
'white': 'white',
'black': 'black',
'light_aubergine': '#77216F',
'mid_aubergine': '#5E2750',
'dark_aubergine': '#2C001E',
'warm_grey': '#AEA79F',
'cool_grey': '#333',
'small_dot_grey': '#AEA79F',
'text_grey': '#333'}
for k, v in color_map.items():
setattr(cls, k, v)
return cls
@apply_default_colors
class Palette:
pass
STYLES = [('frame_header', Palette.white, Palette.black,
'default', Palette.white, Palette.orange),
('frame_footer', Palette.white, Palette.black),
('body', Palette.white, 'default', 'default',
Palette.white, Palette.orange),
('button_primary', Palette.white, 'default',
'default', Palette.white, Palette.cool_grey),
('button_primary focus', Palette.white,
'default', 'default', Palette.white,
Palette.light_orange),
('button_secondary', Palette.white, 'default',
'default', Palette.white, Palette.cool_grey),
('button_secondary focus', Palette.white,
'default', 'default', Palette.white, Palette.light_orange)]

View File

@ -1,5 +1,16 @@
# 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/>.
""" Subiquity UI Components """
__version__ = "0.0.1"

View File

@ -1,6 +1,19 @@
# 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 WidgetWrap, AttrWrap, Pile, Text, Columns
from urwid import WidgetWrap, AttrWrap, Pile, Text
class Header(WidgetWrap):
@ -11,11 +24,13 @@ class Header(WidgetWrap):
:param str title: Title of Header
:returns: Header()
"""
def __init__(self, title="Ubuntu Server Installer"):
title = title
title_widget = AttrWrap(Text(title), "frame_header")
title = "Ubuntu Server Installer"
def __init__(self):
title_widget = AttrWrap(Text(self.title), "frame_header")
pile = Pile([title_widget])
super().__init__(Columns(pile))
super().__init__(pile)
class Footer(WidgetWrap):
@ -26,11 +41,14 @@ class Footer(WidgetWrap):
"""
def __init__(self):
status = Pile([Text("")])
super().__init__(Columns(status))
super().__init__(status)
class Body(WidgetWrap):
""" Body widget
"""
def __init__(self):
super().__init__(Text("Welcome to the Server Installation"))
self.text = [
Text("Welcome to the Ubuntu Server Installation", align="center")
]
super().__init__(Pile(self.text))

20
subiquity/ui/buttons.py Normal file
View File

@ -0,0 +1,20 @@
# 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 Button
from functools import partial
confirm_btn = partial(Button, label="Confirm", on_press=None)
cancel_btn = partial(Button, label="Cancel", on_press=None)

View File

@ -1,13 +1,27 @@
# 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/>.
""" Base Frame Widget """
from urwid import Frame, WidgetWrap
from subiquity.ui.anchors import Header, Footer, Body
class Base(WidgetWrap):
def __init__(self, header, body, footer):
self.frame = Frame(body,
header,
footer)
super().__init__(self.frame)
class BaseFrame(WidgetWrap):
def __init__(self):
_frame = Frame(Body(),
Header(),
Footer())
super().__init__(_frame)

24
subiquity/ui/utils.py Normal file
View File

@ -0,0 +1,24 @@
# 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/>.
""" UI utilities """
from urwid import Padding as _Padding
from functools import partialmethod
class Padding:
center = partialmethod(_Padding, align='center',
width=('relative', 50))

52
subiquity/views.py Normal file
View File

@ -0,0 +1,52 @@
# 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 (WidgetWrap, ListBox, AttrWrap, Columns, Text,
# emitters
signals, emit_signal)
from subiquity.ui.anchors import Header, Footer, Body # NOQA
from subiquity.ui.buttons import confirm_btn, cancel_btn
from subiquity.ui.utils import Padding
class StartView(WidgetWrap):
__metaclass__ = signals.MetaSignals
signals = ['done']
def __init__(self):
Header.title = "SUbiquity - Ubiquity for Servers"
self.layout = [
Header(),
Text(""),
Text("Begin the installation", align='center'),
Padding.center(self._build_buttons()),
Footer()
]
super().__init__(ListBox(self.layout))
def _build_buttons(self):
self.buttons = [
AttrWrap(confirm_btn(on_press=self.confirm),
'button_primary', 'button_primary focus'),
AttrWrap(cancel_btn(on_press=self.cancel),
'button_secondary', 'button_secondary focus'),
]
return Columns(self.buttons)
def confirm(self, button):
emit_signal(self, 'done', True)
def cancel(self, button):
emit_signal(self, 'done', False)

0
test/.gitkeep Normal file
View File