Skip to content

Commit

Permalink
Factor out "insert USB" screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Jul 29, 2020
1 parent ff6ef51 commit b1601bf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/ovshell_fileman/downloadapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ovshell import widget

from .api import ProgressState, AutomountWatcher, Downloader, DownloadFilter, FileInfo
from .usbcurtain import USBStorageCurtain
from .mountwatch import AutomountWatcherImpl
from .downloader import DownloaderImpl

Expand Down Expand Up @@ -74,20 +75,18 @@ def create(self) -> urwid.Widget:
filtstate = self.shell.settings.get("fileman.download_logs.filter", dict) or {}
self.filter = DownloadFilter.fromdict(filtstate)

self._waiting_text = urwid.Text("Please insert USB storage", align="center")
self._waiting_view = urwid.Filler(self._waiting_text, "middle")
self._file_walker = urwid.SimpleFocusListWalker([])
self._app_view = self._create_app_view()

curtain = USBStorageCurtain(self.mountwatcher, self._app_view)
urwid.connect_signal(curtain, "mounted", self._mounted)

self.frame = urwid.Frame(
self._waiting_view, header=widget.ActivityHeader("Download Flight Logs")
curtain, header=widget.ActivityHeader("Download Flight Logs")
)
return self.frame

def activate(self) -> None:
self.mountwatcher.on_mount(self._mounted)
self.mountwatcher.on_unmount(self._unmounted)
self.mountwatcher.on_device_in(self._device_in)
self.mountwatcher.on_device_out(self._device_out)
self.shell.screen.spawn_task(self, self.mountwatcher.run())

def _create_app_view(self) -> urwid.Widget:
Expand All @@ -101,20 +100,10 @@ def _create_app_view(self) -> urwid.Widget:
]
)

def _mounted(self) -> None:
def _mounted(self, wdg) -> None:
self._populate_file_list()
self.frame.set_body(self._app_view)
self._dl_in_progress = {}

def _unmounted(self) -> None:
self.frame.set_body(self._waiting_view)

def _device_in(self) -> None:
self._waiting_text.set_text("Mounting USB storage...")

def _device_out(self) -> None:
self._waiting_text.set_text("Please insert USB storage")

def _make_filter(self) -> urwid.Widget:
options = urwid.GridFlow(
[
Expand Down
37 changes: 37 additions & 0 deletions src/ovshell_fileman/usbcurtain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import urwid

from .api import AutomountWatcher


class USBStorageCurtain(urwid.WidgetWrap):
signals = ["mounted", "unmounted"]

def __init__(
self, mountwatcher: AutomountWatcher, mounted_widget: urwid.Widget
) -> None:
self.mountwatcher = mountwatcher

self._waiting_text = urwid.Text("Please insert USB storage", align="center")
self._waiting_view = urwid.Filler(self._waiting_text, "middle")
self._mounted_widget = mounted_widget

mountwatcher.on_mount(self._mounted)
mountwatcher.on_unmount(self._unmounted)
mountwatcher.on_device_in(self._device_in)
mountwatcher.on_device_out(self._device_out)

super().__init__(self._waiting_view)

def _mounted(self) -> None:
self._w = self._mounted_widget
self._emit("mounted")

def _unmounted(self) -> None:
self._w = self._waiting_view
self._emit("unmounted")

def _device_in(self) -> None:
self._waiting_text.set_text("Mounting USB storage...")

def _device_out(self) -> None:
self._waiting_text.set_text("Please insert USB storage")

0 comments on commit b1601bf

Please sign in to comment.