我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用gi.repository.Gdk.KEY_Left()。
def on_key_press_event(self, widget, event): try: view = self.get_view() except KeyError: return if (event.type == Gdk.EventType.KEY_PRESS and event.get_state() & Gdk.ModifierType.MOD1_MASK == Gdk.ModifierType.MOD1_MASK# Alt key and event.keyval in (Gdk.KEY_KP_Left, Gdk.KEY_Left) and self.m_history and not solfege.app.m_test_mode): obj, page = self.m_history[-1] self.trim_history(obj, page) # Find the box_dict key for obj for k, o in self.box_dict.items(): if o == obj: obj.display_data(page) self.show_view(k) break return True view.on_key_press_event(widget, event)
def __on_progress_key_pressed(self, widget, event): """ Jump to the modified time. """ old_val = self.progress_scale.get_value() if event.keyval == Gdk.KEY_Up or event.keyval == Gdk.KEY_Left: if old_val > 30.0: player.jump_to(old_val - 30) else: player.jump_to(0) elif event.keyval == Gdk.KEY_Down or event.keyval == Gdk.KEY_Right: upper = self.progress_scale.get_adjustment().get_upper() if old_val + 30.0 < upper: player.jump_to(old_val + 30) else: player.jump_to(upper) return False
def _on_key_press_event(self, widget, event, tr): kv = event.keyval #print kv r = False if kv == Gdk.KEY_Right: # right-key btn = tr.get_button_by_name(CellButtonIDs.ACTION) if btn is None: return # Bug #846779 if btn.state != Gtk.StateFlags.INSENSITIVE: btn.has_focus = True btn = tr.get_button_by_name(CellButtonIDs.INFO) btn.has_focus = False elif kv == Gdk.KEY_Left: # left-key btn = tr.get_button_by_name(CellButtonIDs.ACTION) if btn is None: return # Bug #846779 btn.has_focus = False btn = tr.get_button_by_name(CellButtonIDs.INFO) btn.has_focus = True elif kv == Gdk.KEY_space: # spacebar for btn in tr.get_buttons(): if (btn is not None and btn.has_focus and btn.state != Gtk.StateFlags.INSENSITIVE): btn.set_state(Gtk.StateFlags.ACTIVE) sel = self.get_selection() model, it = sel.get_selected() path = model.get_path(it) if path: #self._init_activated(btn, self.get_model(), path) r = True break self.queue_draw() return r
def on_key_press(self, window, event): if not self.m_editable: return key_dict = {Gdk.KEY_1: 1, Gdk.KEY_2: 2, Gdk.KEY_3: 4, Gdk.KEY_4: 8, Gdk.KEY_5: 16, Gdk.KEY_6: 32, } if event.keyval in (Gdk.KEY_Right, Gdk.KEY_KP_Right): self.cursor_next() self.queue_draw() elif event.keyval in (Gdk.KEY_Left, Gdk.KEY_KP_Left): self.cursor_prev() self.queue_draw() elif event.keyval == Gdk.KEY_BackSpace: self.backspace() elif event.keyval in (Gdk.KEY_Delete, Gdk.KEY_KP_Delete): self.delete() elif event.keyval in key_dict: if self.m_input_mode == self.NOTE_INPUT: added = self.on_add_item(elems.Note(MusicalPitch.new_from_notename("c"), Duration(key_dict[event.keyval], 0))) else: assert self.m_input_mode == self.REST_INPUT added = self.on_add_item(elems.Rest( Duration(key_dict[event.keyval], 0))) if added: self.cursor_next() self.queue_draw() self.grab_focus() elif event.keyval == Gdk.KEY_period: self.on_toggle_dots(1) elif event.keyval == Gdk.KEY_colon: self.on_toggle_dots(-1) elif event.keyval == Gdk.KEY_t: self.on_toggle_tie() elif event.keyval == Gdk.KEY_r: if self.m_input_mode == self.NOTE_INPUT: self.m_input_mode = self.REST_INPUT else: self.m_input_mode = self.NOTE_INPUT
def on_key_press_event(self, widget, event): if event.keyval == Gdk.KEY_Left: self.x -= self.POS_INCREMENT/self.zoom_ratio self.queue_draw() return True if event.keyval == Gdk.KEY_Right: self.x += self.POS_INCREMENT/self.zoom_ratio self.queue_draw() return True if event.keyval == Gdk.KEY_Up: self.y -= self.POS_INCREMENT/self.zoom_ratio self.queue_draw() return True if event.keyval == Gdk.KEY_Down: self.y += self.POS_INCREMENT/self.zoom_ratio self.queue_draw() return True if event.keyval in (Gdk.KEY_Page_Up, Gdk.KEY_plus, Gdk.KEY_equal, Gdk.KEY_KP_Add): self.zoom_image(self.zoom_ratio * self.ZOOM_INCREMENT) self.queue_draw() return True if event.keyval in (Gdk.KEY_Page_Down, Gdk.KEY_minus, Gdk.KEY_KP_Subtract): self.zoom_image(self.zoom_ratio / self.ZOOM_INCREMENT) self.queue_draw() return True if event.keyval == Gdk.KEY_Escape: self.drag_action.abort() self.drag_action = NullAction(self) return True if event.keyval == Gdk.KEY_r: self.reload() return True if event.keyval == Gdk.KEY_f: win = widget.get_toplevel() find_toolitem = win.uimanager.get_widget('/ToolBar/Find') textentry = find_toolitem.get_children() win.set_focus(textentry[0]) return True if event.keyval == Gdk.KEY_q: Gtk.main_quit() return True if event.keyval == Gdk.KEY_p: self.on_print() return True return False