Skip to content

Commit

Permalink
add shortcut save console Widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbautista committed Sep 16, 2024
1 parent 881374a commit a989ba7
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions qtconsole/console_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ class ShortcutManager(HasTraits):
shortcut_cut = Unicode().tag(config=True)
shortcut_copy = Unicode().tag(config=True)
shortcut_paste = Unicode().tag(config=True)
shortcut_save = Unicode.tag(config=True)

@default('shortcut_save')
def _default_shortcut_save(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Save).toString()

@default('shortcut_cut')
def _default_shortcut_cut(self):
Expand All @@ -67,10 +72,9 @@ def _default_shortcut_copy(self):
def _default_shortcut_paste(self):
return QtGui.QKeySequence(QtGui.QKeySequence.Paste).toString()

@observe('shortcut_print', 'shortcut_select_all','shortcut_cut','shortcut_copy','shortcut_paste')
@observe('shortcut_print', 'shortcut_select_all','shortcut_cut','shortcut_copy','shortcut_paste','shortcut_save')
def _on_shortcut_changed(self, change):
print(f"Shortcut for {change['name']} changed to: {change['new']}")

self.log.debug(f"Shortcut for {change['name']} changed to: {change['new']}")


class ConsoleWidget(MetaQObjectHasTraits('NewBase', (LoggingConfigurable, superQ(QtWidgets.QWidget)), {})):
Expand Down Expand Up @@ -367,11 +371,12 @@ def __init__(self, parent=None, **kw):
self.shortcut_manager.observe(self.update_shortcuts, names=['shortcut_print'])

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

action = QtWidgets.QAction('Select All', None)
action.setEnabled(True)
Expand Down

0 comments on commit a989ba7

Please sign in to comment.