Make header narrower, move right_icon into header.
This commit is contained in:
parent
d8d5b2e265
commit
a96c5c8805
|
@ -36,6 +36,7 @@ COLORS = [
|
||||||
]
|
]
|
||||||
|
|
||||||
STYLES = [
|
STYLES = [
|
||||||
|
('frame_header_fringe', 'orange', 'bg'),
|
||||||
('frame_header', 'fg', 'orange'),
|
('frame_header', 'fg', 'orange'),
|
||||||
('frame_footer', 'fg', 'brand'),
|
('frame_footer', 'fg', 'brand'),
|
||||||
('body', 'fg', 'bg'),
|
('body', 'fg', 'bg'),
|
||||||
|
|
|
@ -490,7 +490,6 @@ class FilesystemView(BaseView):
|
||||||
if not todos:
|
if not todos:
|
||||||
return None
|
return None
|
||||||
rows = [
|
rows = [
|
||||||
TableRow([Text("")]),
|
|
||||||
TableRow([
|
TableRow([
|
||||||
Text("To continue you need to:"),
|
Text("To continue you need to:"),
|
||||||
Text(todos[0]),
|
Text(todos[0]),
|
||||||
|
@ -498,6 +497,7 @@ class FilesystemView(BaseView):
|
||||||
]
|
]
|
||||||
for todo in todos[1:]:
|
for todo in todos[1:]:
|
||||||
rows.append(TableRow([Text(""), Text(todo)]))
|
rows.append(TableRow([Text(""), Text(todo)]))
|
||||||
|
rows.append(TableRow([Text("")]))
|
||||||
return TablePile(rows)
|
return TablePile(rows)
|
||||||
|
|
||||||
def _build_buttons(self):
|
def _build_buttons(self):
|
||||||
|
|
|
@ -16,8 +16,9 @@
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from urwid import (
|
from urwid import (
|
||||||
|
int_scale,
|
||||||
|
SolidFill,
|
||||||
Text,
|
Text,
|
||||||
ProgressBar,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
from subiquitycore.ui.container import (
|
from subiquitycore.ui.container import (
|
||||||
|
@ -25,83 +26,54 @@ from subiquitycore.ui.container import (
|
||||||
Pile,
|
Pile,
|
||||||
WidgetWrap,
|
WidgetWrap,
|
||||||
)
|
)
|
||||||
from subiquitycore.ui.utils import Padding, Color
|
from subiquitycore.ui.utils import Color
|
||||||
from subiquitycore.ui.width import widget_width
|
from subiquitycore.ui.width import widget_width
|
||||||
|
|
||||||
log = logging.getLogger('subiquitycore.ui.anchors')
|
log = logging.getLogger('subiquitycore.ui.anchors')
|
||||||
|
|
||||||
|
|
||||||
class Header(WidgetWrap):
|
class HeaderColumns(Columns):
|
||||||
""" Header Widget
|
|
||||||
|
|
||||||
This widget uses the style key `frame_header`
|
|
||||||
|
|
||||||
:param str title: Title of Header
|
|
||||||
:returns: Header()
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, title):
|
|
||||||
if isinstance(title, str):
|
|
||||||
title = Text(title)
|
|
||||||
title = Padding.center_79(title, min_width=76)
|
|
||||||
super().__init__(Color.frame_header(
|
|
||||||
Pile(
|
|
||||||
[Text(""), title, Text("")])))
|
|
||||||
|
|
||||||
|
|
||||||
class StepsProgressBar(ProgressBar):
|
|
||||||
|
|
||||||
def get_text(self):
|
|
||||||
return "{} / {}".format(self.current, self.done)
|
|
||||||
|
|
||||||
|
|
||||||
class MyColumns(Columns):
|
|
||||||
# The idea is to render output like this:
|
# The idea is to render output like this:
|
||||||
#
|
#
|
||||||
# message [ help ]
|
# [ pad ][ message ][ btn ][ pad ]
|
||||||
# [ lpad ][ middle ][ rpad ][ right ]
|
|
||||||
#
|
#
|
||||||
# The constraints are:
|
# The constraints are:
|
||||||
#
|
#
|
||||||
# 1. lpad + rpad + right + message = maxcol
|
# 1. pad + message + btn + pad = maxcol
|
||||||
#
|
#
|
||||||
# 2. lpad and rpad are at least 1
|
# 2. pad is at least 1
|
||||||
#
|
#
|
||||||
# 3. right is fixed
|
# 3. btn is fixed
|
||||||
#
|
#
|
||||||
# 4. if possible, lpad = rpad + right and middle is 79% of maxcol
|
# 4. message + btn is 79% of maxcol or 76, whichever is greater.
|
||||||
# or 76, whichever is greater.
|
|
||||||
|
|
||||||
def column_widths(self, size, focus=False):
|
def column_widths(self, size, focus=False):
|
||||||
maxcol = size[0]
|
maxcol = size[0]
|
||||||
right = widget_width(self.contents[3][0])
|
btn = widget_width(self.contents[2][0])
|
||||||
|
|
||||||
center = max(79*maxcol//100, 76)
|
center = max(int_scale(79, 101, maxcol + 1), 76)
|
||||||
lpad = (maxcol - center)//2
|
message = center - btn
|
||||||
rpad = lpad - right
|
pad = (maxcol - center)//2
|
||||||
if rpad < 1:
|
return [pad, message, btn, pad]
|
||||||
rpad = 1
|
|
||||||
middle = maxcol - (lpad + rpad + right)
|
|
||||||
return [lpad, middle, rpad, right]
|
|
||||||
|
|
||||||
|
|
||||||
class Footer(WidgetWrap):
|
class Header(WidgetWrap):
|
||||||
""" Footer widget
|
""" Header Widget """
|
||||||
|
|
||||||
Style key: `frame_footer`
|
def __init__(self, title, right_icon):
|
||||||
|
if isinstance(title, str):
|
||||||
"""
|
title = Text(title)
|
||||||
|
title = HeaderColumns([
|
||||||
def __init__(self, message, right_icon, current, complete):
|
Text(""),
|
||||||
if isinstance(message, str):
|
title,
|
||||||
message = Text(message)
|
right_icon,
|
||||||
progress_bar = Padding.center_60(
|
Text(""),
|
||||||
StepsProgressBar(normal='progress_incomplete',
|
])
|
||||||
complete='progress_complete',
|
super().__init__(
|
||||||
current=current, done=complete))
|
Pile([
|
||||||
status = [
|
(1, Color.frame_header_fringe(
|
||||||
progress_bar,
|
SolidFill("\N{lower half block}"))),
|
||||||
Padding.line_break(""),
|
Color.frame_header(title),
|
||||||
MyColumns([Text(""), message, Text(""), right_icon]),
|
(1, Color.frame_header_fringe(
|
||||||
]
|
SolidFill("\N{upper half block}"))),
|
||||||
super().__init__(Color.frame_footer(Pile(status)))
|
]))
|
||||||
|
|
|
@ -37,7 +37,7 @@ class SubiquityCoreUI(WidgetWrap):
|
||||||
right_icon = Text("")
|
right_icon = Text("")
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.header = Header("")
|
self.header = Header("", self.right_icon)
|
||||||
self.pile = Pile([
|
self.pile = Pile([
|
||||||
('pack', self.header),
|
('pack', self.header),
|
||||||
ListBox([Text("")]),
|
ListBox([Text("")]),
|
||||||
|
@ -48,7 +48,7 @@ class SubiquityCoreUI(WidgetWrap):
|
||||||
self.pile.contents[i] = (w, self.pile.contents[i][1])
|
self.pile.contents[i] = (w, self.pile.contents[i][1])
|
||||||
|
|
||||||
def set_header(self, title=None):
|
def set_header(self, title=None):
|
||||||
self._assign_contents(0, Header(title))
|
self._assign_contents(0, Header(title, self.right_icon))
|
||||||
|
|
||||||
def set_footer(self, message):
|
def set_footer(self, message):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -153,6 +153,7 @@ STYLE_NAMES = set([
|
||||||
'done_button',
|
'done_button',
|
||||||
'frame_footer',
|
'frame_footer',
|
||||||
'frame_header',
|
'frame_header',
|
||||||
|
'frame_header_fringe',
|
||||||
'info_error',
|
'info_error',
|
||||||
'info_minor',
|
'info_minor',
|
||||||
'info_primary',
|
'info_primary',
|
||||||
|
@ -245,11 +246,10 @@ def screen(rows, buttons=None, focus_buttons=True, excerpt=None,
|
||||||
excerpt_rows = []
|
excerpt_rows = []
|
||||||
if excerpt is not None:
|
if excerpt is not None:
|
||||||
excerpt_rows = [
|
excerpt_rows = [
|
||||||
('pack', Text("")),
|
|
||||||
('pack', Text(excerpt)),
|
('pack', Text(excerpt)),
|
||||||
|
('pack', Text("")),
|
||||||
]
|
]
|
||||||
body = [
|
body = [
|
||||||
('pack', Text("")),
|
|
||||||
rows,
|
rows,
|
||||||
('pack', Text("")),
|
('pack', Text("")),
|
||||||
]
|
]
|
||||||
|
@ -260,7 +260,7 @@ def screen(rows, buttons=None, focus_buttons=True, excerpt=None,
|
||||||
])
|
])
|
||||||
pile = Pile(excerpt_rows + body)
|
pile = Pile(excerpt_rows + body)
|
||||||
if focus_buttons:
|
if focus_buttons:
|
||||||
pile.focus_position = len(excerpt_rows) + 3
|
pile.focus_position = len(excerpt_rows) + 2
|
||||||
return Padding.center_79(pile, min_width=76)
|
return Padding.center_79(pile, min_width=76)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue