Source code for ibl_alignment_gui.plugins.upload_dialog

from typing import TYPE_CHECKING

from qtpy import QtWidgets

from ibl_alignment_gui.utils.qt.custom_widgets import CheckBoxGroup

if TYPE_CHECKING:
    from ibl_alignment_gui.app.app_controller import AlignmentGUIController

PLUGIN_NAME = 'Upload dialog'


[docs] def setup(controller: 'AlignmentGUIController'): """ Set up the upload dialog and connect its accepted signal to the callback. Parameters ---------- controller: AlignmentController The main application controller. """ controller.upload_dialog = UploadDialog(controller)
[docs] def display(controller: 'AlignmentGUIController'): """ Configure and show the upload dialog. Parameters ---------- controller: The main application controller. """ controller.upload_dialog.add_shanks() controller.upload_dialog.exec_() return controller.upload_dialog.shanks_to_upload
[docs] class UploadDialog(QtWidgets.QDialog): """ Dialog for selecting shanks to upload. Parameters ---------- controller: AlignmentGUIController The main application controller. """ def __init__(self, controller: 'AlignmentGUIController'): super().__init__(controller.view) self.controller = controller self.setWindowTitle('Upload shanks') self.resize(300, 150) self.shanks_to_upload: list = list() self.setup()
[docs] def setup(self): """Set up the dialog layout and widgets.""" self.shank_options = CheckBoxGroup('Select shanks to upload:', orientation='vertical') button_box = QtWidgets.QDialogButtonBox( QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel ) button_box.accepted.connect(self.on_accept) button_box.rejected.connect(self.reject) # Assemble layout self.dialog_layout = QtWidgets.QVBoxLayout() self.dialog_layout.addWidget(self.shank_options) self.dialog_layout.addWidget(button_box) self.setLayout(self.dialog_layout)
[docs] def add_shanks(self) -> None: """Add the current shanks to the dropdown options.""" # Replace the options in the CheckBoxGroup options = ['All'] + self.controller.all_shanks self.shank_options.add_options(options) # Set the currently selected shank self.shank_options.set_checked([self.controller.model.selected_shank]) # Connect the callback self.shank_options.setup_callback(self.on_shank_button_clicked) # Force a repaint to ensure old buttons are gone self.shank_options.update() self.shank_options.repaint() self.dialog_layout.update() self.update()
[docs] def on_shank_button_clicked(self, checked: bool, button: str) -> None: """ Update the shank selections based on button clicks. If the clicked button is 'All', it checks all shanks when checked, or reverts to the currently selected shank when unchecked. Parameters ---------- checked: bool Whether the button is checked or not. button: str The text of the button that was clicked. """ if button == 'All' and checked: self.shank_options.set_checked(self.controller.all_shanks + ['All']) elif button == 'All' and not checked: self.shank_options.set_checked([self.controller.model.selected_shank])
[docs] def on_accept(self) -> None: """Find the selected shanks and accept the dialog.""" selected = self.shank_options.get_checked() self.shanks_to_upload = [s for s in selected if s != 'All'] self.accept()