Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pywr component config in tooltip of AbstractModelComponentLineE… #221

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from typing import TYPE_CHECKING, Literal

from PySide6.QtCore import Slot
from PySide6.QtGui import QIcon
from PySide6.QtWidgets import QHBoxLayout

from pywr_editor.form import FormField, FormWidget, Validation
from pywr_editor.utils import Logging
from pywr_editor.utils import Logging, ModelComponentTooltip
from pywr_editor.widgets import ComboBox, ParameterIcon, RecorderIcon

if TYPE_CHECKING:
Expand Down Expand Up @@ -50,14 +51,14 @@ def __init__(
self.model_config = self.form.model_config
if self.is_parameter:
self.comp_data = self.model_config.pywr_parameter_data
model_prop = self.model_config.parameters
model_comp_names = list(model_prop.get_all().keys())
self.model_prop = self.model_config.parameters
model_comp_names = list(self.model_prop.get_all().keys())
include_method = self.model_config.includes.get_custom_parameters
icon_class = ParameterIcon
elif self.is_recorder:
self.comp_data = self.model_config.pywr_recorder_data
model_prop = self.model_config.recorders
model_comp_names = list(model_prop.get_all().keys())
self.model_prop = self.model_config.recorders
model_comp_names = list(self.model_prop.get_all().keys())
include_method = self.model_config.includes.get_custom_recorders
icon_class = RecorderIcon
else:
Expand All @@ -80,9 +81,10 @@ def __init__(

# add component names with icon
self.combo_box = ComboBox()
self.combo_box.currentTextChanged.connect(self.set_tooltip)
self.combo_box.addItem("None")
for name in model_comp_names:
param_obj = model_prop.config(name, as_dict=False)
param_obj = self.model_prop.config(name, as_dict=False)
key = param_obj.key

# filter component keys
Expand Down Expand Up @@ -167,3 +169,19 @@ def is_recorder(self) -> bool:
:return: True if the type is a recorder, False otherwise
"""
return self.component_type == "recorder"

@Slot(str)
def set_tooltip(self, name: str) -> None:
"""
Set the tooltip containing the model component configuration.
:param name: The component name.
:return: None
"""
if name != "None":
tooltip = ModelComponentTooltip(
model_config=self.model_config,
comp_obj=self.model_prop.config(name, as_dict=False),
)
self.combo_box.setToolTip(tooltip.render())
else:
self.combo_box.setToolTip("")
Loading