Skip to content

Commit

Permalink
Use eds for suggestor message
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Nov 17, 2023
1 parent 3429dfd commit 4b8b232
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 55 deletions.
12 changes: 7 additions & 5 deletions src/ert/config/parsing/error_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,21 @@ def __gt__(self, other: "ErrorInfo") -> bool:
return getattr(self, attr) > getattr(other, attr)
return self.message > other.message

def __str__(self) -> str:
def location(self) -> str:
msg = ""
if self.filename is not None:
msg += f"{self.filename}: "
msg += f"{self.filename} "
if self.line is not None:
msg += f"Line {self.line} "
if self.column is not None and self.end_column is None:
msg += f"(Column {self.column}): "
msg += f"(Column {self.column})"
if self.column is not None and self.end_column is not None:
msg += f"(Column {self.column}-{self.end_column}): "
msg += self.message
msg += f"(Column {self.column}-{self.end_column})"
return msg

def __str__(self) -> str:
return self.location() + ": " + self.message

def _attach_to_context(self, token: Optional[FileContextToken]) -> None:
if token is not None:
self.filename = token.filename
Expand Down
68 changes: 35 additions & 33 deletions src/ert/gui/ertwidgets/suggestor_message.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,52 @@
from PyQt5 import QtSvg
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QHBoxLayout, QLabel, QWidget
from PyQt5.QtWidgets import QHBoxLayout, QLabel, QSizePolicy, QVBoxLayout, QWidget


def _svg_icon(image_name):
widget = QtSvg.QSvgWidget(f"img:{image_name}.svg")
widget.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
widget.setStyleSheet("width: 40px; height: 40px;")
return widget


class SuggestorMessage(QWidget):
def __init__(self, lbl_text, color, text):
QWidget.__init__(self)
common_style = """
border-style: outset;
border-width: 2px;
border-radius: 10px;
border-color: darkgrey;
padding: 6px;"""

self.type_lbl = QLabel(lbl_text)
self.type_lbl.setAlignment(Qt.AlignCenter)
self.type_lbl.setStyleSheet(
common_style
+ f"""
background-color: {color};
font: bold 14px;
max-width: 6em;
min-width: 6em;
max-height: 1em;"""
def __init__(self, header, icon, info):
super().__init__()
self.setAttribute(Qt.WA_StyledBackground)
self.setStyleSheet("background-color: white;")

self.icon = icon
self.lbl = QLabel(
"<b>"
+ header
+ "</b>"
+ info.message
+ '<p style="font-family: courier; font-style: mono; font-size: 12px;">'
+ info.location()
+ "</p>"
)

self.lbl = QLabel(text)
self.lbl.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.lbl.setTextInteractionFlags(Qt.TextSelectableByMouse)
self.lbl.setWordWrap(True)
self.lbl.setStyleSheet(common_style + "background-color: lightgray;")

self.hbox = QHBoxLayout()
self.hbox.addWidget(self.type_lbl)
self.hbox.setSpacing(16)
self.hbox.setContentsMargins(16, 0, 16, 0)
self.hbox.addWidget(self.icon, alignment=Qt.AlignLeft)
self.hbox.addWidget(self.lbl)
self.setLayout(self.hbox)

@classmethod
def error_msg(cls, text):
color = "#ff0000"
return SuggestorMessage("ERROR", color, text)
def error_msg(cls, info):
return SuggestorMessage("Error: ", _svg_icon("error_solidcircle"), info)

@classmethod
def warning_msg(cls, text):
color = "#ff6a00"
return SuggestorMessage("WARNING", color, text)
def warning_msg(cls, info):
return SuggestorMessage("Warning: ", _svg_icon("warning_solidcircle"), info)

@classmethod
def deprecation_msg(cls, text):
color = "#faf339"
return SuggestorMessage("DEPRECATION", color, text)
def deprecation_msg(cls, info):
return SuggestorMessage(
"Deprecation: ", _svg_icon("thumbs_down_solidcircle"), info
)
32 changes: 15 additions & 17 deletions src/ert/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from signal import SIG_DFL, SIGINT, signal
from typing import Optional, cast

from PyQt5.QtGui import QIcon
from PyQt5.QtGui import QFont, QFontDatabase, QIcon
from qtpy.QtCore import QDir, QLocale, QSize, Qt
from qtpy.QtWidgets import (
QApplication,
Expand Down Expand Up @@ -58,8 +58,14 @@ def run_gui(args: Namespace, plugin_manager: Optional[ErtPluginManager] = None):
QDir.addSearchPath(
"img", os.path.join(os.path.dirname(__file__), "resources/gui/img")
)

app = QApplication([]) # Early so that QT is initialized before other imports
db = QFontDatabase()
id = db.addApplicationFont(
os.path.join(
os.path.dirname(__file__), "resources/gui/font", "Equinor-Regular.woff"
)
)
app.setFont(QFont("Equinor, Regular"))
app.setWindowIcon(QIcon("img:application/window_icon_cutout"))
with add_gui_log_handler() as log_handler:
window, ens_path, ensemble_size, parameter_config = _start_initial_gui_window(
Expand Down Expand Up @@ -111,18 +117,18 @@ def _start_initial_gui_window(
ert = EnKFMain(ert_config)
except ConfigValidationError as error:
config_warnings = [
str(w.message)
w.message.info
for w in all_warnings
if w.category == ConfigWarning
and not cast(ConfigWarning, w.message).info.is_deprecation
]
deprecations = [
str(w.message)
w.message.info
for w in all_warnings
if w.category == ConfigWarning
and cast(ConfigWarning, w.message).info.is_deprecation
]
error_messages += error.messages()
error_messages += error.errors
logger.info("Error in config file shown in gui: '%s'", str(error))
return (
_setup_suggester(
Expand All @@ -136,13 +142,13 @@ def _start_initial_gui_window(
None,
)
config_warnings = [
str(w.message)
w.message.info
for w in all_warnings
if w.category == ConfigWarning
and not cast(ConfigWarning, w.message).info.is_deprecation
]
deprecations = [
str(w.message)
w.message.info
for w in all_warnings
if w.category == ConfigWarning
and cast(ConfigWarning, w.message).info.is_deprecation
Expand Down Expand Up @@ -236,6 +242,8 @@ def _setup_suggester(

for menu_label, link in help_links.items():
button = QPushButton(menu_label)
if "GitHub" in menu_label:
button.setIcon(QIcon("img:github.svg"))
button.setObjectName(menu_label)
button.clicked.connect(
functools.partial(_clicked_help_button, menu_label, link)
Expand Down Expand Up @@ -268,15 +276,11 @@ def _setup_suggester(
suggest_layout = QVBoxLayout()
buttons_layout = QHBoxLayout()

text = ""
for msg in errors:
text += msg + "\n"
suggest_layout.addWidget(SuggestorMessage.error_msg(msg))
for msg in warning_msgs:
text += msg + "\n"
suggest_layout.addWidget(SuggestorMessage.warning_msg(msg))
for msg in suggestions:
text += msg + "\n"
suggest_layout.addWidget(SuggestorMessage.deprecation_msg(msg))

suggest_layout.addStretch()
Expand All @@ -287,9 +291,6 @@ def _setup_suggester(
scroll.setWidgetResizable(True)
scroll.setWidget(suggest_msgs)

def copy_text():
QApplication.clipboard().setText(text)

def run_pressed():
ert_window.show()
ert_window.activateWindow()
Expand All @@ -299,15 +300,12 @@ def run_pressed():

run = QPushButton("Open ERT")
give_up = QPushButton("Exit")
copy = QPushButton("Copy messages")

run.setObjectName("run_ert_button")
run.setEnabled(ert_window is not None)
run.pressed.connect(run_pressed)
copy.pressed.connect(copy_text)
give_up.pressed.connect(container.close)

buttons_layout.addWidget(copy)
buttons_layout.insertStretch(-1, -1)
buttons_layout.addWidget(run)
buttons_layout.addWidget(give_up)
Expand Down

0 comments on commit 4b8b232

Please sign in to comment.