Allow the UI to have a widget in the bottom right of the screen

This will be a help button in subiquity soon.
This commit is contained in:
Michael Hudson-Doyle 2019-09-05 12:05:19 +12:00
parent 3f8c005237
commit 3c2fd87e9b
2 changed files with 45 additions and 5 deletions

View File

@ -13,15 +13,22 @@
# 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 logging
from urwid import (
Text,
ProgressBar,
)
from subiquitycore.ui.container import (
Columns,
Pile,
WidgetWrap,
)
from subiquitycore.ui.utils import Padding, Color
from subiquitycore.ui.width import widget_width
log = logging.getLogger('subiquitycore.ui.anchors')
class Header(WidgetWrap):
@ -48,6 +55,36 @@ class StepsProgressBar(ProgressBar):
return "{} / {}".format(self.current, self.done)
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]
class Footer(WidgetWrap):
""" Footer widget
@ -55,10 +92,9 @@ class Footer(WidgetWrap):
"""
def __init__(self, message, current, complete):
def __init__(self, message, right_icon, current, complete):
if isinstance(message, str):
message = Text(message)
message = Padding.center_79(message, min_width=76)
progress_bar = Padding.center_60(
StepsProgressBar(normal='progress_incomplete',
complete='progress_complete',
@ -66,6 +102,6 @@ class Footer(WidgetWrap):
status = [
progress_bar,
Padding.line_break(""),
message,
MyColumns([Text(""), message, Text(""), right_icon]),
]
super().__init__(Color.frame_footer(Pile(status)))

View File

@ -34,9 +34,11 @@ log = logging.getLogger('subiquitycore.ui.frame')
class SubiquityCoreUI(WidgetWrap):
right_icon = Text("")
def __init__(self):
self.header = Header("")
self.footer = Footer("", 0, 1)
self.footer = Footer("", self.right_icon, 0, 1)
self.progress_current = 0
self.progress_completion = 0
# After the install starts, we want to stop setting the footer
@ -58,7 +60,9 @@ class SubiquityCoreUI(WidgetWrap):
def set_footer(self, message):
self._assign_contents(
2,
Footer(message, self.progress_current, self.progress_completion))
Footer(
message, self.right_icon,
self.progress_current, self.progress_completion))
@property
def body(self):