From e19e591a5cfb95d0a4bed2437c5cd319c4a46280 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 28 Jul 2016 11:01:52 -0500 Subject: [PATCH 1/9] Add shortcuts Summary Window --- spyder/widgets/shortcuts.py | 122 ++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 spyder/widgets/shortcuts.py diff --git a/spyder/widgets/shortcuts.py b/spyder/widgets/shortcuts.py new file mode 100644 index 00000000000..8bd8a0bc464 --- /dev/null +++ b/spyder/widgets/shortcuts.py @@ -0,0 +1,122 @@ +# -*- coding: utf-8 -*- +# +# Copyright © 2009- The Spyder Development Team +# Licensed under the terms of the MIT License +# (see spyderlib/__init__.py for details) + +"""Shortcut Summary dialog""" + +# TODO: +# calculate windows size from screen size + +# Standard library imports +from operator import itemgetter +from itertools import groupby + +# Third party imports +from qtpy.QtCore import Qt +from qtpy.QtGui import QFont +from qtpy.QtWidgets import (QDialog, QLabel, QGridLayout, QGroupBox, + QVBoxLayout, QHBoxLayout) + +# Local imports +from spyder.config.base import _ +from spyder.config.gui import iter_shortcuts + +# Constants +SHORTCUT_SHOURTCUTS_SUMMARY = "Ctrl+H" +MAX_SHOURCUTS_COLUMN = 28 + + +class ShortCutsSummaryDialog(QDialog): + def __init__(self, parent=None, offset=0, force_float=False): + QDialog.__init__(self, parent=parent) + + self._shortcuts_summary_title = _("Spyder Keyboard ShortCuts") + + # Widgets + style = """ + QDialog { + margin:0px; + padding:0px; + border-radius: 2px; + }""" + self.setStyleSheet(style) + + groupbox_style = "QGroupBox { font-weight: bold;}" + + font_titles = QFont() + font_titles.setBold(True) + + title_label = QLabel(self._shortcuts_summary_title) + title_label.setAlignment(Qt.AlignCenter) + title_label.setFont(font_titles) + + # iter over shortcuts and create GroupBox for each context + # with shortcuts in a grid + + columns_layout = QHBoxLayout() + added_shortcuts = 0 + # group shortcuts by context + shortcuts = groupby(sorted(iter_shortcuts()), key=itemgetter(0)) + + for context, group_shortcuts in shortcuts: + for i, (context, name, keystr) in enumerate(group_shortcuts): + # start of every column + if added_shortcuts == 0: + column_layout = QVBoxLayout() + + # at start of new context add previous context group + if i == 0 and added_shortcuts > 0: + column_layout.addWidget(group) + + # create group at start of column or context + if added_shortcuts == 0 or i == 0: + if context == '_': context = 'Global' + + group = QGroupBox(context.capitalize()) + group.setStyleSheet(groupbox_style) + + group_layout = QGridLayout() + group.setLayout(group_layout) + + # Widgets + label_name = QLabel(name.capitalize().replace('_', ' ')) + label_name.setFont(font_titles) + label_keystr = QLabel(keystr) + + group_layout.addWidget(label_name, i, 0) + group_layout.addWidget(label_keystr, i, 1) + + added_shortcuts += 1 + + if added_shortcuts >= MAX_SHOURCUTS_COLUMN: + column_layout.addWidget(group) + columns_layout.addLayout(column_layout) + added_shortcuts = 0 + + column_layout.addWidget(group) + column_layout.addStretch() # avoid lasts sections to appear too big + columns_layout.addLayout(column_layout) + + # widget setup + self.setWindowFlags(Qt.FramelessWindowHint) + self.setWindowOpacity(0.95) + + # layout + self._layout = QVBoxLayout() + self._layout.addWidget(title_label) + self._layout.addLayout(columns_layout) + self.setLayout(self._layout) + + +def test(): # pragma: no cover + from spyder.utils.qthelpers import qapplication + app = qapplication() + dlg_shortcuts = ShortCutsSummaryDialog(None) + dlg_shortcuts.show() + app.exec_() + + +if __name__ == "__main__": # pragma: no cover + test() From d6543b65f6f93942a6c9fbf53dfa4d9a9cd27af0 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Mon, 19 Sep 2016 16:10:29 -0500 Subject: [PATCH 2/9] Add menu item and shortcut for shortcuts summary --- spyder/app/mainwindow.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index e48799b134e..150af81d9ae 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -924,6 +924,10 @@ def create_edit_action(text, tr_text, icon): else: tut_action = None + shortcuts_action = create_action(self, _("Shortcuts Sumary"), + shortcut="Meta+F1", + triggered=self.show_shortcuts_dialog) + #----- Tours self.tour = tour.AnimatedTour(self) self.tours_menu = QMenu(_("Interactive tours")) @@ -945,7 +949,8 @@ def trigger(i=i, self=self): # closure needed! self.tours_menu.addActions(self.tour_menu_actions) - self.help_menu_actions = [doc_action, tut_action, self.tours_menu, + self.help_menu_actions = [doc_action, tut_action, shortcuts_action, + self.tours_menu, MENU_SEPARATOR, report_action, dep_action, self.check_updates_action, support_action, MENU_SEPARATOR] @@ -2621,6 +2626,13 @@ def apply_shortcuts(self): for index in sorted(toberemoved, reverse=True): self.shortcut_data.pop(index) + @Slot() + def show_shortcuts_dialog(self): + from spyder.widgets.shortcuts import ShortCutsSummaryDialog + dlg = ShortCutsSummaryDialog(None) + dlg.show() + dlg.exec_() + # -- Open files server def start_open_files_server(self): self.open_files_server.setsockopt(socket.SOL_SOCKET, From 60a8f9889a756f03205877e6b44bc4c9bfb543e6 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Thu, 22 Sep 2016 09:45:52 -0500 Subject: [PATCH 3/9] Shortcuts Summary: Calculate font_size and amount of elements per column using screen size --- spyder/widgets/shortcuts.py | 40 +++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/spyder/widgets/shortcuts.py b/spyder/widgets/shortcuts.py index 8bd8a0bc464..54661f7daac 100644 --- a/spyder/widgets/shortcuts.py +++ b/spyder/widgets/shortcuts.py @@ -17,16 +17,15 @@ from qtpy.QtCore import Qt from qtpy.QtGui import QFont from qtpy.QtWidgets import (QDialog, QLabel, QGridLayout, QGroupBox, - QVBoxLayout, QHBoxLayout) + QVBoxLayout, QHBoxLayout, QDesktopWidget) # Local imports from spyder.config.base import _ from spyder.config.gui import iter_shortcuts # Constants -SHORTCUT_SHOURTCUTS_SUMMARY = "Ctrl+H" -MAX_SHOURCUTS_COLUMN = 28 - +MAX_FONT_SIZE = 16 +MIN_FONT_SIZE = 8 class ShortCutsSummaryDialog(QDialog): def __init__(self, parent=None, offset=0, force_float=False): @@ -34,6 +33,12 @@ def __init__(self, parent=None, offset=0, force_float=False): self._shortcuts_summary_title = _("Spyder Keyboard ShortCuts") + # Calculate font and amount of elements in each column according screen size + width, height = self.get_screen_resolution() + font_size = height / 80 + font_size = max(min(font_size, MAX_FONT_SIZE), MIN_FONT_SIZE) + shortcuts_column = (height - 8 * font_size) / (font_size +16) + # Widgets style = """ QDialog { @@ -43,14 +48,20 @@ def __init__(self, parent=None, offset=0, force_float=False): }""" self.setStyleSheet(style) - groupbox_style = "QGroupBox { font-weight: bold;}" + font_names = QFont() + font_names.setPointSize(font_size) + font_names.setBold(True) - font_titles = QFont() - font_titles.setBold(True) + font_keystr = QFont() + font_keystr.setPointSize(font_size) + + font_title = QFont() + font_title.setPointSize(font_size+2) + font_title.setBold(True) title_label = QLabel(self._shortcuts_summary_title) title_label.setAlignment(Qt.AlignCenter) - title_label.setFont(font_titles) + title_label.setFont(font_title) # iter over shortcuts and create GroupBox for each context # with shortcuts in a grid @@ -75,22 +86,23 @@ def __init__(self, parent=None, offset=0, force_float=False): if context == '_': context = 'Global' group = QGroupBox(context.capitalize()) - group.setStyleSheet(groupbox_style) + group.setFont(font_names) group_layout = QGridLayout() group.setLayout(group_layout) # Widgets label_name = QLabel(name.capitalize().replace('_', ' ')) - label_name.setFont(font_titles) + label_name.setFont(font_names) label_keystr = QLabel(keystr) + label_keystr.setFont(font_keystr) group_layout.addWidget(label_name, i, 0) group_layout.addWidget(label_keystr, i, 1) added_shortcuts += 1 - if added_shortcuts >= MAX_SHOURCUTS_COLUMN: + if added_shortcuts >= shortcuts_column: column_layout.addWidget(group) columns_layout.addLayout(column_layout) added_shortcuts = 0 @@ -109,6 +121,12 @@ def __init__(self, parent=None, offset=0, force_float=False): self._layout.addLayout(columns_layout) self.setLayout(self._layout) + def get_screen_resolution(self): + """Return the screen resolution of the primary screen.""" + widget = QDesktopWidget() + geometry = widget.availableGeometry(widget.primaryScreen()) + return geometry.width(), geometry.height() + def test(): # pragma: no cover from spyder.utils.qthelpers import qapplication From 7b9252213422349518a959595f0e01cf52fd2e28 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Tue, 27 Sep 2016 14:01:59 -0500 Subject: [PATCH 4/9] Several Fixes: - Fix misspelling Summary - Remove dlg.show() - Change spyderlib for spyder in Copyright comment - Remove TODO out of date - Add docstring - Remove unused parameters --- spyder/app/mainwindow.py | 3 +-- spyder/widgets/shortcuts.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index 150af81d9ae..2b5ad4e54ed 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -924,7 +924,7 @@ def create_edit_action(text, tr_text, icon): else: tut_action = None - shortcuts_action = create_action(self, _("Shortcuts Sumary"), + shortcuts_action = create_action(self, _("Shortcuts Summary"), shortcut="Meta+F1", triggered=self.show_shortcuts_dialog) @@ -2630,7 +2630,6 @@ def apply_shortcuts(self): def show_shortcuts_dialog(self): from spyder.widgets.shortcuts import ShortCutsSummaryDialog dlg = ShortCutsSummaryDialog(None) - dlg.show() dlg.exec_() # -- Open files server diff --git a/spyder/widgets/shortcuts.py b/spyder/widgets/shortcuts.py index 54661f7daac..75484647c32 100644 --- a/spyder/widgets/shortcuts.py +++ b/spyder/widgets/shortcuts.py @@ -2,12 +2,10 @@ # # Copyright © 2009- The Spyder Development Team # Licensed under the terms of the MIT License -# (see spyderlib/__init__.py for details) +# (see spyder/__init__.py for details) """Shortcut Summary dialog""" -# TODO: -# calculate windows size from screen size # Standard library imports from operator import itemgetter @@ -28,7 +26,16 @@ MIN_FONT_SIZE = 8 class ShortCutsSummaryDialog(QDialog): - def __init__(self, parent=None, offset=0, force_float=False): + """ + Dialog window listing the spyder and plugins shortcuts. + + It contains all the shortcuts avalaible through iter_shortcuts + function + + The shortcuts are dysplayed in different columns, and grouped by + context (global, editor, console...) + """ + def __init__(self, parent=None): QDialog.__init__(self, parent=parent) self._shortcuts_summary_title = _("Spyder Keyboard ShortCuts") From f2a1947555dcf712676653cd510b9f9186cab550 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Wed, 30 Nov 2016 16:57:22 -0500 Subject: [PATCH 5/9] Rename shortcuts.py file to shortcutssummary.py --- spyder/app/mainwindow.py | 2 +- spyder/widgets/{shortcuts.py => shortcutssummary.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename spyder/widgets/{shortcuts.py => shortcutssummary.py} (100%) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index 2b5ad4e54ed..58ae6d25db4 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -2628,7 +2628,7 @@ def apply_shortcuts(self): @Slot() def show_shortcuts_dialog(self): - from spyder.widgets.shortcuts import ShortCutsSummaryDialog + from spyder.widgets.shortcutssummary import ShortCutsSummaryDialog dlg = ShortCutsSummaryDialog(None) dlg.exec_() diff --git a/spyder/widgets/shortcuts.py b/spyder/widgets/shortcutssummary.py similarity index 100% rename from spyder/widgets/shortcuts.py rename to spyder/widgets/shortcutssummary.py From aa61d8dbba32576a22dfea5b87630a178e0d85f0 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Wed, 30 Nov 2016 16:58:25 -0500 Subject: [PATCH 6/9] Fix little typo in ShortcutsSummaryDialog class name --- spyder/app/mainwindow.py | 4 ++-- spyder/widgets/shortcutssummary.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py index 58ae6d25db4..7a66a948eb9 100644 --- a/spyder/app/mainwindow.py +++ b/spyder/app/mainwindow.py @@ -2628,8 +2628,8 @@ def apply_shortcuts(self): @Slot() def show_shortcuts_dialog(self): - from spyder.widgets.shortcutssummary import ShortCutsSummaryDialog - dlg = ShortCutsSummaryDialog(None) + from spyder.widgets.shortcutssummary import ShortcutsSummaryDialog + dlg = ShortcutsSummaryDialog(None) dlg.exec_() # -- Open files server diff --git a/spyder/widgets/shortcutssummary.py b/spyder/widgets/shortcutssummary.py index 75484647c32..154871cd1b2 100644 --- a/spyder/widgets/shortcutssummary.py +++ b/spyder/widgets/shortcutssummary.py @@ -25,7 +25,7 @@ MAX_FONT_SIZE = 16 MIN_FONT_SIZE = 8 -class ShortCutsSummaryDialog(QDialog): +class ShortcutsSummaryDialog(QDialog): """ Dialog window listing the spyder and plugins shortcuts. @@ -138,7 +138,7 @@ def get_screen_resolution(self): def test(): # pragma: no cover from spyder.utils.qthelpers import qapplication app = qapplication() - dlg_shortcuts = ShortCutsSummaryDialog(None) + dlg_shortcuts = ShortcutsSummaryDialog(None) dlg_shortcuts.show() app.exec_() From 25df8bb2a468fcc130058959ba125fe2fd4cd922 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Tue, 9 May 2017 16:54:17 -0500 Subject: [PATCH 7/9] ShortcutsSummary: Initialize group variable to prevent possible errors --- spyder/widgets/shortcutssummary.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyder/widgets/shortcutssummary.py b/spyder/widgets/shortcutssummary.py index 154871cd1b2..6572514f8ea 100644 --- a/spyder/widgets/shortcutssummary.py +++ b/spyder/widgets/shortcutssummary.py @@ -75,6 +75,7 @@ def __init__(self, parent=None): columns_layout = QHBoxLayout() added_shortcuts = 0 + group = None # group shortcuts by context shortcuts = groupby(sorted(iter_shortcuts()), key=itemgetter(0)) From eda8cfca289f87599ac37d98d1176f21ae6f18a7 Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Tue, 9 May 2017 17:12:18 -0500 Subject: [PATCH 8/9] ShortcutsSummary: Use a ScrollArea to avoid the dialog to be greater than the screen. --- spyder/widgets/shortcutssummary.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/spyder/widgets/shortcutssummary.py b/spyder/widgets/shortcutssummary.py index 6572514f8ea..f5b9cb6aeb4 100644 --- a/spyder/widgets/shortcutssummary.py +++ b/spyder/widgets/shortcutssummary.py @@ -15,7 +15,8 @@ from qtpy.QtCore import Qt from qtpy.QtGui import QFont from qtpy.QtWidgets import (QDialog, QLabel, QGridLayout, QGroupBox, - QVBoxLayout, QHBoxLayout, QDesktopWidget) + QVBoxLayout, QHBoxLayout, QDesktopWidget, + QScrollArea, QWidget) # Local imports from spyder.config.base import _ @@ -119,6 +120,12 @@ def __init__(self, parent=None): column_layout.addStretch() # avoid lasts sections to appear too big columns_layout.addLayout(column_layout) + # Scroll widget + self.scroll_widget = QWidget() + self.scroll_widget.setLayout(columns_layout) + self.scroll_area = QScrollArea() + self.scroll_area.setWidget(self.scroll_widget) + # widget setup self.setWindowFlags(Qt.FramelessWindowHint) self.setWindowOpacity(0.95) @@ -126,9 +133,12 @@ def __init__(self, parent=None): # layout self._layout = QVBoxLayout() self._layout.addWidget(title_label) - self._layout.addLayout(columns_layout) + + self._layout.addWidget(self.scroll_area) self.setLayout(self._layout) + self.setGeometry(0, 0, width, height) + def get_screen_resolution(self): """Return the screen resolution of the primary screen.""" widget = QDesktopWidget() From 01a0510768e1ed1d81cd705642df476a7a6ff01d Mon Sep 17 00:00:00 2001 From: Rafael Laverde Date: Wed, 10 May 2017 08:53:51 -0500 Subject: [PATCH 9/9] ShortcutsSummary: Take titles in account for calculate amount of shortcuts in each column. --- spyder/widgets/shortcutssummary.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spyder/widgets/shortcutssummary.py b/spyder/widgets/shortcutssummary.py index f5b9cb6aeb4..b2cc1ea3e95 100644 --- a/spyder/widgets/shortcutssummary.py +++ b/spyder/widgets/shortcutssummary.py @@ -100,6 +100,9 @@ def __init__(self, parent=None): group_layout = QGridLayout() group.setLayout(group_layout) + # Count space for titles + added_shortcuts += 1 + # Widgets label_name = QLabel(name.capitalize().replace('_', ' ')) label_name.setFont(font_names)