コード例 #1
0
def track_color_changed(selection, polys):
    """Update the color of any loaded GPX tracks."""
    color = selection.get_color()
    Gst.set_color(color)
    one = make_clutter_color(color)
    two = one.lighten().lighten()
    for i, polygon in enumerate(polys):
        polygon.set_stroke_color(two if i % 2 else one)
コード例 #2
0
def remember_location(view):
    """Add current location to history stack."""
    history = list(Gst.get('history'))
    location = tuple([
        view.get_property(x) for x in ('latitude', 'longitude', 'zoom-level')])
    if history[-1] != location:
        history.append(location)
    Gst.set_history(history[-30:])
コード例 #3
0
ファイル: xmlfiles.py プロジェクト: akadig/gottengeography
def track_color_changed(selection, polys):
    """Update the color of any loaded GPX tracks."""
    color = selection.get_color()
    Gst.set_color(color)
    one = make_clutter_color(color)
    two = one.lighten().lighten()
    for i, polygon in enumerate(polys):
        polygon.set_stroke_color(two if i % 2 else one)
コード例 #4
0
 def __init__(self):
     Clutter.Box.__init__(self)
     self.set_layout_manager(Clutter.BinLayout())
     self.set_color(Clutter.Color.new(0, 0, 0, 96))
     Gst.bind('show-map-coords', self, 'visible')
     MapView.bin_layout_add(self, START, START)
     self.get_layout_manager().add(CoordLabel, CENTER, CENTER)
     MapView.connect('notify::width',
                     lambda *ignore: self.set_size(MapView.get_width(), 30))
コード例 #5
0
ファイル: actor.py プロジェクト: TheNeuralBit/gottengeography
 def __init__(self):
     Clutter.Box.__init__(self)
     self.set_layout_manager(Clutter.BinLayout())
     self.set_color(Clutter.Color.new(0, 0, 0, 96))
     Gst.bind('show-map-coords', self, 'visible')
     MapView.bin_layout_add(self, START, START)
     self.get_layout_manager().add(CoordLabel, CENTER, CENTER)
     MapView.connect('notify::width',
         lambda *ignore: self.set_size(MapView.get_width(), 30))
コード例 #6
0
def remember_location(view):
    """Add current location to history stack."""
    history = list(Gst.get('history'))
    location = tuple([
        view.get_property(x) for x in ('latitude', 'longitude', 'zoom-level')
    ])
    if history[-1] != location:
        history.append(location)
    Gst.set_history(history[-30:])
コード例 #7
0
    def __init__(self):
        last_source = Gst.get_string('map-source-id')
        Gst.bind_with_convert('map-source-id', MapView, 'map-source',
                              MAP_SOURCES.get, lambda x: x.get_id())

        for source_id in sorted(MAP_SOURCES):
            menu_item = RadioMenuItem(MAP_SOURCES[source_id])
            if last_source == source_id:
                menu_item.set_active(True)

        Widgets.map_source_menu.show_all()
コード例 #8
0
def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')
コード例 #9
0
ファイル: actor.py プロジェクト: TheNeuralBit/gottengeography
    def __init__(self):
        last_source = Gst.get_string('map-source-id')
        Gst.bind_with_convert('map-source-id', MapView, 'map-source',
            MAP_SOURCES.get, lambda x: x.get_id())

        for source_id in sorted(MAP_SOURCES):
            menu_item = RadioMenuItem(MAP_SOURCES[source_id])
            if last_source == source_id:
                menu_item.set_active(True)

        Widgets.map_source_menu.show_all()
コード例 #10
0
def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')
コード例 #11
0
def teardown():
    """Clean it all up."""
    TrackFile.clear_all()
    for camera in Camera.instances:
        camera.photos.clear()
    for photo in list(Photograph.instances):
        photo.destroy()
    Photograph.cache.clear()
    modified.clear()
    selected.clear()
    Widgets.loaded_photos.clear()
    system('git checkout demo')
    for key in Gst.list_keys():
        Gst.reset(key)
コード例 #12
0
ファイル: __init__.py プロジェクト: telkel/gottengeography
def teardown():
    """Clean it all up."""
    TrackFile.clear_all()
    for camera in Camera.instances:
        camera.photos.clear()
    for photo in list(Photograph.instances):
        photo.destroy()
    Photograph.cache.clear()
    modified.clear()
    selected.clear()
    Widgets.loaded_photos.clear()
    system('git checkout demo')
    for key in Gst.list_keys():
        Gst.reset(key)
コード例 #13
0
def animate_in(anim=True):
    """Fade in all the map actors."""
    for i in range(Gst.get_int('animation-steps') if anim else 1, 0, -1):
        for actor in (Crosshair, Box, Scale):
            actor.set_opacity(256 - i)
        Widgets.redraw_interface()
        sleep(0.01)
コード例 #14
0
ファイル: photos.py プロジェクト: apapillon/gottengeography
def fetch_thumbnail(filename, size=Gst.get_int('thumbnail-size'), orient=1):
    """Load a photo's thumbnail from disk

    >>> fetch_thumbnail('gg/widgets.py')
    Traceback (most recent call last):
    OSError: gg/widgets.py: No thumbnail found.
    >>> type(fetch_thumbnail('demo/IMG_2411.JPG'))
    <class 'gi.repository.GdkPixbuf.Pixbuf'>
    """
    try:
        exif = GExiv2.Metadata(filename)
    except GObject.GError:
        raise OSError('{}: No thumbnail found.'.format(filename))

    with ignored(KeyError, ValueError):
        orient = int(exif['Exif.Image.Orientation'])

    try:
        thumb = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, size, size)
    except GObject.GError:
        try:
            preview = exif.get_preview_properties()
            data = exif.get_preview_image(preview[0]).get_data()
        except (IndexError, GObject.GError):
            raise OSError('{}: No thumbnail found.'.format(filename))

        return GdkPixbuf.Pixbuf.new_from_stream_at_scale(
            Gio.MemoryInputStream.new_from_data(data, None), size, size, True,
            None)

    return ROTATIONS.get(orient, lambda x: x)(thumb)
コード例 #15
0
ファイル: photos.py プロジェクト: akadig/gottengeography
def fetch_thumbnail(filename, size=Gst.get_int('thumbnail-size'), orient=1):
    """Load a photo's thumbnail from disk

    >>> fetch_thumbnail('gg/widgets.py')
    Traceback (most recent call last):
    OSError: gg/widgets.py: No thumbnail found.
    >>> type(fetch_thumbnail('demo/IMG_2411.JPG'))
    <class 'gi.repository.GdkPixbuf.Pixbuf'>
    """
    try:
        exif = GExiv2.Metadata(filename)
    except GObject.GError:
        raise OSError('{}: No thumbnail found.'.format(filename))

    with ignored(KeyError, ValueError):
        orient = int(exif['Exif.Image.Orientation'])

    try:
        thumb = GdkPixbuf.Pixbuf.new_from_file_at_size(filename, size, size)
    except GObject.GError:
        try:
            data = exif.get_preview_image().get_data()
        except GObject.GError:
            raise OSError('{}: No thumbnail found.'.format(filename))

        return GdkPixbuf.Pixbuf.new_from_stream_at_scale(
            Gio.MemoryInputStream.new_from_data(data, None),
            size, size, True, None)

    return ROTATIONS.get(orient, lambda x: x)(thumb)
コード例 #16
0
ファイル: actor.py プロジェクト: TheNeuralBit/gottengeography
def animate_in(anim=True):
    """Fade in all the map actors."""
    for i in range(Gst.get_int('animation-steps') if anim else 1, 0, -1):
        for actor in (Crosshair, Box, Scale):
            actor.set_opacity(256 - i)
        Widgets.redraw_interface()
        sleep(0.01)
コード例 #17
0
    def launch(self):
        """Do some things that GtkBuilder XML can't do.

        Ideally this method would not exist. If you see something here that
        can be done directly in the GtkBuilder XML, please let me know.
        """
        self.loaded_photos.set_sort_column_id(3, Gtk.SortType.ASCENDING)

        self.about.set_version(str(REVISION))
        self.about.set_program_name(APPNAME)
        self.about.set_logo(GdkPixbuf.Pixbuf.new_from_file_at_size(
            join(PKG_DATA_DIR, PACKAGE + '.svg'), 192, 192))

        self.main.resize(*Gst.get('window-size'))
        self.main.show_all()

        Gst.bind('left-pane-page', self.photo_camera_gps, 'page')
        Gst.bind('use-dark-theme', Gtk.Settings.get_default(),
                 'gtk-application-prefer-dark-theme')

        placeholder = self.empty_photo_list
        toolbar = self.photo_btn_bar

        def photo_pane_visibility(liststore, *ignore):
            """Hide the placeholder and show the toolbar when appropriate."""
            empty = liststore.get_iter_first() is None
            placeholder.set_visible(empty)
            toolbar.set_visible(not empty)

        self.loaded_photos.connect('row-inserted', photo_pane_visibility)
        self.loaded_photos.connect('row-deleted', photo_pane_visibility)
        self.photos_selection.connect('changed', self.update_highlights)
        self.photos_selection.connect('changed', self.button_sensitivity)
        self.photos_view.connect('button-press-event', self.photoview_pressed)
        self.photos_view.connect('button-release-event', self.photoview_released)
        self.photos_view.connect('row-activated', self.show_large_preview)
        self.large_preview_window.connect('delete_event',
            lambda *ignore: self.large_preview_window.hide_on_delete())

        self.error_bar.connect('response',
            lambda widget, signal: widget.hide())
コード例 #18
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 OSError('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)
コード例 #19
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 OSError('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)
コード例 #20
0
 def __init__(self):
     Champlain.Point.__init__(self)
     self.set_size(4)
     self.set_color(Clutter.Color.new(0, 0, 0, 64))
     Gst.bind('show-map-center', self, 'visible')
     MapView.bin_layout_add(self, CENTER, CENTER)
コード例 #21
0
ファイル: actor.py プロジェクト: TheNeuralBit/gottengeography
 def __init__(self):
     Champlain.Point.__init__(self)
     self.set_size(4)
     self.set_color(Clutter.Color.new(0, 0, 0, 64))
     Gst.bind('show-map-center', self, 'visible')
     MapView.bin_layout_add(self, CENTER, CENTER)
コード例 #22
0
ファイル: actor.py プロジェクト: TheNeuralBit/gottengeography
 def __init__(self):
     Champlain.Scale.__init__(self)
     self.connect_view(MapView)
     Gst.bind('show-map-scale', self, 'visible')
     MapView.bin_layout_add(self, START, END)
コード例 #23
0
    Gst.set_history(history[-30:])


def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')


def zoom_button_sensitivity(view, signal, inn_sensitive, out_sensitive):
    """Ensure zoom buttons are only sensitive when they need to be."""
    zoom = view.get_zoom_level()
    out_sensitive(view.get_min_zoom_level() != zoom)
    inn_sensitive(view.get_max_zoom_level() != zoom)


for prop in ('latitude', 'longitude', 'zoom-level'):
    Gst.bind(prop, MapView, prop)

MapView.connect('notify::zoom-level', zoom_button_sensitivity,
                Widgets.zoom_in_button.set_sensitive,
                Widgets.zoom_out_button.set_sensitive)
MapView.connect('realize', remember_location)
コード例 #24
0
 def __init__(self):
     Champlain.Scale.__init__(self)
     self.connect_view(MapView)
     Gst.bind('show-map-scale', self, 'visible')
     MapView.bin_layout_add(self, START, END)
コード例 #25
0
def go_back(*ignore):
    """Return the map view to where the user last set it."""
    history = list(Gst.get('history'))
    lat, lon, zoom = history.pop()
    if valid_coords(lat, lon):
        MapView.set_zoom_level(zoom)
        MapView.center_on(lat, lon)
    if len(history) > 1:
        Gst.set_history(history)
    else:
        Gst.reset('history')


def zoom_button_sensitivity(view, signal, inn_sensitive, out_sensitive):
    """Ensure zoom buttons are only sensitive when they need to be."""
    zoom = view.get_zoom_level()
    out_sensitive(view.get_min_zoom_level() != zoom)
    inn_sensitive(view.get_max_zoom_level() != zoom)


for prop in ('latitude', 'longitude', 'zoom-level'):
    Gst.bind(prop, MapView, prop)


MapView.connect(
    'notify::zoom-level',
    zoom_button_sensitivity,
    Widgets.zoom_in_button.set_sensitive,
    Widgets.zoom_out_button.set_sensitive)
MapView.connect('realize', remember_location)