Re: Connecting event to underlying actor widget



On Fri, Nov 25, 2011 at 09:35, Gerard Toonstra <gtoonstra gmail com> wrote:
> On Thu, Nov 24, 2011 at 7:06 PM, 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 ?
>>
>> 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()
>>
>
> Hey,
>
> 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 )

That's true, but unless you are painting something on top of the map
(e.g. by implementing your own ChamplainLayer), you don't have to care
about this signal.

Jiri


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