11"""Widget for viewing the SBML model."""
22
3+ import qtawesome as qta
34from PySide6 .QtCore import Qt
45from PySide6 .QtWidgets import (
56 QLabel ,
@@ -20,6 +21,9 @@ class SbmlViewer(QWidget):
2021 def __init__ (self , parent = None , logger_view = None ):
2122 super ().__init__ (parent )
2223
24+ # Reference to menu action (set by controller)
25+ self .sbml_toggle_action = None
26+
2327 # Main layout for the SBML tab
2428 layout = QVBoxLayout (self )
2529 vertical_splitter = QSplitter (Qt .Vertical )
@@ -36,6 +40,11 @@ def __init__(self, parent=None, logger_view=None):
3640 self .sbml_text_edit .setWhatsThis (
3741 WHATS_THIS ["sbml_view" ]["sbml_editor" ]
3842 )
43+ # Enable custom context menu
44+ self .sbml_text_edit .setContextMenuPolicy (Qt .CustomContextMenu )
45+ self .sbml_text_edit .customContextMenuRequested .connect (
46+ self ._show_sbml_context_menu
47+ )
3948 sbml_layout .addWidget (self .sbml_text_edit )
4049
4150 # Add forward changes button for SBML
@@ -51,6 +60,11 @@ def __init__(self, parent=None, logger_view=None):
5160 self .sbml_text_edit .setWhatsThis (
5261 WHATS_THIS ["sbml_view" ]["antimony_editor" ]
5362 )
63+ # Enable custom context menu
64+ self .antimony_text_edit .setContextMenuPolicy (Qt .CustomContextMenu )
65+ self .antimony_text_edit .customContextMenuRequested .connect (
66+ self ._show_antimony_context_menu
67+ )
5468 antimony_layout .addWidget (self .antimony_text_edit )
5569
5670 # Add forward changes button for Antimony
@@ -75,3 +89,47 @@ def __init__(self, parent=None, logger_view=None):
7589 layout .addWidget (vertical_splitter )
7690 vertical_splitter .setStretchFactor (0 , 7 )
7791 vertical_splitter .setStretchFactor (1 , 3 )
92+
93+ def _show_sbml_context_menu (self , position ):
94+ """Show context menu for SBML text edit."""
95+ if not self .sbml_toggle_action :
96+ return
97+
98+ menu = self .sbml_text_edit .createStandardContextMenu ()
99+ menu .addSeparator ()
100+
101+ # Add hide SBML option
102+ hide_action = menu .addAction (
103+ qta .icon ("mdi6.chevron-left" ), "Hide SBML Editor"
104+ )
105+ hide_action .triggered .connect (
106+ lambda : self .sbml_toggle_action .setChecked (False )
107+ )
108+
109+ menu .exec (self .sbml_text_edit .mapToGlobal (position ))
110+
111+ def _show_antimony_context_menu (self , position ):
112+ """Show context menu for Antimony text edit."""
113+ if not self .sbml_toggle_action :
114+ return
115+
116+ menu = self .antimony_text_edit .createStandardContextMenu ()
117+ menu .addSeparator ()
118+
119+ # Add show/hide SBML option
120+ if self .sbml_widget .isVisible ():
121+ action = menu .addAction (
122+ qta .icon ("mdi6.chevron-left" ), "Hide SBML Editor"
123+ )
124+ action .triggered .connect (
125+ lambda : self .sbml_toggle_action .setChecked (False )
126+ )
127+ else :
128+ action = menu .addAction (
129+ qta .icon ("mdi6.chevron-right" ), "Show SBML Editor"
130+ )
131+ action .triggered .connect (
132+ lambda : self .sbml_toggle_action .setChecked (True )
133+ )
134+
135+ menu .exec (self .antimony_text_edit .mapToGlobal (position ))
0 commit comments