Beispiel #1
0
    def __key_press_event_cb(self, view, event):
        buf = view.get_buffer()
        state = event.state & Gtk.accelerator_get_default_mod_mask()
        ctrl = state & Gdk.ModifierType.CONTROL_MASK

        if event.keyval == Gdk.KEY_Return:
            buf.process_command_line()
            return True

        if event.keyval in (Gdk.KEY_KP_Down, Gdk.KEY_Down):
            buf.history.down(buf.get_command_line())
            return True
        if event.keyval in (Gdk.KEY_KP_Up, Gdk.KEY_Up):
            buf.history.up(buf.get_command_line())
            return True

        if event.keyval in (Gdk.KEY_KP_Left, Gdk.KEY_Left, Gdk.KEY_BackSpace):
            return buf.is_cursor(at=True)

        if event.keyval in (Gdk.KEY_KP_Home, Gdk.KEY_Home):
            buf.place_cursor(buf.get_iter_at_mark(buf.prompt_mark))
            return True

        if (ctrl and event.keyval == Gdk.KEY_d) or event.keyval == Gdk.KEY_Escape:
            return self.emit("eof")

        return False
Beispiel #2
0
 def get_modifiers(self, state):
     modifiers = Gtk.accelerator_get_default_mod_mask()
     ctrl_on = (state & modifiers) == Gdk.ModifierType.CONTROL_MASK
     shift_on = (state & modifiers) == Gdk.ModifierType.SHIFT_MASK
     alt_on = (state & modifiers) == Gdk.ModifierType.MOD1_MASK
     caps_on = (state & modifiers) == Gdk.ModifierType.LOCK_MASK
     return (ctrl_on, shift_on, alt_on, caps_on)
Beispiel #3
0
 def _on_key_press(self, widget, event):
     modifiers = Gtk.accelerator_get_default_mod_mask()
     if (event.keyval == Gdk.KEY_f and
             (event.state & modifiers) == Gdk.ModifierType.CONTROL_MASK):
         self._show_searchbar(not self.toolbar.searchbar.get_child_revealed())
     elif (event.keyval == Gdk.KEY_Escape and (event.state & modifiers) == 0):
         self._show_searchbar(False)
Beispiel #4
0
    def on_accelerator_key_press(self, entry, event):
        mask = event.state & Gtk.accelerator_get_default_mod_mask()

        if event.keyval == Gdk.KEY_Escape:
            self.update_accelerator_label()
            self['commands'].grab_focus()
            return True
        elif event.keyval in range(Gdk.KEY_F1, Gdk.KEY_F12 + 1):
            # New accelerator
            if self.set_accelerator(event.keyval, mask):
                self.update_accelerator_label()
                self['commands'].grab_focus()

            # Capture all `normal characters`
            return True
        elif Gdk.keyval_to_unicode(event.keyval):
            if mask:
                # New accelerator
                if self.set_accelerator(event.keyval, mask):
                    self.update_accelerator_label()
                    self['commands'].grab_focus()
            # Capture all `normal characters`
            return True
        else:
            return False
Beispiel #5
0
    def on_accelerator_key_press(self, entry, event):
        mask = event.state & Gtk.accelerator_get_default_mod_mask()

        if event.keyval == Gdk.KEY_Escape:
            entry.set_text(default(self.current_node.shortcut, ""))
            self["commands"].grab_focus()
            return True
        elif event.keyval == Gdk.KEY_Delete or event.keyval == Gdk.KEY_BackSpace:
            entry.set_text("")
            self.remove_accelerator(self.current_node)
            self.current_node.shortcut = None
            self["commands"].grab_focus()
            return True
        elif event.keyval in range(Gdk.KEY_F1, Gdk.KEY_F12 + 1):
            # New accelerator
            if self.set_accelerator(event.keyval, mask):
                entry.set_text(default(self.current_node.shortcut, ""))
                self["commands"].grab_focus()

            # Capture all `normal characters`
            return True
        elif Gdk.keyval_to_unicode(event.keyval):
            if mask:
                # New accelerator
                if self.set_accelerator(event.keyval, mask):
                    entry.set_text(default(self.current_node.shortcut, ""))
                    self["commands"].grab_focus()
            # Capture all `normal characters`
            return True
        else:
            return False
Beispiel #6
0
def is_accel(event, *accels):
    """Checks if the given keypress Gdk.Event matches
    any of accelerator strings.

    example: is_accel(event, "<shift><ctrl>z")
    """

    assert accels

    if event.type != Gdk.EventType.KEY_PRESS:
        return False

    # ctrl+shift+x gives us ctrl+shift+X and accelerator_parse returns
    # lowercase values for matching, so lowercase it if possible
    keyval = event.keyval
    if not keyval & ~0xFF:
        keyval = ord(chr(keyval).lower())

    default_mod = Gtk.accelerator_get_default_mod_mask()

    for accel in accels:
        accel_keyval, accel_mod = Gtk.accelerator_parse(accel)

        # If the accel contains non default modifiers matching will
        # never work and since no one should use them, complain
        non_default = accel_mod & ~default_mod
        if non_default:
            print_w("Accelerator '%s' contains a non default modifier '%s'." %
                (accel, Gtk.accelerator_name(0, non_default) or ""))

        # Remove everything except default modifiers and compare
        if (accel_keyval, accel_mod) == (keyval, event.state & default_mod):
            return True

    return False
    def on_window_key_press_event(self, window, event, notebooks):
        key = Gdk.keyval_name(event.keyval)
        state = event.state & Gtk.accelerator_get_default_mod_mask()

        if key == 'Control_L':
            self._ctrl_l = True

        if key == 'Control_R':
            self._ctrl_r = True

        if key in self.META_KEYS or not state & Gdk.ModifierType.CONTROL_MASK:
            return False

        is_ctrl = state == Gdk.ModifierType.CONTROL_MASK
        is_ctrl_shift = state == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK
        is_tab_key = key in ('ISO_Left_Tab', 'Tab')
        is_page_key = key in ('Page_Up', 'Page_Down')
        is_up_dir = key in ('ISO_Left_Tab', 'Page_Up')

        if not (((is_ctrl or is_ctrl_shift) and is_tab_key) or (is_ctrl and is_page_key)):
            self._end_switching()
            return False
        print("Keyval:", str(event.keyval))
        print(key)

        cur = window.get_active_tab()
        if cur:
            notebook = cur.get_parent()
            stack, model = notebooks[notebook]
            if is_page_key:
                tabs = stack
            else:
                tabs = notebook.get_children()
            tlen = len(tabs)

            if tlen > 1 and cur in tabs:
                if is_up_dir:
                    i = -1
                else:
                    i = 1
                next = tabs[(tabs.index(cur) + i) % tlen]

                model[stack.index(cur)][self.SELECTED_TAB_COLUMN] = False
                model[stack.index(next)][self.SELECTED_TAB_COLUMN] = True

                if is_page_key:
                    view = self._view
                    tabwin = view.get_toplevel()

                    min_size, nat_size = view.get_preferred_size()
                    tabwin.set_size_request(-1, min(nat_size.height, self.MAX_TAB_WINDOW_HEIGHT))
                    tabwin.present()

                    self._tabbing = True
                else:
                    self._paging = True

                window.set_active_tab(next)

        return True
Beispiel #8
0
def handle_keys(widget, event):
    print event
    modifiers = Gtk.accelerator_get_default_mod_mask()
    for mod in dir(Gdk.ModifierType):  # just printing what the modifier is
        if (event.state & modifiers) == getattr(Gdk.ModifierType, mod):
            print (mod)
    print Gdk.keyval_name(event.keyval)
Beispiel #9
0
    def _on_key_press(self, widget, event):
        modifiers = Gtk.accelerator_get_default_mod_mask()
        event_and_modifiers = (event.state & modifiers)

        if event_and_modifiers != 0:
            # Open search bar on Ctrl + F
            if (event.keyval == Gdk.KEY_f and
                    event_and_modifiers == Gdk.ModifierType.CONTROL_MASK):
                self.toolbar.searchbar.toggle_bar()
            # Go back from Album view on Alt + Left
            if (event.keyval == Gdk.KEY_Left and
                    event_and_modifiers == Gdk.ModifierType.MOD1_MASK):
                if (self.toolbar._state != ToolbarState.MAIN):
                    self.curr_view.set_visible_child(self.curr_view._grid)
                    self.toolbar.set_state(ToolbarState.MAIN)
        else:
            # Close search bar after Esc is pressed
            if event.keyval == Gdk.KEY_Escape:
                self.toolbar.searchbar.show_bar(False)
                # Also disable selection
                if self.toolbar._selectionMode:
                    self.toolbar.set_selection_mode(False)

        # Open search bar when typing printable chars if it not opened
        # Make sure we skip unprintable chars and don't grab space press
        # (this is used for play/pause)
        if not self.toolbar.searchbar.get_reveal_child() and not event.keyval == Gdk.KEY_space:
            if (event_and_modifiers == Gdk.ModifierType.SHIFT_MASK or
                    event_and_modifiers == 0) and \
                    GLib.unichar_isprint(chr(Gdk.keyval_to_unicode(event.keyval))):
                self.toolbar.searchbar.show_bar(True)
        else:
            if not self.toolbar.searchbar.get_reveal_child():
                if event.keyval == Gdk.KEY_space and self.player.actionbar.get_visible():
                    self.player.play_pause()
Beispiel #10
0
    def on_scroll_event(self, view, event):
        state = event.state & Gtk.accelerator_get_default_mod_mask()

        if state != Gdk.ModifierType.CONTROL_MASK:
            return False

        # Scroll to the keep the line in the centre of the screen anchored
        visible_rect = self.view.get_visible_rect()
        central_line_y = visible_rect.height / 2 + visible_rect.y
        central_line_iter, _ = self.view.get_line_at_y(central_line_y)
        self.view.scroll_to_iter(central_line_iter, 0, True, 0.5, 0.5)

        if event.direction == Gdk.ScrollDirection.UP:
            self.larger_text()
            return True
        elif event.direction == Gdk.ScrollDirection.DOWN:
            self.smaller_text()
            return True
        elif event.direction == Gdk.ScrollDirection.SMOOTH:
            if event.delta_y > 0:
                self.smaller_text()
            elif event.delta_y < 0:
                self.larger_text()

        return False
    def on_key_press_event(self, view, event):
        mods = Gtk.accelerator_get_default_mod_mask()
        # if tab or shift+tab:
        # with shift+tab key is GDK_ISO_Left_Tab (yay! on win32 and mac too!)
        if ((event.keyval == Gdk.KEY_Tab or event.keyval == Gdk.KEY_KP_Tab or event.keyval == Gdk.KEY_ISO_Left_Tab) and ((event.state & mods) == 0 or (event.state & mods) == Gdk.ModifierType.SHIFT_MASK)):

            if ((event.state & mods) == Gdk.ModifierType.SHIFT_MASK):
                doc = view.get_buffer()

                if doc.get_has_selection():
                    start_iter, end_iter = doc.get_selection_bounds()
                    start_line_nb = start_iter.get_line()
                    end_line_nb = end_iter.get_line()

                    doc.begin_user_action()

                    for i in xrange(start_line_nb, end_line_nb + 1):
                        self.reverseTab(doc, i)
                    doc.end_user_action()


                else:
                    doc.begin_user_action()

                    cursorLineNr = doc.get_iter_at_mark(doc.get_insert()).get_line()
                    self.reverseTab(doc, cursorLineNr)

                    doc.end_user_action()

                return True


        return False
    def on_key_press_event(self, view, event):
        #Bail out if text is selected
        doc = view.get_buffer()
        if doc.get_has_selection():
            return False

        # If we're at the begining of the line,
        # then, we don't have a need for anything special
        cur = doc.get_iter_at_mark(doc.get_insert())
        offset = cur.get_line_offset()
        if offset == 0:
            return False

	#Collect some state helpers
        mods = Gtk.accelerator_get_default_mod_mask()
        shift_pressed = event.state & Gdk.ModifierType.SHIFT_MASK != 0

        if event.keyval == Gdk.KEY_Return and event.state & mods == 0:
            return self.HandleReturn(doc, cur)

        if event.keyval == Gdk.KEY_Tab and not(shift_pressed):
            return self.HandleTab(doc, cur)

        if shift_pressed and event.keyval == Gdk.KEY_ISO_Left_Tab:
            return self.HandleShiftTab(doc, cur)

#        if event.keyval == Gdk.KEY_BackSpace:
#            return self.HandleBackSpace(doc, cur)

        return False # We didn't handle this event, pass it on
Beispiel #13
0
    def on_vte_key_press(self, term, event):
        modifiers = event.state & Gtk.accelerator_get_default_mod_mask()
        if event.keyval in (Gdk.KEY_Tab, Gdk.KEY_KP_Tab, Gdk.KEY_ISO_Left_Tab):
            if modifiers == Gdk.ModifierType.CONTROL_MASK:
                self.get_toplevel().child_focus(Gtk.DirectionType.TAB_FORWARD)
                return True
            elif modifiers == Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.SHIFT_MASK:
                self.get_toplevel().child_focus(Gtk.DirectionType.TAB_BACKWARD)
                return True

        for name in self._accels:
            path = self._accel_base + '/' + name
            entry = Gtk.AccelMap.lookup_entry(path)

            if entry and entry[0] and entry[1].accel_key == event.keyval and entry[1].accel_mods == modifiers:
                self._accels[name][2]()
                return True

        keyval_name = Gdk.keyval_name(Gdk.keyval_to_upper(event.keyval))

        # Special case some Vte.Terminal shortcuts
        # so the global shortcuts do not override them
        if modifiers == Gdk.ModifierType.CONTROL_MASK and keyval_name in 'ACDEHKLRTUWZ':
            return False

        if modifiers == Gdk.ModifierType.MOD1_MASK and keyval_name in 'BF':
            return False

        return Gtk.accel_groups_activate(self.get_toplevel(),
                                         event.keyval, modifiers)
Beispiel #14
0
 def on_button_press_event(self, eventbox, event):
     self.grab_focus()
     widget = eventbox.get_child()
     modifiers = Gtk.accelerator_get_default_mod_mask()
     ctrl = event.state & modifiers == Gdk.ModifierType.CONTROL_MASK
     shift = event.state & modifiers == Gdk.ModifierType.SHIFT_MASK
     selected_old = self.selected[:]
     self.secondary_cursor_at = self.cursor_at
     self.cursor_at = self.ordered_children.index(widget)
     if not ctrl:
         self.selected = []
     if shift:
         if self.secondary_cursor_at is not None:
             cursors = [self.secondary_cursor_at, self.cursor_at]
             cursors.sort()
             smaller = cursors[0]
             greater = cursors[1]
             self.selected = self.ordered_children[smaller:greater+1]
             # When using shift, cursor should remain the same
             self.cursor_at, self.secondary_cursor_at = \
                 self.secondary_cursor_at, self.cursor_at
     else:
         self.secondary_cursor_at = self.cursor_at
     if ctrl:
         if widget in self.selected:
             self.selected.remove(widget)
         else:
             self.selected.append(widget)
     elif widget not in self.selected:
         self.selected.append(widget)
     self.update_selection(selected_old)
Beispiel #15
0
 def move_selection_by_key(self, event):
     keyname = Gdk.keyval_name(event.keyval)
     modifiers = Gtk.accelerator_get_default_mod_mask()
     ctrl = event.state & modifiers == Gdk.ModifierType.CONTROL_MASK
     shift = event.state & modifiers == Gdk.ModifierType.SHIFT_MASK
     dif = {"Up": -self.columns, "Down": self.columns,
           "Left": -1, "Right":1}
     selected_old = self.selected[:]
     if ctrl:
         pass #TODO implement
     elif shift and self.cursor_at is not None:
         if (0 <= self.secondary_cursor_at + dif[keyname] 
                 < len(self.ordered_children)):
             self.secondary_cursor_at += dif[keyname]
             cursors = [self.secondary_cursor_at, self.cursor_at]
             cursors.sort()
             smaller = cursors[0]
             greater = cursors[1]
             self.selected = self.ordered_children[smaller:greater+1]
             self.update_selection(selected_old)
     elif self.cursor_at is not None:
         if self.secondary_cursor_at is not None:
             self.cursor_at = self.secondary_cursor_at
         if 0 <= self.cursor_at + dif[keyname] < len(self.ordered_children):    
             self.cursor_at += dif[keyname]
             self.secondary_cursor_at = self.cursor_at
             self.selected = [self.ordered_children[self.cursor_at]]
             self.update_selection(selected_old)
     if self.cursor_at is None:
         self.cursor_at = 0
         self.selected = [self.ordered_children[self.cursor_at]]
         self.update_selection([])
     return True    
Beispiel #16
0
    def handle_key_press_event(self, event):
        """Handle a key press event.

        By default, escape and alt + up will make the popup popdown.
        Return, KP_Enter, KP_Space and Tab will make it confirm.
        Subclasses can override this to handle more options.

        :param event: the gdk event
        :returns: ``True`` if the event was handled, ``False`` otherwise
        """
        keyval = event.get_keyval()[1]
        state = event.get_state()
        if state:
            state &= Gtk.accelerator_get_default_mod_mask()

        if (keyval == Gdk.KEY_Escape or
            (state == Gdk.ModifierType.MOD1_MASK and
             (keyval == Gdk.KEY_Up or keyval == Gdk.KEY_KP_Up))):
            self.popdown()
            return True
        elif keyval in [Gdk.KEY_Return,
                        Gdk.KEY_KP_Enter,
                        Gdk.KEY_KP_Space,
                        Gdk.KEY_Tab]:
            self.confirm()
            return True

        return False
Beispiel #17
0
    def __on_key_press(self, widget, event=None):
        grid = System.properties.grid
        modifier_mask = Gtk.accelerator_get_default_mod_mask()
        event.state = event.state & modifier_mask
        if event.state == Gdk.ModifierType.CONTROL_MASK:
            if event.keyval == Gdk.KEY_Up:
                self.move_selected_blocks(0, -grid*5)
                return True

            if event.keyval == Gdk.KEY_Down:
                self.move_selected_blocks(0, grid*5)
                return True
            if event.keyval == Gdk.KEY_Left:
                self.move_selected_blocks(-grid*5, 0)
                return True
            if event.keyval == Gdk.KEY_Right:
                self.move_selected_blocks(grid*5, 0)
                return True

        if event.keyval == Gdk.KEY_Delete:
            self.delete()
            return True

        if event.keyval == Gdk.KEY_Up:
            self.move_selected_blocks(0, -grid)
            return True
        if event.keyval == Gdk.KEY_Down:
            self.move_selected_blocks(0, grid)
            return True
        if event.keyval == Gdk.KEY_Left:
            self.move_selected_blocks(-grid, 0)
            return True
        if event.keyval == Gdk.KEY_Right:
            self.move_selected_blocks(grid, 0)
            return True
Beispiel #18
0
 def _on_key_press(self, view, event):
     """ Delegate key presses to sub-handlers """
     sub_handlers = [
         (config.MARK_TOGGLE, self._do_mark_toggle, ()),
         (config.MARK_UP, self._do_mark_vert, (True, False)),
         (config.MARK_DOWN, self._do_mark_vert, (False, False)),
         (config.MARK_ALT_UP, self._do_mark_vert, (True, True)),
         (config.MARK_ALT_DOWN, self._do_mark_vert, (False, True)),
     ]
     # Only valid if in imitation mode
     if self._marks:
         sub_handlers += [
             (config.CLEAR_MARKS, self._do_clear_marks, ()),
             (config.BACKSPACE, self._do_delete, (-1,)),
             (config.DELETE, self._do_delete, (1,)),
             (config.INCR_NUM, self._do_increment, (0,)),
             (config.INCR_NUM1, self._do_increment, (1,)),
             (config.INCR_LOWER, self._do_increment, ('a',)),
             (config.INCR_UPPER, self._do_increment, ('A',)),
         ]
     # Find and call sub-handler
     keyval = Gdk.keyval_to_lower(event.keyval)  # Accels always lowercase
     state = Gtk.accelerator_get_default_mod_mask() & event.state
     for accelerator, handler, args in sub_handlers:
         if keyval == accelerator[0] and state == accelerator[1]:
             handler(*args)
             return True
     return False
Beispiel #19
0
        def on_entry_accelerator_key_press(self, entry, event):
                source_view = self['source_view_snippet']

                if event.keyval == Gdk.keyval_from_name('Escape'):
                        # Reset
                        entry.set_text(self.snippet.accelerator_display())
                        self.tree_view.grab_focus()
                        
                        return True
                elif event.keyval == Gdk.keyval_from_name('Delete') or \
                                event.keyval == Gdk.keyval_from_name('BackSpace'):
                        # Remove the accelerator
                        entry.set_text('')
                        self.snippet['accelerator'] = ''
                        self.tree_view.grab_focus()
                        
                        self.snippet_changed()
                        return True
                elif Library().valid_accelerator(event.keyval, event.state):
                        # New accelerator
                        self.set_accelerator(event.keyval, \
                                        event.state & Gtk.accelerator_get_default_mod_mask())
                        entry.set_text(self.snippet.accelerator_display())
                        self.snippet_changed()
                        self.tree_view.grab_focus()

                else:
                        return True
    def on_key_press(self, term, event):
        modifiers = event.state & Gtk.accelerator_get_default_mod_mask()
        if event.keyval in (Gdk.KEY_X, Gdk.KEY_x):
            if modifiers == Gdk.ModifierType.CONTROL_MASK:
                self.on_cut_line_key_press(self);

        return False
Beispiel #21
0
    def handle_keys(self, widget, event):
        if event.keyval == Gdk.KEY_Escape:
            self.quit()

        modifiers = Gtk.accelerator_get_default_mod_mask()
        ctrl = (event.state & modifiers) == Gdk.ModifierType.CONTROL_MASK
        if ctrl and event.keyval in self.ctrl_keys_bind.keys():
            self.ctrl_keys_bind[event.keyval]()
Beispiel #22
0
    def on_button_press_event(self, view, event):
        state = event.state & Gtk.accelerator_get_default_mod_mask()

        if state == Gdk.ModifierType.CONTROL_MASK and event.button == 2:
            self.normal_size()
            return True
        else:
            return False
    def on_key_press_event(self, view, event):
        defmod = Gtk.accelerator_get_default_mod_mask() & event.state

        for handler in self._event_handlers:
            if (not handler[3] or self._in_mode) and event.keyval in handler[0] and (defmod == handler[1]):
                return handler[2](event)

        return False
Beispiel #24
0
    def _on_album_event(self, evbox, event, data=None):
        modifiers = Gtk.accelerator_get_default_mod_mask()
        if ((event.get_state() & modifiers) == Gdk.ModifierType.CONTROL_MASK
                and not self.props.selection_mode):
            self.props.selection_mode = True

        if self.props.selection_mode:
            self.props.selected = not self.props.selected
Beispiel #25
0
    def _key_press_cb(self, widget, event):
        """App-wide keypress handler for toplevel windows."""

        if not self.enabled:
            return
        # See gtk sourcecode in gtkmenu.c function gtk_menu_key_press,
        # which uses the same code as below when changing an accelerator.
        keymap = Gdk.Keymap.get_default()

        # Instead of using event.keyval, we do it the lowlevel way.
        # Reason: ignoring CAPSLOCK and checking if SHIFT was pressed
        state = Gdk.ModifierType(event.state & ~Gdk.ModifierType.LOCK_MASK)
        res = keymap.translate_keyboard_state(event.hardware_keycode, state,
                                              event.group)
        if not res:
            # PyGTK returns None when gdk_keymap_translate_keyboard_state()
            # returns false.  Not sure if this is a bug or a feature - the only
            # time I have seen this happen is when I put my laptop into sleep
            # mode.
            logger.warning('translate_keyboard_state() returned None. '
                           'Strange key pressed?')
            return

        keyval = res[1]
        consumed_modifiers = res[4]

        # We want to ignore irrelevant modifiers like ScrollLock.  The stored
        # key binding does not include modifiers that affected its keyval.
        modifiers = (
            event.state
            & Gtk.accelerator_get_default_mod_mask()
            & ~consumed_modifiers
        )

        # Except that key bindings are always stored in lowercase.
        keyval_lower = Gdk.keyval_to_lower(keyval)
        if keyval_lower != keyval:
            modifiers |= Gdk.ModifierType.SHIFT_MASK
        action = self.keymap.get((keyval_lower, modifiers))
        if not action:
            # try hardcoded keys
            action = self.keymap2.get((keyval_lower, modifiers))

        # Don't dispatch if the window is only sensitive to a subset of
        # actions, and the action is not in that set.
        if action is not None and isinstance(action, Gtk.Action):
            win_actions = self.window_actions.get(widget, None)
            if win_actions is not None:
                if action.get_name() not in win_actions:
                    return False

        # If the lookup succeeded, activate the corresponding action.
        if action:
            return self.activate_keydown_event(action, event)

        # Otherwise, dispatch the event to the active doc.
        return self._dispatch_fallthru_key_press_event(widget, event)
 def on_key_press(self, view, event):
   keyval = Gdk.keyval_to_lower(event.keyval)
   mask = Gtk.accelerator_get_default_mod_mask() & event.state
   for shortcut in self.keymap.values():
     if ((shortcut['accel'][0] == keyval) and 
         (shortcut['accel'][1] == mask)):
       shortcut['action']()
       return(True)
   return(False)
Beispiel #27
0
	def on_key_pressed(self, widget, event):
		defmod = Gtk.accelerator_get_default_mod_mask() & event.state

		if event.keyval == 0xff52 and defmod == Gdk.ModifierType.CONTROL_MASK:
			self.raise_selection()
		elif event.keyval == 0xff54 and defmod == Gdk.ModifierType.CONTROL_MASK:
			self.lower_selection()
		else:
			return False
		return True
Beispiel #28
0
    def dialog_key_press_cb(self, source, event):

        keyval = event.keyval
        modifier_mask = event.state & gtk.accelerator_get_default_mod_mask()

        if gtk.accelerator_valid(keyval, modifier_mask):
            self.set_value(gtk.accelerator_name(keyval, modifier_mask))
            self.emit('changed')
            gdk.Device.ungrab(gtk.get_current_event_device(), gtk.get_current_event_time())
            self.dialog.hide()
Beispiel #29
0
    def translate_keyboard_event(self, widget, event):
        keymap = Gdk.Keymap.get_for_display(widget.get_display())
        # translate keys properly
        _wasmapped, keyval, egroup, level, consumed = keymap.translate_keyboard_state(
                    event.hardware_keycode, event.get_state(), event.group)
        modifiers = Gtk.accelerator_get_default_mod_mask() & ~consumed

        state = event.get_state() & modifiers

        return keyval, state
    def on_key_release_event(self, view, event):

        mods = Gtk.accelerator_get_default_mod_mask()
        # if tab or shift+tab:
        # with shift+tab key is GDK_ISO_Left_Tab (yay! on win32 and mac too!)
        if ((event.keyval == Gdk.KEY_Tab or event.keyval == Gdk.KEY_KP_Tab or event.keyval == Gdk.KEY_ISO_Left_Tab) and ((event.state & mods) == 0 or (event.state & mods) == Gdk.ModifierType.SHIFT_MASK)):
            doc = view.get_buffer()


            if doc.get_has_selection():
                start_iter, end_iter = doc.get_selection_bounds()
                start_line_nb = start_iter.get_line()
                end_line_nb = end_iter.get_line()

                doc.begin_user_action()

                for i in xrange(start_line_nb, end_line_nb + 1):
                    lineIterStart = doc.get_iter_at_line(i)
                    while lineIterStart.get_char() == '\t':
                        lineIterStart.forward_char()

                    lineIterEnd = lineIterStart.copy()

                    while True:
                        lineIterEnd.forward_chars(8)
                        if lineIterStart.get_text(lineIterEnd) == "        ":
                            doc.delete(lineIterStart, lineIterEnd)
                            doc.insert(lineIterStart, "\t")
                            lineIterEnd = lineIterStart.copy()
                        else:
                            break
                doc.end_user_action()

            else:
#                doc.begin_user_action()
                cursorLineNr = doc.get_iter_at_mark(doc.get_insert()).get_line()
                lineIterStart = doc.get_iter_at_line(cursorLineNr)

                while lineIterStart.get_char() == '\t':
                    lineIterStart.forward_char()

                lineIterEnd = lineIterStart.copy()

                while True:
                    lineIterEnd.forward_chars(8)
                    if lineIterStart.get_text(lineIterEnd) == "        ":
                        doc.delete(lineIterStart, lineIterEnd)
                        doc.insert(lineIterStart, "\t")
                        lineIterEnd = lineIterStart.copy()
                    else:
                        break
#                doc.end_user_action()
#            print dir(doc)

        return False