Merge pull request #1511 from mwhudson/spinner-no-loop
rewrite Spinner to not require a loop parameter
This commit is contained in:
commit
09defa104b
|
@ -91,7 +91,7 @@ class DriversView(BaseView):
|
||||||
def make_waiting(self, install: bool) -> None:
|
def make_waiting(self, install: bool) -> None:
|
||||||
""" Change the view into a spinner and start waiting for drivers
|
""" Change the view into a spinner and start waiting for drivers
|
||||||
asynchronously. """
|
asynchronously. """
|
||||||
self.spinner = Spinner(self.controller.app.aio_loop, style='dots')
|
self.spinner = Spinner(style='dots')
|
||||||
self.spinner.start()
|
self.spinner.start()
|
||||||
|
|
||||||
if self.local_only:
|
if self.local_only:
|
||||||
|
|
|
@ -181,7 +181,7 @@ class ErrorReportStretchy(Stretchy):
|
||||||
for n, b in self.btns.items():
|
for n, b in self.btns.items():
|
||||||
self.btns[n] = Padding(b, width=w, align='center')
|
self.btns[n] = Padding(b, width=w, align='center')
|
||||||
|
|
||||||
self.spinner = Spinner(app.aio_loop, style='dots')
|
self.spinner = Spinner(style='dots')
|
||||||
self.pile = Pile([])
|
self.pile = Pile([])
|
||||||
self.pile.contents[:] = [
|
self.pile.contents[:] = [
|
||||||
(w, self.pile.options('pack')) for w in self._pile_elements()]
|
(w, self.pile.options('pack')) for w in self._pile_elements()]
|
||||||
|
|
|
@ -42,7 +42,7 @@ class SlowProbing(BaseView):
|
||||||
|
|
||||||
def __init__(self, controller):
|
def __init__(self, controller):
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.spinner = Spinner(aio_loop=controller.app.aio_loop, style="dots")
|
self.spinner = Spinner(style="dots")
|
||||||
self.spinner.start()
|
self.spinner.start()
|
||||||
super().__init__(screen(
|
super().__init__(screen(
|
||||||
[
|
[
|
||||||
|
|
|
@ -100,7 +100,7 @@ class ProgressView(BaseView):
|
||||||
def event_start(self, context_id, context_parent_id, message):
|
def event_start(self, context_id, context_parent_id, message):
|
||||||
self.event_finish(context_parent_id)
|
self.event_finish(context_parent_id)
|
||||||
walker = self.event_listbox.base_widget.body
|
walker = self.event_listbox.base_widget.body
|
||||||
spinner = Spinner(self.controller.app.aio_loop)
|
spinner = Spinner()
|
||||||
spinner.start()
|
spinner.start()
|
||||||
new_line = Columns([
|
new_line = Columns([
|
||||||
('pack', Text(message)),
|
('pack', Text(message)),
|
||||||
|
|
|
@ -139,7 +139,7 @@ class RefreshView(BaseView):
|
||||||
def __init__(self, controller):
|
def __init__(self, controller):
|
||||||
self.controller = controller
|
self.controller = controller
|
||||||
self.check_task = None
|
self.check_task = None
|
||||||
self.spinner = Spinner(self.controller.app.aio_loop, style="dots")
|
self.spinner = Spinner(style="dots")
|
||||||
|
|
||||||
if self.controller.status.availability == RefreshCheckState.UNKNOWN:
|
if self.controller.status.availability == RefreshCheckState.UNKNOWN:
|
||||||
self.check_state_checking()
|
self.check_state_checking()
|
||||||
|
|
|
@ -366,7 +366,7 @@ class SnapListView(BaseView):
|
||||||
self.loaded(data)
|
self.loaded(data)
|
||||||
|
|
||||||
def wait_load(self):
|
def wait_load(self):
|
||||||
spinner = Spinner(self.controller.app.aio_loop, style='dots')
|
spinner = Spinner(style='dots')
|
||||||
spinner.start()
|
spinner.start()
|
||||||
self._w = screen(
|
self._w = screen(
|
||||||
[spinner], [ok_btn(label=_("Continue"), on_press=self.done)],
|
[spinner], [ok_btn(label=_("Continue"), on_press=self.done)],
|
||||||
|
|
|
@ -157,7 +157,7 @@ class SSHForm(Form):
|
||||||
class FetchingSSHKeys(WidgetWrap):
|
class FetchingSSHKeys(WidgetWrap):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
spinner = Spinner(parent.controller.app.aio_loop, style='dots')
|
spinner = Spinner(style='dots')
|
||||||
spinner.start()
|
spinner.start()
|
||||||
text = _("Fetching SSH keys...")
|
text = _("Fetching SSH keys...")
|
||||||
button = cancel_btn(label=_("Cancel"), on_press=self.cancel)
|
button = cancel_btn(label=_("Cancel"), on_press=self.cancel)
|
||||||
|
|
|
@ -261,7 +261,7 @@ class CheckingContractToken(WidgetWrap):
|
||||||
def __init__(self, parent: BaseView):
|
def __init__(self, parent: BaseView):
|
||||||
""" Initializes the loading animation widget. """
|
""" Initializes the loading animation widget. """
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
spinner = Spinner(parent.controller.app.aio_loop, style="dots")
|
spinner = Spinner(style="dots")
|
||||||
spinner.start()
|
spinner.start()
|
||||||
text = _("Checking Ubuntu Pro subscription...")
|
text = _("Checking Ubuntu Pro subscription...")
|
||||||
button = cancel_btn(label=_("Cancel"), on_press=self.cancel)
|
button = cancel_btn(label=_("Cancel"), on_press=self.cancel)
|
||||||
|
|
|
@ -196,8 +196,7 @@ class TuiApplication(Application):
|
||||||
|
|
||||||
def show_load():
|
def show_load():
|
||||||
nonlocal ld
|
nonlocal ld
|
||||||
ld = LoadingDialog(
|
ld = LoadingDialog(self.ui.body, message, task_to_cancel)
|
||||||
self.ui.body, self.aio_loop, message, task_to_cancel)
|
|
||||||
self.ui.body.show_overlay(ld, width=ld.width)
|
self.ui.body.show_overlay(ld, width=ld.width)
|
||||||
|
|
||||||
def hide_load():
|
def hide_load():
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
# You should have received a copy of the GNU Affero General Public License
|
# 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/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import asyncio
|
||||||
|
|
||||||
from urwid import (
|
from urwid import (
|
||||||
Text,
|
Text,
|
||||||
)
|
)
|
||||||
|
@ -32,28 +34,28 @@ styles = {
|
||||||
|
|
||||||
|
|
||||||
class Spinner(Text):
|
class Spinner(Text):
|
||||||
def __init__(self, aio_loop=None, style='spin', align='center'):
|
def __init__(self, style='spin', align='center'):
|
||||||
self.aio_loop = aio_loop
|
|
||||||
self.spin_index = 0
|
self.spin_index = 0
|
||||||
self.spin_text = styles[style]['texts']
|
self.spin_text = styles[style]['texts']
|
||||||
self.rate = styles[style]['rate']
|
self.rate = styles[style]['rate']
|
||||||
super().__init__('', align=align)
|
super().__init__('', align=align)
|
||||||
self.handle = None
|
self._spin_task = None
|
||||||
|
|
||||||
def spin(self):
|
def spin(self):
|
||||||
self.spin_index = (self.spin_index + 1) % len(self.spin_text)
|
self.spin_index = (self.spin_index + 1) % len(self.spin_text)
|
||||||
self.set_text(self.spin_text[self.spin_index])
|
self.set_text(self.spin_text[self.spin_index])
|
||||||
|
|
||||||
def _advance(self):
|
async def _spin(self):
|
||||||
self.spin()
|
while True:
|
||||||
self.handle = self.aio_loop.call_later(self.rate, self._advance)
|
self.spin()
|
||||||
|
await asyncio.sleep(self.rate)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
self.stop()
|
self.stop()
|
||||||
self._advance()
|
self._spin_task = asyncio.create_task(self._spin())
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.set_text('')
|
self.set_text('')
|
||||||
if self.handle is not None:
|
if self._spin_task is not None:
|
||||||
self.handle.cancel()
|
self._spin_task.cancel()
|
||||||
self.handle = None
|
self._spin_task = None
|
||||||
|
|
|
@ -367,9 +367,9 @@ class SomethingFailed(Stretchy):
|
||||||
|
|
||||||
class LoadingDialog(WidgetWrap):
|
class LoadingDialog(WidgetWrap):
|
||||||
|
|
||||||
def __init__(self, parent, aio_loop, msg, task_to_cancel):
|
def __init__(self, parent, msg, task_to_cancel):
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
self.spinner = Spinner(aio_loop, style='dots')
|
self.spinner = Spinner(style='dots')
|
||||||
self.spinner.start()
|
self.spinner.start()
|
||||||
self.closed = False
|
self.closed = False
|
||||||
# | text |
|
# | text |
|
||||||
|
|
|
@ -168,8 +168,7 @@ class NetworkDeviceTable(WidgetWrap):
|
||||||
address_info.extend(
|
address_info.extend(
|
||||||
[(label, Text(addr)) for addr in addrs])
|
[(label, Text(addr)) for addr in addrs])
|
||||||
elif dhcp_status.state == DHCPState.PENDING:
|
elif dhcp_status.state == DHCPState.PENDING:
|
||||||
s = Spinner(
|
s = Spinner(align='left')
|
||||||
self.parent.controller.app.aio_loop, align='left')
|
|
||||||
s.rate = 0.3
|
s.rate = 0.3
|
||||||
s.start()
|
s.start()
|
||||||
address_info.append((label, s))
|
address_info.append((label, s))
|
||||||
|
@ -339,7 +338,7 @@ class NetworkView(BaseView):
|
||||||
)
|
)
|
||||||
|
|
||||||
def show_apply_spinner(self):
|
def show_apply_spinner(self):
|
||||||
s = Spinner(self.controller.app.aio_loop)
|
s = Spinner()
|
||||||
s.start()
|
s.start()
|
||||||
c = TablePile([
|
c = TablePile([
|
||||||
TableRow([
|
TableRow([
|
||||||
|
|
Loading…
Reference in New Issue