| 76 | |
| 77 | |
| 78 | class LoadingScreen(BaseScreen[ValueT]): |
| 79 | CSS = """ |
| 80 | LoadingScreen { |
| 81 | align: center middle; |
| 82 | background: transparent; |
| 83 | } |
| 84 | |
| 85 | .content-container { |
| 86 | width: 1fr; |
| 87 | height: 1fr; |
| 88 | max-height: 100%; |
| 89 | |
| 90 | margin-top: 2; |
| 91 | margin-bottom: 2; |
| 92 | |
| 93 | background: transparent; |
| 94 | } |
| 95 | |
| 96 | LoadingIndicator { |
| 97 | align: center middle; |
| 98 | } |
| 99 | """ |
| 100 | |
| 101 | def __init__( |
| 102 | self, |
| 103 | timer: int = 3, |
| 104 | data_callback: Callable[[], Any] | None = None, |
| 105 | header: str | None = None, |
| 106 | ): |
| 107 | super().__init__() |
| 108 | self._timer = timer |
| 109 | self._header = header |
| 110 | self._data_callback = data_callback |
| 111 | |
| 112 | async def run(self) -> Result[ValueT]: |
| 113 | assert TApp.app |
| 114 | return await TApp.app.show(self) |
| 115 | |
| 116 | @override |
| 117 | def compose(self) -> ComposeResult: |
| 118 | with Vertical(classes='content-container'): |
| 119 | if self._header: |
| 120 | with Center(): |
| 121 | yield Label(self._header, classes='header', id='loading_header') |
| 122 | |
| 123 | yield Center(LoadingIndicator()) |
| 124 | |
| 125 | yield Footer() |
| 126 | |
| 127 | def on_mount(self) -> None: |
| 128 | _translate_bindings(self._merged_bindings, self._bindings) |
| 129 | if self._data_callback: |
| 130 | self._exec_callback() |
| 131 | else: |
| 132 | self.set_timer(self._timer, self.action_pop_screen) |
| 133 | |
| 134 | self._set_cursor() |
| 135 |
no outgoing calls
no test coverage detected