ui: reorder history audio actions and align checkbox column

This commit is contained in:
Ilgiz Kalmetyev 2026-04-10 14:28:02 +05:00
parent abf7e2cc4d
commit b6fd6c2369
2 changed files with 51 additions and 30 deletions

View File

@ -106,9 +106,9 @@ def test_history_dialog_loads_records_and_supports_audio_actions(monkeypatch) ->
assert dialog.transcription_value.toPlainText() == "newer transcript"
assert dialog.history_table.item(0, 0).checkState() == Qt.CheckState.Unchecked
assert dialog.history_table.horizontalHeader().check_state() == Qt.CheckState.Unchecked
assert dialog.history_table.item(0, 6).text() == "Cached"
assert dialog.history_table.cellWidget(0, 8).isEnabled()
assert dialog.history_table.cellWidget(0, 9).isEnabled()
assert dialog.history_table.item(0, 8).text() == "Cached"
assert dialog.history_table.cellWidget(0, 1).isEnabled()
assert dialog.history_table.cellWidget(0, 2).isEnabled()
dialog.history_table.horizontalHeader().sectionClicked.emit(0)
app.processEvents()
@ -131,13 +131,13 @@ def test_history_dialog_loads_records_and_supports_audio_actions(monkeypatch) ->
assert dialog.copy_selected_transcript() is True
assert clipboard.text() == "older transcript"
dialog.history_table.cellWidget(0, 8).click()
dialog.history_table.cellWidget(0, 1).click()
app.processEvents()
assert player.play_calls and player.play_calls[0].name.endswith("newer.wav")
export_path = root / "exports" / "copied.wav"
monkeypatch.setattr(QFileDialog, "getSaveFileName", lambda *args, **kwargs: (str(export_path), "WAV files (*.wav)"))
dialog.history_table.cellWidget(0, 9).click()
dialog.history_table.cellWidget(0, 2).click()
app.processEvents()
assert export_path.exists()
assert export_path.read_bytes() == player.play_calls[0].read_bytes()
@ -190,9 +190,9 @@ def test_history_dialog_disables_audio_buttons_when_cache_missing() -> None:
dialog = HistoryDialog(store, audio_player=FakeAudioPlayer())
assert dialog.history_table.rowCount() == 1
assert dialog.history_table.item(0, 6).text() == "Missing"
assert not dialog.history_table.cellWidget(0, 8).isEnabled()
assert not dialog.history_table.cellWidget(0, 9).isEnabled()
assert dialog.history_table.item(0, 8).text() == "Missing"
assert not dialog.history_table.cellWidget(0, 1).isEnabled()
assert not dialog.history_table.cellWidget(0, 2).isEnabled()
assert dialog.audio_cache_value.text().startswith("Missing:")
dialog.close()

View File

@ -14,7 +14,6 @@ from PySide6.QtWidgets import (
QFormLayout,
QFrame,
QHeaderView,
QHBoxLayout,
QLabel,
QMessageBox,
QPushButton,
@ -24,6 +23,7 @@ from PySide6.QtWidgets import (
QStyleOptionButton,
QTableWidget,
QTableWidgetItem,
QToolButton,
QVBoxLayout,
QWidget,
)
@ -66,7 +66,7 @@ class SelectAllHeaderView(QHeaderView):
option.rect = rect
indicator_rect = self.style().subElementRect(QStyle.SubElement.SE_CheckBoxIndicator, option, self)
indicator_rect.moveCenter(rect.center())
indicator_rect.moveTo(rect.left() + 3, rect.center().y() - indicator_rect.height() // 2)
option.rect = indicator_rect
self.style().drawControl(QStyle.ControlElement.CE_CheckBox, option, painter, self)
@ -125,6 +125,8 @@ class HistoryDialog(QDialog):
self.history_table = QTableWidget(0, 10, self)
self.history_table.setHorizontalHeaderLabels([
"",
"Play",
"Save as",
"Recorded at",
"Model",
"Backend",
@ -132,8 +134,6 @@ class HistoryDialog(QDialog):
"Injection",
"Audio",
"Error",
"Play",
"Save As",
])
self.history_table.setSelectionBehavior(QTableWidget.SelectionBehavior.SelectRows)
self.history_table.setSelectionMode(QTableWidget.SelectionMode.SingleSelection)
@ -144,8 +144,8 @@ class HistoryDialog(QDialog):
header = self.history_table.horizontalHeader()
header.sectionClicked.connect(self._on_header_section_clicked)
header.setSectionResizeMode(0, QHeaderView.ResizeMode.Fixed)
header.resizeSection(0, 42)
header.setSectionResizeMode(8, QHeaderView.ResizeMode.ResizeToContents)
header.setSectionResizeMode(1, QHeaderView.ResizeMode.Fixed)
header.setSectionResizeMode(2, QHeaderView.ResizeMode.Fixed)
header.setSectionResizeMode(9, QHeaderView.ResizeMode.ResizeToContents)
self.history_table.itemChanged.connect(self._sync_checkbox_state_from_table)
self.history_table.itemSelectionChanged.connect(self._sync_selection_from_table)
@ -235,7 +235,11 @@ class HistoryDialog(QDialog):
self._set_record_row(row_index, record)
self.history_table.resizeColumnsToContents()
self.history_table.setColumnWidth(0, 42)
checkbox_width = self.style().pixelMetric(QStyle.PixelMetric.PM_IndicatorWidth, None, self.history_table) + 6
action_button_width = max(self.style().pixelMetric(QStyle.PixelMetric.PM_IndicatorWidth, None, self.history_table) + 18, 32)
self.history_table.setColumnWidth(0, checkbox_width)
self.history_table.setColumnWidth(1, action_button_width)
self.history_table.setColumnWidth(2, action_button_width)
self.history_table.setColumnWidth(8, 90)
self.history_table.setColumnWidth(9, 100)
self.history_table.blockSignals(False)
@ -388,26 +392,32 @@ class HistoryDialog(QDialog):
| Qt.ItemFlag.ItemIsUserCheckable
)
selection_item.setCheckState(Qt.CheckState.Unchecked)
selection_item.setTextAlignment(Qt.AlignmentFlag.AlignCenter)
selection_item.setTextAlignment(Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter)
self.history_table.setItem(row_index, 0, selection_item)
self.history_table.setItem(row_index, 1, QTableWidgetItem(self._format_timestamp(record.timestamp_utc)))
self.history_table.setItem(row_index, 2, QTableWidgetItem(record.selected_model or "-"))
self.history_table.setItem(row_index, 3, QTableWidgetItem(record.effective_backend or "-"))
self.history_table.setItem(row_index, 4, QTableWidgetItem(self._format_duration(record.audio_duration_seconds)))
self.history_table.setItem(row_index, 5, QTableWidgetItem(record.injection_status or "-"))
self.history_table.setItem(row_index, 6, QTableWidgetItem(self._format_audio_cache_status(record)))
self.history_table.setItem(row_index, 7, QTableWidgetItem(record.error_text or ""))
play_button = QPushButton("Play", self.history_table)
play_button = self._create_action_button(
self.style().standardIcon(QStyle.StandardPixmap.SP_MediaPlay),
"Play cached audio",
lambda _checked=False, rec=record: self.play_record_audio(rec),
)
play_button.setEnabled(self._resolve_audio_cache_path(record) is not None)
play_button.clicked.connect(lambda _checked=False, rec=record: self.play_record_audio(rec))
self.history_table.setCellWidget(row_index, 8, play_button)
self.history_table.setCellWidget(row_index, 1, play_button)
save_button = QPushButton("Save As", self.history_table)
save_button = self._create_action_button(
self.style().standardIcon(QStyle.StandardPixmap.SP_DialogSaveButton),
"Save cached audio as...",
lambda _checked=False, rec=record: self.save_record_audio(rec),
)
save_button.setEnabled(self._resolve_audio_cache_path(record) is not None)
save_button.clicked.connect(lambda _checked=False, rec=record: self.save_record_audio(rec))
self.history_table.setCellWidget(row_index, 9, save_button)
self.history_table.setCellWidget(row_index, 2, save_button)
self.history_table.setItem(row_index, 3, QTableWidgetItem(self._format_timestamp(record.timestamp_utc)))
self.history_table.setItem(row_index, 4, QTableWidgetItem(record.selected_model or "-"))
self.history_table.setItem(row_index, 5, QTableWidgetItem(record.effective_backend or "-"))
self.history_table.setItem(row_index, 6, QTableWidgetItem(self._format_duration(record.audio_duration_seconds)))
self.history_table.setItem(row_index, 7, QTableWidgetItem(record.injection_status or "-"))
self.history_table.setItem(row_index, 8, QTableWidgetItem(self._format_audio_cache_status(record)))
self.history_table.setItem(row_index, 9, QTableWidgetItem(record.error_text or ""))
def _sync_selection_from_table(self) -> None:
row = self.history_table.currentRow()
@ -527,3 +537,14 @@ class HistoryDialog(QDialog):
timestamp = record.timestamp_utc.astimezone(timezone.utc).strftime("%Y%m%d_%H%M%S")
record_id = record.id if record.id is not None else "record"
return f"voiceptt_export_{timestamp}_{record_id}.wav"
def _create_action_button(self, icon, tooltip: str, callback) -> QToolButton:
button = QToolButton(self.history_table)
button.setAutoRaise(True)
button.setToolButtonStyle(Qt.ToolButtonStyle.ToolButtonIconOnly)
button.setIcon(icon)
button.setToolTip(tooltip)
button.setAccessibleName(tooltip)
button.setFixedSize(28, 28)
button.clicked.connect(callback)
return button