Repository: spyder-ide/spyder

Issue:
MacOS displaying Windows icons and shortcuts
### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [x] ~~Could not reproduce inside ``jupyter qtconsole`` (if console-related)~~
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [x] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [x] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The Spyder is displaying windows icons and windows shortcuts on a MacOS. I have tried intalling the Spyder, ran all the resets and also reinstalled the Anaconda. Nothing helped


### What steps reproduce the problem?

1. No steps needed besides opening Spyder.
2. 
3. 

### What is the expected output? What do you see instead?
The UI in Spyder dedicated to MacOS with MacOS shortcuts.



### Paste Traceback/Error Below (if applicable)

![image](https://user-images.githubusercontent.com/11056746/40255703-c41aafdc-5af0-11e8-8f3a-17a91f55aaad.png)
![image](https://user-images.githubusercontent.com/11056746/40255796-1b8dce8e-5af1-11e8-9664-0d09fcfa5281.png)


## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 3.2.8
* Python version: 3.6.4 
* Qt version: 5.6.2
* PyQt version: 5.6.0
* Operating System name/version: Mac OS High Sierra Version 10.13.4

### Dependencies
IPython >=4.0    :  6.2.1 (OK)
cython >=0.21    :  0.27.3 (OK)
jedi >=0.9.0     :  0.11.1 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
numpy >=1.7      :  1.14.0 (OK)
pandas >=0.13.1  :  0.22.0 (OK)
psutil >=0.3     :  5.4.3 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pyflakes >=0.6.0 :  1.6.0 (OK)
pygments >=2.0   :  2.2.0 (OK)
pylint >=0.25    :  1.8.2 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
rope >=0.9.4     :  0.10.7 (OK)
sphinx >=0.6.6   :  1.6.6 (OK)
sympy >=0.7.3    :  1.1.1 (OK)


Discussion:
Thanks for reporting, and going through all that. This seems unlikely to be a bug, and rather simply that we've currently not yet implemented platform-specific shortcut names there. Not sure how high a priority it will be for a fix, but for now, you can remember that <kbd>Ctrl</kbd> is equivalent to <kbd>Command</kbd> on a Mac, and <kbd>Alt</kbd> is equivalent to option (as should be printed on your keyboard).
Oh. Thank you for the feedback! 👍 I will then wait for the fix 
If you'd rather, and assuming @ccordoba12 thinks its a valid and good idea, you're welcome to take a shot at it yourself and we'd be glad to review a PR. I'm not sure anyone on the core dev team has ready access to a Mac to test it in any case, but we'd be glad to point to toward exactly what you'd need to change. Spyder is written in the very same Python language your code is, so presumably it shouldn't be too hard.
Sure, it's a valid concern.
Seems like an interesting challenge, so I am absolutely up for it.
So where should one start? Currently just exploring the code.
Hey, so the file [spyder/widgets/shortcutssummary.py](https://github.com/spyder-ide/spyder/blob/3.x/spyder/widgets/shortcutssummary.py) is where all the shortcut dialog related code is, and right around line 109 is where the actual label (title of the keystroke) gets set. So, a simple approach would just check for ``sys.platform.startswith('darwin')`` and if so, just ``.replace('Ctrl', 'Cmd')`` and so on with the shortcut text. Make sure you use the ``3.x`` branch as the base for your changes so they get implemented quickly.
> This seems unlikely to be a bug, and rather simply that we've currently not yet implemented platform-specific shortcut names there.

I found out that ^F1 (Control F1) for Help > Shortcuts Summary does not work, Command Tab to go to next file is bound with MacOS shortcut
> I found out that ^F1 (Control F1) for Help > Shortcuts Summary does not work

Can you try ``Command-F1``? I apparently can't test the default on Windows, since its mapped to ``Meta-F1``, which I guess Qt substitutes ``Control`` for on Macs. 

In fact, a lot of shortcuts have a ``Meta+<Key>`` assigned to them by default, and I'm not sure why other than it being a highly platform specific thing since no modern keyboards have it directly, and trying ``Esc``, ``Alt``, and ``Win`` to emulate it didn't work at least on Windows. Of course, that its a separate issue...

 @ccordoba12 Should I create an issue? I've been wondering why there were so many Meta shortcuts ever since I started using Spyder, but I'd just assumed I was just dumb and missing an obvious way to emulate it. Perhaps the Windows key words for this purpose on Linux, and maybe ``Control`` or ``Command`` does so on macOS, but for the majority of our users unfortunately stuck on Windows this is useless and confusing to users; even if they are on Linux or Mac they might not know what the Meta key is. Therefore, it seems we should either pick proper cross-platform shortcuts for our defaults, if we don't have separate defaults per platform.
@CAM-Gerlach It's mapped to the `Start` or `Windows` key for me in Ubuntu.  

I think most programs in Linux call that the `super` key these days.

That shortcut menu opened full screen on my 32 inch monitor with no clear indication how to close it(There were no window controls. `Esc` worked). I think a pop-up dialogue might work better 
> It's mapped to the `Start` or `Windows` key for me in Ubuntu.  

I see, as I figured it might (I couldn't reliably test it in my Fedora VM). Thanks for confirming.

In any case, I really don't think its a good idea to use a key that isn't accessible from at least one, if not two of our three major OSes (and the one its certainly not accessible from being our largest), as part of around 1/4th of our default shortcuts, much less one that doesn't directly match a key on any modern keyboard and isn't one of the standard three that most users generally expect.

> That shortcut menu opened full screen on my 32 inch monitor with no clear indication how to close it(There were no window controls. `Esc` worked).

Yup, same here on Windows. I naturally went for ``Esc`` to close, but I imagine not all users may have such an instinct and there should be at least one visible UI element to close it.
> Can you try Command-F1? I apparently can't test the default on Windows, since its mapped to Meta-F1, which I guess Qt substitutes Control for on Macs.

Command F1 does not work. Meta key is indeed Control. The shortcuts with meta that I tried work.
Look forward to your design decision.

Okay, thanks @minhtriet . So it works for everything, except

> ^F1 (Control F1) for Help > Shortcuts Summary does not work

Also, just to clarify, in the UI (the menu items, the shortcuts summary, and/or the keyboard shortcuts editor in the preferences), is Meta displayed as ``Meta`` or ``^``/``Control``? 

Finally, maybe this has changed since my days using Macs (I was a Mac user my whole life until 2012-2013), but I recall very few applications used ``Control`` for primary shortcuts (other than as a modifier key for performing other actions, and of course ``Control``-clicking) besides a few Linux ports. However, its been a while and Macs were never my primary development environment—any thoughts on this?

>  Command Tab to go to next file is bound with MacOS shortcut

Ah, that's a problem—it should be bound to ``^ Tab`` on Mac instead. I thought there was an issue somewhere about that, but I can't find it...it might even be fixed in the development branch (Spyder 3.3) already.
Hey,

So the menu item displays `^`.

The shortcut preferences are also using the correct symbolism. The shortcut preferences are using ctrl. The shortcut summary on a Mac with touchbar will have the touchbar display only the Esc item, which to an extent is of assistance. See pictures below:
<img width="354" alt="screen shot 2018-06-09 at 07 16 32" src="https://user-images.githubusercontent.com/11056746/41187592-842042ea-6bb5-11e8-86e5-c7981cc41d9c.png">
<img width="257" alt="screen shot 2018-06-09 at 07 16 04" src="https://user-images.githubusercontent.com/11056746/41187594-845ada9a-6bb5-11e8-8284-c112b8025f25.png">
<img width="254" alt="screen shot 2018-06-09 at 07 15 55" src="https://user-images.githubusercontent.com/11056746/41187595-8495e2de-6bb5-11e8-9f9b-a2b4e0c4768c.png">
<img width="457" alt="screen shot 2018-06-09 at 07 15 17" src="https://user-images.githubusercontent.com/11056746/41187596-84d0c9b2-6bb5-11e8-97e9-289a827e7033.png">

So, in summary on a Mac, it seems shortcuts are displayed with their correct Mac-localized symbols (Command, Option, Control) in the menus and Shortcut Editor, while in the Shortcut Summary, they are rendered with the default Linux names (Ctrl, Alt, Meta). That seems consistant with @GertL posted above, and what they said they would work on.

I guess the other separate issue I see, if @ccordoba12 agrees, is that right now a substantial fraction (~1/4) of the default shortcuts are broken and inapplicable on Windows, apparently our most popular OS judging from our bug tracker (i.e. anything with ``Meta``, since no application-accessible ``Meta`` key exists for the OS), while on Mac, those shortcuts are correctly mapped to ``^`` although that modifier isn't conventionally used much (but would still be well within the lexicon of an experienced Mac user), and on Linux its presumably much more common and accessible. Options to resolve would be either remapping those shortcuts to a common key, or localizing the default shortcuts to the user's OS, i.e. using different shortcuts or substituting another key for ``Meta`` on Windows, and possibly reconsidering some of the choices on Mac as well (more functional and OS-appropriate, but adding significant complexity and less cross-platform commonality).

Resolving patch:
diff --git a/spyder/widgets/shortcutssummary.py b/spyder/widgets/shortcutssummary.py
--- a/spyder/widgets/shortcutssummary.py
+++ b/spyder/widgets/shortcutssummary.py
@@ -13,9 +13,9 @@
 
 # Third party imports
 from qtpy.QtCore import Qt
-from qtpy.QtGui import QFont
+from qtpy.QtGui import QFont, QKeySequence
 from qtpy.QtWidgets import (QDialog, QLabel, QGridLayout, QGroupBox,
-                            QVBoxLayout, QHBoxLayout, QDesktopWidget, 
+                            QVBoxLayout, QHBoxLayout, QDesktopWidget,
                             QScrollArea, QWidget)
 
 # Local imports
@@ -106,6 +106,8 @@ def __init__(self, parent=None):
                 # Widgets
                 label_name = QLabel(name.capitalize().replace('_', ' '))
                 label_name.setFont(font_names)
+
+                keystr = QKeySequence(keystr).toString(QKeySequence.NativeText)
                 label_keystr = QLabel(keystr)
                 label_keystr.setFont(font_keystr)
 


Test patch:
diff --git a/spyder/widgets/tests/test_shortcutssummary.py b/spyder/widgets/tests/test_shortcutssummary.py
new file mode 100644
--- /dev/null
+++ b/spyder/widgets/tests/test_shortcutssummary.py
@@ -0,0 +1,65 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright © Spyder Project Contributors
+# Licensed under the terms of the MIT License
+#
+
+"""
+Tests for the Shortcut Summary Widget.
+"""
+import sys
+from random import sample
+
+import pytest
+from qtpy.QtCore import Qt
+
+from spyder.widgets.shortcutssummary import ShortcutsSummaryDialog
+
+
+@pytest.fixture
+def dlg_shortcuts(qtbot):
+    """Set up shortcut summary widget."""
+    dlg_shortcuts = ShortcutsSummaryDialog(None)
+    qtbot.addWidget(dlg_shortcuts)
+    dlg_shortcuts.show()
+    yield dlg_shortcuts
+    dlg_shortcuts.close()
+
+
+def test_shortcutssummary(dlg_shortcuts, qtbot):
+    """Test that shortcut summary is visible and is not empty"""
+    # Test that the dialog exists and is shown
+    assert dlg_shortcuts.isVisible()
+
+    # Test that the dialog is not empty
+    assert not dlg_shortcuts._layout.isEmpty()
+
+    # Test that the dialog is closed properly on Esc keypress
+    qtbot.keyClick(dlg_shortcuts, Qt.Key_Escape)
+    assert not dlg_shortcuts.isVisible()
+
+
+def test_shortcutssummary_texts(dlg_shortcuts, qtbot):
+    """Test that each shortcut has platform-specific key names."""
+    children = dlg_shortcuts.scroll_widget.layout().children()
+    for column_layout in sample(children, 3):
+        for group_idx in range(column_layout.count()):
+            try:
+                group_layout = (column_layout.itemAt(group_idx)
+                                .widget().layout())
+            except AttributeError:  # Since some groups are not present
+                continue
+            for shortcut_idx in range(group_layout.rowCount()):
+                try:
+                    shortcut_keystr = (
+                        group_layout.itemAtPosition(shortcut_idx, 1)
+                        .widget().text())
+                except AttributeError:  # Since some items are not present
+                    continue
+
+                if sys.platform.startswith('darwin'):
+                    keywords = [u'⇧', u'⌃', u'⌘', u'⌥', u'⌦',  u'⎋', 'F']
+                else:
+                    keywords = ['Alt', 'Ctrl', 'Del', 'Escape', 'F', 'Meta',
+                                'Shift']
+                assert any([key in shortcut_keystr for key in keywords])