2015-06-09 03:40:41 +00:00
|
|
|
# Copyright 2015 Canonical, Ltd.
|
2015-06-10 20:59:55 +00:00
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
2019-09-05 00:05:19 +00:00
|
|
|
import logging
|
|
|
|
|
2018-06-21 21:38:18 +00:00
|
|
|
from urwid import (
|
|
|
|
Text,
|
|
|
|
ProgressBar,
|
|
|
|
)
|
2019-09-05 00:05:19 +00:00
|
|
|
|
2018-06-21 21:38:18 +00:00
|
|
|
from subiquitycore.ui.container import (
|
2019-09-05 00:05:19 +00:00
|
|
|
Columns,
|
2018-06-21 21:38:18 +00:00
|
|
|
Pile,
|
|
|
|
WidgetWrap,
|
|
|
|
)
|
2016-06-30 18:17:01 +00:00
|
|
|
from subiquitycore.ui.utils import Padding, Color
|
2019-09-05 00:05:19 +00:00
|
|
|
from subiquitycore.ui.width import widget_width
|
|
|
|
|
|
|
|
log = logging.getLogger('subiquitycore.ui.anchors')
|
2015-06-09 03:40:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Header(WidgetWrap):
|
|
|
|
""" Header Widget
|
|
|
|
|
|
|
|
This widget uses the style key `frame_header`
|
|
|
|
|
|
|
|
:param str title: Title of Header
|
|
|
|
:returns: Header()
|
|
|
|
"""
|
2015-06-10 20:59:55 +00:00
|
|
|
|
2018-05-18 04:27:05 +00:00
|
|
|
def __init__(self, title):
|
2019-02-05 00:55:17 +00:00
|
|
|
if isinstance(title, str):
|
|
|
|
title = Text(title)
|
|
|
|
title = Padding.center_79(title, min_width=76)
|
|
|
|
super().__init__(Color.frame_header(
|
|
|
|
Pile(
|
|
|
|
[Text(""), title, Text("")])))
|
2015-06-09 03:40:41 +00:00
|
|
|
|
|
|
|
|
2017-09-26 13:01:22 +00:00
|
|
|
class StepsProgressBar(ProgressBar):
|
|
|
|
|
|
|
|
def get_text(self):
|
|
|
|
return "{} / {}".format(self.current, self.done)
|
|
|
|
|
2018-05-22 16:41:43 +00:00
|
|
|
|
2019-09-05 00:05:19 +00:00
|
|
|
class MyColumns(Columns):
|
|
|
|
# The idea is to render output like this:
|
|
|
|
#
|
|
|
|
# message [ help ]
|
|
|
|
# [ lpad ][ middle ][ rpad ][ right ]
|
|
|
|
#
|
|
|
|
# The constraints are:
|
|
|
|
#
|
|
|
|
# 1. lpad + rpad + right + message = maxcol
|
|
|
|
#
|
|
|
|
# 2. lpad and rpad are at least 1
|
|
|
|
#
|
|
|
|
# 3. right is fixed
|
|
|
|
#
|
|
|
|
# 4. if possible, lpad = rpad + right and middle is 79% of maxcol
|
|
|
|
# or 76, whichever is greater.
|
|
|
|
|
|
|
|
def column_widths(self, size, focus=False):
|
|
|
|
maxcol = size[0]
|
|
|
|
right = widget_width(self.contents[3][0])
|
|
|
|
|
|
|
|
center = max(79*maxcol//100, 76)
|
|
|
|
lpad = (maxcol - center)//2
|
|
|
|
rpad = lpad - right
|
|
|
|
if rpad < 1:
|
|
|
|
rpad = 1
|
|
|
|
middle = maxcol - (lpad + rpad + right)
|
|
|
|
return [lpad, middle, rpad, right]
|
|
|
|
|
|
|
|
|
2015-06-09 03:40:41 +00:00
|
|
|
class Footer(WidgetWrap):
|
|
|
|
""" Footer widget
|
|
|
|
|
|
|
|
Style key: `frame_footer`
|
|
|
|
|
|
|
|
"""
|
2015-06-16 23:16:40 +00:00
|
|
|
|
2019-09-05 00:05:19 +00:00
|
|
|
def __init__(self, message, right_icon, current, complete):
|
2018-02-23 01:52:03 +00:00
|
|
|
if isinstance(message, str):
|
2019-02-04 03:17:58 +00:00
|
|
|
message = Text(message)
|
2015-08-31 15:55:46 +00:00
|
|
|
progress_bar = Padding.center_60(
|
2017-09-26 13:01:22 +00:00
|
|
|
StepsProgressBar(normal='progress_incomplete',
|
|
|
|
complete='progress_complete',
|
|
|
|
current=current, done=complete))
|
2017-01-13 02:08:17 +00:00
|
|
|
status = [
|
2017-09-26 13:01:22 +00:00
|
|
|
progress_bar,
|
2015-08-31 15:55:46 +00:00
|
|
|
Padding.line_break(""),
|
2019-09-05 00:05:19 +00:00
|
|
|
MyColumns([Text(""), message, Text(""), right_icon]),
|
2017-01-13 02:08:17 +00:00
|
|
|
]
|
2017-09-07 10:47:56 +00:00
|
|
|
super().__init__(Color.frame_footer(Pile(status)))
|