Ejemplo n.º 1
0
    def load_gpx_from_file(self, uri):
        """Parse GPX data, drawing each GPS track segment on the map."""
        start_time = clock()

        open_file = KMLFile if uri[-3:].lower() == 'kml' else GPXFile
        gpx = open_file(uri, self.progressbar)

        # Emitting this signal ensures the new tracks get the correct color.
        get_obj('colorselection').emit('color-changed')

        self.status_message(
            _('%d points loaded in %.2fs.') %
            (len(gpx.tracks), clock() - start_time), True)

        if len(gpx.tracks) < 2:
            return

        points.update(gpx.tracks)
        metadata.alpha = min(metadata.alpha, gpx.alpha)
        metadata.omega = max(metadata.omega, gpx.omega)

        map_view.emit('realize')
        map_view.set_zoom_level(map_view.get_max_zoom_level())
        bounds = Champlain.BoundingBox.new()
        for poly in polygons:
            bounds.compose(poly.get_bounding_box())
        gpx.latitude, gpx.longitude = bounds.get_center()
        map_view.ensure_visible(bounds, False)

        self.prefs.gpx_timezone = gpx.lookup_geoname()
        self.prefs.set_timezone()
        gpx_sensitivity()
Ejemplo n.º 2
0
 def load_gpx_from_file(self, uri):
     """Parse GPX data, drawing each GPS track segment on the map."""
     start_time = clock()
     
     open_file = KMLFile if uri[-3:].lower() == 'kml' else GPXFile
     gpx = open_file(uri, self.progressbar)
     
     # Emitting this signal ensures the new tracks get the correct color.
     get_obj('colorselection').emit('color-changed')
     
     self.status_message(_('%d points loaded in %.2fs.') %
         (len(gpx.tracks), clock() - start_time), True)
     
     if len(gpx.tracks) < 2:
         return
     
     points.update(gpx.tracks)
     metadata.alpha = min(metadata.alpha, gpx.alpha)
     metadata.omega = max(metadata.omega, gpx.omega)
     
     map_view.emit('realize')
     map_view.set_zoom_level(map_view.get_max_zoom_level())
     bounds = Champlain.BoundingBox.new()
     for poly in polygons:
         bounds.compose(poly.get_bounding_box())
     gpx.latitude, gpx.longitude = bounds.get_center()
     map_view.ensure_visible(bounds, False)
     
     self.prefs.gpx_timezone = gpx.lookup_geoname()
     self.prefs.set_timezone()
     gpx_sensitivity()
Ejemplo n.º 3
0
 def destroy(self, button=None):
     """Die a horrible death."""
     for polygon in self.polygons:
         MapView.remove_layer(polygon)
     self.polygons.clear()
     self.widgets.trackfile_settings.destroy()
     del self.cache[self.filename]
     TrackFile.instances.discard(self)
     points.clear()
     for trackfile in TrackFile.instances:
         points.update(trackfile.tracks)
     TrackFile.update_range()
Ejemplo n.º 4
0
 def __init__(self, filename, root, watch):
     self.watchlist = watch
     self.filename = filename
     self.progress = Widgets.progressbar
     self.polygons = set()
     self.widgets = Builder('trackfile')
     self.append = None
     self.tracks = {}
     self.clock = clock()
     
     self.gst = GSettings('trackfile', basename(filename))
     if self.gst.get_string('start-timezone') is '':
         # Then this is the first time this file has been loaded
         # and we should honor the user-selected global default
         # track color instead of using the schema-defined default
         self.gst.set_value('track-color', Gst.get_value('track-color'))
     
     self.gst.bind_with_convert(
         'track-color',
         self.widgets.colorpicker,
         'color',
         lambda x: Gdk.Color(*x),
         lambda x: (x.red, x.green, x.blue))
     
     self.widgets.trackfile_label.set_text(basename(filename))
     self.widgets.unload.connect('clicked', self.destroy)
     self.widgets.colorpicker.set_title(basename(filename))
     self.widgets.colorpicker.connect('color-set',
                                      track_color_changed,
                                      self.polygons)
     
     Widgets.trackfile_unloads_group.add_widget(self.widgets.unload)
     Widgets.trackfile_colors_group.add_widget(self.widgets.colorpicker)
     Widgets.trackfiles_group.add_widget(self.widgets.trackfile_label)
     
     self.parse(filename, root, watch, self.element_start, self.element_end)
     
     if not self.tracks:
         raise IOError('No points found')
     
     points.update(self.tracks)
     keys = self.tracks.keys()
     self.alpha = min(keys)
     self.omega = max(keys)
     self.start = Coordinates(latitude = self.tracks[self.alpha].lat,
                              longitude = self.tracks[self.alpha].lon)
     
     self.gst.set_string('start-timezone', self.start.lookup_geodata())
     
     Widgets.trackfiles_view.add(self.widgets.trackfile_settings)
Ejemplo n.º 5
0
 def __init__(self, filename, root, watch):
     self.filename = filename
     self.progress = get_obj('progressbar')
     self.clock    = clock()
     self.append   = None
     self.tracks   = {}
     self.polygons = set()
     
     self.parser = XMLSimpleParser(root, watch)
     self.parser.parse(filename, self.element_start, self.element_end)
     
     empty_trackfile_label.hide()
     
     points.update(self.tracks)
     keys = self.tracks.keys()
     self.alpha = min(keys)
     self.omega = max(keys)
     self.latitude = self.tracks[self.alpha].lat
     self.longitude = self.tracks[self.alpha].lon
     
     # TODO find some kind of parent widget that can group these together
     # to make it easier to get them and insert them into places.
     builder = Builder('trackfile')
     self.colorpicker = builder.get_object('colorpicker')
     self.trash = builder.get_object('unload')
     self.label = builder.get_object('trackfile_label')
     
     self.label.set_text(basename(filename))
     self.colorpicker.set_title(basename(filename))
     self.colorpicker.connect('color-set', track_color_changed, self.polygons)
     self.trash.connect('clicked', self.destroy)
     
     get_obj('trackfiles_view').attach_next_to(
         builder.get_object('trackfile_settings'), None, BOTTOM, 1, 1)
     
     self.gst = GSettings('trackfile', basename(filename))
     
     if self.gst.get_string('start-timezone') is '':
         # Then this is the first time this file has been loaded
         # and we should honor the user-selected global default
         # track color instead of using the schema-defined default
         self.gst.set_value('track-color', gst.get_value('track-color'))
     
     self.gst.set_string('start-timezone', self.lookup_geoname())
     self.gst.bind_with_convert('track-color', self.colorpicker, 'color',
         lambda x: Gdk.Color(*x), lambda x: (x.red, x.green, x.blue))
     self.colorpicker.emit('color-set')