Skip to content

Commit

Permalink
Fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-el committed Sep 23, 2024
1 parent c3f2c1a commit e00765f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
51 changes: 28 additions & 23 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 TYPE_CHECKING, Dict, Optional
from typing import TYPE_CHECKING, Optional

from qtpy.QtCore import QSize, Qt, Signal, Slot
from qtpy.QtGui import QCloseEvent, QCursor, QIcon
Expand All @@ -15,10 +15,11 @@
QMenu,
QPushButton,
QVBoxLayout,
QWidget,
)

from ert import LibresFacade
from ert.config import ert_config
from ert.config import ErtConfig
from ert.gui.about_dialog import AboutDialog
from ert.gui.ertnotifier import ErtNotifier
from ert.gui.find_ert_info import find_ert_info
Expand Down Expand Up @@ -70,20 +71,20 @@ class ErtMainWindow(QMainWindow):
def __init__(
self,
config_file: str,
ert_config: ert_config,
ert_config: ErtConfig,
plugin_manager: Optional[ErtPluginManager] = None,
log_handler: Optional[GUILogHandler] = None,
):
QMainWindow.__init__(self)
self.notifier = ErtNotifier(config_file)
self.tools: Dict[str, Tool] = {}
self.plugins_tool: Optional[PluginsTool] = None
self.ert_config = ert_config
self.config_file = config_file
self.log_handler = log_handler

self.setWindowTitle(f"ERT - {config_file} - {find_ert_info()}")
self.dialog_panels = []
self.central_panels = []
self.dialog_panels: list[RunDialog] = []
self.central_panels: list[QWidget] = []

self.plugin_manager = plugin_manager
self.central_widget = QFrame(self)
Expand Down Expand Up @@ -128,8 +129,7 @@ def __init__(
self.__add_help_menu()

@Slot(object)
def slot_add_widget(self, run_dialog: RunDialog):
print("hello!")
def slot_add_widget(self, run_dialog: RunDialog) -> None:
for widget in self.central_panels:
widget.setVisible(False)

Expand All @@ -139,13 +139,16 @@ def slot_add_widget(self, run_dialog: RunDialog):
self.central_layout.addWidget(run_dialog)
self.results_button.setEnabled(True)
date_time = datetime.datetime.utcnow().strftime("%Y-%d-%m %H:%M:%S")
act = self.results_button.menu().addAction(date_time)
act.setProperty("index", len(self.dialog_panels) - 1)
act.triggered.connect(self.select_dialog_panel)
act = self.results_button.menu()

def select_dialog_panel(self):
if act:
act.addAction(date_time)
act.setProperty("index", len(self.dialog_panels) - 1)
act.triggered.connect(self.select_dialog_panel)

def select_dialog_panel(self) -> None:
actor = self.sender()
index = int(actor.property("index"))
index = int(actor.property("index")) if actor else 0

for w in self.central_panels:
w.hide()
Expand All @@ -164,7 +167,7 @@ def select_widget(self) -> None:
should_be_visible = i == index
self.central_panels[i].setVisible(should_be_visible)

def post_init(self):
def post_init(self) -> None:
experiment_panel = ExperimentPanel(
self.ert_config,
self.notifier,
Expand All @@ -181,9 +184,10 @@ def post_init(self):
[wfj for wfj in self.ert_config.workflow_jobs.values() if wfj.is_plugin()],
self,
)
plugins_tool = PluginsTool(plugin_handler, self.notifier, self.ert_config)
plugins_tool.setParent(self)
self.menuBar().addMenu(plugins_tool.get_menu())
self.plugins_tool = PluginsTool(plugin_handler, self.notifier, self.ert_config)
if self.plugins_tool:
self.plugins_tool.setParent(self)
self.menuBar().addMenu(self.plugins_tool.get_menu())

Check failure on line 190 in src/ert/gui/main_window.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Item "None" of "QMenuBar | None" has no attribute "addMenu"

def _create_sidebar_button(self, tool: Optional[Tool] = None) -> QPushButton:
button = QPushButton(self.side_frame)
Expand Down Expand Up @@ -238,7 +242,7 @@ def __add_help_menu(self) -> None:
help_link_item = help_menu.addAction(menu_label)
assert help_link_item is not None
help_link_item.setMenuRole(QAction.MenuRole.ApplicationSpecificRole)
help_link_item.triggered.connect(functools.partial(webbrowser.open, link)) # type: ignore
help_link_item.triggered.connect(functools.partial(webbrowser.open, link))

Check failure on line 245 in src/ert/gui/main_window.py

View workflow job for this annotation

GitHub Actions / type-checking (3.12)

Argument 1 to "connect" of "pyqtBoundSignal" has incompatible type "partial[bool]"; expected "Callable[..., None] | pyqtBoundSignal"

show_about = help_menu.addAction("About")
assert show_about is not None
Expand Down Expand Up @@ -275,11 +279,12 @@ def __add_tools_menu(self) -> None:
tools_menu.addAction(self._load_results_tool.getAction())

def closeEvent(self, closeEvent: Optional[QCloseEvent]) -> None:
if closeEvent is not None and self.notifier.is_simulation_running:
closeEvent.ignore()
else:
self.close_signal.emit()
QMainWindow.closeEvent(self, closeEvent)
if closeEvent is not None:
if self.notifier.is_simulation_running:
closeEvent.ignore()
else:
self.close_signal.emit()
QMainWindow.closeEvent(self, closeEvent)

def __showAboutMessage(self) -> None:
diag = AboutDialog(self)
Expand Down
2 changes: 1 addition & 1 deletion src/ert/gui/tools/plugins/plugins_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
plugin_action.setToolTip(plugin.getDescription())
plugin_action.triggered.connect(plugin_runner.run)

def get_menu(self):
def get_menu(self) -> QMenu:
return self.menu

def trigger(self) -> None:
Expand Down

0 comments on commit e00765f

Please sign in to comment.