Repository: spyder-ide/spyder
Pull request: PR: Improve shortcuts entry in Preferences
<!--- Make sure to read the Contributing Guidelines:                   --->
<!--- https://github.com/spyder-ide/spyder/blob/master/CONTRIBUTING.md --->
<!--- and follow PEP 8, PEP 257 and Spyder's code style:               --->
<!--- https://github.com/spyder-ide/spyder/wiki/Dev:-Coding-Style      --->

## Description of Changes


* [ ] Wrote at least one-line docstrings (for any new functions)
* [ ] Added unit test(s) covering the changes (if testable)
<!--- Remember that an image/animation is worth a thousand words! --->
* [x] Included a screenshot or animation (if affecting the UI, see [Licecap](https://www.cockos.com/licecap/))


<!--- Explain what you've done and why --->
Add a text label and placeholder for users to know they can customise their shortcuts. 

<img width="1038" alt="Captura de pantalla 2019-07-30 a la(s) 11 17 08 a  m" src="https://user-images.githubusercontent.com/20992645/62146718-97633300-b2bb-11e9-84b4-306b45f35c13.png">


### Issue(s) Resolved

<!--- List the issue(s) below, in the form "Fixes #1234"; one per line --->

Fixes #9891 


### Affirmation

By submitting this Pull Request or typing my (user)name below,
I affirm the [Developer Certificate of Origin](https://developercertificate.org)
with respect to all commits and content included in this PR,
and understand I am releasing the same under Spyder's MIT (Expat) license.

<!--- TYPE YOUR USER/NAME AFTER THE FOLLOWING: --->
I certify the above statement is true and correct: steff456

<!--- Thanks for your help making Spyder better for everyone! --->


Problem statement:
Improve shortcuts table UI
Right now there's very hard for people to know that they can customize our keyboard shortcuts in our Preferences. That's because there's no message mentioning that and no UI element signaling the possibility.

To fix this I think that we could do the following:

1. Add this message on top of the shortcuts table:
    > Here you can browse the list of all available shortcuts in Spyder. You can also customize them by clicking on any entry in this table.

2. Change the cursor to be a hand when hovering the shortcuts table and make a single click open the dialog to change shortcuts.

@goanpeca, @jnsebgosselin, what do you think about my suggestions?

Hints from issue discussion:
Hi @ccordoba12. I think the message should suffice :-), but i see no harm in adding the hand as well
Great! @steff456, please work on implementing my suggestions then.

Commit message: changes to placeholder and text label

Patch to review:
diff --git a/spyder/preferences/shortcuts.py b/spyder/preferences/shortcuts.py
index ff1565d92b4..84a6ae063c2 100644
--- a/spyder/preferences/shortcuts.py
+++ b/spyder/preferences/shortcuts.py
@@ -14,7 +14,7 @@
 from qtpy import PYQT5
 from qtpy.compat import from_qvariant, to_qvariant
 from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QEvent
-from qtpy.QtGui import QKeySequence, QIcon
+from qtpy.QtGui import QKeySequence, QIcon, QCursor, QMouseEvent
 from qtpy.QtWidgets import (QAbstractItemView, QApplication, QDialog,
                             QGridLayout, QHBoxLayout, QLabel,
                             QLineEdit, QMessageBox, QPushButton, QSpacerItem,
@@ -796,6 +796,15 @@ def keyPressEvent(self, event):
     def mouseDoubleClickEvent(self, event):
         """Qt Override."""
         self.show_editor()
+        self.update()
+
+    def mouseMoveEvent(self, event):
+        """Qt Override."""
+        QApplication.setOverrideCursor(QCursor(Qt.PointingHandCursor))
+
+    def leaveEvent(self, event):
+        """Qt Override."""
+        QApplication.setOverrideCursor(QCursor(Qt.ArrowCursor))
 
 
 class ShortcutsConfigPage(GeneralConfigPage):
@@ -808,12 +817,22 @@ def setup_page(self):
         self.table = ShortcutsTable(self, text_color=ima.MAIN_FG_COLOR)
         self.finder = ShortcutFinder(self.table, self.table.set_regex)
         self.table.finder = self.finder
+        self.table.finder.setPlaceholderText(
+            _("Search a shortcut in the table"))
+        self.table.setMouseTracking(True)
         self.label_finder = QLabel(_('Search: '))
         self.reset_btn = QPushButton(_("Reset to default values"))
+        self.label = QLabel()
+        self.label.setText(
+            _("Here you can browse the list of all available shortcuts in "
+              "Spyder. You can also customize them by double-clicking on any "
+              "entry in this table."))
+        self.label.setWordWrap(True)
 
         # Layout
         hlayout = QHBoxLayout()
         vlayout = QVBoxLayout()
+        vlayout.addWidget(self.label)
         hlayout.addWidget(self.label_finder)
         hlayout.addWidget(self.finder)
         vlayout.addWidget(self.table)


Code review comments:
diff_hunk: @@ -14,7 +14,7 @@
 from qtpy import PYQT5
 from qtpy.compat import from_qvariant, to_qvariant
 from qtpy.QtCore import QAbstractTableModel, QModelIndex, Qt, Slot, QEvent
-from qtpy.QtGui import QKeySequence, QIcon
+from qtpy.QtGui import QKeySequence, QIcon, QCursor, QMouseEvent
path: spyder/preferences/shortcuts.py
text: @user1:
Please remove `QCursor` and `QMouseEvent` because they are no longer needed.

diff_hunk: @@ -796,6 +796,15 @@ def keyPressEvent(self, event):
     def mouseDoubleClickEvent(self, event):
         """Qt Override."""
         self.show_editor()
+        self.update()
+
+    def mouseMoveEvent(self, event):
+        """Qt Override."""
+        QApplication.setOverrideCursor(QCursor(Qt.PointingHandCursor))
+
+    def leaveEvent(self, event):
+        """Qt Override."""
+        QApplication.setOverrideCursor(QCursor(Qt.ArrowCursor))
path: spyder/preferences/shortcuts.py
text: @user1:
Let's remove these two methods because `PointingHandCursor` is usually associated with a single click instead of a double one.

diff_hunk: @@ -808,12 +817,22 @@ def setup_page(self):
         self.table = ShortcutsTable(self, text_color=ima.MAIN_FG_COLOR)
         self.finder = ShortcutFinder(self.table, self.table.set_regex)
         self.table.finder = self.finder
+        self.table.finder.setPlaceholderText(
+            _("Search a shortcut in the table"))
+        self.table.setMouseTracking(True)
path: spyder/preferences/shortcuts.py
text: @user1:
I think this is not necessary anymore, so please remove it.

diff_hunk: @@ -808,12 +817,22 @@ def setup_page(self):
         self.table = ShortcutsTable(self, text_color=ima.MAIN_FG_COLOR)
         self.finder = ShortcutFinder(self.table, self.table.set_regex)
         self.table.finder = self.finder
+        self.table.finder.setPlaceholderText(
+            _("Search a shortcut in the table"))
path: spyder/preferences/shortcuts.py
text: @user1:
Let's change this to

    Search for a shortcut in the table above