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
|
from gi.repository import Gtk
Gtk.require_version('2.0')
from gi.repository import Grip
# XXX For now, we'll use Grip directly. Once we have a good sense of what's
# going to be needed in general for general Python code using Grip, we might
# want to put that stuff in a wrapper grip module, and import everything from
# there instead.
class GestureTester(object):
def __init__(self):
builder = Gtk.Builder()
builder.add_from_file("pygrip-gestures.xml")
builder.connect_signals(self)
self.window = builder.get_object("window1")
self.window.show()
def window_mapped(self, widget, data=None):
# The gesture manager is only going to be needed for GTK2, since GTK3
# will have the gesture API natively. Conversely, pygrip will only be
# for GTK2, since PyGTK3 will having the bindings.
gesture_manager = Grip.GestureManager()
# For the purpose of this example, we are registering all gestures; we
# could limit this by choosing a different pygrip.GRIP_GESTURE_*
# mask. Similarly, we're using one set of callbacks for all the
# gestures; we could have different callbacks for different registered
# gestures.
# XXX the comment above is for the new API; the example below has been
# reverted to the older API until the new one is merged to trunk.
finger_count = 2
gesture_manager.register_window(
self.window, Grip.GestureType.PINCH, finger_count, self.callback, None)
def callback(self, window, time_type, gesture_type, gesture_event):
print "received gesture"
def quit(self, widget, data=None):
Gtk.main_quit()
if __name__ == "__main__":
app = GestureTester()
Gtk.main()
|