Skip to content

Commit

Permalink
Backport PR #22928 on branch 6.x (PR: Fix saving modifications to def…
Browse files Browse the repository at this point in the history
…ault run parameters (Run)) (#22941)
  • Loading branch information
ccordoba12 authored Nov 11, 2024
1 parent 4d3b665 commit df51e61
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
24 changes: 14 additions & 10 deletions spyder/plugins/run/confpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,16 @@ def show_editor(self, new=False, clone=False):
(extension, context, params) = model[index]

self.dialog = ExecutionParametersDialog(
self,
plugin_name,
executor_params,
self.model().get_parameter_names(),
extensions,
contexts,
params,
extension,
context,
new
parent=self,
executor_name=plugin_name,
executor_params=executor_params,
param_names=self.model().get_parameter_names(),
extensions=extensions,
contexts=contexts,
current_params=params,
extension=extension,
context=context,
new_config=new,
)

self.dialog.setup()
Expand Down Expand Up @@ -507,4 +507,8 @@ def apply_settings(self):

self._params_to_delete = {}

# This is necessary to prevent giving focus to the executor combobox,
# which is odd.
self.setFocus()

return {'parameters'}
36 changes: 25 additions & 11 deletions spyder/plugins/run/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def __init__(
param_names: Dict[Tuple[str, str], List[str]],
extensions: Optional[List[str]] = None,
contexts: Optional[Dict[str, List[str]]] = None,
default_params: Optional[ExtendedRunExecutionParameters] = None,
current_params: Optional[ExtendedRunExecutionParameters] = None,
extension: Optional[str] = None,
context: Optional[str] = None,
new_config: bool = False
Expand All @@ -185,19 +185,19 @@ def __init__(
self.executor_name = executor_name
self.executor_params = executor_params
self.param_names = param_names
self.default_params = default_params
self.current_params = current_params
self.extensions = extensions or []
self.contexts = contexts or {}
self.extension = extension
self.context = context
self.new_config = new_config

self.parameters_name = None
if default_params is not None:
if current_params is not None:
self.parameters_name = (
_("Default")
if default_params["default"]
else default_params["name"]
if current_params["default"]
else current_params["name"]
)

self.current_widget = None
Expand Down Expand Up @@ -342,7 +342,7 @@ def setup(self):
self.store_params_text.setText(self.parameters_name)

# Don't allow to change name for default or already saved params.
if self.default_params["default"] or not self.new_config:
if self.current_params["default"] or not self.new_config:
self.store_params_text.setEnabled(False)

# --- Stylesheet
Expand Down Expand Up @@ -403,8 +403,8 @@ def context_changed(self, index: int, reset: bool = False):

default_params = self.current_widget.get_default_configuration()

if self.default_params:
params = self.default_params['params']
if self.current_params:
params = self.current_params['params']
working_dir_params = params['working_dir']
exec_params = params

Expand Down Expand Up @@ -490,8 +490,8 @@ def accept(self) -> None:
exec_params = RunExecutionParameters(
working_dir=cwd_opts, executor_params=widget_conf)

if self.default_params:
uuid = self.default_params['uuid']
if self.current_params:
uuid = self.current_params['uuid']
else:
uuid = str(uuid4())

Expand All @@ -515,12 +515,26 @@ def accept(self) -> None:
)
return

# Check if params are app default ones.
# Fixes spyder-ide/spyder#22649
if self.current_params is None:
# The user is trying to create new params, so this is not a
# default.
is_default = False
else:
if self.current_params["default"]:
# Default params
is_default = True
else:
# User created params
is_default = False

ext_exec_params = ExtendedRunExecutionParameters(
uuid=uuid,
name=name,
params=exec_params,
file_uuid=None,
default=False,
default=is_default,
)

self.saved_conf = (self.selected_extension, self.selected_context,
Expand Down

0 comments on commit df51e61

Please sign in to comment.