Re: Connecting event to underlying actor widget

On Thu, Nov 24, 2011 at 7:06 PM, Nicolas Évrard <nicoe altern org> wrote:
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
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
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
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)
26        window.show_all()
27        Gtk.main()
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()
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)
42    def key_press(champlain_embeded, event):
43        if event.keyval in (ord('q'), ord('Q')):
44            Gtk.main_quit()
46    def test(champlain_view, event):
47        print event, type(event)
49    if __name__ == '__main__':
50        main()


I got similar problems by using the source factory as well. I raised a bug about this, see bugzilla.
( It was requested to deliver a simple use case, so maybe this can serve as one ). No time at the moment.

You're using the embedded widget to indicate scrolling/zooming changes. Keep in mind that you can get a super event
that detects any changes on the map that require repainting as follows:

view.connect( 'layer-relocated', self.on_relocate )


rather than accessing the view using "props", consider accessing it this way. I derived from the GtkChamplainEmbed
and then just call methods on the subclass:

class MapView( GtkChamplain.Embed ):

    def __init__(self, lat, lon):
        super(MapView, self).__init__()




You can create your own map sources this way, for now, until the other method starts working:

    def set_map_chain(self, view, tile_size, id, name, minzoom, maxzoom, url, file_cache_size, img_cache_size):       
        map_chain = Champlain.MapSourceChain()
        errorRenderer = tile_size )
        null_source = Champlain.NullTileSource.new_full( errorRenderer )
        map_chain.push( null_source )

        imgrenderer = Champlain.ImageRenderer()
        tile_source = Champlain.NetworkTileSource.new_full(
            imgrenderer )
        map_chain.push( tile_source )

        map_chain.push( Champlain.FileCache.new_full( file_cache_size, None, imgrenderer ) )
        map_chain.push( Champlain.MemoryCache.new_full( img_cache_size, imgrenderer ))

        view.set_map_source( map_chain )


        self.set_map_chain( mapview.get_view(), 256, "local", "Localhost Sources", 0, 17, "http://localhost/tiles/#Z#/#X#/#Y#.png", 100000, 100 )
        mapsources = self.get_map_sources()
        mapsources = {}
        mapsources[ "local" ] = "local"


Gerard Toonstra

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