Python gi.repository.Gdk 模块,keyval_name() 实例源码

我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用gi.repository.Gdk.keyval_name()

项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_key_press(self, app, key_event):
        """
            Keyboard Listener handling
        """
        keyname = Gdk.keyval_name(key_event.keyval).lower()
        if not settings.get_is_locked():
            if not self.no_account_box.is_visible():
                if keyname == "s" or keyname == "escape":
                    if key_event.state == Gdk.ModifierType.CONTROL_MASK or not self.hb.select_button.get_visible():
                        self.toggle_select()
                        return True

            if keyname == "n":
                if key_event.state == Gdk.ModifierType.CONTROL_MASK:
                    self.add_account()
                    return True
            if keyname == "m":
                if key_event.state == Gdk.ModifierType.CONTROL_MASK:
                    self.hb.toggle_view_mode()
                    return True
        return False
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_key_press(self, key, key_event):
        """
            Keyboard Listener handler
        """
        key_name = Gdk.keyval_name(key_event.keyval).lower()
        if key_name == "escape":
            self.close_window()
            return True

        if key_name == "return":
            if self.apply_button.get_sensitive():
                self.add_account()
                return True

        if key_event.state & Gdk.ModifierType.CONTROL_MASK:
            if key_name == 's':
                self.on_qr_scan()
                return True

        return False
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __on_key_press(self, widget, event):
        keyname = Gdk.keyval_name(event.keyval).lower()
        if keyname == 'escape' and self.search_button.get_active():
            if self.search_entry.is_focus():
                self.search_button.set_active(False)
                self.search_entry.set_text("")
            else:
                self.focus()

        if not settings.get_is_locked():
            if keyname == "backspace":
                if self.is_empty() and self.is_visible():
                    self.search_button.set_active(False)
                    return True

            if event.state & Gdk.ModifierType.CONTROL_MASK:
                if keyname == 'f':
                    self.search_button.set_active(
                        not self.search_button.get_active())
                    return True
        return False
项目:python-gui    作者:neovim    | 项目源码 | 文件源码
def _gtk_key(self, widget, event, *args):
        # This function was adapted from pangoterm source code
        keyval = event.keyval
        state = event.state
        # GtkIMContext will eat a Shift-Space and not tell us about shift.
        # Also don't let IME eat any GDK_KEY_KP_ events
        done = (False if state & SHIFT and keyval == ord(' ') else
                False if Gdk.KEY_KP_Space <= keyval <= Gdk.KEY_KP_Divide else
                self._im_context.filter_keypress(event))
        if done:
            # input method handled keypress
            return True
        if event.is_modifier:
            # We don't need to track the state of modifier bits
            return
        # translate keyval to nvim key
        key_name = Gdk.keyval_name(keyval)
        if key_name.startswith('KP_'):
            key_name = key_name[3:]
        input_str = _stringify_key(KEY_TABLE.get(key_name, key_name), state)
        self._bridge.input(input_str)
项目:razerCommander    作者:GabMus    | 项目源码 | 文件源码
def on_recordKeystrokeToggleBtn_key_release_event(self, toggle_btn, event):
        if toggle_btn.get_active():
            keyname = Gdk.keyval_name(event.keyval)
            self.key_stroke_n -= 1
            if not self.key_stroke_n:
                keystroke = ''
                for i in range(0, 4):
                    if self.keystroke_shortcuts_all_mods[i].get_active():
                        keystroke += self.keystroke_shortcuts_all_mods_str[i]+'+'
                keystroke += '+'.join(self.key_stroke_list)
                self.macro_current_keystroke_label.set_text(keystroke)
                self.key_stroke_list = []
                self.key_stroke_n = 0
                toggle_btn.set_active(False)
        else:
            self.key_stroke_n = 0
            self.key_stroke_list = []

    # Handler functions END
项目:Icon-Requests    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __on_key_press(self, widget, event):
        keyname = Gdk.keyval_name(event.keyval).lower()
        is_ready = self.main_stack.get_visible_child_name() != "loading"
        if keyname == 'escape' and self.search_button.get_active() and is_ready:
            if self.search_entry.is_focus():
                self.search_button.set_active(False)
                self.search_entry.set_text("")
            else:
                self.search_entry.grab_focus_without_selecting()
            return True

        if keyname == "backspace":
            if (len(self.search_entry.get_text()) == 0
                    and self.revealer.get_reveal_child()):
                self.search_button.set_active(False)
                return True

        if event.state & Gdk.ModifierType.CONTROL_MASK:
            if keyname == 'f':
                self.search_button.set_active(
                    not self.search_button.get_active())
                return True
        return False
项目:PyCut    作者:FOSSRIT    | 项目源码 | 文件源码
def _keyevent(self, widget, event, type):
        key = Gdk.keyval_name(event.keyval)
        if key is None:
            # No idea what this key is.
            return False 

        keycode = None
        if key in self.key_trans:
            keycode = self.key_trans[key]
        elif hasattr(pygame, 'K_'+key.upper()):
            keycode = getattr(pygame, 'K_'+key.upper())
        elif hasattr(pygame, 'K_'+key.lower()):
            keycode = getattr(pygame, 'K_'+key.lower())
        elif key == 'XF86Start':
            # view source request, specially handled...
            self._mainwindow.view_source()
        else:
            print 'Key %s unrecognized' % key

        if keycode is not None:
            if type == pygame.KEYDOWN:
                mod = self._keymods()
            self.__keystate[keycode] = type == pygame.KEYDOWN
            if type == pygame.KEYUP:
                mod = self._keymods()
            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
            if ukey == '\000':
                ukey = ''
            evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
            self._post(evt)

        return True
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __on_key_press(self, widget, event):
        keyname = Gdk.keyval_name(event.keyval).lower()
        if settings.get_is_locked():
            if keyname == "return":
                self.on_unlock()
                return True
        else:
            pass_enabled = settings.get_can_be_locked()
            if keyname == "l" and pass_enabled:
                if event.state & Gdk.ModifierType.CONTROL_MASK:
                    self.on_lock()
                    return True

        return False
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def navigate(self, *args):
        """
            Keyboard Listener handling
        """
        keyname = Gdk.keyval_name(args[2]).lower()
        if not settings.get_is_locked():
            count = len(self.get_children())
            dx = -1 if keyname == "up" else 1
            selected_row = self.get_selected_row()
            if selected_row is not None:
                index = selected_row.get_index()
                new_index = (index + dx) % count
                self.select_row(self.get_row_at_index(new_index))
                return True
        return False
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_key_press(self, widget, event):
        keyname = Gdk.keyval_name(event.keyval).lower()
        if not self.window.is_locked():
            if self.parent.get_selected_row_id() == self.account.get_id():
                is_search_bar = self.window.search_bar.is_visible()
                is_editing_name = self.name_entry.is_visible()
                if keyname == "delete" and not is_search_bar and not is_editing_name:
                    self.remove()
                    return True

                if keyname == "escape":
                    if is_editing_name:
                        self.toggle_edit_mode(False)
                        return True

                if event.state & Gdk.ModifierType.CONTROL_MASK:
                    if keyname == 'e':
                        self.edit()
                        return True

                if keyname == "return":
                    if is_editing_name:
                        self.apply_edit_name()
                    else:
                        self.toggle_code_box()
                    return True

                if event.state & Gdk.ModifierType.CONTROL_MASK:
                    if keyname == 'c':
                        self.copy_code()
                        return True
        return False
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def __on_key_press(self, key, key_event):
        """
            Keyboard Listener handler
        """
        if Gdk.keyval_name(key_event.keyval).lower() == "escape":
            self.close_window()
项目:Gnome-Authenticator    作者:bil-elmoussaoui    | 项目源码 | 文件源码
def on_key_press(self, key, key_event):
        """
            Keyboard listener handler
        """
        if Gdk.keyval_name(key_event.keyval) == "Escape":
            self.close_window()
项目:PyIDE    作者:raggesilver    | 项目源码 | 文件源码
def complete(self, view, event):
        self.hasSelection = self.sbuff.props.has_selection

        if self.hasSelection:
            bounds = self.sbuff.get_selection_bounds()
            self.start, self.end = bounds
            self.selectionText = self.sbuff.get_text(self.start, self.end, False)

        ignore = Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.MOD1_MASK

        if (event.type != Gdk.EventType.KEY_PRESS or event.state & ignore or Gdk.keyval_name(event.key.keyval) not in self.chars):
            self.hadSelection = self.hasSelection
            return

        insert = self.get_insert()
        closing = self.chars[Gdk.keyval_name(event.key.keyval)]

        if Gdk.keyval_name(event.key.keyval) == 'less' and not self.sbuff.get_language() is None and self.sbuff.get_language().get_name().lower() != 'html':
            return

        if not self.hadSelection and not self.hasSelection:
            self.sbuff.begin_user_action()
            self.sbuff.insert(insert, closing)
            self.sbuff.end_user_action()
            insert.backward_chars(1)
            self.sbuff.place_cursor(insert)

        else:
            self.sbuff.begin_user_action()
            self.selectionText += closing
            self.sbuff.insert(insert, self.selectionText)
            self.sbuff.end_user_action()
            insert.backward_chars(1)
            self.sbuff.place_cursor(insert)
项目:Ebook-Viewer    作者:michaldaniel    | 项目源码 | 文件源码
def __on_keypress_viewer(self, wiget, data):
        """
        Handles Left and Right arrow key presses
        :param wiget:
        :param data:
        """
        if self.content_provider.status:
            key_value = Gdk.keyval_name(data.keyval)
            if key_value == "Right":
                self.load_chapter(self.content_provider.current_chapter + 1)
            elif key_value == "Left":
                self.load_chapter(self.content_provider.current_chapter - 1)
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def on_txt_goto_key_press_event(self, wiget, event):
        keyval_name = Gdk.keyval_name(event.keyval)
        if keyval_name == "Return":
            self.__manage_goto()
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def on_txt_search_key_press_event(self, widget, event):
        keyval_name = Gdk.keyval_name(event.keyval)
        if keyval_name == "Return" and any(self.model):
            self.__focus_song(self.model[0][0])
项目:HFOSSFinal    作者:AlanLeeson    | 项目源码 | 文件源码
def _keyevent(self, widget, event, type):
        key = Gdk.keyval_name(event.keyval)
        if key is None:
            # No idea what this key is.
            return False 

        keycode = None
        if key in self.key_trans:
            keycode = self.key_trans[key]
        elif hasattr(pygame, 'K_'+key.upper()):
            keycode = getattr(pygame, 'K_'+key.upper())
        elif hasattr(pygame, 'K_'+key.lower()):
            keycode = getattr(pygame, 'K_'+key.lower())
        elif key == 'XF86Start':
            # view source request, specially handled...
            self._mainwindow.view_source()
        else:
            print 'Key %s unrecognized' % key

        if keycode is not None:
            if type == pygame.KEYDOWN:
                mod = self._keymods()
            self.__keystate[keycode] = type == pygame.KEYDOWN
            if type == pygame.KEYUP:
                mod = self._keymods()
            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
            if ukey == '\000':
                ukey = ''
            evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
            self._post(evt)

        return True
项目:Linalfred    作者:PeterHo    | 项目源码 | 文件源码
def catch_button(window, event, label):
    keyval = event.keyval
    name = Gdk.keyval_name(keyval)
    print(event.state)
    mod = Gtk.accelerator_get_label(keyval, event.state)
    label.set_markup('<span size="xx-large">%s\n%d</span>' % (mod, keyval))
项目:input-paste    作者:RPing    | 项目源码 | 文件源码
def on_key_press(self, widget, event):
        keyname = Gdk.keyval_name(event.keyval)
        if event.state & Gdk.ModifierType.CONTROL_MASK and keyname == 'Return' or keyname == 'Return':
            self.copy_to_clipboard()
            self.destroy(self, widget)
            p = pyautogui.position()
            pyautogui.click(p)
            pyautogui.hotkey('ctrl', 'v')
        if keyname == 'Escape':
            Gtk.main_quit()
项目:razerCommander    作者:GabMus    | 项目源码 | 文件源码
def on_recordKeystrokeToggleBtn_key_press_event(self, toggle_btn, event):
        if toggle_btn.get_active():
            keyname = Gdk.keyval_name(event.keyval)
            if keyname not in self.key_stroke_list:
                self.key_stroke_list.append(keyname)
                self.key_stroke_n += 1
        else:
            self.key_stroke_n = 0
            self.key_stroke_list = []
项目:math-hurdler    作者:craigcabrey    | 项目源码 | 文件源码
def _keyevent(self, widget, event, type):
        key = Gdk.keyval_name(event.keyval)
        if key is None:
            # No idea what this key is.
            return False 

        keycode = None
        if key in self.key_trans:
            keycode = self.key_trans[key]
        elif hasattr(pygame, 'K_'+key.upper()):
            keycode = getattr(pygame, 'K_'+key.upper())
        elif hasattr(pygame, 'K_'+key.lower()):
            keycode = getattr(pygame, 'K_'+key.lower())
        elif key == 'XF86Start':
            # view source request, specially handled...
            self._mainwindow.view_source()
        else:
            print 'Key %s unrecognized' % key

        if keycode is not None:
            if type == pygame.KEYDOWN:
                mod = self._keymods()
            self.__keystate[keycode] = type == pygame.KEYDOWN
            if type == pygame.KEYUP:
                mod = self._keymods()
            ukey = unichr(Gdk.keyval_to_unicode(event.keyval))
            if ukey == '\000':
                ukey = ''
            evt = pygame.event.Event(type, key=keycode, unicode=ukey, mod=mod)
            self._post(evt)

        return True
项目:kickoff-player    作者:jonian    | 项目源码 | 文件源码
def on_window_main_key_release_event(self, _widget, event):
    stack = self.app.get_stack_visible_child()
    kname = Gdk.keyval_name(event.keyval)

    if stack == self.stack and kname == 'F11':
      self.toggle_fullscreen()
项目:MokaPlayer    作者:vedard    | 项目源码 | 文件源码
def on_window_key_press(self, widget, event):
        keyval_name = Gdk.keyval_name(event.keyval)
        ctrl = (event.state & Gdk.ModifierType.CONTROL_MASK)

        if ctrl and keyval_name == 'f':
            search_mode = self.search_bar.get_search_mode()
            self.search_bar.set_search_mode(not search_mode)
            if not search_mode:
                self.txt_search.grab_focus()
                self.goto_bar.set_search_mode(False)
        elif ctrl and keyval_name == 'l':
            self.__show_lyrics(self.player.queue.peek())
        elif ctrl and keyval_name == 'p':
            search_mode = self.goto_bar.get_search_mode()
            self.goto_bar.set_search_mode(not search_mode)
            if not search_mode:
                self.txt_goto.grab_focus()
                self.search_bar.set_search_mode(False)
        elif ctrl and keyval_name == 'o':
            self.__focus_song(self.player.queue.peek())
        elif ctrl and keyval_name == 'y':
            self.on_view_toggle_visualization_activate(None)
        elif ctrl and keyval_name == 'g':
            if self.player.queue.peek():
                self.current_playlist = ArtistPlaylist(song_path=self.player.queue.peek())
                self.__show_current_playlist()
        elif ctrl and keyval_name == 'Left':
            self.player.streamer.volume -= 0.05
        elif ctrl and keyval_name == 'Right':
            self.player.streamer.volume += 0.05
        elif keyval_name == "Escape":
            self.txt_search.set_text('')
            self.txt_goto.set_text('')
            self.search_bar.set_search_mode(False)
            self.goto_bar.set_search_mode(False)
        elif keyval_name == "space" and not self.txt_search.has_focus():
            self.player.toggle()
        elif keyval_name == "F11":
            self.toggle_fullscreen()
        else:
            return False

        return True