Skip to content

Commit

Permalink
Will remember column visibility and add context menu to table header (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
raivisdejus authored Oct 5, 2024
1 parent 6723821 commit 2dbe80f
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion buzz/widgets/transcription_tasks_table_widget.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import enum
import logging
import os
from dataclasses import dataclass
from datetime import datetime, timedelta
Expand All @@ -13,6 +14,7 @@
from PyQt6.QtWidgets import (
QWidget,
QMenu,
QHeaderView,
QTableView,
QAbstractItemView,
QStyledItemDelegate,
Expand Down Expand Up @@ -143,13 +145,37 @@ def format_record_status_text(record: QSqlRecord) -> str:
),
]

class TranscriptionTasksTableHeaderView(QHeaderView):
def __init__(self, orientation, parent=None):
super().__init__(orientation, parent)

def contextMenuEvent(self, event):
menu = QMenu(self)
for definition in column_definitions:
if not definition.hidden_toggleable:
continue
action = menu.addAction(definition.header)
action.setCheckable(True)
action.setChecked(not self.isSectionHidden(definition.column.value))
action.toggled.connect(
lambda checked, column_index=definition.column.value: self.on_column_checked(
column_index, checked
)
)
menu.exec(event.globalPos())

def on_column_checked(self, column_index: int, checked: bool):
self.setSectionHidden(column_index, not checked)
self.parent().save_column_visibility()

class TranscriptionTasksTableWidget(QTableView):
return_clicked = pyqtSignal()

def __init__(self, parent: Optional[QWidget] = None):
super().__init__(parent)

self.setHorizontalHeader(TranscriptionTasksTableHeaderView(Qt.Orientation.Horizontal, self))

self._model = QSqlTableModel()
self._model.setTable("transcription")
self._model.setEditStrategy(QSqlTableModel.EditStrategy.OnManualSubmit)
Expand All @@ -172,7 +198,8 @@ def __init__(self, parent: Optional[QWidget] = None):
definition.header,
)

visible = self.settings.settings.value(definition.id, True)
visible = self.settings.settings.value(definition.id, "true") == "true"

self.setColumnHidden(definition.column.value, not visible)
if definition.width is not None:
self.setColumnWidth(definition.column.value, definition.width)
Expand Down

0 comments on commit 2dbe80f

Please sign in to comment.