Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/petab_gui/controllers/mother_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def __init__(self, view, model: PEtabModel):

self.setup_connections()
self.setup_task_bar()
self.setup_context_menu()

def setup_context_menu(self):
"""Sets up context menus for the tables."""
self.measurement_controller.setup_context_menu(self.actions)
self.observable_controller.setup_context_menu(self.actions)
self.parameter_controller.setup_context_menu(self.actions)
self.condition_controller.setup_context_menu(self.actions)

def setup_task_bar(self):
"""Create shortcuts for the main window."""
Expand Down
5 changes: 5 additions & 0 deletions src/petab_gui/controllers/table_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ def setup_connections(self):
self.set_index_on_new_row
)

def setup_context_menu(self, actions):
"""Setup context menu for this table."""
view = self.view.table_view
view.setup_context_menu(actions)

def validate_changed_cell(self, row, column):
"""Validate the changed cell and whether its linting is correct."""
if not self.check_petab_lint_mode:
Expand Down
1 change: 0 additions & 1 deletion src/petab_gui/models/pandas_table_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,6 @@ def maybe_add_rows(self, start_row, n_rows):
self._data_frame.shape[0],
start_row + n_rows - self._data_frame.shape[0]
)
self.layoutChanged.emit()

def determine_background_color(self, row, column):
"""Determine the background color of a cell.
Expand Down
1 change: 1 addition & 0 deletions src/petab_gui/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ def __init__(self, parent=None, width=5, height=4, dpi=100):
self.axes = fig.add_subplot(111)
super(PlotWidget, self).__init__(fig)


class SignalForwarder(QObject):
"""Forward signals from one object to another."""
forwarded_signal = Signal()
Expand Down
25 changes: 25 additions & 0 deletions src/petab_gui/views/context_menu_mananger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from PySide6.QtWidgets import QMenu


class ContextMenuManager:
"""Manage context menu actions for the tables."""
def __init__(self, actions, table_view, parent=None):
self.parent = parent()
self.actions = actions
self.table_view = table_view

def create_context_menu(self, position):
"""Create the context menu."""
menu = QMenu(self.parent)
# Copy, Paste
menu.addAction(self.actions["copy"])
menu.addAction(self.actions["paste"])
menu.addSeparator()
menu.addAction(self.actions["add_row"])
menu.addAction(self.actions["delete_row"])
menu.addAction(self.actions["add_column"])
menu.addAction(self.actions["delete_column"])
menu.addSeparator()

# execute the menu
menu.exec_(self.table_view.viewport().mapToGlobal(position))
11 changes: 11 additions & 0 deletions src/petab_gui/views/table_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from PySide6.QtGui import QGuiApplication, QColor

from ..utils import get_selected_rectangles
from .context_menu_mananger import ContextMenuManager
import re
import pandas as pd

Expand Down Expand Up @@ -191,6 +192,16 @@ def __init__(self, parent=None):
self.autofit_column
)

def setup_context_menu(self, actions):
"""Setup the context menu for the table view."""
self.context_menu_manager = ContextMenuManager(
actions, self, self.parent
)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(
self.context_menu_manager.create_context_menu
)

def setModel(self, model):
"""Ensures selection model exists before connecting signals"""
super().setModel(model)
Expand Down