spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.22k stars 1.59k forks source link

Focus lost when switching between terminal/notebook and other panes. #21277

Open adam-urbanczyk opened 1 year ago

adam-urbanczyk commented 1 year ago

Issue Report Checklist

Problem Description

Switching to terminal or notebook using keyboard shortcuts does not restore focus - one cannot immediately start typing when switching to those panes from e.g. editor or console.

What steps reproduce the problem?

  1. Install terminal and notebook plugin
  2. Set keyboard shortcuts for switching
  3. Set focus to terminal or notebook, switch to editor or console, switch back.

What is the expected output? What do you see instead?

Focus is restored when switching back.

Paste Traceback/Error Below (if applicable)

NA

Versions

Dependencies

# Mandatory:
atomicwrites >=1.2.0                                                        :  1.4.1 (OK)
chardet >=2.0.0                                                             :  4.0.0 (OK)
cloudpickle >=0.5.0                                                         :  2.2.1 (OK)
cookiecutter >=1.6.0                                                        :  2.3.0 (OK)
diff_match_patch >=20181111                                                 :  20230430 (OK)
intervaltree >=3.0.2                                                        :  3.1.0 (OK)
IPython >=7.31.1,<9.0.0,!=8.8.0,!=8.9.0,!=8.10.0,!=8.11.0,!=8.12.0,!=8.12.1 :  8.0.1 (OK)
jedi >=0.17.2,<0.19.0                                                       :  0.18.1 (OK)
jellyfish >=0.7                                                             :  1.0.0 (OK)
jsonschema >=3.2.0                                                          :  4.17.3 (OK)
keyring >=17.0.0                                                            :  23.9.3 (OK)
nbconvert >=4.0                                                             :  7.7.4 (OK)
numpydoc >=0.6.0                                                            :  1.5.0 (OK)
paramiko >=2.4.0                                                            :  3.3.1 (OK)
parso >=0.7.0,<0.9.0                                                        :  0.8.3 (OK)
pexpect >=4.4.0                                                             :  4.8.0 (OK)
pickleshare >=0.4                                                           :  0.7.5 (OK)
psutil >=5.3                                                                :  5.8.0 (OK)
pygments >=2.0                                                              :  2.11.1 (OK)
pylint >=2.5.0,<3.0                                                         :  2.14.4 (OK)
pylint_venv >=3.0.2                                                         :  3.0.2 (OK)
pyls_spyder >=0.4.0                                                         :  0.4.0 (OK)
pylsp >=1.7.4,<1.8.0                                                        :  1.7.4 (OK)
pylsp_black >=1.2.0,<3.0.0                                                  :  1.2.0 (OK)
qdarkstyle >=3.0.2,<3.2.0                                                   :  3.1 (OK)
qstylizer >=0.2.2                                                           :  0.2.2 (OK)
qtawesome >=1.2.1                                                           :  1.2.3 (OK)
qtconsole >=5.4.2,<5.5.0                                                    :  5.4.3 (OK)
qtpy >=2.1.0                                                                :  2.3.1 (OK)
rtree >=0.9.7                                                               :  1.0.1 (OK)
setuptools >=49.6.0                                                         :  65.6.3 (OK)
sphinx >=0.6.6                                                              :  5.1.1 (OK)
spyder_kernels >=2.4.4,<2.5.0                                               :  2.4.4 (OK)
textdistance >=4.2.0                                                        :  4.5.0 (OK)
three_merge >=0.1.1                                                         :  0.1.1 (OK)
watchdog >=0.10.3                                                           :  3.0.0 (OK)
zmq >=22.1.0                                                                :  25.1.1 (OK)

# Optional:
cython >=0.21                                                               :  None (NOK)
matplotlib >=3.0.0                                                          :  None (NOK)
numpy >=1.7                                                                 :  None (NOK)
pandas >=1.1.1                                                              :  None (NOK)
scipy >=0.17.0                                                              :  None (NOK)
sympy >=0.7.3                                                               :  None (NOK)

# Spyder plugins:
spyder_notebook.notebookplugin 0.5.1                                        :  0.5.1 (OK)
spyder_terminal.terminalplugin 1.2.2                                        :  1.2.2 (OK)
dalthviz commented 1 year ago

Hi @adam-urbanczyk thank you for the feedback! I think I was able to reproduce this! Checking with the Terminal plugin, although the plugin pane gets raised, the actual focus is still either in the Editor pane or in the IPython Console pane.

We will try to check this in a future release :+1:

ccordoba12 commented 1 year ago

I think this is not something we can do here. Instead, it should be a matter of setting the RAISE_AND_FOCUS plugin constant to True in those plugins:

https://github.com/spyder-ide/spyder/blob/617c15cc6f9906b84296be9c245a35aba09f63d5/spyder/api/plugins/new_api.py#L941-L944

@jitseniesen, could you try that on Spyder-notebook to see if it works with that plugin?

adam-urbanczyk commented 1 year ago

If this is the solution, maybe you could change the default to True?

dalthviz commented 1 year ago

I think this is not something we can do here. Instead, it should be a matter of setting the RAISE_AND_FOCUS plugin constant to True in those plugins

Just in case, checked changing the default value of the constant to True in the Spyder code and seems like that indeed fixes this. In the case of the Terminal pluing the prompt gets focused. Is there any reason why the default value of the constant is False @ccordoba12 ?

jitseniesen commented 1 year ago

could you try that on Spyder-notebook to see if it works with that plugin?

Good call! Yes, it works. I created PR spyder-ide/spyder-notebook#440 with that fix.

Is there any reason why the default value of the constant is False

My understanding is that this is for informational panes like the Variable Explorer and Code Analysis. When a user is typing code in the editor or console, they may want to raise those informational panes to have a look at them, but they typically want to continue in the editor or console so they don't want to give focus to the informational panes.

ccordoba12 commented 1 year ago

Is there any reason why the default value of the constant is False @ccordoba12 ?

It's exactly as @jitseniesen described: there are some plugins (actually, most of them) to which you don't want to give focus, just raise them to visibility to see what they are displaying.

dalthviz commented 1 year ago

Makes sense, thanks for the explanations! Will create then an issue for the Terminal plugin referencing this one. Probably after that we could close this one right?

adam-urbanczyk commented 1 year ago

AFAICT this part is not true, so maybe still a bug of spyder?

 # If False, the widget will be raised but focus will not be given until 
 # the action to switch is called a second time. 
ccordoba12 commented 1 year ago

Yeah, that's a good point but I'm not sure if we should implement it.

@jitseniesen, @dalthviz, what do you think?

dalthviz commented 1 year ago

Not totally sure either 🤔 That behavior was working at some point then? If that is the case then makes sense to me to implemented/reimplemented, otherwise no

jitseniesen commented 1 year ago

I think the RAISE_AND_FOCUS behaviour originates from PR #11684 and I assume it worked at that time. But it does not work in current Spyder 5 and as far as I know nobody complained about it, so I'd say it is not a priority.

On the other hand, I think it is important for accessibility, to make sure that all functionality can be accessed without the mouse. However this is probably best done as part of a complete accessibility assessment.