Skip to content

Commit

Permalink
shortcuts for mainWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbautista committed Oct 1, 2024
1 parent 1591daf commit 28465a1
Showing 1 changed file with 43 additions and 7 deletions.
50 changes: 43 additions & 7 deletions qtconsole/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,22 @@ def _shortcut_next_tab_default(self):
return next_key
shortcut_rename_window = Unicode('Alt+R').tag(config=True)
shortcut_rename_current_tab = Unicode('Ctrl+R').tag(config=True)

@observe('shortcut_full_screen')
shortcut_actions = {}
@observe('shortcut_clear')
def update_shortcuts(self, change):
shortcut_actions = {
'shortcut_full_screen': self.full_screen_act
}
self.full_screen_act.setShortcut(change['new'])
self.log.debug(f"Shortcut for {change['name']} updated to: {change['new']}")
action = self.shortcut_actions.get(change['name'])
if action:
action.setShortcut(change['new'])
self.log.debug(f"Shortcut for {change['name']} updated to: {change['new']}")
else:
self.log.debug(f"No action found for shortcut {change['name']}")

def update_all_shortcuts(self):
for shortcut, action in self.shortcut_actions.items():
if action:
ns = getattr(self, shortcut, None)
action.setShortcut(ns)
self.log.debug(f"Shortcut for {action} set to {shortcut} shortcut {ns}")

#---------------------------------------------------------------------------
# 'object' interface
Expand Down Expand Up @@ -468,18 +476,21 @@ def init_file_menu(self):
shortcut=self.shortcut_new_kernel_tab,
triggered=self.create_tab_with_new_frontend)
self.add_menu_action(self.file_menu, self.new_kernel_tab_act)
self.shortcut_actions['shortcut_new_kernel_tab'] = self.new_kernel_tab_act

self.slave_kernel_tab_act = QtWidgets.QAction("New Tab with Sa&me kernel",
self,
shortcut=self.shortcut_slave_kernel_tab,
triggered=self.create_tab_with_current_kernel)
self.add_menu_action(self.file_menu, self.slave_kernel_tab_act)
self.shortcut_actions['shortcut_slave_kernel_tab'] = self.slave_kernel_tab_act

self.existing_kernel_tab_act = QtWidgets.QAction("New Tab with &Existing kernel",
self,
shortcut=self.shortcut_existing_kernel_tab,
triggered=self.create_tab_with_existing_kernel)
self.add_menu_action(self.file_menu, self.existing_kernel_tab_act)
self.shortcut_actions['shortcut_existing_kernel_tab'] = self.existing_kernel_tab_act

self.file_menu.addSeparator()

Expand All @@ -489,13 +500,15 @@ def init_file_menu(self):
triggered=self.close_active_frontend
)
self.add_menu_action(self.file_menu, self.close_action)
self.shortcut_actions['shortcut_close'] = self.close_action

self.export_action=QtWidgets.QAction("&Save to HTML/XHTML",
self,
shortcut=self.shortcut_save,
triggered=self.export_action_active_frontend
)
self.add_menu_action(self.file_menu, self.export_action, True)
self.shortcut_actions['shortcut_save'] = self.export_action

self.file_menu.addSeparator()

Expand All @@ -509,6 +522,7 @@ def init_file_menu(self):
shortcut=self.shortcut_print,
triggered=self.print_action_active_frontend)
self.add_menu_action(self.file_menu, self.print_action, True)
self.shortcut_actions['shortcut_print'] = self.print_action

if sys.platform != 'darwin':
# OSX always has Quit in the Application menu, only add it
Expand All @@ -522,6 +536,7 @@ def init_file_menu(self):
triggered=self.close,
)
self.add_menu_action(self.file_menu, self.quit_action)
self.shortcut_actions['shortcut_quit'] = self.quit_action


def init_edit_menu(self):
Expand All @@ -534,13 +549,15 @@ def init_edit_menu(self):
triggered=self.undo_active_frontend
)
self.add_menu_action(self.edit_menu, self.undo_action)
self.shortcut_actions['shortcut_undo'] = self.undo_action

self.redo_action = QtWidgets.QAction("&Redo",
self,
shortcut=self.shortcut_redo,
statusTip="Redo last action if possible",
triggered=self.redo_active_frontend)
self.add_menu_action(self.edit_menu, self.redo_action)
self.shortcut_actions['shortcut_redo'] = self.redo_action

self.edit_menu.addSeparator()

Expand All @@ -550,27 +567,31 @@ def init_edit_menu(self):
triggered=self.cut_active_frontend
)
self.add_menu_action(self.edit_menu, self.cut_action, True)
self.shortcut_actions['shortcut_cut'] = self.cut_action

self.copy_action = QtWidgets.QAction("&Copy",
self,
shortcut=self.shortcut_copy,
triggered=self.copy_active_frontend
)
self.add_menu_action(self.edit_menu, self.copy_action, True)
self.shortcut_actions['shortcut_copy'] = self.copy_action

self.copy_raw_action = QtWidgets.QAction("Copy (&Raw Text)",
self,
shortcut=self.shortcut_copy_raw,
triggered=self.copy_raw_active_frontend
)
self.add_menu_action(self.edit_menu, self.copy_raw_action, True)
self.shortcut_actions['shortcut_copy_raw'] = self.copy_raw_action

self.paste_action = QtWidgets.QAction("&Paste",
self,
shortcut=self.shortcut_paste,
triggered=self.paste_active_frontend
)
self.add_menu_action(self.edit_menu, self.paste_action, True)
self.shortcut_actions['shortcut_paste'] = self.paste_action

self.edit_menu.addSeparator()

Expand All @@ -585,6 +606,7 @@ def init_edit_menu(self):
triggered=self.select_all_active_frontend
)
self.add_menu_action(self.edit_menu, self.select_all_action, True)
self.shortcut_actions['shortcut_select_all'] = self.select_all_action


def init_view_menu(self):
Expand All @@ -598,6 +620,7 @@ def init_view_menu(self):
statusTip="Toggle visibility of menubar",
triggered=self.toggle_menu_bar)
self.add_menu_action(self.view_menu, self.toggle_menu_bar_act)
self.shortcut_actions['shortcut_ctrl_shift_m'] = self.toggle_menu_bar_act

self.full_screen_act = QtWidgets.QAction("&Full Screen",
self,
Expand All @@ -606,6 +629,7 @@ def init_view_menu(self):
triggered=self.toggleFullScreen)

self.add_menu_action(self.view_menu, self.full_screen_act)
self.shortcut_actions['shortcut_full_screen'] = self.full_screen_act

self.view_menu.addSeparator()

Expand All @@ -615,20 +639,23 @@ def init_view_menu(self):
triggered=self.increase_font_size_active_frontend
)
self.add_menu_action(self.view_menu, self.increase_font_size, True)
self.shortcut_actions['shortcut_zoom_in'] = self.increase_font_size

self.decrease_font_size = QtWidgets.QAction("Zoom &Out",
self,
shortcut=self.shortcut_zoom_out,
triggered=self.decrease_font_size_active_frontend
)
self.add_menu_action(self.view_menu, self.decrease_font_size, True)
self.shortcut_actions['shortcut_zoom_out'] = self.decrease_font_size

self.reset_font_size = QtWidgets.QAction("Zoom &Reset",
self,
shortcut=self.shortcut_reset_font_size,
triggered=self.reset_font_size_active_frontend
)
self.add_menu_action(self.view_menu, self.reset_font_size, True)
self.shortcut_actions['shortcut_reset_font_size'] = self.reset_font_size

self.view_menu.addSeparator()

Expand All @@ -638,6 +665,7 @@ def init_view_menu(self):
statusTip="Clear the console",
triggered=self.clear_active_frontend)
self.add_menu_action(self.view_menu, self.clear_action)
self.shortcut_actions['shortcut_clear'] = self.clear_action

self.completion_menu = self.view_menu.addMenu("&Completion type")

Expand Down Expand Up @@ -722,13 +750,15 @@ def init_kernel_menu(self):
shortcut=self.shortcut_interrupt_kernel,
)
self.add_menu_action(self.kernel_menu, self.interrupt_kernel_action)
self.shortcut_actions['shortcut_interrupt_kernel'] = self.interrupt_kernel_action

self.restart_kernel_action = QtWidgets.QAction("&Restart current Kernel",
self,
triggered=self.restart_kernel_active_frontend,
shortcut=self.shortcut_restart_kernel,
)
self.add_menu_action(self.kernel_menu, self.restart_kernel_action)
self.shortcut_actions['shortcut_restart_kernel'] = self.restart_kernel_action

self.kernel_menu.addSeparator()

Expand Down Expand Up @@ -759,7 +789,9 @@ def init_window_menu(self):
triggered=self.toggleMaximized)

self.add_menu_action(self.window_menu, self.minimizeAct)
self.shortcut_actions['shortcut_minimize'] = self.minimizeAct
self.add_menu_action(self.window_menu, self.maximizeAct)
self.shortcut_actions['shortcut_ctrl_shift_m'] = self.maximizeAct
self.window_menu.addSeparator()

self.prev_tab_act = QtWidgets.QAction("Pre&vious Tab",
Expand All @@ -768,20 +800,23 @@ def init_window_menu(self):
statusTip="Select previous tab",
triggered=self.prev_tab)
self.add_menu_action(self.window_menu, self.prev_tab_act)
self.shortcut_actions['shortcut_prev_tab'] = self.prev_tab_act

self.next_tab_act = QtWidgets.QAction("Ne&xt Tab",
self,
shortcut=self.shortcut_next_tab,
statusTip="Select next tab",
triggered=self.next_tab)
self.add_menu_action(self.window_menu, self.next_tab_act)
self.shortcut_actions['shortcut_next_tab'] = self.next_tab_act

self.rename_window_act = QtWidgets.QAction("Rename &Window",
self,
shortcut=self.shortcut_rename_window,
statusTip="Rename window",
triggered=self.set_window_title)
self.add_menu_action(self.window_menu, self.rename_window_act)
self.shortcut_actions['shortcut_rename_window'] = self.rename_window_act


self.rename_current_tab_act = QtWidgets.QAction("&Rename Current Tab",
Expand All @@ -790,6 +825,7 @@ def init_window_menu(self):
statusTip="Rename current tab",
triggered=self.set_tab_title)
self.add_menu_action(self.window_menu, self.rename_current_tab_act)
self.shortcut_actions['shortcut_rename_current_tab'] = self.rename_current_tab_act

def init_help_menu(self):
# please keep the Help menu in Mac Os even if empty. It will
Expand Down

0 comments on commit 28465a1

Please sign in to comment.