Skip to content

Commit 6cc737f

Browse files
author
Nejc Stebe
committed
add paused state to progress items in TUI
1 parent ddcef52 commit 6cc737f

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

tui/components.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,12 @@ class ProgressItem(Vertical):
135135
PROCESSING = "PROCESSING"
136136
COMPLETED = "COMPLETED"
137137
STOPPED = "STOPPED"
138+
PAUSED = "PAUSED"
138139

139140
def __init__(self, initial_text: str, **kwargs):
140141
super().__init__(**kwargs)
141142
self.initial_text = initial_text
143+
self.current_status = self.PENDING
142144

143145
def compose(self):
144146
# Main row with status and description
@@ -156,11 +158,14 @@ def _get_status_text(self, status: str) -> str:
156158
return "◉ processing"
157159
elif status == self.STOPPED:
158160
return "◼ stopped"
161+
elif status == self.PAUSED:
162+
return "⏸ paused"
159163
else:
160164
return "○ pending"
161165

162166
async def update_status(self, status: str):
163167
# TODO: Move to plain2code_tui.py
168+
self.current_status = status
164169
try:
165170
# Get the main row container
166171
main_row = self.query_one(f"#{self.id}-main-row", Horizontal)

tui/plain2code_tui.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import threading
12
from typing import Callable, Optional
23

34
from textual.app import App, ComposeResult
@@ -18,7 +19,7 @@
1819
RenderStateUpdated,
1920
)
2021
from render_machine.states import States
21-
from tui.widget_helpers import log_to_widget
22+
from tui.widget_helpers import log_to_widget, set_frid_progress_to_paused
2223

2324
from .components import (
2425
CustomFooter,
@@ -120,7 +121,15 @@ def get_active_script_types(self) -> list[ScriptOutputType]:
120121

121122
def on_mount(self) -> None:
122123
"""Called when the app is mounted."""
123-
self.event_bus.register_dispatch_wrapper(self.call_from_thread)
124+
main_thread_id = threading.get_ident()
125+
126+
def dispatch_wrapper(fn):
127+
if threading.get_ident() == main_thread_id:
128+
fn()
129+
else:
130+
self.call_from_thread(fn)
131+
132+
self.event_bus.register_dispatch_wrapper(dispatch_wrapper)
124133

125134
self.event_bus.subscribe(RenderStateUpdated, self.on_render_state_updated)
126135
self.event_bus.subscribe(RenderCompleted, self.on_render_completed)
@@ -275,6 +284,7 @@ async def action_copy_selection(self) -> None:
275284
def action_pause(self) -> None:
276285
"""Handle ctrl+shift+p: request the render machine to pause."""
277286
if not self._render_finished:
287+
set_frid_progress_to_paused(self)
278288
self.event_bus.publish(PauseRequested())
279289

280290
def action_enter_exit(self) -> None:

tui/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ TestScriptsContainer {
194194
background: #c77777;
195195
}
196196

197+
.status.PAUSED {
198+
color: #fff;
199+
background: #5b8bf5;
200+
}
201+
197202
.description {
198203
margin-left: 1;
199204
}

tui/widget_helpers.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,23 @@ def set_frid_progress_to_stopped(tui):
124124
clear_progress_item_substates(tui, widget_id)
125125

126126

127+
def set_frid_progress_to_paused(tui):
128+
progress_ids = [
129+
TUIComponents.FRID_PROGRESS_RENDER_FR.value,
130+
TUIComponents.FRID_PROGRESS_UNIT_TEST.value,
131+
TUIComponents.FRID_PROGRESS_REFACTORING.value,
132+
TUIComponents.FRID_PROGRESS_CONFORMANCE_TEST.value,
133+
]
134+
135+
for widget_id in progress_ids:
136+
try:
137+
widget = tui.query_one(f"#{widget_id}", ProgressItem)
138+
if widget.current_status == ProgressItem.PROCESSING:
139+
update_progress_item_status(tui, widget_id, ProgressItem.PAUSED)
140+
except Exception:
141+
pass
142+
143+
127144
def display_error_message(tui, error_message: str):
128145
widget: Static = tui.query_one(f"#{TUIComponents.RENDER_STATUS_WIDGET.value}", Static)
129146
widget.add_class("error")

0 commit comments

Comments
 (0)