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

WIP: Add help window to the _TimeViewer #7305

Merged
merged 12 commits into from
Feb 13, 2020

Conversation

GuillaumeFavelier
Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier commented Feb 10, 2020

This PR adds a matplotlib figure to display help. The shortcut is h:

2020-02-10_1920x1080

Closes #7268
It's an item of #7162

@agramfort
Copy link
Member

can you avoid so much blank space ?
Screenshot 2020-02-10 at 16 40 40

cell._loc = 'right'

fig_help.canvas.draw()
plt_show(fig=fig_help, warn=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor this code with the other help windows in mne/viz. They should all use a single call, maybe something like:

def _show_help(options):
    ...

where options is a list (rows) of 2-element lists (cols)? This would be better than a dict because you make it so that some of the "rows" are actually blank, or hline, etc. This function would take that input and pop up a window showing the table, this window should be close-able with hitting esc, etc.

@GuillaumeFavelier GuillaumeFavelier changed the title Add help window to the _TimeViewer WIP: Add help window to the _TimeViewer Feb 10, 2020
@hoechenberger
Copy link
Member

Thanks @GuillaumeFavelier, this will be really useful 🥳

@codecov
Copy link

codecov bot commented Feb 11, 2020

Codecov Report

Merging #7305 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #7305      +/-   ##
==========================================
- Coverage   89.83%   89.81%   -0.03%     
==========================================
  Files         449      449              
  Lines       80791    80801      +10     
  Branches    12880    12881       +1     
==========================================
- Hits        72581    72571      -10     
- Misses       5384     5399      +15     
- Partials     2826     2831       +5     

'u': 'Restore original clim',
'Space': 'Start/Pause playback'
}
text = [str(s) + " : \n" for s in shortcuts.keys()]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dict order is only guaranteed in Python 3.6+, we still support 3.5. You can probably just turn this into a tuple, then do

pairs = [
    ('h', 'Display help window'),
    ...
]
text1, text2 = zip(*pairs)
text1 = '\n'.join(text1)
text2 = '\n'.join(text2)

@GuillaumeFavelier
Copy link
Contributor Author

@GuillaumeFavelier
Copy link
Contributor Author

This change will affect all the current bindings.

@hoechenberger
Copy link
Member

could not find the ascii code for ?.

Isn't it 63?

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 11, 2020

My bad. I mean the ascii code returned by qt_key_to_key_sym()

I don't see it in the following list: https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKInteractorAdapter.cxx#L577-L671

@GuillaumeFavelier
Copy link
Contributor Author

It might be a good idea to test this new key binding system on different configurations actually (especially ?). It works on my linux/azerty keyboards. Is it working for you @hoechenberger, @drammock, @SophieHerbst ?

@hoechenberger
Copy link
Member

hoechenberger commented Feb 12, 2020

It might be a good idea to test this new key binding system on different configurations actually (especially ?). It works on my linux/azerty keyboards. Is it working for you @hoechenberger, @drammock, @SophieHerbst ?

Not working for me on macOS (on an American keyboard, I tried pressing / and Shift + / (which produces a ?)), nothing happens. Other keyboard actions like y are working fine, however.

Had to install pyvista master to try this.

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 12, 2020

Using QtCore.Qt.Key_Question is my last resort now. Hopefully this one works for everyone.

@hoechenberger
Copy link
Member

Using QtCore.Qt.Key_Question is my last resort now. Hopefully this one works.

This doesn't fix it for me, sorry :(

@GuillaumeFavelier
Copy link
Contributor Author

Thanks a lot for your help @hoechenberger ! Apparently there is also Key_questiondown too. If this one does not work, I'll look into matplotlib code.


def keyPressEvent(self, event):
from PyQt5 import QtCore
if event.key() == QtCore.Qt.Key_questiondown:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me on both macOS and Linux

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(BTW if I do print(event.key()) and print(type(event.key()) on macOS I get 63 and int, so it's possible that using the ASCII char code would have also be enough :) )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But what's confusing to me is that QtCore.Qt.Key_questiondown == 191

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh actually it's not being routed through this part of the conditional at all, it's going through the callback=self.key_mindings.get(event.text())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoechenberger tried both event.text() and Key_Question without success.

@GuillaumeFavelier
Copy link
Contributor Author

I tested it on my windows/azerty config and it works too

image

@GuillaumeFavelier
Copy link
Contributor Author

Trying to catch up here.

Okay let's get rid of the unnecessary conditional branch then

I just removed it now, does it still work for you @larsoner ?

So thanks to:

jupyter qtconsole

I believe I can reproduce the behaviour you have, thank you @hoechenberger

So when I add %matplotlib qt in the console, it works for me. What about you @SophieHerbst, @hoechenberger ?

I know this is a workaround but jupyter is not the first target here.

@hoechenberger
Copy link
Member

hoechenberger commented Feb 13, 2020

So when I add %matplotlib qt in the console, it works for me. What about you @SophieHerbst, @hoechenberger ?

Working in qtconsole and VS Code interactive Python window! Only annoying thing is the window opens in the background, not sure if that can be fixed? Btw menus are working properly this way too

@GuillaumeFavelier
Copy link
Contributor Author

Thank you for the fast response,

the window opens in the background, not sure it that can be fixed

This is a bug, I will report it on #7162

# display help
self.help_actor = self.plotter.add_text(
text="Press ? to show help window"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather not sacrifice this much (or really any) screen real estate for this:

Screenshot from 2020-02-13 09-33-22

If it's always ? in all of our plotters we can just document it in a tutorial and in docstrings.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... actually the intuitive way to do it without eating up screen real estate would be to add a Help->Show MNE key bindings... menu option at the top. If it's not too hard to do it it's a nice option

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or more completely / standardly, Help-> Show MNE key bindings... ? (with the ? in the right column of the menu item to indicate it's the shortcut)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion @larsoner. I'm on it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to find this code snippet I did not so long ago...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found it: #7200 (comment)

@GuillaumeFavelier
Copy link
Contributor Author

This is how it looks for me:

image

Copy link
Member

@larsoner larsoner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM +1 for merge

@GuillaumeFavelier GuillaumeFavelier changed the title WIP: Add help window to the _TimeViewer MRG: Add help window to the _TimeViewer Feb 13, 2020
@hoechenberger
Copy link
Member

Still wondering if a hint in very small font size, "[?] Show key bindings", wouldn't be a good idea.

@SophieHerbst
Copy link
Contributor

Indeed, after doing %matplotlib qt the ? works for me (spyder on Mac).

So when I add %matplotlib qt in the console, it works for me. What about you @SophieHerbst, @hoechenberger ?

Working in qtconsole and VS Code interactive Python window! Only annoying thing is the window opens in the background, not sure if that can be fixed? Btw menus are working properly this way too

'press ? for help' (I don't think the term 'key bindings' is very well understood by non-coding experts)

Still wondering if a hint in very small font size, "[?] Show key bindings", wouldn't be a good idea.

@larsoner
Copy link
Member

I don't think it's worth wasting the screen real estate. Putting a "press this for help" in the "working area" is highly abnormal. Putting help in a help menu at the top is about as standard as you can get.

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 13, 2020

Maybe a compromise would be to display the Press ? for help only for a few seconds when you start?
It's not necessary to display this message forever, it's just informative/a reminder.

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 13, 2020

Just throwing ideas. This is something we can always improve in another PR anyway, I believe it works as is.

@agramfort
Copy link
Member

works great. Can I just suggest some better shortcuts:

Toggle interface -> i
Scale -> s
Restore clim -> r

?

@GuillaumeFavelier
Copy link
Contributor Author

Can I just suggest some better shortcuts:

Totally. The diff is really small.
See if you like it now @agramfort

@hoechenberger
Copy link
Member

hoechenberger commented Feb 13, 2020

@GuillaumeFavelier Minor glitch but the default help window height is a little too small on my computer, causing visually unpleasant line spacing
Screen Shot 2020-02-13 at 17 58 02
If I make the window higher, it looks much better. The white space on the left is also a little irritating

@agramfort
Copy link
Member

agramfort commented Feb 13, 2020 via email

@hoechenberger
Copy link
Member

(btw is there any documentation on auto-scaling somewhere? what does it do, exactly?)

@drammock
Copy link
Member

Maybe a compromise would be to display the Press ? for help only for a few seconds when you start?

I'd say for now let's go with the menu. If / when PyVista adds new UI elements and some of the sliders get converted to buttons or dropdown boxes, we can revisit at that point whether there's enough screen space for "press ? for help".

@GuillaumeFavelier
Copy link
Contributor Author

If / when PyVista adds new UI elements and some of the sliders get converted to buttons or dropdown boxes, we can revisit at that point whether there's enough screen space for "press ? for help".

Fair enough.

btw is there any documentation on auto-scaling somewhere? what does it do, exactly?

No documentation so far. A good start is #7153 (comment) and #7218

@GuillaumeFavelier GuillaumeFavelier changed the title MRG: Add help window to the _TimeViewer WIP: Add help window to the _TimeViewer Feb 13, 2020
@larsoner larsoner merged commit 18259f5 into mne-tools:master Feb 13, 2020
@larsoner
Copy link
Member

Thanks @GuillaumeFavelier !

@GuillaumeFavelier
Copy link
Contributor Author

GuillaumeFavelier commented Feb 13, 2020

Whoops. I changed the title to WIP my bad. Very bad timing I suppose.

@larsoner
Copy link
Member

Sorry, missed that change. Just tack whatever you were going to do onto #7247, which we should also merge ASAP

@hoechenberger
Copy link
Member

@GuillaumeFavelier awesome work!!! 🥳

AdoNunes pushed a commit to AdoNunes/mne-python that referenced this pull request Apr 6, 2020
* Add help window

* Update window size and refactor _show_help()

* Use tuple instead of dict

* Refactor key bindings

* Refactor keyPressEvent

* Revert "Refactor keyPressEvent"

This reverts commit f7339c5.

* TST: try Key_questiondown

* Refactor keyPressEvent

* Use help menu instead of help label

* Update shortcuts
AdoNunes pushed a commit to AdoNunes/mne-python that referenced this pull request Apr 6, 2020
* Add help window

* Update window size and refactor _show_help()

* Use tuple instead of dict

* Refactor key bindings

* Refactor keyPressEvent

* Revert "Refactor keyPressEvent"

This reverts commit f7339c5.

* TST: try Key_questiondown

* Refactor keyPressEvent

* Use help menu instead of help label

* Update shortcuts
@GuillaumeFavelier GuillaumeFavelier deleted the time_viewer_help_window branch June 11, 2020 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: Add pop-up key mapping for PyVista stc.plot
6 participants