示例#1
0
    def create_cached_source(self):
        map_tile_url = "https://api.mapbox.com/styles/v1/mapbox/streets-v11/tiles/256/#Z#/#X#/#Y#"
        map_tile_url += "?access_token=pk.eyJ1IjoiZGVsdGFmb3h0cm90IiwiYSI6ImNramg2OXo1ZzRpd2Qyem5"
        map_tile_url += "wOXR5Mm01MWUifQ.5KGdqcPnw-SPU8dfn29a_Q"

        factory = Champlain.MapSourceFactory.dup_default()
        tile_source = Champlain.NetworkTileSource.new_full(
            "mapbox", "mapbox", " (c) mapbox (c) openstreet map contributors",
            "https://www.mapbox.com/tos", 2, 19, 256,
            Champlain.MapProjection.MERCATOR, map_tile_url,
            Champlain.ImageRenderer())

        tile_size = tile_source.get_tile_size()
        error_source = factory.create_error_source(tile_size)
        file_cache = Champlain.FileCache.new_full(CACHE_SIZE, None,
                                                  Champlain.ImageRenderer())

        memory_cache = Champlain.MemoryCache.new_full(
            MEMORY_CACHE_SIZE, Champlain.ImageRenderer())

        source_chain = Champlain.MapSourceChain()
        source_chain.push(error_source)
        source_chain.push(tile_source)
        source_chain.push(file_cache)
        source_chain.push(memory_cache)

        return source_chain
示例#2
0
def create_cached_source():
    factory = Champlain.MapSourceFactory.dup_default()

    tile_source = Champlain.NetworkTileSource.new_full(
        "mapbox", "mapbox", LICENSE_TEXT, LICENSE_URI, MIN_ZOOM, MAX_ZOOM,
        TILE_SIZE, Champlain.MapProjection.MERCATOR,
        "https://a.tiles.mapbox.com/v4/mapbox.streets/#Z#/#X#/#Y#.png?access_token="
        + ACCESS_TOKEN, Champlain.ImageRenderer())

    tile_size = tile_source.get_tile_size()

    error_source = factory.create_error_source(tile_size)
    file_cache = Champlain.FileCache.new_full(CACHE_SIZE, None,
                                              Champlain.ImageRenderer())
    memory_cache = Champlain.MemoryCache.new_full(MEMORY_CACHE_SIZE,
                                                  Champlain.ImageRenderer())

    source_chain = Champlain.MapSourceChain()
    # tile is retrieved in this order:
    # memory_cache -> file_cache -> tile_source -> error_source
    # the first source that contains the tile returns it
    source_chain.push(error_source)
    source_chain.push(tile_source)
    source_chain.push(file_cache)
    source_chain.push(memory_cache)

    return source_chain
示例#3
0
    def __init__(self, parent):
        GtkChamplain.Embed.__init__(self)
        self.set_size_request(640, 480)

        self.parent = parent
        self.view = self.get_view()
        self.view.set_reactive(True)
        self.view.set_kinetic_mode(True)
        self.view.set_zoom_level(13)
        self.view.center_on(36.72341, -4.42428)  # TODO: Set to center of default zone
        self.view.connect('button-release-event', self.mouse_click_cb)

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

        self.points_layer = Champlain.MarkerLayer()
        self.points_layer.set_selection_mode(Champlain.SelectionMode.SINGLE)
        self.labels_layer = Champlain.MarkerLayer()

        # It's important to add points the last. Points are selectable while labels are not
        # If labels is added later, then you click on some point and it doesn't get selected
        # because you are really clicking on the label. Looks like an usability bug?
        self.view.add_layer(self.labels_layer)
        self.view.add_layer(self.points_layer)

        self.menu = Gtk.Menu()
        menuitem1 = Gtk.MenuItem('Create new Guifi.net node here')
        menuitem1.connect('activate', self.create_new_node)
        self.menu.append(menuitem1)
        self.menu.show_all()
示例#4
0
    def show_contacts(self):
        data = {}
        accounts = app.contacts._accounts
        for account in accounts:
            if not app.account_is_connected(account):
                continue
            for contact in accounts[account].contacts._contacts:
                pep = accounts[account].contacts._contacts[contact][0].pep
                if 'location' not in pep:
                    continue
                lat = pep['location'].data.get('lat', None)
                lon = pep['location'].data.get('lon', None)
                if not lat or not lon:
                    continue
                name = accounts[account].contacts.get_first_contact_from_jid(
                    contact).get_shown_name()
                data[contact] = (lat, lon, name)

        self.contacts_layer = Champlain.MarkerLayer()
        for jid in data:
            path = self.get_path_to_generic_or_avatar(self.path_to_image,
                                                      jid=jid,
                                                      suffix='')
            texture = Clutter.Texture()
            texture.set_from_file(path)
            texture.set_size(32, 32)
            marker = Champlain.Label.new_with_image(texture)
            marker.set_text(data[jid][2])
            marker.set_location(float(data[jid][0]), float(data[jid][1]))
            self.contacts_layer.add_marker(marker)

        self.view.add_layer(self.contacts_layer)
        self.contacts_layer.animate_in_all_markers()
        self.markers_is_visible = True
示例#5
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)
示例#6
0
    def __init__(self):
        self.window = Gtk.Window()
        self.window.set_border_width(10)
        self.window.set_title("GeoClue2 + GTK Python Demo")
        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.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()

        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="Current Location")
        button.set_active(False)
        button.connect("toggled", self.get_location)
        bbox.add(button)

        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()
示例#7
0
    def get_map(self, latitude, longitude):
        view = Champlain.View()
        view.set_kinetic_mode(True)
        view.set_property("zoom-level", 18)
        view.set_reactive(True)
        view.set_size(1000, 800)
        view.center_on(latitude, longitude)

        layer = Champlain.MarkerLayer()
        marker = Champlain.Point.new()
        marker.set_location(latitude, longitude)
        layer.add_marker(marker)
        view.add_layer(layer)

        embed = GtkClutter.Embed.new()
        embed.realize()
        stage = embed.get_stage()
        stage.add_actor(view)

        return embed
示例#8
0
文件: ui.py 项目: claudioap/GeoSVG
 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)
示例#9
0
    def __init__(self, stage, image):
        self.image = image

        self.view = MapView()
        self.rectangle = MapShadowRectangle()
        self.marker = PhotoMarker()

        layer = Champlain.MarkerLayer()
        layer.add_marker(self.marker)
        self.view.add_layer(layer)

        stage.add_actor(self.rectangle)
        stage.add_actor(self.view)
示例#10
0
    def __init__(self):
        self.select_all = get_obj('select_all_button')
        self.selection = get_obj('photos_view').get_selection()
        self.selection.set_mode(Gtk.SelectionMode.MULTIPLE)
        self.layer = Champlain.MarkerLayer()
        map_view.add_layer(self.layer)

        self.selection.connect('changed', update_highlights)
        self.selection.connect(
            'changed', selection_sensitivity, *[
                get_obj(name) for name in ('apply_button', 'close_button',
                                           'save_button', 'revert_button')
            ])
示例#11
0
    def make_map(self):
        embed = GtkChamplain.Embed()

        self.view = embed.get_view()
        self.view.set_reactive(True)

        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("Do what you want but I am RMFlynn")

        self.view.center_on(39.739, -104.984)

        self.marker_layer = Champlain.MarkerLayer()
        self.view.add_layer(self.marker_layer)
        self.marker_layer.show()
        return embed
示例#12
0
def get_map(latitude, longitude):
    view = Champlain.View()
    view.set_kinetic_mode(True)
    view.set_property("zoom-level", 12)
    view.set_reactive(True)
    view.set_size(500, 350)
    view.center_on(latitude, longitude)

    embed = GtkClutter.Embed.new()
    embed.realize()
    stage = embed.get_stage()
    stage.add_actor(view)

    return embed
示例#13
0
 def add(self, name):
     """Create a new ChamplainLabel and add it to the map."""
     label = Champlain.Label()
     label.set_name(name)
     label.set_text(basename(name))
     label.set_selectable(True)
     label.set_draggable(True)
     label.set_property('reactive', True)
     label.connect('enter-event', hover, 1.05)
     label.connect('leave-event', hover, 1 / 1.05)
     label.connect('drag-finish', drag_finish, self.selection)
     label.connect('button-press', clicked, self.selection, self.select_all)
     self.layer.add_marker(label)
     return label
示例#14
0
    def __init__(self):
        super(MapView, self).__init__()

        uri = SETTINGS_UI_MAP.get_string('source-uri')
        uri = "http://tile.openstreetmap.org/#Z#/#X#/#Y#.png"

        if uri:
            source = Champlain.NetworkTileSource()
            source.set_uri_format(uri)
            # self.set_map_source(source)

        self.timeline = FadeAnimationTimeline(self)
        self.timeline.timeline_fade_out.connect('completed', self._hide)
        self.zoom = ZoomLevel(self)

        super(MapView, self).hide()
        self.set_opacity(0)
示例#15
0
    def create_marker_layer(self, view):
        orange = Clutter.Color.new(0xf3, 0x94, 0x07, 0xbb)
        layer = Champlain.MarkerLayer()

        marker = Champlain.Label.new_with_text(
            "Montréal\n<span size=\"xx-small\">Québec</span>", "Serif 14", None,
            orange)
        marker.set_use_markup(True)
        marker.set_alignment(Pango.Alignment.RIGHT)
        marker.set_color(orange)

        marker.set_location(45.528178, -73.563788)
        layer.add_marker(marker)
        marker.set_reactive(True)
        marker.connect("button-release-event", self.marker_button_release_cb, view)

        marker = Champlain.Label.new_from_file(
            "icons/emblem-generic.png")
        marker.set_text("New York")
        marker.set_location(40.77, -73.98)
        layer.add_marker(marker)

        marker = Champlain.Label.new_from_file(
            "icons/emblem-important.png")
        marker.set_location(47.130885, -70.764141)
        layer.add_marker(marker)

        marker = Champlain.Label.new_from_file(
            "icons/emblem-favorite.png")
        marker.set_draw_background(False)
        marker.set_location(45.41484, -71.918907)
        layer.add_marker(marker)

        marker = Champlain.Label.new_from_file(
            "icons/emblem-new.png")
        marker.set_draw_background(False)
        marker.set_location(50.639663, 5.570798)
        layer.add_marker(marker)

        layer.set_all_markers_draggable()
        layer.show()
        return 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)
示例#17
0
    def place_marker(self, latitude, longitude, description):
        orange = Clutter.Color.new(0xf3, 0x94, 0x07, 0xbb)
        layer = Champlain.MarkerLayer()

        markup_string = ""
        lines = description.split(',')
        if (len(lines) > 1):
            markup_string = lines[0] + "\n<span size=\"xx-small\">" + \
                ", ".join(lines[1:]) + "</span>"
        elif (len(lines) == 0):
            markup_string = lines[0].strip()

        marker = Champlain.Label.new_with_text(markup_string, "Serif 14", None,
                                               orange)
        marker.set_use_markup(True)
        marker.set_color(orange)

        marker.set_location(latitude, longitude)
        layer.add_marker(marker)
        self.view.center_on(latitude, longitude)
        layer.show()
        self.view.add_layer(layer)
 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 onclickHandler(self,widget):
     srcLocation  = self.srcTextView.get_model().get_value(self.srcTextView.get_active_iter(),0)
     destLocation  = self.destTextView.get_model().get_value(self.destTextView.get_active_iter(),0)
     #print (srcLocation)
     srcNode =   self.cGraphService.getStreetfromNode(long(srcLocation))#srcLocation['targetNode']['osmId']#self.srcTextView.get_model().get_value(self.srcTextView.get_active_iter(),0)
     destNode =  self.cGraphService.getStreetfromNode(long(destLocation))#destLocation['targetNode']['osmId']#self.destTextView.get_model().get_value(self.destTextView.get_active_iter(),0)
     #srcNode = self.nodes_service.getNode(srcOSMId)
     #destNode = self.nodes_service.getNode(destOSMId)
     srcMarker = self.createMarker(srcNode['street']['meta_data']['name'],srcNode['targetNode']["lat"] , srcNode['targetNode']["lng"])
     destMarker = self.createMarker(destNode['street']['meta_data']['name'] ,destNode['targetNode']["lat"], destNode['targetNode']["lng"])
     layer = Champlain.MarkerLayer()
     layer.add_marker(srcMarker)
     srcMarker.set_reactive(True)
     layer.add_marker(destMarker)
     destMarker.set_reactive(True)
     result=self.invokeFSPService(long(srcLocation), long(destLocation))
     #print (result)
     self.updateUIToAddPath(result)
     #self.updateUIToAddPath3(result)
     #layer.set_all_markers_draggable()
     #layer.show()
     self.view.add_layer(layer)
     self.view.ensure_layers_visible(True)
 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)       
示例#21
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)
示例#22
0
    [
        'mapquest-osm', 'MapQuest OSM', 0, 17, 256,
        'Map data provided by MapQuest, Open Street Map and contributors',
        'http://creativecommons.org/licenses/by-sa/2.0/',
        'http://otile1.mqcdn.com/tiles/1.0.0/osm/#Z#/#X#/#Y#.png'
    ],
    [
        'mff-relief', 'Maps for Free Relief', 0, 11, 256,
        'Map data available under GNU Free Documentation license, v1.2 or later',
        'http://www.gnu.org/copyleft/fdl.html',
        'http://maps-for-free.com/layer/relief/z#Z#/row#Y#/#Z#_#X#-#Y#.jpg'
    ],
]:
    mapid, name, min_zoom, max_zoom, size, lic, lic_uri, tile_uri = map_desc

    c = Champlain.MapSourceChain()
    c.push(Champlain.MapSourceFactory.dup_default().create_error_source(size))

    c.push(
        Champlain.NetworkTileSource.new_full(
            mapid, name, lic, lic_uri, min_zoom, max_zoom, size,
            Champlain.MapProjection.MAP_PROJECTION_MERCATOR, tile_uri,
            Champlain.ImageRenderer()))

    c.push(Champlain.FileCache.new_full(1e8, None, Champlain.ImageRenderer()))
    c.push(Champlain.MemoryCache.new_full(100, Champlain.ImageRenderer()))
    MAP_SOURCES[mapid] = c


@memoize
class RadioMenuItem(Gtk.RadioMenuItem):
示例#23
0
    def on_run(self):
        if not self.is_active:
            pres_keys = sorted(self.plugin.config['presets'].keys())
            for key in pres_keys:
                self.preset_liststore.append((key, ))

        for name in self.plugin.config_default_values:
            if name == 'presets':
                continue
            widget = self.xml.get_object(name)
            widget.set_text(str(self.plugin.config[name]))

        map_placeholder = self.xml.get_object('map_placeholder')
        dependency_bar = self.xml.get_object('dependency_warning')

        if CHAMPLAIN_AVAILABLE and not self.is_active:
            map_placeholder.set_no_show_all(True)
            map_placeholder.hide()
            dependency_bar.hide()
            map_box = self.xml.get_object('map_box')
            map_box.set_size_request(400, -1)

            embed = GtkChamplain.Embed()

            self.view = embed.get_view()
            self.view.set_reactive(True)
            self.view.set_property('kinetic-mode', True)
            self.view.set_property('zoom-level', 12)
            self.view.connect('button-release-event', self.map_clicked,
                              self.view)

            scale = Champlain.Scale()
            scale.connect_view(self.view)
            self.view.add_child(scale)

            lat = self.plugin.config['lat']
            lon = self.plugin.config['lon']
            if not self.is_valid_coord(lat, lon):
                self.lat = self.lon = 0.0
                self.xml.get_object('lat').set_text('0.0')
                self.xml.get_object('lon').set_text('0.0')
            self.view.center_on(self.lat, self.lon)

            self.path_to_image = os.path.abspath(
                gtkgui_helpers.get_icon_path('org.gajim.Gajim', 16))
            map_box.pack_start(embed, expand=True, fill=True, padding=0)

            self.is_active = True
            self.layer = Champlain.MarkerLayer()
            texture = Clutter.Texture()
            texture.set_from_file(self.path_to_image)
            texture.set_size(32, 32)
            self.marker = Champlain.Label.new_with_image(texture)
            self.marker.set_location(self.lat, self.lon)
            self.marker.set_text(_('Your location'))
            self.view.add_layer(self.layer)
            self.layer.add_marker(self.marker)
            self.markers_is_visible = False
            self.xml.get_object('lat').connect('changed',
                                               self.on_latlon_changed)
            self.xml.get_object('lon').connect('changed',
                                               self.on_latlon_changed)
            self.layer.animate_in_all_markers()
            self.contacts_layer = Champlain.MarkerLayer()
示例#24
0
def main_quit(data):
    Clutter.main_quit()


if __name__ == '__main__':
    total_width = 0

    stage = Clutter.Stage()
    stage.set_size(800, 600)
    # It complains about the number of arguments passed to main_quit()
    #stage.connect('destroy', Clutter.main_quit)
    stage.connect('destroy', main_quit)

    # Create the map view
    view = Champlain.View()
    view.set_size(800, 600)
    stage.add_child(view)

    # Create the buttons
    buttons = Clutter.Actor()
    buttons.set_position(PADDING, PADDING)

    button = make_button('Zoom in')
    buttons.add_child(button)
    button.set_reactive(True)
    (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)
示例#25
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()
示例#26
0
文件: ui.py 项目: claudioap/GeoSVG
    def __init__(self, controller):
        self.controller = controller

        GObject.threads_init()

        # Glade
        builder = Gtk.Builder()
        builder.add_from_file("GeoSVG.glade")
        self.window = builder.get_object("window")
        boxes = builder.get_object("boxes")
        open_btn = builder.get_object("open_btn")
        self.preview = builder.get_object("preview")
        self.layers_tree = builder.get_object("layers_tree")
        self.lim_north = builder.get_object("lim_north")
        self.lim_south = builder.get_object("lim_south")
        self.lim_east = builder.get_object("lim_east")
        self.lim_west = builder.get_object("lim_west")
        self.rotation = builder.get_object("rotation")
        self.output = builder.get_object("output")
        self.last_click = builder.get_object("last_click")
        replace_north_lim = builder.get_object("replace_north_lim")
        replace_south_lim = builder.get_object("replace_south_lim")
        replace_east_lim = builder.get_object("replace_east_lim")
        replace_west_lim = builder.get_object("replace_west_lim")

        # Map
        embed = GtkChamplain.Embed()
        self.map_view = embed.get_view()
        self.map_view.set_reactive(True)
        self.map_view.set_property('kinetic-mode', True)
        self.map_view.set_property('zoom-level', 16)
        scale = Champlain.Scale()
        scale.connect_view(self.map_view)
        self.map_view.bin_layout_add(scale, Clutter.BinAlignment.START,
                                     Clutter.BinAlignment.END)
        self.map_view.center_on(38.66, -9.20523)
        boxes.add(embed)

        # Layers pane
        self.layers_liststore = Gtk.ListStore(str, bool)
        self.layers_tree.set_model(self.layers_liststore)
        column_text = Gtk.TreeViewColumn("Name",
                                         Gtk.CellRendererText(),
                                         text=0)
        self.layers_tree.append_column(column_text)
        renderer_toggle = Gtk.CellRendererToggle()
        column_toggle = Gtk.TreeViewColumn("Enable", renderer_toggle, active=1)
        self.layers_tree.append_column(column_toggle)

        self.window.show_all()

        # Events
        renderer_toggle.connect("toggled", self.__on_layer_toggled)
        self.window.connect("destroy", Gtk.main_quit)
        open_btn.connect('clicked', self.open_file)
        self.lim_north.connect('changed', self.__update_north_lim)
        self.lim_south.connect('changed', self.__update_south_lim)
        self.lim_east.connect('changed', self.__update_east_lim)
        self.lim_west.connect('changed', self.__update_west_lim)
        self.rotation.connect(
            'changed',
            lambda w: self.controller.update_rotation(w.get_value()))
        self.map_view.connect('button-release-event',
                              self.__on_map_mouse_click, self.map_view)
        replace_north_lim.connect('clicked',
                                  lambda _: self.controller.replace_lim('N'))
        replace_south_lim.connect('clicked',
                                  lambda _: self.controller.replace_lim('S'))
        replace_east_lim.connect('clicked',
                                 lambda _: self.controller.replace_lim('E'))
        replace_west_lim.connect('clicked',
                                 lambda _: self.controller.replace_lim('W'))

        # Drawn layers
        self.layers = []
示例#27
0
    def create_marker_layer(self, view):
        layer = Champlain.MarkerLayer()
        layer.show()

        return layer