Skip to content

Commit

Permalink
Also use the same forgiving callback logic for the errors and warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
danieljohnson2 committed Jan 20, 2025
1 parent 7e2de6b commit be10e7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
23 changes: 12 additions & 11 deletions lutris/gui/config/widget_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,11 @@ def update_option_container(self, option, container: Gtk.Box, wrapper: Gtk.Box):
"""This method updates an option container and its wrapper; this re-evaluates the
relevant options in case they contain callables and those callables return different
results."""
args = self.callback_args
kwargs = self.callback_kwargs
option_key = option["option"]

# Update messages in message boxes that support it

for ch in container.get_children():
if hasattr(ch, "update_message"):
ch.update_message(option_key, *args, **kwargs)
ch.update_message(option, self)

# Hide entire container if the option is not visible
visible = self.get_visibility(option)
Expand Down Expand Up @@ -478,7 +474,7 @@ def on_combobox_change(widget):
combobox.connect("scroll-event", on_combobox_scroll)
combobox.set_valign(Gtk.Align.CENTER)

def get_invalidity_error(key: str, *_args):
def get_invalidity_error(key: str):
v = self.get_setting(key, self.get_default(option))
if v in valid_choices:
return None
Expand Down Expand Up @@ -747,7 +743,15 @@ def _evaluate_option(self, key: str, default: Any, option: Dict[str, Any]) -> An
return default

value = option[key]
return self.evaluate_option_value(value, option=option)

def evaluate_option_value(self, value: Any, option: Dict[str, Any]) -> Any:
"""Evaluates the 'value' given, if it is callable. If not, this method just
returns the 'value'.
The 'value' is called with the option-key and then all the callback arguments
given to this generator's __init__. If the 'value' takes fewer arguments than
this, trailing arguments are omitted."""
if callable(value):
sig = signature(value)
argcount = len(sig.parameters)
Expand Down Expand Up @@ -829,12 +833,9 @@ def __init__(self, message, icon_name, **kwargs):
if text:
self.label.set_markup(str(text))

def update_message(self, *args, **kwargs) -> bool:
def update_message(self, option: Dict[str, Any], generator: WidgetGenerator) -> bool:
try:
if callable(self.message):
text = self.message(*args, **kwargs)
else:
text = str(self.message)
text = generator.evaluate_option_value(self.message, option)
except Exception as err:
logger.exception("Unable to generate configuration warning: %s", err)
text = gtk_safe(str(err))
Expand Down
2 changes: 1 addition & 1 deletion lutris/runners/wine.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _get_prefix_warning(_option_key: str, config: LutrisConfig) -> Optional[str]
return _("<b>Warning</b> Some Wine configuration options cannot be applied, if no prefix can be found.")


def _get_dxvk_warning(_config: LutrisConfig, _option_key: str) -> Optional[str]:
def _get_dxvk_warning() -> Optional[str]:
if drivers.is_outdated():
driver_info = drivers.get_nvidia_driver_info()
return _(
Expand Down

0 comments on commit be10e7c

Please sign in to comment.