argos-cli 0.3.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- argos/__init__.py +5 -0
- argos/__main__.py +4 -0
- argos/adapters/__init__.py +9 -0
- argos/adapters/_libreoffice_worker.py +111 -0
- argos/adapters/ai.py +1506 -0
- argos/adapters/ai_remote.py +654 -0
- argos/adapters/attachment_conversion.py +132 -0
- argos/adapters/capabilities.py +31 -0
- argos/adapters/chart_render.py +72 -0
- argos/adapters/docx_pdf.py +2953 -0
- argos/adapters/limesurvey.py +1079 -0
- argos/adapters/model_call.py +274 -0
- argos/adapters/report_publication.py +1530 -0
- argos/adapters/url_fetch.py +146 -0
- argos/adapters/xlsx.py +454 -0
- argos/analytics.py +731 -0
- argos/assets.py +257 -0
- argos/audit_result.py +369 -0
- argos/booleans.py +105 -0
- argos/catalog.py +1205 -0
- argos/cli.py +606 -0
- argos/contracts.py +532 -0
- argos/core.py +325 -0
- argos/default_skills/README.md +23 -0
- argos/default_skills/criar-matriz-planejamento/SKILL.md +200 -0
- argos/default_skills/elaborar-survey-limesurvey/SKILL.md +106 -0
- argos/default_skills/operar-argos/SKILL.md +74 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/SKILL.md +129 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/assets/relatorio-avaliacao.md +54 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/contrato-saidas.md +36 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/papeis-das-pastas.md +37 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/references/roteiro-verificacoes.md +27 -0
- argos/default_skills/verificar-diretrizes-fiscalizacao/scripts/avaliacao.py +253 -0
- argos/engines/__init__.py +3 -0
- argos/engines/adjustments.py +571 -0
- argos/engines/analytics.py +195 -0
- argos/engines/audit.py +2730 -0
- argos/engines/evaluation.py +6088 -0
- argos/engines/index.py +1683 -0
- argos/engines/matrix.py +5736 -0
- argos/engines/matrix_html.py +698 -0
- argos/engines/model_request.py +201 -0
- argos/engines/report_document.py +137 -0
- argos/engines/reports.py +1200 -0
- argos/engines/survey.py +4445 -0
- argos/envfile.py +53 -0
- argos/errors.py +29 -0
- argos/evidence_staging.py +293 -0
- argos/executions.py +565 -0
- argos/findings_matrix.py +2549 -0
- argos/fingerprints.py +487 -0
- argos/index_dsl.py +2100 -0
- argos/matrix_markdown.py +475 -0
- argos/matrix_widths.py +280 -0
- argos/pipeline.py +1745 -0
- argos/products.py +220 -0
- argos/progress.py +221 -0
- argos/project.py +608 -0
- argos/report_config.py +158 -0
- argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_ACHADOS.md +539 -0
- argos/resources/ESPECIFICACAO_MARKDOWN_MATRIZ_PLANEJAMENTO.md +1000 -0
- argos/resources/ESPECIFICACAO_UNIFICADA_MATRIZES_V1_3.md +1142 -0
- argos/resources/anexo-evidencias-base.docx +0 -0
- argos/resources/argos-index-dsl-v1.schema.json +539 -0
- argos/resources/argos-report-config-v1.schema.json +113 -0
- argos/resources/diretrizes-projeto.md +476 -0
- argos/resources/env.example +37 -0
- argos/resources/exemplos/matriz_achados_boilerplate.md +61 -0
- argos/resources/exemplos/matriz_achados_draft.md +106 -0
- argos/resources/exemplos/matriz_achados_larguras_v1_3.md +114 -0
- argos/resources/exemplos/matriz_achados_v1_3.md +107 -0
- argos/resources/exemplos/matriz_planejamento_boilerplate.md +64 -0
- argos/resources/exemplos/matriz_planejamento_larguras_v1_3.md +115 -0
- argos/resources/exemplos/matriz_planejamento_v1_3.md +108 -0
- argos/resources/template-base-estilos-sigiloso.docx +0 -0
- argos/resources/template-base-estilos.docx +0 -0
- argos/resources/template-matriz-planejamento.docx +0 -0
- argos/resources/template-relatorio-consolidado-comum.docx +0 -0
- argos/resources/template-relatorio-consolidado-institucional.docx +0 -0
- argos/response_profiles.py +856 -0
- argos/scheduler.py +142 -0
- argos/status.py +367 -0
- argos/store.py +1228 -0
- argos/survey_collection.py +832 -0
- argos/telemetry.py +84 -0
- argos/tui.py +1262 -0
- argos/tui.tcss +827 -0
- argos/tui_models.py +466 -0
- argos/tui_path.py +155 -0
- argos/tui_widgets.py +482 -0
- argos/version.py +3 -0
- argos_cli-0.3.1.dist-info/METADATA +570 -0
- argos_cli-0.3.1.dist-info/RECORD +96 -0
- argos_cli-0.3.1.dist-info/WHEEL +5 -0
- argos_cli-0.3.1.dist-info/entry_points.txt +2 -0
- argos_cli-0.3.1.dist-info/top_level.txt +1 -0
argos/tui_widgets.py
ADDED
|
@@ -0,0 +1,482 @@
|
|
|
1
|
+
"""Widgets reutilizáveis da home Textual do Argos."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Iterable
|
|
6
|
+
|
|
7
|
+
from textual.app import ComposeResult
|
|
8
|
+
from textual.containers import Grid, Horizontal, Vertical
|
|
9
|
+
from textual.message import Message
|
|
10
|
+
from textual.widget import Widget
|
|
11
|
+
from textual.widgets import Button, Label, ProgressBar, Static
|
|
12
|
+
|
|
13
|
+
from .tui_models import AREA_ANALYSIS, AREA_EXECUTION, AREA_OTHER, AREA_PLANNING, AREA_REPORT, AuditSnapshot, AuditStage, OperationDirectory, OperationView, OPERATION_AREAS, format_date
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class HeaderBar(Static):
|
|
17
|
+
def __init__(self, version: str, **kwargs) -> None:
|
|
18
|
+
super().__init__("", markup=False, id="header-bar", **kwargs)
|
|
19
|
+
self.version = version
|
|
20
|
+
|
|
21
|
+
def set_state(self, snapshot: AuditSnapshot, status: str) -> None:
|
|
22
|
+
audit = f"{snapshot.number} · {snapshot.name}" if snapshot.loaded else "nenhuma auditoria carregada"
|
|
23
|
+
self.update(f"ARGOS v{self.version} AUDITORIA: {audit} STATUS: {status}")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ArgosBrandPanel(Widget):
|
|
27
|
+
def compose(self) -> ComposeResult:
|
|
28
|
+
yield Static(" | | |\n |-+-|\n | | |", id="brand-logo", markup=False)
|
|
29
|
+
yield Static("ARGOS", id="brand-name", markup=False)
|
|
30
|
+
yield Static(
|
|
31
|
+
"Argos é sua central de auditorias.\n"
|
|
32
|
+
"Planeje, execute e acompanhe cada etapa\n"
|
|
33
|
+
"com clareza e rastreabilidade.",
|
|
34
|
+
id="brand-copy",
|
|
35
|
+
markup=False,
|
|
36
|
+
)
|
|
37
|
+
with Vertical(id="brand-actions"):
|
|
38
|
+
yield Button("Nova auditoria [N]", id="action-new", classes="nav-action")
|
|
39
|
+
yield Button("Abrir auditoria [A]", id="action-open", classes="nav-action")
|
|
40
|
+
yield Button("Recentes [R]", id="action-recent", classes="nav-action")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class CurrentAuditPanel(Widget):
|
|
44
|
+
"""Painel compacto com somente a identidade da auditoria."""
|
|
45
|
+
|
|
46
|
+
def compose(self) -> ComposeResult:
|
|
47
|
+
yield Static("INFORMAÇÕES", classes="panel-title", markup=False)
|
|
48
|
+
yield Static("Nenhuma auditoria carregada.", id="audit-empty", markup=False)
|
|
49
|
+
with Vertical(id="audit-loaded"):
|
|
50
|
+
yield Static("Número do processo: —", id="audit-number", markup=False)
|
|
51
|
+
yield Static("Nome : —", id="audit-name", markup=False)
|
|
52
|
+
|
|
53
|
+
def set_snapshot(self, snapshot: AuditSnapshot) -> None:
|
|
54
|
+
empty = self.query_one("#audit-empty", Static)
|
|
55
|
+
loaded = self.query_one("#audit-loaded", Vertical)
|
|
56
|
+
empty.display = not snapshot.loaded
|
|
57
|
+
loaded.display = snapshot.loaded
|
|
58
|
+
if not snapshot.loaded:
|
|
59
|
+
return
|
|
60
|
+
self.query_one("#audit-number", Static).update(f"Número do processo: {snapshot.number or '—'}")
|
|
61
|
+
self.query_one("#audit-name", Static).update(f"Nome : {snapshot.name or '—'}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class AuditStageWidget(Static):
|
|
65
|
+
class Selected(Message):
|
|
66
|
+
def __init__(self, stage: AuditStage, stage_index: int) -> None:
|
|
67
|
+
super().__init__()
|
|
68
|
+
self.stage = stage
|
|
69
|
+
self.stage_index = stage_index
|
|
70
|
+
|
|
71
|
+
can_focus = False
|
|
72
|
+
|
|
73
|
+
def __init__(self, stage: AuditStage, position: int, stage_index: int, **kwargs) -> None:
|
|
74
|
+
super().__init__("", markup=False, classes="stage-widget", **kwargs)
|
|
75
|
+
self.stage = stage
|
|
76
|
+
self.position = position
|
|
77
|
+
self.stage_index = stage_index
|
|
78
|
+
self._render_stage()
|
|
79
|
+
|
|
80
|
+
def update_stage(self, stage: AuditStage) -> None:
|
|
81
|
+
self.stage = stage
|
|
82
|
+
self._render_stage()
|
|
83
|
+
|
|
84
|
+
def _render_stage(self) -> None:
|
|
85
|
+
labels = {
|
|
86
|
+
"completed": "[OK] Concluída",
|
|
87
|
+
"current": "[RUN] Em andamento",
|
|
88
|
+
"pending": "[ ] Pendente",
|
|
89
|
+
"blocked": "[BLOCK] Bloqueada",
|
|
90
|
+
"error": "[ERR] Erro",
|
|
91
|
+
"outdated": "[STALE] Desatualizada",
|
|
92
|
+
"review": "[REVIEW] Revisão humana",
|
|
93
|
+
}
|
|
94
|
+
for status in ("completed", "current", "pending", "blocked", "error", "outdated", "review"):
|
|
95
|
+
self.remove_class(f"stage-{status}")
|
|
96
|
+
self.add_class(f"stage-{self.stage.status}")
|
|
97
|
+
detail = self.stage.detail
|
|
98
|
+
if self.stage.completed_at:
|
|
99
|
+
detail = f"{detail}\n{format_date(self.stage.completed_at)}"
|
|
100
|
+
elif self.stage.progress is not None:
|
|
101
|
+
detail = f"{detail}\n{self.stage.progress}%"
|
|
102
|
+
self.update(f"{self.position}. {self.stage.title}\n\n{labels.get(self.stage.status, '[ ] Pendente')}\n{detail}")
|
|
103
|
+
|
|
104
|
+
def on_click(self) -> None:
|
|
105
|
+
workflow = self.screen.query_one(AuditWorkflow)
|
|
106
|
+
workflow.activate_stage(self.stage_index)
|
|
107
|
+
self.post_message(self.Selected(self.stage, self.stage_index))
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
class AuditWorkflow(Widget):
|
|
111
|
+
def __init__(self, stages: Iterable[AuditStage] = (), **kwargs) -> None:
|
|
112
|
+
super().__init__(**kwargs)
|
|
113
|
+
self.stages = tuple(stages)
|
|
114
|
+
self._stage_widgets: list[AuditStageWidget] = []
|
|
115
|
+
self._focus_index = 0
|
|
116
|
+
|
|
117
|
+
def compose(self) -> ComposeResult:
|
|
118
|
+
yield Static("FLUXO DA AUDITORIA", classes="panel-title", markup=False)
|
|
119
|
+
with Horizontal(id="workflow-summary"):
|
|
120
|
+
yield Static("Progresso", classes="workflow-progress-title", markup=False)
|
|
121
|
+
yield ProgressBar(
|
|
122
|
+
total=100,
|
|
123
|
+
show_percentage=False,
|
|
124
|
+
show_eta=False,
|
|
125
|
+
id="workflow-progress",
|
|
126
|
+
)
|
|
127
|
+
yield Static("—", id="workflow-progress-label", markup=False)
|
|
128
|
+
with Horizontal(id="workflow-stages"):
|
|
129
|
+
for position, stage in enumerate(self.stages, start=1):
|
|
130
|
+
if position > 1:
|
|
131
|
+
yield Static("->", classes="stage-connector", markup=False)
|
|
132
|
+
yield AuditStageWidget(stage, position, position - 1)
|
|
133
|
+
|
|
134
|
+
def on_mount(self) -> None:
|
|
135
|
+
self._stage_widgets = list(self.query(AuditStageWidget))
|
|
136
|
+
self._render_active_stage()
|
|
137
|
+
|
|
138
|
+
def set_snapshot(self, snapshot: AuditSnapshot) -> None:
|
|
139
|
+
self.stages = snapshot.stages
|
|
140
|
+
if not self._stage_widgets:
|
|
141
|
+
self._stage_widgets = list(self.query(AuditStageWidget))
|
|
142
|
+
for widget, stage in zip(self._stage_widgets, snapshot.stages):
|
|
143
|
+
widget.update_stage(stage)
|
|
144
|
+
progress = self.query_one("#workflow-progress", ProgressBar)
|
|
145
|
+
label = self.query_one("#workflow-progress-label", Static)
|
|
146
|
+
if snapshot.progress is None:
|
|
147
|
+
progress.display = False
|
|
148
|
+
label.update("—")
|
|
149
|
+
else:
|
|
150
|
+
progress.display = True
|
|
151
|
+
progress.update(progress=snapshot.progress)
|
|
152
|
+
label.update(f"{snapshot.progress}%")
|
|
153
|
+
|
|
154
|
+
def _render_active_stage(self) -> None:
|
|
155
|
+
for index, widget in enumerate(self._stage_widgets):
|
|
156
|
+
widget.set_class(index == self._focus_index, "stage-active")
|
|
157
|
+
|
|
158
|
+
def select_stage(self, index: int, *, focus_operations: bool = True) -> None:
|
|
159
|
+
if not self._stage_widgets:
|
|
160
|
+
return
|
|
161
|
+
self._focus_index = index % len(self._stage_widgets)
|
|
162
|
+
self._render_active_stage()
|
|
163
|
+
dashboard = self.screen.query_one(OperationsDashboard)
|
|
164
|
+
dashboard.set_active_stage(self._focus_index)
|
|
165
|
+
if focus_operations:
|
|
166
|
+
if not dashboard.focus_for_stage(self._focus_index, 0):
|
|
167
|
+
dashboard.focus()
|
|
168
|
+
|
|
169
|
+
def move_stage(self, delta: int) -> None:
|
|
170
|
+
if not self._stage_widgets:
|
|
171
|
+
return
|
|
172
|
+
self.select_stage(self._focus_index + delta)
|
|
173
|
+
|
|
174
|
+
def activate_stage(self, index: int) -> None:
|
|
175
|
+
self.select_stage(index)
|
|
176
|
+
|
|
177
|
+
def focus_operation(self, stage_index: int, delta: int) -> None:
|
|
178
|
+
self.select_stage(stage_index, focus_operations=False)
|
|
179
|
+
self._focus_operations(stage_index, delta)
|
|
180
|
+
|
|
181
|
+
def _focus_operations(self, stage_index: int, delta: int) -> None:
|
|
182
|
+
dashboard = self.screen.query_one(OperationsDashboard)
|
|
183
|
+
dashboard.set_active_stage(stage_index)
|
|
184
|
+
dashboard.focus_for_stage(stage_index, delta)
|
|
185
|
+
|
|
186
|
+
def focus_current(self) -> None:
|
|
187
|
+
if not self._stage_widgets:
|
|
188
|
+
return
|
|
189
|
+
current = next(
|
|
190
|
+
(index for index, widget in enumerate(self._stage_widgets) if widget.stage.status == "current"),
|
|
191
|
+
0,
|
|
192
|
+
)
|
|
193
|
+
self.select_stage(current)
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class OperationItem(Widget):
|
|
197
|
+
class Selected(Message):
|
|
198
|
+
def __init__(self, operation: OperationView) -> None:
|
|
199
|
+
super().__init__()
|
|
200
|
+
self.operation = operation
|
|
201
|
+
|
|
202
|
+
can_focus = True
|
|
203
|
+
|
|
204
|
+
def __init__(self, operation: OperationView | None, **kwargs) -> None:
|
|
205
|
+
super().__init__(classes="operation-item", **kwargs)
|
|
206
|
+
self.operation = operation
|
|
207
|
+
|
|
208
|
+
def compose(self) -> ComposeResult:
|
|
209
|
+
yield Label("", id="operation-id", classes="operation-id")
|
|
210
|
+
yield Label("", id="operation-name", classes="operation-name")
|
|
211
|
+
yield Static("", id="operation-description", classes="operation-description", markup=False)
|
|
212
|
+
|
|
213
|
+
def on_mount(self) -> None:
|
|
214
|
+
self._render_operation()
|
|
215
|
+
|
|
216
|
+
def update_operation(self, operation: OperationView | None) -> None:
|
|
217
|
+
self.operation = operation
|
|
218
|
+
if self.is_mounted:
|
|
219
|
+
self._render_operation()
|
|
220
|
+
|
|
221
|
+
def _render_operation(self) -> None:
|
|
222
|
+
enabled = self.operation is not None
|
|
223
|
+
self.display = enabled
|
|
224
|
+
self.can_focus = enabled
|
|
225
|
+
self.query_one("#operation-id", Label).update(self.operation.id if enabled else "")
|
|
226
|
+
self.query_one("#operation-name", Label).update(self.operation.name if enabled else "")
|
|
227
|
+
self.query_one("#operation-description", Static).update(self.operation.description if enabled else "")
|
|
228
|
+
|
|
229
|
+
def on_click(self) -> None:
|
|
230
|
+
if self.operation is None:
|
|
231
|
+
return
|
|
232
|
+
self.focus()
|
|
233
|
+
self.post_message(self.Selected(self.operation))
|
|
234
|
+
|
|
235
|
+
def on_key(self, event) -> None:
|
|
236
|
+
if self.operation is None:
|
|
237
|
+
event.stop()
|
|
238
|
+
return
|
|
239
|
+
if event.key in {"enter", "space"}:
|
|
240
|
+
self.post_message(self.Selected(self.operation))
|
|
241
|
+
event.stop()
|
|
242
|
+
return
|
|
243
|
+
panel = self.screen.query_one(OperationsDashboard).panel_for_item(self)
|
|
244
|
+
if panel is None:
|
|
245
|
+
return
|
|
246
|
+
if event.key in {"up", "down"}:
|
|
247
|
+
panel.focus_relative(-1 if event.key == "up" else 1)
|
|
248
|
+
event.stop()
|
|
249
|
+
elif event.key in {"left", "right"}:
|
|
250
|
+
workflow = self.screen.query_one(AuditWorkflow)
|
|
251
|
+
workflow.move_stage(-1 if event.key == "left" else 1)
|
|
252
|
+
event.stop()
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
class OperationCategoryPanel(Widget):
|
|
256
|
+
def __init__(
|
|
257
|
+
self,
|
|
258
|
+
area: str,
|
|
259
|
+
directory: OperationDirectory,
|
|
260
|
+
*,
|
|
261
|
+
current_phase: str | None = None,
|
|
262
|
+
**kwargs,
|
|
263
|
+
) -> None:
|
|
264
|
+
key = _area_key(area)
|
|
265
|
+
super().__init__(id=f"category-{key}", classes="operation-category", **kwargs)
|
|
266
|
+
self.area = area
|
|
267
|
+
self.directory = directory
|
|
268
|
+
self.current_phase = current_phase
|
|
269
|
+
self._items = directory.prioritized(area)
|
|
270
|
+
self._slots: list[OperationItem] = []
|
|
271
|
+
self._window_start = 0
|
|
272
|
+
self._selected_index = 0
|
|
273
|
+
self._more_focused = False
|
|
274
|
+
self._more_button: Button | None = None
|
|
275
|
+
self._active = False
|
|
276
|
+
|
|
277
|
+
def compose(self) -> ComposeResult:
|
|
278
|
+
with Horizontal(classes="category-heading"):
|
|
279
|
+
yield Static(_area_marker(self.area), classes="category-marker", markup=False)
|
|
280
|
+
yield Static(self.area.upper(), classes="category-title", markup=False)
|
|
281
|
+
if not self._items:
|
|
282
|
+
yield Static("Nenhuma operação disponível.", classes="category-empty", markup=False)
|
|
283
|
+
else:
|
|
284
|
+
with Vertical(id=f"window-{_area_key(self.area)}", classes="operation-window"):
|
|
285
|
+
for index in range(3):
|
|
286
|
+
item = self._items[index] if index < len(self._items) else None
|
|
287
|
+
operation_item = OperationItem(item)
|
|
288
|
+
self._slots.append(operation_item)
|
|
289
|
+
yield operation_item
|
|
290
|
+
if len(self._items) > 3:
|
|
291
|
+
remaining = len(self._items) - 3
|
|
292
|
+
self._more_button = Button(
|
|
293
|
+
f"[ ... +{remaining} outras ]",
|
|
294
|
+
id=f"more-{_area_key(self.area)}",
|
|
295
|
+
name=self.area,
|
|
296
|
+
classes="more-operations",
|
|
297
|
+
)
|
|
298
|
+
yield self._more_button
|
|
299
|
+
|
|
300
|
+
def on_mount(self) -> None:
|
|
301
|
+
self._render_window()
|
|
302
|
+
|
|
303
|
+
def set_context(self, current_phase: str | None) -> None:
|
|
304
|
+
self.current_phase = current_phase
|
|
305
|
+
self.set_active(False)
|
|
306
|
+
|
|
307
|
+
def set_active(self, active: bool) -> None:
|
|
308
|
+
self._active = active
|
|
309
|
+
if not active:
|
|
310
|
+
self._more_focused = False
|
|
311
|
+
self.set_class(active, "category-current")
|
|
312
|
+
self.set_class(not active, "category-secondary")
|
|
313
|
+
for item in self._slots:
|
|
314
|
+
item.can_focus = active and item.operation is not None
|
|
315
|
+
if self._more_button is not None:
|
|
316
|
+
self._more_button.can_focus = active
|
|
317
|
+
|
|
318
|
+
def _render_window(self) -> None:
|
|
319
|
+
for slot, offset in zip(self._slots, range(3)):
|
|
320
|
+
index = self._window_start + offset
|
|
321
|
+
slot.update_operation(self._items[index] if index < len(self._items) else None)
|
|
322
|
+
slot.set_class(index == self._selected_index and self._active, "operation-selected")
|
|
323
|
+
slot.can_focus = self._active and slot.operation is not None
|
|
324
|
+
if self._more_button is not None:
|
|
325
|
+
self._more_button.can_focus = self._active
|
|
326
|
+
self._more_button.set_class(self._more_focused and self._active, "more-selected")
|
|
327
|
+
|
|
328
|
+
def focus_relative(self, delta: int) -> bool:
|
|
329
|
+
if not self._items:
|
|
330
|
+
return False
|
|
331
|
+
if delta > 0 and self._more_focused:
|
|
332
|
+
return True
|
|
333
|
+
if delta < 0 and self._more_focused:
|
|
334
|
+
self._more_focused = False
|
|
335
|
+
self._render_window()
|
|
336
|
+
self._slots[self._selected_index - self._window_start].focus()
|
|
337
|
+
return True
|
|
338
|
+
if delta > 0 and self._selected_index >= len(self._items) - 1:
|
|
339
|
+
return self.focus_more() or self._focus_selected()
|
|
340
|
+
self._selected_index = max(
|
|
341
|
+
0,
|
|
342
|
+
min(len(self._items) - 1, self._selected_index + delta),
|
|
343
|
+
)
|
|
344
|
+
if self._selected_index < self._window_start:
|
|
345
|
+
self._window_start = self._selected_index
|
|
346
|
+
elif self._selected_index >= self._window_start + 3:
|
|
347
|
+
self._window_start = self._selected_index - 2
|
|
348
|
+
return self._focus_selected()
|
|
349
|
+
|
|
350
|
+
def _focus_selected(self) -> bool:
|
|
351
|
+
self._more_focused = False
|
|
352
|
+
self._render_window()
|
|
353
|
+
slot_index = self._selected_index - self._window_start
|
|
354
|
+
self._slots[slot_index].focus()
|
|
355
|
+
return True
|
|
356
|
+
|
|
357
|
+
def focus_more(self) -> bool:
|
|
358
|
+
if self._more_button is None:
|
|
359
|
+
return False
|
|
360
|
+
self._more_focused = True
|
|
361
|
+
self._render_window()
|
|
362
|
+
self._more_button.focus()
|
|
363
|
+
return True
|
|
364
|
+
|
|
365
|
+
def focus_first(self) -> bool:
|
|
366
|
+
self._selected_index = 0
|
|
367
|
+
self._window_start = 0
|
|
368
|
+
self._more_focused = False
|
|
369
|
+
self._render_window()
|
|
370
|
+
if not self._items:
|
|
371
|
+
return False
|
|
372
|
+
self._slots[0].focus()
|
|
373
|
+
return True
|
|
374
|
+
|
|
375
|
+
def focus_last(self) -> bool:
|
|
376
|
+
self._selected_index = max(0, len(self._items) - 1)
|
|
377
|
+
self._window_start = max(0, self._selected_index - 2)
|
|
378
|
+
self._more_focused = False
|
|
379
|
+
self._render_window()
|
|
380
|
+
if not self._items:
|
|
381
|
+
return False
|
|
382
|
+
self._slots[self._selected_index - self._window_start].focus()
|
|
383
|
+
return True
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
class OperationsDashboard(Widget):
|
|
387
|
+
can_focus = True
|
|
388
|
+
|
|
389
|
+
def __init__(self, directory: OperationDirectory, **kwargs) -> None:
|
|
390
|
+
super().__init__(**kwargs)
|
|
391
|
+
self.directory = directory
|
|
392
|
+
self.current_phase: str | None = None
|
|
393
|
+
self.active_stage_index = 0
|
|
394
|
+
|
|
395
|
+
def compose(self) -> ComposeResult:
|
|
396
|
+
yield Static("OPERAÇÕES DISPONÍVEIS", classes="panel-title", markup=False)
|
|
397
|
+
yield Static(
|
|
398
|
+
"←/→ etapas ↑/↓ operações ENTER configura / catálogo completo",
|
|
399
|
+
id="operations-context",
|
|
400
|
+
markup=False,
|
|
401
|
+
)
|
|
402
|
+
with Grid(id="operations-grid"):
|
|
403
|
+
for area in OPERATION_AREAS:
|
|
404
|
+
yield OperationCategoryPanel(area, self.directory, current_phase=self.current_phase)
|
|
405
|
+
|
|
406
|
+
def on_mount(self) -> None:
|
|
407
|
+
self.set_context(self.current_phase)
|
|
408
|
+
|
|
409
|
+
def on_key(self, event) -> None:
|
|
410
|
+
workflow = self.screen.query_one(AuditWorkflow)
|
|
411
|
+
if event.key in {"left", "right"}:
|
|
412
|
+
workflow.move_stage(-1 if event.key == "left" else 1)
|
|
413
|
+
event.stop()
|
|
414
|
+
elif event.key in {"up", "down"}:
|
|
415
|
+
self.focus_for_stage(self.active_stage_index, -1 if event.key == "up" else 1)
|
|
416
|
+
event.stop()
|
|
417
|
+
|
|
418
|
+
def set_context(self, current_phase: str | None) -> None:
|
|
419
|
+
self.current_phase = current_phase
|
|
420
|
+
phase_to_stage = {
|
|
421
|
+
"Planejamento": 0,
|
|
422
|
+
"Coleta de dados": 1,
|
|
423
|
+
"Análise": 2,
|
|
424
|
+
"Achados": 3,
|
|
425
|
+
"Relatório": 4,
|
|
426
|
+
"Encerramento": 5,
|
|
427
|
+
}
|
|
428
|
+
self.set_active_stage(phase_to_stage.get(current_phase or "", 0))
|
|
429
|
+
context = self.query_one("#operations-context", Static)
|
|
430
|
+
if current_phase:
|
|
431
|
+
context.update(f"Fase em destaque: {current_phase}. Use ↑/↓ para escolher uma operação.")
|
|
432
|
+
|
|
433
|
+
def set_active_stage(self, stage_index: int) -> None:
|
|
434
|
+
self.active_stage_index = stage_index
|
|
435
|
+
active_area = _stage_area(stage_index)
|
|
436
|
+
for panel in self.query(OperationCategoryPanel):
|
|
437
|
+
panel.set_active(panel.area == active_area)
|
|
438
|
+
|
|
439
|
+
def focus_for_stage(self, stage_index: int, delta: int) -> bool:
|
|
440
|
+
self.set_active_stage(stage_index)
|
|
441
|
+
panel = self.query_one(
|
|
442
|
+
f"#category-{_area_key(_stage_area(stage_index))}",
|
|
443
|
+
OperationCategoryPanel,
|
|
444
|
+
)
|
|
445
|
+
return panel.focus_last() if delta < 0 else panel.focus_first()
|
|
446
|
+
|
|
447
|
+
def panel_for_item(self, item: OperationItem) -> OperationCategoryPanel | None:
|
|
448
|
+
for panel in self.query(OperationCategoryPanel):
|
|
449
|
+
if item in panel._slots:
|
|
450
|
+
return panel
|
|
451
|
+
return None
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
def _stage_area(stage_index: int) -> str:
|
|
455
|
+
return (
|
|
456
|
+
AREA_PLANNING,
|
|
457
|
+
AREA_EXECUTION,
|
|
458
|
+
AREA_ANALYSIS,
|
|
459
|
+
AREA_ANALYSIS,
|
|
460
|
+
AREA_REPORT,
|
|
461
|
+
AREA_OTHER,
|
|
462
|
+
)[max(0, min(stage_index, 5))]
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
def _area_key(area: str) -> str:
|
|
466
|
+
return {
|
|
467
|
+
AREA_PLANNING: "planejamento",
|
|
468
|
+
AREA_EXECUTION: "execucao",
|
|
469
|
+
AREA_ANALYSIS: "analise",
|
|
470
|
+
AREA_REPORT: "relatorio",
|
|
471
|
+
AREA_OTHER: "outros",
|
|
472
|
+
}.get(area, "outros")
|
|
473
|
+
|
|
474
|
+
|
|
475
|
+
def _area_marker(area: str) -> str:
|
|
476
|
+
return {
|
|
477
|
+
AREA_PLANNING: "[+]",
|
|
478
|
+
AREA_EXECUTION: "[>]",
|
|
479
|
+
AREA_ANALYSIS: "[#]",
|
|
480
|
+
AREA_REPORT: "[=]",
|
|
481
|
+
AREA_OTHER: "[?]",
|
|
482
|
+
}.get(area, "[?]")
|
argos/version.py
ADDED