GUI: Remove selected samples from the queue
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
from PySide6.QtCore import Signal, Slot
|
||||
from PySide6.QtCore import Signal, Slot, Qt
|
||||
from PySide6.QtWidgets import QFrame, QVBoxLayout, QHBoxLayout, QPushButton, QHeaderView, QSizePolicy, \
|
||||
QTableView
|
||||
from PySide6.QtGui import QKeySequence, QShortcut
|
||||
from aaredaqlib.models import SampleShortInfoList, SampleShortInfo
|
||||
|
||||
from aaregui.models.sample_queue_model import SampleQueueSpreadsheet
|
||||
@@ -39,23 +40,50 @@ class SampleQueuePanel(QFrame):
|
||||
self.table_view.setAcceptDrops(True)
|
||||
self.table_view.setDropIndicatorShown(True)
|
||||
|
||||
# Enable selection of multiple rows
|
||||
self.table_view.setSelectionBehavior(QTableView.SelectionBehavior.SelectRows)
|
||||
|
||||
# Set up keyboard shortcut for delete
|
||||
self.delete_shortcut = QShortcut(QKeySequence.StandardKey.Delete, self.table_view)
|
||||
self.delete_shortcut.activated.connect(self.remove_selected_samples)
|
||||
|
||||
layout.addWidget(self.table_view) # Add table to the layout
|
||||
|
||||
# Create a horizontal layout for the buttons
|
||||
button_layout = QHBoxLayout()
|
||||
self.play_button = QPushButton("▶ Run", self)
|
||||
self.play_button.clicked.connect(self.run)
|
||||
|
||||
self.remove_button = QPushButton("🗑 Remove selected", self)
|
||||
self.remove_button.clicked.connect(self.remove_selected_samples)
|
||||
|
||||
self.clear_button = QPushButton("✖ Clear list", self)
|
||||
self.clear_button.clicked.connect(self.clear)
|
||||
|
||||
self.clear_button.clicked.connect(self.table_model.clearSamples)
|
||||
|
||||
button_layout.addWidget(self.play_button)
|
||||
button_layout.addWidget(self.remove_button)
|
||||
button_layout.addWidget(self.clear_button)
|
||||
|
||||
# Add the button layout to the main layout
|
||||
layout.addLayout(button_layout)
|
||||
|
||||
def remove_selected_samples(self):
|
||||
"""Remove selected samples from the queue."""
|
||||
selected_indexes = self.table_view.selectionModel().selectedRows()
|
||||
if not selected_indexes:
|
||||
return
|
||||
|
||||
# Get the row numbers and sort them in descending order
|
||||
# This ensures we remove from bottom to top to avoid index shifting
|
||||
rows = sorted([index.row() for index in selected_indexes], reverse=True)
|
||||
|
||||
# Remove samples by their database IDs
|
||||
for row in rows:
|
||||
if 0 <= row < len(self.table_model.samples):
|
||||
sample = self.table_model.samples[row]
|
||||
self.table_model.remove_sample(sample.db_id)
|
||||
|
||||
def run(self):
|
||||
if self.__pause:
|
||||
|
||||
Reference in New Issue
Block a user