Skip to content

Commit

Permalink
shortcuts frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbautista committed Sep 16, 2024
1 parent a989ba7 commit 5d8cb80
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion qtconsole/frontend_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@
from .util import import_item


class ShortcutManager(HasTraits):
"""Default shortcuts definition and changes event handler."""

# Define traits for shortcuts
shortcut_copy_raw = Unicode('Ctrl+Shift+C').tag(config=True)

@observe('shortcut_copy_raw')
def _on_shortcut_changed(self, change):
self.log.debug(f"Shortcut for {change['name']} changed to: {change['new']}")


class FrontendHighlighter(PygmentsHighlighter):
""" A PygmentsHighlighter that understands and ignores prompts.
"""
Expand Down Expand Up @@ -187,14 +198,18 @@ def __init__(self, local_kernel=_local_kernel, *args, **kw):
self._call_tip_widget.setFont(self.font)
self.font_changed.connect(self._call_tip_widget.setFont)

self.shortcut_manager = ShortcutManager()

# Configure actions.
action = self._copy_raw_action
action.setEnabled(False)
action.setShortcut(QtGui.QKeySequence("Ctrl+Shift+C"))
action.setShortcut(self.shortcut_manager.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
self.shortcut_manager.observe(self.update_shortcuts, names=['shortcut_copy_raw'])

# Connect signal handlers.
document = self._control.document()
Expand All @@ -210,6 +225,10 @@ def __init__(self, local_kernel=_local_kernel, *args, **kw):
# 'ConsoleWidget' public interface
#---------------------------------------------------------------------------

def update_shortcuts(self, change):
if change['name'] == 'shortcut_copy_raw':
self.copy_raw_action.setShortcut(change['new'])

def copy(self):
""" Copy the currently selected text to the clipboard, removing prompts.
"""
Expand Down

0 comments on commit 5d8cb80

Please sign in to comment.