Merge pull request #296 from CanonicalLtd/mwhudson/shift-tab-fixery

keyboard fixes: show dialog while applying, re-setup shift tab afterwards
This commit is contained in:
Michael Hudson-Doyle 2018-03-14 10:04:35 +13:00 committed by GitHub
commit e1bc2eb45d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 89 additions and 26 deletions

View File

@ -60,7 +60,11 @@ class KeyboardController(BaseController):
self.done(layout, variant)
def done(self, layout, variant):
self.model.set_keyboard(layout, variant)
self.run_in_bg(
lambda: self.model.set_keyboard(layout, variant),
self._done)
def _done(self, fut):
self.signal.emit_signal('next-screen')
def cancel(self):

View File

@ -101,3 +101,6 @@ class KeyboardModel:
fp.write(self.config_content)
if self.root == '/':
run_command(['setupcon', '--save', '--force'])
run_command(['/snap/bin/subiquity.subiquity-loadkeys'])
else:
run_command(['sleep', '1'])

54
subiquity/ui/spinner.py Normal file
View File

@ -0,0 +1,54 @@
# Copyright 2017 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 (
Text,
)
styles = {
'dots': {
'texts': [t.replace('*', '\N{bullet}') for t in ['|*----|', '|-*---|', '|--*--|', '|---*-|', '|----*|', '|---*-|', '|--*--|', '|-*---|']],
'rate': 0.2,
},
'spin': {
'texts': ['-', '\\', '|', '/'],
'rate': 0.1,
},
}
class Spinner(Text):
def __init__(self, loop, style='spin', align='center'):
self.loop = loop
self.spin_index = 0
self.spin_text = styles[style]['texts']
self.rate = styles[style]['rate']
super().__init__('', align=align)
self.handle = None
def _advance(self, sender=None, user_data=None):
self.spin_index = (self.spin_index + 1)%len(self.spin_text)
self.set_text(self.spin_text[self.spin_index])
self.handle = self.loop.set_alarm_in(self.rate, self._advance)
def start(self):
self.stop()
self._advance()
def stop(self):
self.set_text('')
if self.handle is not None:
self.loop.remove_alarm(self.handle)
self.handle = None

View File

@ -25,6 +25,8 @@ from subiquitycore.ui.buttons import cancel_btn, ok_btn, other_btn
from subiquitycore.ui.container import Columns, ListBox, Pile
from subiquitycore.ui.utils import button_pile, Padding
from subiquity.ui.spinner import Spinner
log = logging.getLogger("subiquity.views.installprogress")
class MyLineBox(LineBox):
@ -34,29 +36,6 @@ class MyLineBox(LineBox):
else:
return ""
class Spinner(Text):
def __init__(self, loop):
self.loop = loop
self.spin_index = 0
self.spin_text = r'-\|/'
super().__init__('')
self.handle = None
def _advance(self, sender=None, user_data=None):
self.spin_index = (self.spin_index + 1)%len(self.spin_text)
self.set_text(self.spin_text[self.spin_index])
self.handle = self.loop.set_alarm_in(0.1, self._advance)
def start(self):
self.stop()
self._advance()
def stop(self):
self.set_text('')
if self.handle is not None:
self.loop.remove_alarm(self.handle)
self.handle = None
class ProgressView(BaseView):
def __init__(self, controller):

View File

@ -36,6 +36,7 @@ from subiquitycore.ui.selector import Option, Selector
from subiquitycore.ui.utils import button_pile, Color, Padding
from subiquitycore.view import BaseView
from subiquity.ui.spinner import Spinner
from subiquity.ui.views import pc105
log = logging.getLogger("subiquity.ui.views.keyboard")
@ -249,6 +250,21 @@ class Detector:
self.overlay.start()
self.keyboard_view.show_overlay(self.overlay)
class ApplyingConfig(WidgetWrap):
def __init__(self, loop):
spinner = Spinner(loop, style='dots')
spinner.start()
text = _("Applying config")
# | text |
# 12 34
self.width = len(text) + 4
super().__init__(
LineBox(
Pile([
('pack', Text(' ' + text)),
('pack', spinner),
])))
class ChoiceField(FormField):
@ -333,6 +349,8 @@ class KeyboardView(BaseView):
variant = ''
if self.form.variant.widget.value is not None:
variant = self.form.variant.widget.value
ac = ApplyingConfig(self.controller.loop)
self.show_overlay(ac, width=ac.width, min_width=None)
self.controller.done(layout, variant)
def cancel(self, result=None):

View File

@ -36,13 +36,18 @@ class BaseView(WidgetWrap):
valign='middle',
height='pack'
)
PADDING = 3
# Don't expect callers to account for the padding if they pass a fixed width.
if 'width' in kw:
if isinstance(kw['width'], int):
kw['width'] += 2*PADDING
args.update(kw)
top = Pile([
('pack', Text("")),
Columns([
(3, Text("")),
(PADDING, Text("")),
overlay_widget,
(3, Text(""))
(PADDING, Text(""))
]),
('pack', Text("")),
])