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] PR: Changes for handling Shortcuts with traitlets in consoleWidget #621

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
b8e75a3
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 2, 2024
e200cae
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 2, 2024
92549cb
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 2, 2024
fce7517
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 2, 2024
52ea153
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 9, 2024
cfe85aa
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 9, 2024
43524ac
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 9, 2024
881374a
Apply suggestions from code review
jsbautista Sep 14, 2024
a989ba7
add shortcut save console Widget
jsbautista Sep 16, 2024
5d8cb80
shortcuts frontend
jsbautista Sep 16, 2024
f999c97
add shortcut save console Widget
jsbautista Sep 16, 2024
213eedc
shortcuts frontend
jsbautista Sep 16, 2024
83c5a6a
Fix observe
jsbautista Sep 16, 2024
6f12aa5
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 23, 2024
c21cc13
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 23, 2024
6410fdc
Changes for handling Shortcuts with traitlets in consoleWidget
jsbautista Sep 29, 2024
6f70a04
shortcuts frontend
jsbautista Sep 29, 2024
5d3c768
Clean code
jsbautista Sep 29, 2024
4152b0f
Clean code
jsbautista Sep 29, 2024
38bfe95
shortcuts for mainWindow
jsbautista Sep 30, 2024
3e28103
shortcuts for mainWindow
jsbautista Sep 30, 2024
1591daf
shortcuts for mainWindow
jsbautista Sep 30, 2024
28465a1
shortcuts for mainWindow
jsbautista Oct 1, 2024
ffaece1
shortcuts for mainWindow
jsbautista Oct 2, 2024
3f74b2e
shortcuts console widget
jsbautista Oct 2, 2024
d1cd581
Delete update shortcut
jsbautista Oct 8, 2024
e027971
Apply suggestions
jsbautista Oct 17, 2024
97fcb75
Merge branch 'jupyter:main' into shortcutTraitlets
jsbautista Oct 17, 2024
6b0bef1
Apply suggestions
jsbautista Oct 17, 2024
891f3a9
Merge branch 'shortcutTraitlets' of https://github.com/jsbautista/qtc…
jsbautista Oct 17, 2024
1b8afd2
add test shortcuts
jsbautista Oct 21, 2024
709ccc6
add test shortcuts
jsbautista Oct 28, 2024
f0ad735
Clean Code
jsbautista Nov 5, 2024
c117dfb
Merge branch 'jupyter:main' into shortcutTraitlets
jsbautista Nov 5, 2024
fb73b90
Clean Code
jsbautista Nov 5, 2024
535130a
Merge branch 'shortcutTraitlets' of https://github.com/jsbautista/qtc…
jsbautista Nov 5, 2024
449c6c7
Clean Code
jsbautista Nov 5, 2024
4a28546
Add linux shortcut
jsbautista Nov 5, 2024
d87bc52
Add linux shortcuts
jsbautista Nov 5, 2024
8e1672e
Add linux shortcuts
jsbautista Nov 5, 2024
b1da48e
Add linux shortcuts
jsbautista Nov 5, 2024
6c0b2f6
Add linux shortcuts
jsbautista Nov 5, 2024
b8f348c
Add linux shortcuts
jsbautista Nov 5, 2024
1c68f9e
Add linux shortcuts
jsbautista Nov 5, 2024
3ce3707
Add linux shortcuts
jsbautista Nov 5, 2024
48ab8e8
Add linux shortcuts
jsbautista Nov 5, 2024
de5a9b7
Add linux shortcuts
jsbautista Nov 5, 2024
18fe59f
Add linux shortcuts
jsbautista Nov 5, 2024
e9fc85e
fix matches mainwindow
jsbautista Nov 5, 2024
0d90363
fix matches mainwindow
jsbautista Nov 5, 2024
4e14958
add test shortcuts
jsbautista Nov 12, 2024
10a4a4e
add test shortcuts
jsbautista Nov 12, 2024
f72bdf4
Fix test shortcuts
jsbautista Nov 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 47 additions & 13 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from traitlets.config.configurable import LoggingConfigurable
from traitlets import Bool, Enum, Integer, Unicode
from traitlets import default, HasTraits, observe

from .ansi_code_processor import QtAnsiCodeProcessor
from .completion_widget import CompletionWidget
Expand All @@ -44,6 +45,7 @@ def is_whitespace(char):
# Classes
#-----------------------------------------------------------------------------


class ConsoleWidget(MetaQObjectHasTraits('NewBase', (LoggingConfigurable, superQ(QtWidgets.QWidget)), {})):
""" An abstract base class for console-type widgets. This class has
functionality for:
Expand All @@ -60,6 +62,28 @@ class ConsoleWidget(MetaQObjectHasTraits('NewBase', (LoggingConfigurable, superQ

#------ Configuration ------------------------------------------------------

shortcut_print = Unicode('Ctrl+P').tag(config=True)
shortcut_select_all = Unicode('Ctrl+A').tag(config=True)
shortcut_cut = Unicode().tag(config=True)
shortcut_copy = Unicode().tag(config=True)
shortcut_paste = Unicode().tag(config=True)
shortcut_save = Unicode().tag(config=True)
shortcut_zoom_in = Unicode().tag(config=True)
shortcut_zoom_out = Unicode().tag(config=True)
shortcut_reset_font_size = Unicode('Ctrl+0').tag(config=True)
shortcut_actions = {}
def _shortcut_save_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Save).toString()
def _shortcut_cut_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Cut).toString()
def _shortcut_copy_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Copy).toString()
def _shortcut_paste_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Paste).toString()
def _shortcut_zoom_in_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.ZoomIn).toString()
def _shortcut_zoom_out_default(self):
return QtGui.QKeySequence(QtGui.QKeySequence.ZoomOut).toString()
ansi_codes = Bool(True, config=True,
help="Whether to process ANSI escape codes."
)
Expand Down Expand Up @@ -223,6 +247,7 @@ def _font_family_default(self):
# 'QObject' interface
#---------------------------------------------------------------------------


def __init__(self, parent=None, **kw):
""" Create a ConsoleWidget.

Expand Down Expand Up @@ -322,60 +347,66 @@ def __init__(self, parent=None, **kw):
# Configure actions.
action = QtWidgets.QAction('Print', None)
action.setEnabled(True)
printkey = QtGui.QKeySequence(QtGui.QKeySequence.Print)
printkey = QtGui.QKeySequence(self.shortcut_print)
if printkey.matches("Ctrl+P") and sys.platform != 'darwin':
# Only override the default if there is a collision.
# Qt ctrl = cmd on OSX, so the match gets a false positive on OSX.
printkey = "Ctrl+Shift+P"
action.setShortcut(printkey)
self.shortcut_print = "Ctrl+Shift+P"
action.setShortcut(self.shortcut_print)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.print_)
self.addAction(action)
self.print_action = action
self.shortcut_actions['shortcut_print']=self.print_action

action = QtWidgets.QAction('Save as HTML/XML', None)
action.setShortcut(QtGui.QKeySequence.Save)
action.setShortcut(self.shortcut_save)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.export_html)
self.addAction(action)
self.export_action = action
self.shortcut_actions['shortcut_save']=self.export_action

action = QtWidgets.QAction('Select All', None)
action.setEnabled(True)
selectall = QtGui.QKeySequence(QtGui.QKeySequence.SelectAll)
selectall = QtGui.QKeySequence(self.shortcut_select_all)
if selectall.matches("Ctrl+A") and sys.platform != 'darwin':
# Only override the default if there is a collision.
# Qt ctrl = cmd on OSX, so the match gets a false positive on OSX.
selectall = "Ctrl+Shift+A"
action.setShortcut(selectall)
self.shortcut_select_all = "Ctrl+Shift+A"
action.setShortcut(self.shortcut_select_all)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.select_all_smart)
self.addAction(action)
self.select_all_action = action
self.shortcut_actions['shortcut_select_all']=self.select_all_action

self.increase_font_size = QtWidgets.QAction("Bigger Font",
self,
shortcut=QtGui.QKeySequence.ZoomIn,
shortcut=self.shortcut_zoom_in,
shortcutContext=QtCore.Qt.WidgetWithChildrenShortcut,
statusTip="Increase the font size by one point",
triggered=self._increase_font_size)
self.addAction(self.increase_font_size)
self.shortcut_actions['shortcut_zoom_in']=self.increase_font_size

self.decrease_font_size = QtWidgets.QAction("Smaller Font",
self,
shortcut=QtGui.QKeySequence.ZoomOut,
shortcut=self.shortcut_zoom_out,
shortcutContext=QtCore.Qt.WidgetWithChildrenShortcut,
statusTip="Decrease the font size by one point",
triggered=self._decrease_font_size)
self.addAction(self.decrease_font_size)
self.shortcut_actions['shortcut_zoom_out']=self.decrease_font_size

self.reset_font_size = QtWidgets.QAction("Normal Font",
self,
shortcut="Ctrl+0",
shortcut=self.shortcut_reset_font_size,
shortcutContext=QtCore.Qt.WidgetWithChildrenShortcut,
statusTip="Restore the Normal font size",
triggered=self.reset_font)
self.addAction(self.reset_font_size)
self.shortcut_actions['shortcut_reset_font_size']=self.reset_font_size

# Accept drag and drop events here. Drops were already turned off
# in self._control when that widget was created.
Expand Down Expand Up @@ -1146,15 +1177,18 @@ def _context_menu_make(self, pos):

self.cut_action = menu.addAction('Cut', self.cut)
self.cut_action.setEnabled(self.can_cut())
self.cut_action.setShortcut(QtGui.QKeySequence.Cut)
self.cut_action.setShortcut(self.shortcut_cut)
self.shortcut_actions['shortcut_cut']=self.cut_action

self.copy_action = menu.addAction('Copy', self.copy)
self.copy_action.setEnabled(self.can_copy())
self.copy_action.setShortcut(QtGui.QKeySequence.Copy)
self.copy_action.setShortcut(self.shortcut_copy)
self.shortcut_actions['shortcut_copy']=self.copy_action

self.paste_action = menu.addAction('Paste', self.paste)
self.paste_action.setEnabled(self.can_paste())
self.paste_action.setShortcut(QtGui.QKeySequence.Paste)
self.paste_action.setShortcut(self.shortcut_paste)
self.shortcut_actions['shortcut_paste']=self.paste_action

anchor = self._control.anchorAt(pos)
if anchor:
Expand Down
7 changes: 6 additions & 1 deletion qtconsole/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

from qtconsole.base_frontend_mixin import BaseFrontendMixin
from traitlets import Any, Bool, Instance, Unicode, DottedObjectName, default
from traitlets.config.configurable import LoggingConfigurable
from traitlets import Enum, Integer, observe
from .bracket_matcher import BracketMatcher
from .call_tip_widget import CallTipWidget
from .history_console_widget import HistoryConsoleWidget
Expand Down Expand Up @@ -142,6 +144,8 @@ def _lexer_default(self):
lexer_class = import_item(self.lexer_class)
return lexer_class()

shortcut_copy_raw = Unicode('Ctrl+Shift+C').tag(config=True)

# Emitted when a user visible 'execute_request' has been submitted to the
# kernel from the FrontendWidget. Contains the code to be executed.
executing = QtCore.Signal(object)
Expand Down Expand Up @@ -190,11 +194,12 @@ def __init__(self, local_kernel=_local_kernel, *args, **kw):
# Configure actions.
action = self._copy_raw_action
action.setEnabled(False)
action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+C"))
action.setShortcut(self.shortcut_copy_raw)
action.setShortcutContext(QtCore.Qt.WidgetWithChildrenShortcut)
action.triggered.connect(self.copy_raw)
self.copy_available.connect(action.setEnabled)
self.addAction(action)
self.copy_raw_action = action

# Connect signal handlers.
document = self._control.document()
Expand Down
Loading
Loading