3
3
import datetime
4
4
import functools
5
5
import webbrowser
6
- from typing import Dict , Optional
6
+ from typing import Dict , List , Optional
7
7
8
8
from qtpy .QtCore import QSize , Qt , Signal , Slot
9
9
from qtpy .QtGui import QCloseEvent , QCursor , QIcon
61
61
)
62
62
63
63
64
+ class SidebarToolButton (QToolButton ):
65
+ right_clicked = Signal ()
66
+
67
+ def mousePressEvent (self , event ):
68
+ if event .button () == Qt .RightButton :
69
+ self .right_clicked .emit ()
70
+ else :
71
+ super ().mousePressEvent (event )
72
+
73
+
64
74
class ErtMainWindow (QMainWindow ):
65
75
close_signal = Signal ()
66
76
@@ -87,6 +97,7 @@ def __init__(
87
97
self .central_widget .setLayout (self .central_layout )
88
98
self .facade = LibresFacade (self .ert_config )
89
99
self .side_frame = QFrame (self )
100
+ self ._external_plot_windows : List [PlotWindow ] = []
90
101
91
102
if self .is_dark_mode ():
92
103
self .side_frame .setStyleSheet ("background-color: rgb(64, 64, 64);" )
@@ -122,6 +133,13 @@ def __init__(
122
133
def is_dark_mode (self ) -> bool :
123
134
return self .palette ().base ().color ().value () < 70
124
135
136
+ def right_clicked (self ):
137
+ actor = self .sender ()
138
+ if actor and actor .property ("index" ) == "Create plot" :
139
+ pw = PlotWindow (self .config_file , None )
140
+ pw .show ()
141
+ self ._external_plot_windows .append (pw )
142
+
125
143
def select_central_widget (self ) -> None :
126
144
actor = self .sender ()
127
145
if actor :
@@ -231,8 +249,8 @@ def post_init(self) -> None:
231
249
self .help_menu .menuAction (), self .plugins_tool .get_menu ()
232
250
)
233
251
234
- def _add_sidebar_button (self , name : str , icon : QIcon ) -> QToolButton :
235
- button = QToolButton (self .side_frame )
252
+ def _add_sidebar_button (self , name : str , icon : QIcon ) -> SidebarToolButton :
253
+ button = SidebarToolButton (self .side_frame )
236
254
button .setFixedSize (85 , 95 )
237
255
button .setCursor (QCursor (Qt .CursorShape .PointingHandCursor ))
238
256
@@ -253,6 +271,7 @@ def _add_sidebar_button(self, name: str, icon: QIcon) -> QToolButton:
253
271
self .vbox_layout .addWidget (button )
254
272
255
273
button .clicked .connect (self .select_central_widget )
274
+ button .right_clicked .connect (self .right_clicked )
256
275
button .setProperty ("index" , name )
257
276
return button
258
277
@@ -305,6 +324,10 @@ def __add_tools_menu(self) -> None:
305
324
tools_menu .addAction (self .load_results_tool .getAction ())
306
325
307
326
def closeEvent (self , closeEvent : Optional [QCloseEvent ]) -> None :
327
+ for plot_window in self ._external_plot_windows :
328
+ if plot_window :
329
+ plot_window .close ()
330
+
308
331
if closeEvent is not None :
309
332
if self .notifier .is_simulation_running :
310
333
closeEvent .ignore ()
0 commit comments