def on_key_press_event(self, window, event): if global_settings.main_menu_mode: if main_menu.handle_key_press(event): return True # We have a <Control>Return accelerator, but this hooks up <Control>KP_Enter as well; # maybe someone wants that if ((event.keyval == gtk.keysyms.Return or event.keyval == gtk.keysyms.KP_Enter) and (event.state & gtk.gdk.CONTROL_MASK != 0) and (event.state & gtk.gdk.SHIFT_MASK == 0)): if self.current_editor and self.current_editor.needs_calculate: self.current_editor.calculate() return True return False
def on_key_press_event(self, window, event): if global_settings.main_menu_mode: if main_menu.handle_key_press(event): return True # Hook up KP_Enter to work like the Return key. In keeping with # Mathematica, KP_Enter without modifiers works as <shift>Return. if event.keyval == gtk.keysyms.KP_Enter: if self.current_editor and self.current_editor.needs_calculate: if event.state & gtk.gdk.CONTROL_MASK != 0: self.current_editor.calculate(end_at_insert=False) else: self.current_editor.calculate(end_at_insert=True) return True # If the calculate and calculate-to-line actions are insensitive, # GTK+ ignores the Return keybinding, and passes them through to the editor. # But the user didn't want to insert a line break, so block such keys if (event.keyval == gtk.keysyms.Return and (event.state & gtk.gdk.CONTROL_MASK != 0 or event.state & gtk.gdk.SHIFT_MASK != 0)): if self.current_editor and not self.current_editor.needs_calculate: return True return False