Skip to content

Commit

Permalink
Add capability to open external plot windows
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Nov 1, 2024
1 parent 3b1db99 commit 5b7d8a9
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/ert/gui/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import datetime
import functools
import webbrowser
from typing import Dict, Optional
from typing import Dict, List, Optional

from qtpy.QtCore import QSize, Qt, Signal, Slot
from qtpy.QtGui import QCloseEvent, QCursor, QIcon
Expand Down Expand Up @@ -61,6 +61,16 @@
)


class SidebarToolButton(QToolButton):
right_clicked = Signal()

def mousePressEvent(self, event) -> None:
if event.button() == Qt.MouseButton.RightButton:
self.right_clicked.emit()
else:
super().mousePressEvent(event)


class ErtMainWindow(QMainWindow):
close_signal = Signal()

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

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

def right_clicked(self) -> None:
actor = self.sender()
if actor and actor.property("index") == "Create plot":
pw = PlotWindow(self.config_file, None)
pw.show()
self._external_plot_windows.append(pw)

def select_central_widget(self) -> None:
actor = self.sender()
if actor:
Expand Down Expand Up @@ -231,8 +249,8 @@ def post_init(self) -> None:
self.help_menu.menuAction(), self.plugins_tool.get_menu()
)

def _add_sidebar_button(self, name: str, icon: QIcon) -> QToolButton:
button = QToolButton(self.side_frame)
def _add_sidebar_button(self, name: str, icon: QIcon) -> SidebarToolButton:
button = SidebarToolButton(self.side_frame)
button.setFixedSize(85, 95)
button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))

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

button.clicked.connect(self.select_central_widget)
button.right_clicked.connect(self.right_clicked)
button.setProperty("index", name)
return button

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

def closeEvent(self, closeEvent: Optional[QCloseEvent]) -> None:
for plot_window in self._external_plot_windows:
if plot_window:
plot_window.close()

if closeEvent is not None:
if self.notifier.is_simulation_running:
closeEvent.ignore()
Expand Down

0 comments on commit 5b7d8a9

Please sign in to comment.