Beispiel #1
0
def main():
    # Create the map view
    actor = champlain.View()
    actor.set_size(640, 480)
    actor.set_property('scroll-mode', champlain.SCROLL_MODE_KINETIC)
    actor.center_on(45.466, -73.75)
    actor.set_property('zoom-level', 12)

    # Create the buttons
    buttons = clutter.Group()
    buttons.set_position(PADDING, PADDING)
    
    button = make_button('Zoom in')
    button.set_reactive(True)
    width = button.get_size()[0]
    total_width = width+PADDING
    button.connect('button-release-event', zoom_in, actor)
    buttons.add(button)

    button = make_button('Zoom out')
    button.set_reactive(True)
    button.set_position(total_width, 0)
    width = button.get_size()[0]
    total_width += width+PADDING
    button.connect('button-release-event', zoom_out, actor)
    buttons.add(button)
    
    # Create the markers and marker layer
    layer = create_marker_layer(actor)
    actor.add_layer(layer)
 
    stage = clutter.Stage(default=True)
    stage.set_size(640, 480)
    stage.add(actor)
    stage.add(buttons)
    stage.show()

    # Connect to the click event
    actor.set_reactive(True)
    actor.connect('button-release-event', map_view_button_release_cb, actor)
    def __init__(self):
        self.window = Gtk.Window()
        self.window.set_border_width(10)
        self.window.set_title("libchamplain Gtk+ demo (python introspection)")
        self.window.connect("destroy", Gtk.main_quit)

        vbox = Gtk.VBox(False, 10)

        embed = GtkChamplain.Embed()

        self.view = embed.get_view()
        self.view.set_reactive(True)
        self.view.connect('button-release-event', self.mouse_click_cb,
            self.view)

        self.view.set_property('kinetic-mode', True)
        self.view.set_property('zoom-level', 5)

        scale = Champlain.Scale()
        scale.connect_view(self.view)
        self.view.bin_layout_add(scale, Clutter.BinAlignment.START,
            Clutter.BinAlignment.END)

        license = self.view.get_license_actor()
        license.set_extra_text("Don't eat cereals with orange juice\nIt tastes bad")

        self.view.center_on(45.466, -73.75)

        self.layer = create_marker_layer(self.view)
        self.view.add_layer(self.layer)
        self.layer.hide_all_markers()

        self.path_layer = Champlain.PathLayer()
        # Cheap approx of Highway 10
        self.add_node(self.path_layer, 45.4095, -73.3197)
        self.add_node(self.path_layer, 45.4104, -73.2846)
        self.add_node(self.path_layer, 45.4178, -73.2239)
        self.add_node(self.path_layer, 45.4176, -73.2181)
        self.add_node(self.path_layer, 45.4151, -73.2126)
        self.add_node(self.path_layer, 45.4016, -73.1926)
        self.add_node(self.path_layer, 45.3994, -73.1877)
        self.add_node(self.path_layer, 45.4000, -73.1815)
        self.add_node(self.path_layer, 45.4151, -73.1218)
        self.view.add_layer(self.path_layer)

        embed.set_size_request(640, 480)

        bbox = Gtk.HBox(False, 10)
        button = Gtk.Button(stock=Gtk.STOCK_ZOOM_IN)
        button.connect("clicked", self.zoom_in)
        bbox.add(button)

        button = Gtk.Button(stock=Gtk.STOCK_ZOOM_OUT)
        button.connect("clicked", self.zoom_out)
        bbox.add(button)

        button = Gtk.ToggleButton(label="Markers")
        button.set_active(False)
        button.connect("toggled", self.toggle_layer)
        bbox.add(button)

        combo = Gtk.ComboBox()
        map_source_factory = Champlain.MapSourceFactory.dup_default()
        liststore = Gtk.ListStore(str, str)
        for source in map_source_factory.get_registered():
            liststore.append([source.get_id(), source.get_name()])
        combo.set_model(liststore)
        cell = Gtk.CellRendererText()
        combo.pack_start(cell, False)
        combo.add_attribute(cell, 'text', 1)
        combo.connect("changed", self.map_source_changed)
        combo.set_active(0)
        bbox.add(combo)

        self.spinbutton = Gtk.SpinButton.new_with_range(0, 20, 1)
        self.spinbutton.connect("changed", self.zoom_changed)
        self.view.connect("notify::zoom-level", self.map_zoom_changed)
        self.spinbutton.set_value(5)
        bbox.add(self.spinbutton)

        button = Gtk.Image()
        self.view.connect("notify::state", self.view_state_changed, button)
        bbox.pack_end(button, False, False, 0)

        vbox.pack_start(bbox, expand=False, fill=False, padding=0)
        vbox.add(embed)

        self.window.add(vbox)

        self.window.show_all()
Beispiel #3
0
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_border_width(10)
        self.window.set_title("The world seen through the eyes of a Python")
        self.window.connect("destroy", gtk.main_quit)

        vbox = gtk.VBox(False, 12)

        embed = champlaingtk.ChamplainEmbed()
        embed.set_size_request(640, 480)

        self.view = embed.get_view()

        self.layer = create_marker_layer(self.view)
        self.view.add_layer(self.layer)
        self.layer.hide_all_markers()

        self.polygon = polygon = champlain.Polygon()
        # Cheap approx of Highway 10
        polygon.append_point(45.4095, -73.3197)
        polygon.append_point(45.4104, -73.2846)
        polygon.append_point(45.4178, -73.2239)
        polygon.append_point(45.4176, -73.2181)
        polygon.append_point(45.4151, -73.2126)
        polygon.append_point(45.4016, -73.1926)
        polygon.append_point(45.3994, -73.1877)
        polygon.append_point(45.4000, -73.1815)
        polygon.append_point(45.4151, -73.1218)
        polygon.set_stroke_width(5.0);
        polygon.set_property("mark-points", True)
        self.view.add_polygon(polygon)
        polygon.hide()

        bbox = gtk.HBox(False, 6)
        button = gtk.Button(stock=gtk.STOCK_ZOOM_IN)
        button.connect("clicked", self.zoom_in)
        bbox.add(button)

        button = gtk.Button(stock=gtk.STOCK_ZOOM_OUT)
        button.connect("clicked", self.zoom_out)
        bbox.add(button)

        button = gtk.ToggleButton(label="Markers")
        button.set_active(False)
        button.connect("toggled", self.toggle_layer)
        bbox.add(button)

        combo = gtk.combo_box_new_text()
        self.map_source_factory = champlain.map_source_factory_dup_default()
        liststore = gtk.ListStore(str, str)
        for source in self.map_source_factory.dup_list():
            liststore.append([source.id, source.name])
            combo.append_text(source.name)
        combo.set_model(liststore)
        combo.set_attributes(combo.get_cells()[0], text=1)
        combo.set_active(0)
        combo.connect("changed", self.map_source_changed)
        bbox.add(combo)

        self.spinbutton = gtk.SpinButton(gtk.Adjustment(lower=0, upper=20, 
            value=1, step_incr=1))
        self.spinbutton.connect("changed", self.zoom_changed)
        self.view.connect("notify::zoom-level", self.map_zoom_changed)
        self.spinbutton.set_value(5)
        bbox.add(self.spinbutton)

        vbox.pack_start(bbox, expand=False, fill=False)
        vbox.add(embed)

        self.window.add(vbox)

        self.window.show_all()
        self.view.center_on(45.466, -73.75)