Skip to content

Commit

Permalink
Display a message when starting and finishing XCSoar
Browse files Browse the repository at this point in the history
  • Loading branch information
kedder committed Jun 29, 2020
1 parent 65caeac commit 2e09f54
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/ovshell/protocol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,21 @@ class Dialog(Protocol):
def add_button(self, label: str, handler: Callable[[], bool]) -> None:
pass

@abstractmethod
def no_buttons(self) -> None:
pass


class IndicatorLocation(enum.Enum):
LEFT = "left"
RIGHT = "right"


class ScreenManager(Protocol):
@abstractmethod
def draw(self) -> None:
pass

@abstractmethod
def push_activity(
self, activity: Activity, palette: Optional[List[Tuple]] = None
Expand Down
6 changes: 6 additions & 0 deletions src/ovshell/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def _create_layout(self) -> urwid.Widget:
footer=urwid.AttrMap(self._footer, "bg"),
)

def draw(self) -> None:
self._mainloop.draw_screen()

def push_activity(self, activity: Activity, palette: List[Tuple] = None) -> None:
self._hide_shown_activity()

Expand Down Expand Up @@ -303,6 +306,9 @@ def add_button(self, label: str, handler: Callable[[], bool]) -> None:
self.buttons.contents = contents
self.custom_buttons = True

def no_buttons(self) -> None:
self.buttons.contents = []

def _on_button_clicked(
self, handler: Callable[[], bool], btn: urwid.Widget
) -> None:
Expand Down
6 changes: 6 additions & 0 deletions src/ovshell/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ def __init__(self, title: str, content: urwid.Widget):
def add_button(self, label: str, handler: Callable[[], bool]) -> None:
self.buttons[label] = handler

def no_buttons(self) -> None:
self.buttons = {}

def stub_press_button(self, label: str):
return self.buttons[label]()

Expand All @@ -90,6 +93,9 @@ def __init__(self, log: List[str]) -> None:
self._dialog = None
self._indicators = {}

def draw(self) -> None:
self._log.append("Screen redrawn")

def push_activity(
self, activity: protocol.Activity, palette: Optional[List[Tuple]] = None
) -> None:
Expand Down
12 changes: 10 additions & 2 deletions src/ovshell_xcsoar/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,16 @@ def launch(self) -> None:
align="center", width=("relative", 90), valign="middle", height="pack",
)
try:
completed = subprocess.run(cmdline, capture_output=True, env=env)
self.shell.os.sync()
message = urwid.Text("Running XCSoar...")
self.shell.screen.push_dialog("XCSoar", message).no_buttons()
self.shell.screen.draw()
try:
completed = subprocess.run(cmdline, capture_output=True, env=env)
finally:
message.set_text("Finishing XCSoar...")
self.shell.screen.draw()
self.shell.os.sync()
self.shell.screen.pop_activity()
except FileNotFoundError as e:
self.shell.screen.push_modal(
AppOutputActivity(self.shell, str(e)), modal_opts
Expand Down

0 comments on commit 2e09f54

Please sign in to comment.