Re: Connecting event to underlying actor widget



Hi Nicolas,

On Thu, Nov 24, 2011 at 19:06, Nicolas Évrard <nicoe altern org> wrote:
> 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 ?

Yes, only reactive actors generate events. You have to call
set_reactive(True) on ChamplainView object. See
clutter_actor_set_reactive () in clutter documentation for more
details.

>
> 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.

I believe I've fixed it (in master). It happened because of wrong
introspection annotations for transfer mode of the create methods.
Originally I used (transfer full) because the objects were created and
not owned by the factory object but because the created objects are of
type GInitiallyUnowned, there must be (transfer none) otherwise they
are unreffed one more times and destroyed. More details here:

https://bugzilla.gnome.org/show_bug.cgi?id=638542

Cheers,

Jiri


>
> 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
>  `¯
> _______________________________________________
> libchamplain-list mailing list
> libchamplain-list gnome org
> http://mail.gnome.org/mailman/listinfo/libchamplain-list
>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]