Connecting event to underlying actor widget
- From: Nicolas Évrard <nicoe altern org>
- To: libchamplain-list gnome org
- Subject: Connecting event to underlying actor widget
- Date: Thu, 24 Nov 2011 19:06:30 +0100
Hello,
I'd like to integrate libchamplain to the tryton client. So I am
currently playing a bit with the library and I am trying to do a
simple application in python (code at the bottom).
My first issue is at line 20. I'd like to connect the motion event to
a callback but I never receive any event. I tried other events without
any success. Is there anything specific to do ?
Another issue is on lines 12-18, I can not select the MapSource I want
to display, I always use the same tileset …
By the way I tried to print
champlain_embeded.get_map_source.get_name() and my application
crashed. I am using libchamplain 0.12.0.
Any thank you for libchamplain it looks really intersting.
00 import sys
01
02 from gi.repository import Gtk
03 from gi.repository import Gdk
04 from gi.repository import Clutter
05 from gi.repository import Champlain
06 from gi.repository import GtkChamplain
07
08 def main():
09 Clutter.init(sys.argv)
10 window = Gtk.Window()
11 window.connect('destroy', Gtk.main_quit)
12 source_factory = Champlain.MapSourceFactory.dup_default()
13 print source_factory
14
15 champlain_embeded = GtkChamplain.Embed()
16 champlain_view = champlain_embeded.props.champlain_view
17 new_source = source_factory.create_cached_source(Champlain.MAP_SOURCE_OSM_CYCLE_MAP)
18 champlain_view.set_map_source(new_source)
19 champlain_view.props.keep_center_on_resize = False
20 champlain_view.connect('motion-event', test)
21 champlain_embeded.connect('scroll-event', scroll_map)
22 champlain_embeded.connect('button-press-event', move_map)
23 champlain_embeded.connect('key-press-event', key_press)
24 window.add(champlain_embeded)
25
26 window.show_all()
27 Gtk.main()
28
29 def scroll_map(champlain_embeded, event):
30 view = champlain_embeded.props.champlain_view
31 if event.direction == Gdk.ScrollDirection.UP:
32 view.zoom_in()
33 else:
34 view.zoom_out()
35
36 def move_map(champlain_embeded, event):
37 view = champlain_embeded.props.champlain_view
38 longitude = view.x_to_longitude(event.x)
39 latitude = view.y_to_latitude(event.y)
40 view.center_on(latitude, longitude)
41
42 def key_press(champlain_embeded, event):
43 if event.keyval in (ord('q'), ord('Q')):
44 Gtk.main_quit()
45
46 def test(champlain_view, event):
47 print event, type(event)
48
49 if __name__ == '__main__':
50 main()
--
(°> Nicolas Évrard
( ) Liège
`¯
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]