This repository has been archived by the owner on Aug 4, 2018. It is now read-only.
forked from Guake/guake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
52 lines (37 loc) · 1.66 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
class CellRendererAccel(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self)
self.set_title("CellRendererAccel")
self.connect("destroy", Gtk.main_quit)
self.liststore = Gtk.ListStore(str, str)
self.liststore.append(["New", "<Primary>n"])
self.liststore.append(["Open", "<Primary>o"])
self.liststore.append(["Save", "<Primary>s"])
treeview = Gtk.TreeView()
treeview.set_model(self.liststore)
self.add(treeview)
cellrenderertext = Gtk.CellRendererText()
treeviewcolumn = Gtk.TreeViewColumn("Action")
treeview.append_column(treeviewcolumn)
treeviewcolumn.pack_start(cellrenderertext, True)
treeviewcolumn.add_attribute(cellrenderertext, "text", 0)
cellrendereraccel = Gtk.CellRendererAccel()
cellrendereraccel.set_property("editable", True)
cellrendereraccel.connect("accel-edited", self.on_accel_edited)
cellrendereraccel.connect("accel-cleared", self.on_accel_cleared)
treeviewcolumn = Gtk.TreeViewColumn("Accelerator")
treeview.append_column(treeviewcolumn)
treeviewcolumn.pack_start(cellrendereraccel, True)
treeviewcolumn.add_attribute(cellrendereraccel, "text", 1)
def on_accel_edited(self, cellrendereraccel, path, key, mods, hwcode):
accelerator = Gtk.accelerator_name(key, mods)
self.liststore[path][1] = accelerator
def on_accel_cleared(self, cellrendereraccel, path):
self.liststore[path][1] = "None"
window = CellRendererAccel()
window.show_all()
Gtk.main()