Skip to content

Commit 3c7cd5f

Browse files
committed
Add capability to open external plot windows
1 parent 3b1db99 commit 3c7cd5f

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/ert/gui/main_window.py

+26-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import datetime
44
import functools
55
import webbrowser
6-
from typing import Dict, Optional
6+
from typing import Dict, List, Optional
77

88
from qtpy.QtCore import QSize, Qt, Signal, Slot
99
from qtpy.QtGui import QCloseEvent, QCursor, QIcon
@@ -61,6 +61,16 @@
6161
)
6262

6363

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+
6474
class ErtMainWindow(QMainWindow):
6575
close_signal = Signal()
6676

@@ -87,6 +97,7 @@ def __init__(
8797
self.central_widget.setLayout(self.central_layout)
8898
self.facade = LibresFacade(self.ert_config)
8999
self.side_frame = QFrame(self)
100+
self._external_plot_windows: List[PlotWindow] = []
90101

91102
if self.is_dark_mode():
92103
self.side_frame.setStyleSheet("background-color: rgb(64, 64, 64);")
@@ -122,6 +133,13 @@ def __init__(
122133
def is_dark_mode(self) -> bool:
123134
return self.palette().base().color().value() < 70
124135

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+
125143
def select_central_widget(self) -> None:
126144
actor = self.sender()
127145
if actor:
@@ -231,8 +249,8 @@ def post_init(self) -> None:
231249
self.help_menu.menuAction(), self.plugins_tool.get_menu()
232250
)
233251

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)
236254
button.setFixedSize(85, 95)
237255
button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
238256

@@ -253,6 +271,7 @@ def _add_sidebar_button(self, name: str, icon: QIcon) -> QToolButton:
253271
self.vbox_layout.addWidget(button)
254272

255273
button.clicked.connect(self.select_central_widget)
274+
button.right_clicked.connect(self.right_clicked)
256275
button.setProperty("index", name)
257276
return button
258277

@@ -305,6 +324,10 @@ def __add_tools_menu(self) -> None:
305324
tools_menu.addAction(self.load_results_tool.getAction())
306325

307326
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+
308331
if closeEvent is not None:
309332
if self.notifier.is_simulation_running:
310333
closeEvent.ignore()

0 commit comments

Comments
 (0)