Added moving of events.

This commit is contained in:
jupfi 2023-07-30 14:02:19 +02:00
parent 6df745452b
commit 916a9c1bf2
2 changed files with 79 additions and 5 deletions

View file

@ -24,7 +24,7 @@ class PulseProgrammerController(ModuleController):
self.module.model.events_changed.emit() self.module.model.events_changed.emit()
@pyqtSlot(str, str) @pyqtSlot(str, str)
def change_event_name(self, old_name, new_name): def change_event_name(self, old_name : str, new_name : str):
logger.debug("Changing event name from %s to %s", old_name, new_name) logger.debug("Changing event name from %s to %s", old_name, new_name)
for event in self.module.model.pulse_sequence.events: for event in self.module.model.pulse_sequence.events:
if event.name == old_name: if event.name == old_name:
@ -33,7 +33,7 @@ class PulseProgrammerController(ModuleController):
self.module.model.events_changed.emit() self.module.model.events_changed.emit()
@pyqtSlot(str, str) @pyqtSlot(str, str)
def change_event_duration(self, event_name, duration): def change_event_duration(self, event_name:str, duration):
logger.debug("Changing duration of event %s to %s", event_name, duration) logger.debug("Changing duration of event %s to %s", event_name, duration)
for event in self.module.model.pulse_sequence.events: for event in self.module.model.pulse_sequence.events:
if event.name == event_name: if event.name == event_name:
@ -47,6 +47,29 @@ class PulseProgrammerController(ModuleController):
break break
self.module.model.events_changed.emit() self.module.model.events_changed.emit()
@pyqtSlot(str)
def on_move_event_left(self, event_name: str):
"""This method moves the event one position to the left if possible."""
logger.debug("Moving event %s to the left", event_name)
for i, event in enumerate(self.module.model.pulse_sequence.events):
if event.name == event_name:
if i > 0:
self.module.model.pulse_sequence.events[i], self.module.model.pulse_sequence.events[i-1] = self.module.model.pulse_sequence.events[i-1], self.module.model.pulse_sequence.events[i]
break
self.module.model.events_changed.emit()
@pyqtSlot(str)
def on_move_event_right(self, event_name : str):
""" This method moves the event one position to the right if possible. """
logger.debug("Moving event %s to the right", event_name)
for i, event in enumerate(self.module.model.pulse_sequence.events):
if event.name == event_name:
if i < len(self.module.model.pulse_sequence.events) - 1:
self.module.model.pulse_sequence.events[i], self.module.model.pulse_sequence.events[i+1] = self.module.model.pulse_sequence.events[i+1], self.module.model.pulse_sequence.events[i]
break
self.module.model.events_changed.emit()
def save_pulse_sequence(self, path): def save_pulse_sequence(self, path):
logger.debug("Saving pulse sequence to %s", path) logger.debug("Saving pulse sequence to %s", path)
sequence = self.module.model.pulse_sequence.to_json() sequence = self.module.model.pulse_sequence.to_json()

View file

@ -134,6 +134,10 @@ class PulseProgrammerView(ModuleView):
event_options_widget.change_event_duration.connect(self.module.controller.change_event_duration) event_options_widget.change_event_duration.connect(self.module.controller.change_event_duration)
# Connect the change_event_name signal to the on_change_event_name slot # Connect the change_event_name signal to the on_change_event_name slot
event_options_widget.change_event_name.connect(self.module.controller.change_event_name) event_options_widget.change_event_name.connect(self.module.controller.change_event_name)
# Connect the move_event_left signal to the on_move_event_left slot
event_options_widget.move_event_left.connect(self.module.controller.on_move_event_left)
# Connect the move_event_right signal to the on_move_event_right slot
event_options_widget.move_event_right.connect(self.module.controller.on_move_event_right)
self.pulse_table.setCellWidget(row_idx, column_idx, event_options_widget) self.pulse_table.setCellWidget(row_idx, column_idx, event_options_widget)
self.pulse_table.setRowHeight(row_idx, event_options_widget.layout().sizeHint().height()) self.pulse_table.setRowHeight(row_idx, event_options_widget.layout().sizeHint().height())
@ -196,6 +200,8 @@ class EventOptionsWidget(QWidget):
delete_event = pyqtSignal(str) delete_event = pyqtSignal(str)
change_event_duration = pyqtSignal(str, str) change_event_duration = pyqtSignal(str, str)
change_event_name = pyqtSignal(str, str) change_event_name = pyqtSignal(str, str)
move_event_left = pyqtSignal(str)
move_event_right = pyqtSignal(str)
def __init__(self, event): def __init__(self, event):
super().__init__() super().__init__()
@ -203,13 +209,16 @@ class EventOptionsWidget(QWidget):
self_path = Path(__file__).parent self_path = Path(__file__).parent
layout = QHBoxLayout() layout = QVBoxLayout()
upper_layout = QHBoxLayout()
# Edit button
self.edit_button = QToolButton() self.edit_button = QToolButton()
icon = QIcon(str(self_path / "resources/Pen_16x16.png")) icon = QIcon(str(self_path / "resources/Pen_16x16.png"))
self.edit_button.setIcon(icon) self.edit_button.setIcon(icon)
self.edit_button.setIconSize(icon.availableSizes()[0]) self.edit_button.setIconSize(icon.availableSizes()[0])
self.edit_button.setFixedSize(icon.availableSizes()[0]) self.edit_button.setFixedSize(icon.availableSizes()[0])
self.edit_button.clicked.connect(self.edit_event) self.edit_button.clicked.connect(self.edit_event)
# Delete button # Delete button
self.delete_button = QToolButton() self.delete_button = QToolButton()
icon = QIcon(str(self_path / "resources/Garbage_16x16.png")) icon = QIcon(str(self_path / "resources/Garbage_16x16.png"))
@ -218,12 +227,39 @@ class EventOptionsWidget(QWidget):
self.delete_button.setFixedSize(icon.availableSizes()[0]) self.delete_button.setFixedSize(icon.availableSizes()[0])
self.delete_button.clicked.connect(self.create_delete_event_dialog) self.delete_button.clicked.connect(self.create_delete_event_dialog)
layout.addWidget(self.edit_button) upper_layout.addWidget(self.edit_button)
layout.addWidget(self.delete_button) upper_layout.addWidget(self.delete_button)
lower_layout = QHBoxLayout()
# Move left button
self.move_left_button = QToolButton()
icon = QIcon(str(self_path / "resources/ArrowLeft_16x16.png"))
self.move_left_button.setIcon(icon)
self.move_left_button.setIconSize(icon.availableSizes()[0])
self.move_left_button.setFixedSize(icon.availableSizes()[0])
self.move_left_button.clicked.connect(self.move_event_left_button_clicked)
# Move right button
self.move_right_button = QToolButton()
icon = QIcon(str(self_path / "resources/ArrowRight_16x16.png"))
self.move_right_button.setIcon(icon)
self.move_right_button.setIconSize(icon.availableSizes()[0])
self.move_right_button.setFixedSize(icon.availableSizes()[0])
self.move_right_button.clicked.connect(self.move_event_right_button_clicked)
lower_layout.addWidget(self.move_left_button)
lower_layout.addWidget(self.move_right_button)
layout.addLayout(upper_layout)
layout.addLayout(lower_layout)
self.setLayout(layout) self.setLayout(layout)
self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) self.setSizePolicy(QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
@pyqtSlot()
def edit_event(self): def edit_event(self):
"""This method is called when the edit button is clicked. It opens a dialog that allows the user to change the event name and duration.
If the user clicks ok, the change_event_name and change_event_duration signals are emitted."""
logger.debug("Edit button clicked for event %s", self.event.name) logger.debug("Edit button clicked for event %s", self.event.name)
# Create a QDialog to edit the event # Create a QDialog to edit the event
@ -263,7 +299,11 @@ class EventOptionsWidget(QWidget):
self.change_event_duration.emit(self.event.name, duration_lineedit.text()) self.change_event_duration.emit(self.event.name, duration_lineedit.text())
@pyqtSlot()
def create_delete_event_dialog(self): def create_delete_event_dialog(self):
"""This method is called when the delete button is clicked. It creates a dialog that asks the user if he is sure he wants to delete the event.
If the user clicks yes, the delete_event signal is emitted.
"""
# Create an 'are you sure' dialog # Create an 'are you sure' dialog
logger.debug("Delete button clicked") logger.debug("Delete button clicked")
dialog = QDialog(self) dialog = QDialog(self)
@ -280,6 +320,17 @@ class EventOptionsWidget(QWidget):
if result: if result:
self.delete_event.emit(self.event.name) self.delete_event.emit(self.event.name)
@pyqtSlot()
def move_event_left_button_clicked(self):
"""This method is called when the move left button is clicked."""
logger.debug("Move event left: %s", self.event.name)
self.move_event_left.emit(self.event.name)
def move_event_right_button_clicked(self):
"""This """
logger.debug("Move event right: %s", self.event.name)
self.move_event_right.emit(self.event.name)
class OptionsDialog(QDialog): class OptionsDialog(QDialog):
""" This dialog is created whenever the edit button for a pulse option is clicked. """ This dialog is created whenever the edit button for a pulse option is clicked.