Exemplo n.º 1
0
        def status_changed_cb(activity, status=Activity.Status.PARSED):
            if status != Activity.Status.PARSED:
                return

            f = activity.fit

            layer = Champlain.PathLayer()

            for message in f.records():
                vals = message.get_values()
                try:
                    coord = Champlain.Coordinate.new_full(
                        vals['position_lat'], vals['position_long'])
                    layer.add_node(coord)
                except KeyError:
                    continue

            if layer.get_nodes():
                view = self.embed.get_view()
                view.add_layer(layer)

                # https://bugzilla.gnome.org/show_bug.cgi?id=754718
                # for some reason connecting to to ::realize on view
                # or embed isn't enough. in fact this idle only works
                # most of the time but for now it's good enough.
                view.set_zoom_level(15)
                GLib.idle_add(lambda: view.ensure_layers_visible(False))
            else:
                self.embed.destroy()

            # now labels
            self.distance_label.set_markup('<span font="16">{0:.1f} km</span>\n' \
                '<span color="gray">Distance</span>'.format(f.get_distance() / 1000))

            hours, mins, secs = f.get_elapsed_time()
            self.elapsed_time_label.set_markup('<span font="16">{0}:{1:02d}:{2:02d}</span>\n' \
                '<span color="gray">Elapsed Time</span>'.format(hours, mins, secs))

            elevation = f.get_elevation()
            self.elevation_label.set_markup('{}m\n' \
                '<span color="gray">Elevation</span>'.format(elevation))

            hours, mins, secs = f.get_moving_time()
            self.moving_time_label.set_markup('{0}:{1:02d}:{2:02d}\n' \
                '<span color="gray">Moving Time</span>'.format(hours, mins, secs))

            if activity.uploader is not None:
                activity.uploader.connect(
                    'status-changed',
                    lambda *x: self.strava_id_updated_cb(None, None))

                self.infobar.start(activity.uploader)
                self.infobar.connect(
                    'response',
                    lambda *x: self.strava_id_updated_cb(None, None))

                self.upload_button.set_sensitive(False)
Exemplo n.º 2
0
 def draw_polygons(self, polygons):
     for layer in self.layers:
         self.map_view.remove_layer(layer)
     self.layers.clear()
     for polygon in polygons:
         polygon_layer = Champlain.PathLayer()
         for point in polygon:
             lat, lon = point
             coord = Champlain.Coordinate.new_full(lon, lat)
             polygon_layer.add_node(coord)
         self.map_view.add_layer(polygon_layer)
         self.layers.append(polygon_layer)
 def updateUIToAddPath2(self,fsp_result):
     path_layer = Champlain.PathLayer()
     streets = fsp_result['path']
     for i in range(0,len(streets)-1):
         result = self.invokeGraphHoperRoutingService(streets[i]['targetNode'],streets[i+1]['targetNode']).decode("utf-8")
         #print (result)
         result =json.loads(result)
         if not('paths' in result):
             continue
         instructions = result["paths"][0]["instructions"]
         points = result["paths"][0]["points"]["coordinates"]
         for instruction in instructions:
             #print (instruction['interval'][0])
             src = points[instruction["interval"][0]]
             dest = points[instruction["interval"][1]]
             src_coord = Champlain.Coordinate.new_full(src[0],src[1])
             dest_coord = Champlain.Coordinate.new_full(dest[0],dest[1])
             path_layer.add_node(src_coord)
             path_layer.add_node(dest_coord)
     self.view.add_layer(path_layer)
     self.view.ensure_layers_visible(True)
 def updateUIToAddPath(self,fsp_result):
     print (fsp_result)
     path_layer = Champlain.PathLayer()
     streets = fsp_result['path']
     x = [0,1]
     y= [0,1]
     distance =Gtk.Label()
     distance.set_text("Distance: "+str(fsp_result['distance']/1000)+" Km")
     self.table.attach(distance,x[0],x[1],y[0],y[1])
     y[0]=y[0]+1
     y[1]=y[1]+1
     for node in streets:
         targetNode = node['targetNode']
         street_node = node['street']
         coord = Champlain.Coordinate.new_full(targetNode['lng'], targetNode['lat'])
         path_layer.add_node(coord)
         label = Gtk.Label()
         if 'name' in street_node["meta_data"] and 'highway' in street_node["meta_data"]:
             label.set_text(street_node["meta_data"]['name']+", "+"highway:"+street_node['meta_data']['highway'])
         else:
             label.set_text("highway:"+street_node['meta_data']['highway'])
         self.table.attach(label,x[0],x[1],y[0],y[1])
         y[0]=y[0]+1
         y[1]=y[1]+1
         
         down_image = Gtk.Image()
         down_image.set_from_file(downArrowImage)
         self.table.attach(down_image,x[0],x[1],y[0],y[1])
         down_image.show()
         
         y[0]=y[0]+1
         y[1]=y[1]+1
     finish =Gtk.Label()
     finish.set_text("Finish")
     self.table.attach(finish,x[0],x[1],y[0],y[1])
     self.view.add_layer(path_layer)
     self.view.ensure_layers_visible(True)
     self.table.show_all()
 def updateUIToAddPath3(self,fsp_result):
     path_layer = Champlain.PathLayer()
     dash = [6, 2]
     path_layer.set_dash(dash)
     streets = fsp_result['path']
     result = self.invokeGraphHoperRoutingService(streets[0]['targetNode'],streets[len(streets)-1]['targetNode']).decode("utf-8")
         #print (result)
     result =json.loads(result)
     instructions = result["paths"][0]["instructions"]
     points = result["paths"][0]["points"]["coordinates"]
     for instruction in instructions:
             #print (instruction['interval'][0])
         src = points[instruction["interval"][0]]
         dest = points[instruction["interval"][1]]
         src_coord = Champlain.Coordinate.new_full(src[0],src[1])
         dest_coord = Champlain.Coordinate.new_full(dest[0],dest[1])
         path_layer.add_node(src_coord)
         if instruction['sign'] == 2:
             path_layer.set_rotation(Clutter.RotateAxis().X_AXIS,60.6,src[0],src[1],0)
         #else:
             #path_layer.set_rotation(Clutter.RotateAxis().X_AXIS,-45,src[0],src[1],0)
         path_layer.add_node(dest_coord)
     self.view.add_layer(path_layer)
     self.view.ensure_layers_visible(True)       
Exemplo n.º 6
0
 def start_traceroute_path(self):
     self.tr_points_layer = Champlain.MarkerLayer()
     self.tr_path_layer = Champlain.PathLayer()
     self.view.add_layer(self.tr_points_layer)
     self.view.add_layer(self.tr_path_layer)
Exemplo n.º 7
0
    (width, height) = button.get_size()
    total_width += width + PADDING
    #button.connect('button-release-event', zoom_in, view)
    button.connect('button-release-event', zoom_in, view)

    button = make_button('Zoom out')
    buttons.add_child(button)
    button.set_reactive(True)
    button.set_position(total_width, 0)
    (width, height) = button.get_size()
    button.connect('button-release-event', zoom_out, view)

    stage.add_child(buttons)

    # Draw a line
    layer = Champlain.PathLayer()
    # Cheap approx of Highway 10
    append_point(layer, 45.4104, -73.2846)
    append_point(layer, 45.4178, -73.2239)
    append_point(layer, 45.4176, -73.2181)
    append_point(layer, 45.4151, -73.2126)
    append_point(layer, 45.4016, -73.1926)
    append_point(layer, 45.3994, -73.1877)
    append_point(layer, 45.4000, -73.1815)
    append_point(layer, 45.4151, -73.1218)
    layer.set_stroke_width(4.0)
    view.add_layer(layer)

    dash = [6, 2]
    layer.set_dash(dash)
Exemplo n.º 8
0
    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 = self.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()