Python gi.repository.Gdk.keyval_from_name() Examples
The following are 10
code examples of gi.repository.Gdk.keyval_from_name().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
gi.repository.Gdk
, or try the search function
.
Example #1
Source File: devdocs_desktop.py From devdocs-desktop with GNU General Public License v3.0 | 6 votes |
def set_window_accel_groups(self): group = Gtk.AccelGroup() ctrl = Gdk.ModifierType.CONTROL_MASK group.connect(Gdk.keyval_from_name('f'), ctrl, 0, self.on_revealer_accel_pressed) group.connect(Gdk.keyval_from_name('KP_Subtract'), ctrl, 0, self.on_zoom_decrease_accel_pressed) group.connect(Gdk.keyval_from_name('minus'), ctrl, 0, self.on_zoom_decrease_accel_pressed) group.connect(Gdk.keyval_from_name('KP_Add'), ctrl, 0, self.on_zoom_increase_accel_pressed) group.connect(Gdk.keyval_from_name('plus'), ctrl, 0, self.on_zoom_increase_accel_pressed) group.connect(Gdk.keyval_from_name('KP_0'), ctrl, 0, self.on_zoom_reset_accel_pressed) group.connect(Gdk.keyval_from_name('0'), ctrl, 0, self.on_zoom_reset_accel_pressed) self.window.add_accel_group(group)
Example #2
Source File: log_test.py From vimiv with MIT License | 5 votes |
def test_debug_mode_eventhandler(self): """Run keybinding and mouse click in debug mode and therefore log it.""" # Keybinding event = Gdk.Event().new(Gdk.EventType.KEY_PRESS) event.keyval = Gdk.keyval_from_name("j") self.vimiv["library"].emit("key_press_event", event) last_line = self.read_log(string=False)[-1] self.assertEqual(last_line, "%-15s %s\n" % ("[key]", "j: scroll_lib j")) # Mouse click event = Gdk.Event().new(Gdk.EventType.BUTTON_PRESS) event.button = 1 self.vimiv["window"].emit("button_press_event", event) last_line = self.read_log(string=False)[-1] self.assertEqual(last_line, "%-15s %s\n" % ("[key]", "Button1: next"))
Example #3
Source File: eventhandler_test.py From vimiv with MIT License | 5 votes |
def test_key_press(self): """Press key.""" self.vimiv["library"].file_select(None, Gtk.TreePath(1), None, True) image_before = self.vimiv.get_path() event = Gdk.Event().new(Gdk.EventType.KEY_PRESS) event.keyval = Gdk.keyval_from_name("n") self.vimiv["main_window"].emit("key_press_event", event) image_after = self.vimiv.get_path() self.assertNotEqual(image_before, image_after) event.keyval = Gdk.keyval_from_name("O") self.vimiv["main_window"].emit("key_press_event", event) self.assertTrue(self.vimiv["library"].is_focus())
Example #4
Source File: eventhandler_test.py From vimiv with MIT License | 5 votes |
def test_add_number_via_keypress(self): """Add a number to the numstr by keypress.""" self.assertFalse(self.vimiv["eventhandler"].get_num_str()) event = Gdk.Event().new(Gdk.EventType.KEY_PRESS) event.keyval = Gdk.keyval_from_name("2") self.vimiv["library"].emit("key_press_event", event) self.assertEqual(self.vimiv["eventhandler"].get_num_str(), "2") # Clear as it might interfere self.vimiv["eventhandler"].num_clear()
Example #5
Source File: eventhandler_test.py From vimiv with MIT License | 5 votes |
def test_key_press_modifier(self): """Press key with modifier.""" before = self.settings["show_hidden"].get_value() event = Gdk.Event().new(Gdk.EventType.KEY_PRESS) event.keyval = Gdk.keyval_from_name("h") event.state = Gdk.ModifierType.CONTROL_MASK self.vimiv["library"].emit("key_press_event", event) after = self.settings["show_hidden"].get_value() self.assertNotEqual(before, after)
Example #6
Source File: ConsolePanel.py From pychess with GNU General Public License v3.0 | 5 votes |
def onKeyPress(self, widget, event): if event.keyval in list(map(Gdk.keyval_from_name, ("Return", "KP_Enter"))): if not event.get_state() & Gdk.ModifierType.CONTROL_MASK: buffer = self.entry.get_buffer() if buffer.props.text.startswith("pas"): # don't log password changes self.connection.client.telnet.sensitive = True self.connection.client.run_command(buffer.props.text, show_reply=True) self.emit("messageTyped", buffer.props.text) self.addMessage(buffer.props.text, True) self.history.append(buffer.props.text) buffer.props.text = "" self.pos = len(self.history) return True elif event.keyval == Gdk.keyval_from_name("Up"): if self.pos > 0: buffer = self.entry.get_buffer() self.pos -= 1 buffer.props.text = self.history[self.pos] widget.grab_focus() return True elif event.keyval == Gdk.keyval_from_name("Down"): buffer = self.entry.get_buffer() if self.pos == len(self.history) - 1: self.pos += 1 buffer.props.text = "" elif self.pos < len(self.history): self.pos += 1 buffer.props.text = self.history[self.pos] widget.grab_focus() return True
Example #7
Source File: ChatView.py From pychess with GNU General Public License v3.0 | 5 votes |
def onKeyPress(self, widget, event): if event.keyval in list(map(Gdk.keyval_from_name, ("Return", "KP_Enter"))): if not event.get_state() & Gdk.ModifierType.CONTROL_MASK: buffer = self.writeView.get_buffer() if buffer.props.text: self.emit("messageTyped", buffer.props.text) buffer.props.text = "" return True
Example #8
Source File: searchable.py From bokken with GNU General Public License v2.0 | 5 votes |
def __init__(self, textview, small=False): self.textview = textview self.small = small # By default, don't match case self._matchCaseValue = False # key definitions self.key_f = Gdk.keyval_from_name("f") self.key_g = Gdk.keyval_from_name("g") self.key_G = Gdk.keyval_from_name("G") self.key_F3 = Gdk.keyval_from_name("F3") self.key_Esc = Gdk.keyval_from_name("Escape") # signals self.connect("key-press-event", self._key) self.textview.connect("populate-popup", self._populate_popup) # colors for textview and entry backgrounds self.textbuf = self.textview.get_buffer() self.textbuf.create_tag("yellow-background", background="yellow") #MEOW #colormap = self.get_colormap() #self.bg_normal = colormap.alloc_color("white") #self.bg_notfnd = colormap.alloc_color("red") parse, self.bg_normal = Gdk.Color.parse('white') parse, self.bg_notfnd = Gdk.Color.parse('red') # build the search tab self._build_search(None) self.searching = True self.timer_id = None
Example #9
Source File: QueryGramplet.py From addons-source with GNU General Public License v2.0 | 4 votes |
def on_key_press(self, widget, event): from gi.repository import Gtk from gi.repository import Gdk if (event.keyval == Gdk.keyval_from_name("Home") or ((event.keyval == Gdk.keyval_from_name("a") and event.get_state() & Gdk.ModifierType.CONTROL_MASK))): buffer = widget.get_buffer() cursor_pos = buffer.get_property("cursor-position") iter = buffer.get_iter_at_offset(cursor_pos) line_cnt = iter.get_line() start = buffer.get_iter_at_line(line_cnt) start.forward_chars(2) buffer.place_cursor(start) return True elif (event.keyval == Gdk.keyval_from_name("End") or (event.keyval == Gdk.keyval_from_name("e") and event.get_state() & Gdk.ModifierType.CONTROL_MASK)): buffer = widget.get_buffer() end = buffer.get_end_iter() buffer.place_cursor(end) return True elif event.keyval == Gdk.keyval_from_name("Return"): echo = False buffer = widget.get_buffer() cursor_pos = buffer.get_property("cursor-position") iter = buffer.get_iter_at_offset(cursor_pos) line_cnt = iter.get_line() start = buffer.get_iter_at_line(line_cnt) line_len = iter.get_chars_in_line() buffer_cnt = buffer.get_line_count() if (buffer_cnt - line_cnt) > 1: line_len -= 1 echo = True end = buffer.get_iter_at_line_offset(line_cnt, line_len) line = buffer.get_text(start, end, True) self.append_text("\n") if line.startswith(self.prompt): line = line[2:] else: self.append_text("%s " % self.prompt) end = buffer.get_end_iter() buffer.place_cursor(end) return True if echo: self.append_text(("%s " % self.prompt) + line) end = buffer.get_end_iter() buffer.place_cursor(end) return True _retval = self.process_command(line) if _retval is not None: self.append_text("%s\n" % str(_retval)) self.append_text("%s " % self.prompt) end = buffer.get_end_iter() buffer.place_cursor(end) return True return False
Example #10
Source File: PythonGramplet.py From addons-source with GNU General Public License v2.0 | 4 votes |
def on_key_press(self, widget, event): from gi.repository import Gtk from gi.repository import Gdk if (event.keyval == Gdk.keyval_from_name("Home") or ((event.keyval == Gdk.keyval_from_name("a") and event.get_state() & Gdk.ModifierType.CONTROL_MASK))): buffer = widget.get_buffer() cursor_pos = buffer.get_property("cursor-position") iter = buffer.get_iter_at_offset(cursor_pos) line_cnt = iter.get_line() start = buffer.get_iter_at_line(line_cnt) start.forward_chars(2) buffer.place_cursor(start) return True elif (event.keyval == Gdk.keyval_from_name("End") or (event.keyval == Gdk.keyval_from_name("e") and event.get_state() & Gdk.ModifierType.CONTROL_MASK)): buffer = widget.get_buffer() end = buffer.get_end_iter() buffer.place_cursor(end) return True elif event.keyval == Gdk.keyval_from_name("Return"): echo = False buffer = widget.get_buffer() cursor_pos = buffer.get_property("cursor-position") iter = buffer.get_iter_at_offset(cursor_pos) line_cnt = iter.get_line() start = buffer.get_iter_at_line(line_cnt) line_len = iter.get_chars_in_line() buffer_cnt = buffer.get_line_count() if (buffer_cnt - line_cnt) > 1: line_len -= 1 echo = True end = buffer.get_iter_at_line_offset(line_cnt, line_len) line = buffer.get_text(start, end, True) self.append_text("\n") if line.startswith(self.prompt): line = line[2:] else: self.append_text("%s " % self.prompt) end = buffer.get_end_iter() buffer.place_cursor(end) return True if echo: self.append_text(("%s " % self.prompt) + line) end = buffer.get_end_iter() buffer.place_cursor(end) return True _retval = self.process_command(line) if _retval is not None: self.append_text("%s\n" % str(_retval)) self.append_text("%s " % self.prompt) end = buffer.get_end_iter() buffer.place_cursor(end) return True return False