Пример #1
0
    def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip, data=None):
        if keyboard_tip:
            return False

        if self.show_tooltips:
            p = osmgpsmap.point_new_degrees(0.0, 0.0)
            self.osm.convert_screen_to_geographic(x, y, p)
            lat,lon = p.get_degrees()
            tooltip.set_markup("%+.4f, %+.4f" % (lat, lon ))
            return True

        return False
Пример #2
0
    def __init__(self, database, host, *args, **kwargs):
        super(OSM, self).__init__(*args, **kwargs)
        """ single host geolocation map widget """

        self.layer_add(
            osmgpsmap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=True))

        self.props.has_tooltip = True

        self.host = host
        self.database = database

        self.show()
        self.set_property("height-request", 450)
Пример #3
0
	def addTrace(self, trace):
		filename = trace.get_full_path()
		if filename not in self._tracks:
			gpstracks = []
			for track in trace.get_points():
			  for segment in track:

				gpstrack = OsmGpsMap.MapTrack()				
				gpstrack.props.alpha = 0.8

				for rlat,rlon in segment:
					gpstrack.add_point(OsmGpsMap.MapPoint.new_radians(rlat, rlon))
				gpstracks.append(gpstrack)

			self._tracks[filename] = (trace, gpstracks)
			self.model.append( (trace.get_display_name(), filename) )
			self.emit("track-added", trace, gpstracks)
Пример #4
0
    def __init__(self, core, conn):
        self.core = core
        self.conn = conn

        self.timeControl = TimeControl()
        self.settingsManager = SettingsManager()

        self.builder = Gtk.Builder()
        self.builder.add_from_file(
            os.path.abspath(os.path.dirname(__file__)) + "/mainwindow.glade")
        self.builder.connect_signals(self)

        self.window = self.builder.get_object("main-window")
        self.window.connect("delete-event", self.quit)
        self.window.set_default_size(1024, 600)
        self.window.show_all()
        # self.window.maximize ()

        self.map = self.builder.get_object("map")
        self.map.set_center_and_zoom(39., 9., 6)

        self.chartManager = ChartManager(self.map)
        self.chartManager.loadBaseChart()
        self.map.layer_add(self.chartManager)

        self.gribMapLayer = GribMapLayer(self.core.gribManager,
                                         self.timeControl)
        self.map.layer_add(self.gribMapLayer)

        self.map.layer_add(
            OsmGpsMap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=False))

        self.statusbar = self.builder.get_object("status-bar")

        MainWindowTime.__init__(self)
        MainWindowRouting.__init__(self)
        MainWindowTrack.__init__(self)
        MainWindowPOI.__init__(self)

        Gdk.threads_init()

        self.core.connect('boatPosition', self.boatInfoHandler)
Пример #5
0
    def load_map_clicked(self, button):
        uri = self.repouri_entry.get_text()
        format = self.image_format_entry.get_text()
        if uri and format:
            if self.osm:
                #remove old map
                self.vbox.remove(self.osm)
            try:
                self.osm = osmgpsmap.Map(
                    repo_uri=uri,
                    image_format=format
                )
            except Exception, e:
                print "ERROR:", e
                self.osm = osm.Map()

            self.vbox.pack_start(self.osm, True, True, 0)
            self.osm.connect('button_release_event', self.map_clicked)
            self.osm.show()
Пример #6
0
    def __init__(self, config):
        assert isinstance(config, Configuration)

        self.meta = None
        self.original_position = (0, 0)
        self.config = config

        # Set the Glade file
        builder = Gtk.Builder()
        builder.add_from_file(get_resource("exifgpseditor.glade"))

        handlers = {
            "quit": (lambda _: Gtk.main_quit()),
            "apply": (lambda _: self.save_image()),
            "redraw": (lambda _: self.move_to(None)),
            "origin": (lambda _: self.move_to(self.original_position)),
            "previous": (lambda _: self.move_to(self.config.previous_position))
        }
        builder.connect_signals(handlers)

        # Get the Main Window, and connect the "destroy" event
        self.win_exifgpseditor = builder.get_object("win_exifgpseditor")
        self.win_exifgpseditor.connect('destroy', lambda x: Gtk.main_quit())

        # Add zoom buttons and target to the map
        self.themap = builder.get_object("map_gps")
        self.themap.layer_add(
            OsmGpsMap.MapOsd(
                show_zoom=True,
                show_crosshair=True
            )
        )

        # Get the image widget
        self.img_preview = builder.get_object("img_preview")

        self.win_exifgpseditor.show_all()
Пример #7
0
    def __init__(self, ui_dir, files):
        self.local_tz = LocalTimezone()
        self.recent = Gtk.RecentManager.get_default()

        self.wTree = Gtk.Builder()
        self.wTree.set_translation_domain('gpxviewer')
        self.wTree.add_from_file("%sgpxviewer.ui" % ui_dir)

        signals = {
            "on_windowMain_destroy": self.quit,
            "on_menuitemQuit_activate": self.quit,
            "on_menuitemOpen_activate": self.open_gpx,
            "on_menuitemZoomIn_activate": self.zoom_map_in,
            "on_buttonZoomIn_clicked": self.zoom_map_in,
            "on_menuitemZoomOut_activate": self.zoom_map_out,
            "on_buttonZoomOut_clicked": self.zoom_map_out,
            "on_menuitemAbout_activate": self.open_about_dialog,
            "on_checkmenuitemShowSidebar_toggled": self.show_sidebar_toggled,
            "on_menuitemShowStatistics_activate": self.show_statistics,
            "on_buttonTrackAdd_clicked": self.button_track_add_clicked,
            "on_buttonTrackDelete_clicked": self.button_track_delete_clicked,
            "on_buttonTrackProperties_clicked":
            self.button_track_properties_clicked,
            "on_buttonTrackInspect_clicked": self.button_track_inspect_clicked,
        }

        self.mainWindow = self.wTree.get_object("windowMain")
        self.mainWindow.set_icon_from_file("%sgpxviewer.svg" % ui_dir)
        self.mainWindow.set_title(_("GPX Viewer"))

        i = self.wTree.get_object("checkmenuitemCenter")
        i.connect("toggled", self.auto_center_toggled)
        self.autoCenter = i.get_active()

        self.ui_dir = ui_dir

        self.map = OsmGpsMap.Map(tile_cache=os.path.join(
            GLib.get_user_cache_dir(), 'gpxviewer', 'tiles'))
        self.map.layer_add(
            OsmGpsMap.MapOsd(show_dpad=False,
                             show_zoom=False,
                             show_scale=True,
                             show_coordinates=False))
        self.wTree.get_object("hbox_map").pack_start(self.map, True, True, 0)

        sb = self.wTree.get_object("statusbar1")
        # move zoom control into apple like slider
        self.zoomSlider = MapZoomSlider(self.map)
        self.zoomSlider.show_all()
        a = Gtk.Alignment.new(0.5, 0.5, 1.0, 1.0)
        a.set_padding(0, 0, 0, 4)
        a.add(self.zoomSlider)
        a.show_all()
        sb.pack_end(a, False, False, padding=4)

        # animate a spinner when downloading tiles
        try:
            self.spinner = Gtk.Spinner()
            self.spinner.props.has_tooltip = True
            self.spinner.connect("query-tooltip", self.on_spinner_tooltip)
            self.map.connect("notify::tiles-queued", self.update_tiles_queued)
            self.spinner.set_size_request(
                *Gtk.icon_size_lookup(Gtk.IconSize.MENU)[:2])
            sb.pack_end(self.spinner, False, False, 0)
        except AttributeError:
            self.spinner = None

        self.wTree.connect_signals(signals)

        # add open with external tool submenu items and actions
        programs = {
            'josm': N_('JOSM Editor'),
            'merkaartor': N_('Merkaartor'),
        }
        submenu_open_with = Gtk.Menu()
        for prog, progname in programs.items():
            submenuitem_open_with = Gtk.MenuItem(_(progname))
            submenu_open_with.append(submenuitem_open_with)
            submenuitem_open_with.connect("activate",
                                          self.open_with_external_app, prog)
            submenuitem_open_with.show()

        self.wTree.get_object('menuitemOpenBy').set_submenu(submenu_open_with)

        self.trackManager = _TrackManager()
        self.trackManager.connect("track-added", self.on_track_added)
        self.trackManager.connect("track-removed", self.on_track_removed)

        self.wTree.get_object("menuitemHelp").connect(
            "activate",
            lambda *a: show_url("https://answers.launchpad.net/gpxviewer"))
        self.wTree.get_object("menuitemTranslate").connect(
            "activate", lambda *a: show_url(
                "https://translations.launchpad.net/gpxviewer"))
        self.wTree.get_object("menuitemReportProblem").connect(
            "activate", lambda *a: show_url(
                "https://bugs.launchpad.net/gpxviewer/+filebug"))

        self.tv = Gtk.TreeView(self.trackManager.model)
        self.tv.get_selection().connect("changed", self.on_selection_changed)
        self.tv.append_column(
            Gtk.TreeViewColumn("Track Name",
                               Gtk.CellRendererText(),
                               text=self.trackManager.NAME_IDX))
        self.wTree.get_object("scrolledwindow1").add(self.tv)
        self.sb = self.wTree.get_object("vbox_sidebar")

        self.hide_spinner()
        self.hide_track_selector()

        self.lazyLoadFiles(files)

        self.map.show()
        self.mainWindow.show()
Пример #8
0
    def change_map(self, obj, map_type):
        """
        Change the current map
        """
        if map_type == constants.PERSONAL:
            map_source = config.get('geography.personal-map')
            if map_source == "":
                return
            name = constants.TILES_PATH[map_type]
            self.change_new_map(name, map_source)
            config.set("geography.map_service", map_type)
            self.current_map = map_type
            return
        if obj is not None:
            self.osm.layer_remove_all()
            self.osm.image_remove_all()
            self.vbox.remove(self.osm)
            self.osm.destroy()
        tiles_path = os.path.join(config.get('geography.path'),
                                  constants.TILES_PATH[map_type])
        if not os.path.isdir(tiles_path):
            try:
                os.makedirs(tiles_path, 0o755)  # create dir like mkdir -p
            except:
                ErrorDialog(_("Can't create "
                              "tiles cache directory for '%s'.") %
                            constants.MAP_TITLE[map_type],
                            parent=self.uistate.window)
        config.set("geography.map_service", map_type)
        self.current_map = map_type
        http_proxy = get_env_var('http_proxy')
        if 0:
            self.osm = DummyMapNoGpsPoint()
        else:
            if http_proxy:
                self.osm = osmgpsmap.Map(
                    tile_cache=tiles_path,
                    proxy_uri=http_proxy,
                    map_source=constants.MAP_TYPE[map_type])
            else:
                self.osm = osmgpsmap.Map(
                    tile_cache=tiles_path,
                    map_source=constants.MAP_TYPE[map_type])
        self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
        current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
        self.end_selection = None
        self.osm.layer_add(current_map)
        self.osm.layer_add(DummyLayer())
        self.selection_layer = self.add_selection_layer()
        self.kml_layer = self.add_kml_layer()
        self.lifeway_layer = self.add_lifeway_layer()
        self.marker_layer = self.add_marker_layer()
        self.date_layer = self.add_date_layer()
        self.message_layer = self.add_message_layer()
        self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
        self.set_crosshair(config.get("geography.show_cross"))
        self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                     config.get("geography.center-lon"),
                                     config.get("geography.zoom"))

        self.osm.connect('button_release_event', self.map_clicked)
        self.osm.connect('button_press_event', self.map_clicked)
        self.osm.connect("motion-notify-event", self.motion_event)
        self.osm.connect('changed', self.zoom_changed)
        self.update_shortcuts(True)
        self.osm.show()
        self.vbox.pack_start(self.osm, True, True, 0)
        self.goto_handle(handle=None)
Пример #9
0
    def ors_call(self, dummy):
        try:
            self.osm.track_remove(self.orsRoute)
        except:
            pass
        try:
            sel = self.ors_profile.get_active_iter()
            if sel is not None:
                model = self.ors_profile.get_model()
                orsProfile = model[sel][0]
        except:
            orsProfile = 'driving-car'
        if self.pref_select_fastest.get_active():
            pref = 'fastest'
        else:
            pref = 'shortest'

        try:
            Route = []

            for i in range(len(self.via_route)):
                Route.append([self.via_route[i][1], self.via_route[i][0]])
            Route.insert(0, [self.start_route[1], self.start_route[0]])
            Route.append([self.end_route[1], self.end_route[0]])

            body = {
                "coordinates": Route,
                "elevation": "true",
                "preference": pref
            }

        except:
            return

        headers = {
            'Accept':
            'application/json, application/geo+json, application/gpx+xml, img/png; charset=utf-8',
            'Authorization':
            '5b3ce3597851110001cf624831f2d1f9129542dfbd9a148cd579f14b',
            'Content-Type': 'application/json; charset=utf-8'
        }
        call = requests.post(
            'https://api.openrouteservice.org/v2/directions/' + orsProfile +
            '/geojson',
            json=body,
            headers=headers,
            timeout=10)
        #		print(call.status_code, call.reason)
        #		print(call.text)

        if call.status_code == 200:
            self.route_json = json.loads(call.text)

            self.coords = self.route_json['features'][0]['geometry'][
                'coordinates']

            self.orsRoute = OsmGpsMap.MapTrack(editable=True,
                                               alpha=1,
                                               line_width=2)
            self.orsRoute.connect('point-changed', self.edit)

            for i in range(len(self.coords)):
                pt = OsmGpsMap.MapPoint()
                pt.set_degrees(float(self.coords[i][1]),
                               float(self.coords[i][0]))
                self.orsRoute.add_point(pt)

            self.osm.track_add(self.orsRoute)
            self.calc_track_length(self.orsRoute, 0)  # 0 is for the dummy arg

            bbox = self.route_json['features'][0]['bbox']
            self.osm.zoom_fit_bbox(bbox[1], bbox[4], bbox[0], bbox[3])

            self.instruction = ''
            for i in range(
                    len(self.route_json['features'][0]['properties']
                        ['segments'])):
                for j in range(
                        len(self.route_json['features'][0]['properties']
                            ['segments'][i]['steps'])):
                    step = self.route_json['features'][0]['properties'][
                        'segments'][i]['steps'][j]
                    stepDistance = step['distance']
                    if stepDistance > 1000:
                        stepDistance = str(
                            round((stepDistance / 1609.34) * 100) /
                            100) + ' miles'
                    else:
                        stepDistance = str(stepDistance) + 'm'
                    self.instruction = self.instruction + '- ' + step[
                        'instruction'] + ' (' + stepDistance + ')\n'
Пример #10
0
    def upload_gpx(self, gpx_button):
        dialog = Gtk.FileChooserDialog(title="Please choose a GPX file",
                                       parent=self,
                                       action=Gtk.FileChooserAction.OPEN)
        dialog.add_buttons(
            Gtk.STOCK_CANCEL,
            Gtk.ResponseType.CANCEL,
            Gtk.STOCK_OPEN,
            Gtk.ResponseType.OK,
        )
        filter = Gtk.FileFilter()
        filter.set_name("GPX")
        filter.add_pattern("*.gpx")
        dialog.add_filter(filter)
        filter = Gtk.FileFilter()
        filter.set_name("All files")
        filter.add_pattern("*")
        dialog.add_filter(filter)
        response = dialog.run()
        if response == Gtk.ResponseType.OK:
            gpx_file = open(dialog.get_filename(), 'r')

            gpx = gpxpy.parse(gpx_file)

            tr = []
            self.coords = []
            try:
                for track in gpx.tracks:
                    for segment in track.segments:
                        for pt in segment.points:
                            lat = '{0}'.format(pt.latitude, pt.longitude,
                                               pt.elevation)
                            lon = '{1}'.format(pt.latitude, pt.longitude,
                                               pt.elevation)
                            elev = '{2}'.format(pt.latitude, pt.longitude,
                                                pt.elevation)
                            self.coords.append([lon, lat, elev])
                            pt = OsmGpsMap.MapPoint()
                            pt.set_degrees(float(lat), float(lon))
                            tr.append(pt)
            except:
                pass
            try:
                for waypoint in gpx.waypoints:
                    lat = '{0}'.format(waypoint.latitude, waypoint.longitude,
                                       waypoint.elevation)
                    lon = '{1}'.format(waypoint.latitude, waypoint.longitude,
                                       waypoint.elevation)
                    elev = '{2}'.format(waypoint.latitude, waypoint.longitude,
                                        waypoint.elevation)
                    self.coords.append([lon, lat, elev])
                    waypoint = OsmGpsMap.MapPoint()
                    waypoint.set_degrees(float(lat), float(lon))
                    tr.append(waypoint)
            except:
                pass
            try:
                for trk in gpx.routes:
                    #					for track in gpx.tracks:
                    #						for segment in track.segments:
                    for pt in trk.points:
                        lat = '{0}'.format(pt.latitude, pt.longitude,
                                           pt.elevation)
                        lon = '{1}'.format(pt.latitude, pt.longitude,
                                           pt.elevation)
                        elev = '{2}'.format(pt.latitude, pt.longitude,
                                            pt.elevation)
                        self.coords.append([lon, lat, elev])
                        pt = OsmGpsMap.MapPoint()
                        pt.set_degrees(float(lat), float(lon))
                        tr.append(pt)
            except:
                pass

            if len(tr) > 0:
                self.route = OsmGpsMap.MapTrack(color=Gdk.RGBA(0, 0, 100, 1),
                                                line_width=3,
                                                alpha=1)

                for pt in tr:
                    self.route.add_point(pt)

                self.osm.track_add(self.route)

                try:
                    self.calc_track_length(self.route,
                                           0)  # 0 is for the dummy arg
                except:
                    self.len_label.set_text('No length')
#				self.route.connect('point-changed', self.calc_track_length)

                beg = tr[0].get_degrees()
                end = tr[len(tr) - 1].get_degrees()
                self.osm.zoom_fit_bbox(beg[0], end[0], beg[1], end[1])

                try:
                    st = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        self.path + '/images/marker-start-icon-2x.png', 50, 50)
                    self.startImage = self.osm.image_add(beg[0], beg[1], st)
                    nd = GdkPixbuf.Pixbuf.new_from_file_at_size(
                        self.path + '/images/marker-end-icon-2x.png', 50, 50)
                    self.endImage = self.osm.image_add(end[0], end[1], nd)
                except:
                    pass

            else:
                self.len_label.set_text('Can\'t read GPX')

#		elif response == Gtk.ResponseType.CANCEL:
#			print("Cancel clicked")

        dialog.destroy()
Пример #11
0
    def __init__(self):

        self.path = os.path.dirname(__file__)
        #		print(self.path)

        Gtk.Window.__init__(self, type=Gtk.WindowType.TOPLEVEL)

        self.maximize()
        self.set_title('OpenStreetMap GPS Mapper')

        self.vbox = Gtk.HBox()
        self.add(self.vbox)

        self.osm = OsmGpsMap.Map()
        self.osm.props.map_source = 1

        self.osm.set_center_and_zoom(50.154422760009766, -5.0655341148376465,
                                     12)
        self.osm.layer_add(
            OsmGpsMap.MapOsd(show_zoom=True,
                             show_crosshair=True,
                             show_scale=True))

        self.osm.connect('button_press_event', self.on_mouse_click)
        self.osm.connect('button_release_event', self.on_mouse_click)

        self.osm.set_keyboard_shortcut(OsmGpsMap.MapKey_t.FULLSCREEN,
                                       Gdk.keyval_from_name("F11"))
        self.osm.set_keyboard_shortcut(OsmGpsMap.MapKey_t.UP,
                                       Gdk.keyval_from_name("Up"))
        self.osm.set_keyboard_shortcut(OsmGpsMap.MapKey_t.DOWN,
                                       Gdk.keyval_from_name("Down"))
        self.osm.set_keyboard_shortcut(OsmGpsMap.MapKey_t.LEFT,
                                       Gdk.keyval_from_name("Left"))
        self.osm.set_keyboard_shortcut(OsmGpsMap.MapKey_t.RIGHT,
                                       Gdk.keyval_from_name("Right"))

        gps_button = Gtk.ToggleButton()
        gps_button.set_label('GPS')
        gps_button.connect('clicked', self.get_location)

        cache_button = Gtk.Button()
        cache_button.set_label('Cache')
        cache_button.connect('clicked', self.cache_clicked)

        map_type_store = Gtk.ListStore(str)
        map_type = Gtk.ComboBoxText()
        map_type.set_model(map_type_store)
        mapTypes = [
            'OSM',
            'Topo',
            'Google',
            'Satellite',
        ]
        for mapType in mapTypes:
            map_type_store.append([mapType])
        map_type.set_active(0)
        map_type.connect('changed', self.change_map_type)

        gpx_button = Gtk.Button()
        gpx_button.set_label('Load GPX')
        gpx_button.connect('clicked', self.upload_gpx)

        self.plot_button = Gtk.ToggleButton()
        self.plot_button.set_label('Plot track')
        self.plot_button.connect('clicked', self.plotButton)

        self.len_label = Gtk.Label()

        geosearch_input = Gtk.SearchEntry()
        geosearch_input.set_width_chars(24)
        geosearch_input.connect("activate", self.geoSearch)

        self.gpx_save = Gtk.Button()
        self.gpx_save.set_label('Save GPX')
        self.gpx_save.connect('clicked', self.gpx)

        ors_lbl = Gtk.Label(margin_top=10)
        ors_lbl.set_markup('<b>ORS routing</b>')

        search_lbl = Gtk.Label(margin_top=10)
        search_lbl.set_markup('<b>Search</b>')

        maptype_lbl = Gtk.Label(margin_top=10)
        maptype_lbl.set_markup('<b>Map type</b>')

        ors_profile_store = Gtk.ListStore(str)
        self.ors_profile = Gtk.ComboBoxText()
        self.ors_profile.set_model(ors_profile_store)
        orsProfiles = [
            'foot-walking', 'foot-hiking', 'cycling-mountain', 'cycling-road',
            'driving-car'
        ]
        for orsProfile in orsProfiles:
            ors_profile_store.append([orsProfile])
        self.ors_profile.set_active(0)
        self.ors_profile.connect('changed', self.ors_call)

        self.pref_select_shortest = Gtk.RadioButton(
        ).new_with_label_from_widget(None, 'Shortest')
        self.pref_select_shortest.connect('toggled', self.ors_call)
        self.pref_select_fastest = Gtk.RadioButton(
        ).new_with_label_from_widget(self.pref_select_shortest, 'Fastest')
        prefBox = Gtk.HBox()
        prefBox.pack_start(self.pref_select_shortest, False, False, 0)
        prefBox.pack_start(self.pref_select_fastest, False, False, 0)

        self.elev_button = Gtk.Button()
        self.elev_button.set_label('Elevation')
        self.elev_button.connect('clicked', self.elevation)

        self.dir_button = Gtk.Button()
        self.dir_button.set_label('Directions')
        self.dir_button.connect('clicked', self.dir)

        self.clear_button = Gtk.Button()
        self.clear_button.set_label('Clear')
        self.clear_button.connect('clicked', self.clear)

        self.infowindow = Gtk.VBox()
        self.infoLabel = Gtk.Label(margin=5)
        self.infoLabel.set_line_wrap(True)
        self.infoLabel.set_max_width_chars(23)
        self.infowindow.pack_start(self.infoLabel, False, False, 0)

        self.vbox.pack_end(self.osm, True, True, 0)
        hbox = Gtk.VBox(spacing=3)

        hbox.pack_start(self.plot_button, False, False, 0)
        hbox.pack_start(gpx_button, False, False, 0)
        hbox.pack_start(self.gpx_save, False, False, 0)
        hbox.pack_start(gps_button, False, False, 0)
        hbox.pack_start(ors_lbl, False, False, 0)
        hbox.pack_start(self.ors_profile, False, False, 0)
        hbox.pack_start(prefBox, False, False, 0)
        hbox.pack_start(self.elev_button, False, False, 0)
        hbox.pack_start(self.dir_button, False, False, 0)
        hbox.pack_start(self.clear_button, False, False, 0)
        hbox.pack_start(search_lbl, False, False, 0)
        hbox.pack_start(geosearch_input, False, False, 0)
        hbox.pack_start(maptype_lbl, False, False, 0)
        hbox.pack_start(map_type, False, False, 0)
        hbox.pack_start(self.infowindow, False, False, 0)
        hbox.pack_end(cache_button, False, False, 0)
        hbox.pack_end(self.len_label, False, False, 10)

        self.vbox.pack_start(hbox, False, False, 0)

        self.via_route = []
        self.viaImage = []
Пример #12
0
    def __init__(self):
        Gtk.Window.__init__(self, type=Gtk.WindowType.TOPLEVEL)

        self.set_default_size(500, 500)
        self.connect("destroy", lambda x: Gtk.main_quit())
        self.set_title("OpenStreetMap GPS Mapper")

        self.vbox = Gtk.VBox(homogeneous=False, spacing=0)
        self.add(self.vbox)

        if 0:
            self.osm = DummyMapNoGpsPoint()
        else:
            self.osm = osmgpsmap.Map()
        self.osm.layer_add(
            osmgpsmap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=True)
        )
        self.osm.set_property("map-source", osmgpsmap.MapSource_t.OPENSTREETMAP)
        self.osm.layer_add(DummyLayer())

        self.last_image = None

        self.osm.connect("button_press_event", self.on_button_press)
        self.osm.connect("changed", self.on_map_change)

        # connect keyboard shortcuts
        self.osm.set_keyboard_shortcut(
            osmgpsmap.MapKey_t.FULLSCREEN, Gdk.keyval_from_name("F11")
        )
        self.osm.set_keyboard_shortcut(
            osmgpsmap.MapKey_t.UP, Gdk.keyval_from_name("Up")
        )
        self.osm.set_keyboard_shortcut(
            osmgpsmap.MapKey_t.DOWN, Gdk.keyval_from_name("Down")
        )
        self.osm.set_keyboard_shortcut(
            osmgpsmap.MapKey_t.LEFT, Gdk.keyval_from_name("Left")
        )
        self.osm.set_keyboard_shortcut(
            osmgpsmap.MapKey_t.RIGHT, Gdk.keyval_from_name("Right")
        )

        # connect to tooltip
        self.osm.props.has_tooltip = True
        self.osm.connect("query-tooltip", self.on_query_tooltip)

        self.latlon_entry = Gtk.Entry()

        zoom_in_button = Gtk.Button.new_from_icon_name("zoom-in",
                                                       Gtk.IconSize.BUTTON)
        zoom_in_button.connect("clicked", self.zoom_in_clicked)
        zoom_out_button = Gtk.Button.new_from_icon_name("zoom-out",
                                                        Gtk.IconSize.BUTTON)
        zoom_out_button.connect("clicked", self.zoom_out_clicked)
        home_button = Gtk.Button.new_from_icon_name("go-home",
                                                    Gtk.IconSize.BUTTON)
        home_button.connect("clicked", self.home_clicked)
        cache_button = Gtk.Button(label="Cache")
        cache_button.connect("clicked", self.cache_clicked)

        self.vbox.pack_start(self.osm, True, True, 0)
        hbox = Gtk.HBox(homogeneous=False, spacing=0)
        hbox.pack_start(zoom_in_button, False, True, 0)
        hbox.pack_start(zoom_out_button, False, True, 0)
        hbox.pack_start(home_button, False, True, 0)
        hbox.pack_start(cache_button, False, True, 0)

        # add ability to test custom map URIs
        ex = Gtk.Expander(label="<b>Map Repository URI</b>")
        ex.props.use_markup = True
        vb = Gtk.VBox()
        self.repouri_entry = Gtk.Entry()
        self.repouri_entry.set_text(self.osm.props.repo_uri)
        self.image_format_entry = Gtk.Entry()
        self.image_format_entry.set_text(self.osm.props.image_format)

        lbl = Gtk.Label(
            label="""Enter an repository URL to fetch map tiles \
from in the box below. Special metacharacters may be included in this url

<i>Metacharacters:</i>
\t#X\tMax X location
\t#Y\tMax Y location
\t#Z\tMap zoom (0 = min zoom, fully zoomed out)
\t#S\tInverse zoom (max-zoom - #Z)
\t#Q\tQuadtree encoded tile (qrts)
\t#W\tQuadtree encoded tile (1234)
\t#U\tEncoding not implemeted
\t#R\tRandom integer, 0-4"""
        )
        lbl.props.xalign = 0
        lbl.props.use_markup = True
        lbl.props.wrap = True

        ex.add(vb)
        vb.pack_start(lbl, False, True, 0)

        hb = Gtk.HBox()
        hb.pack_start(Gtk.Label(label="URI: "), False, True, 0)
        hb.pack_start(self.repouri_entry, True, True, 0)
        vb.pack_start(hb, False, True, 0)

        hb = Gtk.HBox()
        hb.pack_start(Gtk.Label(label="Image Format: "), False, True, 0)
        hb.pack_start(self.image_format_entry, True, True, 0)
        vb.pack_start(hb, False, True, 0)

        gobtn = Gtk.Button(label="Load Map URI")
        gobtn.connect("clicked", self.load_map_clicked)
        vb.pack_start(gobtn, False, True, 0)

        self.show_tooltips = False
        cb = Gtk.CheckButton(label="Show Location in Tooltips")
        cb.props.active = self.show_tooltips
        cb.connect("toggled", self.on_show_tooltips_toggled)
        self.vbox.pack_end(cb, False, True, 0)

        cb = Gtk.CheckButton(label="Disable Cache")
        cb.props.active = False
        cb.connect("toggled", self.disable_cache_toggled)
        self.vbox.pack_end(cb, False, True, 0)

        self.vbox.pack_end(ex, False, True, 0)
        self.vbox.pack_end(self.latlon_entry, False, True, 0)
        self.vbox.pack_end(hbox, False, True, 0)

        GLib.timeout_add(500, self.print_tiles)
Пример #13
0
 def setUp(self):
     self.lat = 50
     self.lon = 13
     self.zoom = 15
     self.osm = OsmGpsMap.Map(user_agent="test/0.1")
Пример #14
0
    def change_new_map(self, name, map_source):
        """
        Change the current map with a new provider
        This map is not supported by osm-gps-map

        name       : the name of the provider
        map_source : the url to search for tiles
        """
        try:
            self.osm.layer_remove_all()
            self.osm.image_remove_all()
            self.vbox.remove(self.osm)
            self.osm.destroy()
        except:
            pass
        tiles_path = os.path.join(config.get('geography.path'), name)
        if not os.path.isdir(tiles_path):
            try:
                os.makedirs(tiles_path, 0o755)  # create dir like mkdir -p
            except:
                ErrorDialog(_("Can't create "
                              "tiles cache directory for '%s'.") %
                            constants.MAP_TITLE[self.current_map],
                            parent=self.uistate.window)
        http_proxy = get_env_var('http_proxy')
        if 0:
            self.osm = DummyMapNoGpsPoint()
        else:
            map_type = int(config.get("geography.map_service"))
            if map_type == constants.PERSONAL:
                self.osm = osmgpsmap.Map(repo_uri=map_source)
            else:
                self.osm = osmgpsmap.Map(
                    map_source=constants.MAP_TYPE[map_type])
            if http_proxy:
                self.osm.set_property("proxy_uri", http_proxy)
            self.osm.set_property("tile_cache", tiles_path)
        self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO
        current_map = osmgpsmap.MapOsd(show_dpad=False, show_zoom=True)
        self.end_selection = None
        self.osm.layer_add(current_map)
        self.osm.layer_add(DummyLayer())
        self.selection_layer = self.add_selection_layer()
        self.kml_layer = self.add_kml_layer()
        self.lifeway_layer = self.add_lifeway_layer()
        self.marker_layer = self.add_marker_layer()
        self.date_layer = self.add_date_layer()
        self.message_layer = self.add_message_layer()
        self.cross_map = osmgpsmap.MapOsd(show_crosshair=False)
        self.set_crosshair(config.get("geography.show_cross"))
        self.osm.set_center_and_zoom(config.get("geography.center-lat"),
                                     config.get("geography.center-lon"),
                                     config.get("geography.zoom"))

        self.osm.connect('button_release_event', self.map_clicked)
        self.osm.connect('button_press_event', self.map_clicked)
        self.osm.connect("motion-notify-event", self.motion_event)
        self.osm.connect('changed', self.zoom_changed)
        self.update_shortcuts(True)
        self.osm.show()
        self.vbox.pack_start(self.osm, True, True, 0)
        self.goto_handle(handle=None)
Пример #15
0
    def init_ui(self):
        BaseDialog.init_ui(self)
        #
        vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5)
        self.grid.attach(vbox, 0, 0, 1, 1)

        hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 5)
        vbox.pack_start(hbox, False, False, 0)
        #
        self.entry1 = Gtk.Entry()
        self.entry1.set_width_chars(60)

        self.entry1.set_property('primary_icon_name', 'edit-find-symbolic')
        self.entry1.set_property('secondary_icon_name', 'edit-clear-symbolic')
        self.entry1.set_property('primary_icon_tooltip_text',
                                 _('Search location'))
        self.entry1.set_property('secondary_icon_tooltip_text',
                                 _('Clear location'))
        self.entry1.set_tooltip_text(_('Input the name of your city'))
        self.entry1.connect('icon-press', self.on_icon_press)
        self.entry1.connect('activate', self.on_button1_clicked)
        hbox.pack_start(self.entry1, True, True, 0)
        #
        button1 = Gtk.Button.new_with_label(_('Search'))
        button1.connect('clicked', self.on_button1_clicked)
        hbox.pack_start(button1, False, False, 0)
        #
        button2 = Gtk.Button.new_with_label(_('Find me'))
        button2.connect('clicked', self.on_button2_clicked)
        hbox.pack_start(button2, False, False, 0)
        self.expander = Gtk.Expander(label=_('Locations found'))
        self.expander.set_expanded(False)
        vbox.pack_start(self.expander, False, False, 0)
        #
        frame = Gtk.Frame()
        framebox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 50)
        framebox.add(frame)
        self.expander.add(framebox)
        self.expander.connect("notify::expanded", self.on_expander_expanded)
        #
        scrolledwindow0 = Gtk.ScrolledWindow()
        scrolledwindow0.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scrolledwindow0.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
        scrolledwindow0.set_size_request(450, 100)
        frame.add(scrolledwindow0)
        # city, county, country, latitude, longitude
        store = Gtk.ListStore(str, str, str, float, float)
        store.set_sort_column_id(2, Gtk.SortType.ASCENDING)
        self.treeview = Gtk.TreeView(model=store)
        self.treeview.set_reorderable(True)
        treeviewcolumn0 = Gtk.TreeViewColumn(_('City'),
                                             Gtk.CellRendererText(),
                                             text=0)
        treeviewcolumn0.set_reorderable(True)
        treeviewcolumn0.set_sort_column_id(0)
        treeviewcolumn1 = Gtk.TreeViewColumn(_('State'),
                                             Gtk.CellRendererText(),
                                             text=1)
        treeviewcolumn1.set_reorderable(True)
        treeviewcolumn1.set_sort_column_id(1)
        treeviewcolumn2 = Gtk.TreeViewColumn(_('Country'),
                                             Gtk.CellRendererText(),
                                             text=2)
        treeviewcolumn2.set_reorderable(True)
        treeviewcolumn2.set_sort_column_id(2)
        self.treeview.append_column(treeviewcolumn0)
        self.treeview.append_column(treeviewcolumn1)
        self.treeview.append_column(treeviewcolumn2)
        self.treeview.connect('cursor-changed', self.ontreeviewcursorchanged)
        scrolledwindow0.add(self.treeview)
        #
        #
        scrolledwindow = Gtk.ScrolledWindow()
        scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                  Gtk.PolicyType.AUTOMATIC)
        scrolledwindow.set_shadow_type(Gtk.ShadowType.IN)
        vbox.pack_start(scrolledwindow, True, True, 0)
        #
        self.viewer = OsmGpsMap.Map()
        self.viewer.layer_add(
            OsmGpsMap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=True))
        # connect keyboard shortcuts
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.FULLSCREEN,
                                          Gdk.keyval_from_name("F11"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.UP,
                                          Gdk.keyval_from_name("Up"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.DOWN,
                                          Gdk.keyval_from_name("Down"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.LEFT,
                                          Gdk.keyval_from_name("Left"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.RIGHT,
                                          Gdk.keyval_from_name("Right"))
        scrolledwindow.add(self.viewer)
        scrolledwindow.set_size_request(550, 550)

        if self.latitude and self.longitude:
            if self.location is not None and len(self.location) > 0:
                self.entry1.set_text(self.location)
            else:
                self.do_search_location(self.latitude, self.longitude)
        else:
            self.search_location2()

        self.set_wait_cursor()
        self.search_string = ''
        print('============================')
        print(self.location, self.latitude, self.longitude)
        print('============================')
Пример #16
0
    def __init__(self, app, afile=None):
        Gtk.ApplicationWindow.__init__(self, application=app)

        self.qrcode_file = None
        self.frames = None
        self.background = None
        self.scale = 100
        self.pbuf = None

        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        self.set_title(comun.APP)
        self.set_icon_from_file(comun.ICON)
        self.set_resizable(False)
        self.set_default_size(600, 600)

        self.connect('destroy', self.close_application)
        hbox = Gtk.HBox(spacing=5)
        hbox.set_border_width(5)
        frame = Gtk.Frame()
        set_margins(frame, 5)
        self.add(frame)

        self.main_stack = Gtk.Stack.new()
        self.main_stack.set_transition_type(
            Gtk.StackTransitionType.UNDER_RIGHT)
        frame.add(self.main_stack)

        self.stack = Gtk.Stack.new()
        self.stack.set_transition_type(Gtk.StackTransitionType.UNDER_DOWN)
        self.main_stack.add_named(self.stack, 'Data')

        grid1 = Gtk.Grid()
        set_margins(grid1, 10)
        grid1.set_margin_right(10)
        self.stack.add_named(grid1, QRType.TEXT.name)
        label1 = Gtk.Label(_('Set text to encode: '))
        label1.set_alignment(0, .5)
        grid1.attach(label1, 0, 0, 1, 1)
        self.entry12 = Gtk.Entry()
        self.entry12.set_alignment(0)
        self.entry12.set_width_chars(40)
        grid1.attach(self.entry12, 1, 0, 1, 1)

        grid2 = Gtk.Grid()
        set_margins(grid2, 10)
        self.stack.add_named(grid2, QRType.GEOLOCATION.name)
        scrolledwindow0 = Gtk.ScrolledWindow()
        scrolledwindow0.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scrolledwindow0.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
        scrolledwindow0.set_size_request(550, 550)
        grid2.attach(
            scrolledwindow0,
            0,
            0,
            1,
            1,
        )

        self.viewer = OsmGpsMap.Map()
        self.viewer.layer_add(
            OsmGpsMap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=True))

        # connect keyboard shortcuts
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.FULLSCREEN,
                                          Gdk.keyval_from_name("F11"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.UP,
                                          Gdk.keyval_from_name("Up"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.DOWN,
                                          Gdk.keyval_from_name("Down"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.LEFT,
                                          Gdk.keyval_from_name("Left"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.RIGHT,
                                          Gdk.keyval_from_name("Right"))
        scrolledwindow0.add(self.viewer)
        scrolledwindow0.set_size_request(550, 550)

        grid3 = Gtk.Grid()
        set_margins(grid3, 10)
        self.stack.add_named(grid3, QRType.TELEPHONE_NUMBER.name)
        label1 = Gtk.Label(_('Set number to encode:'))
        label1.set_alignment(0, .5)
        grid3.attach(label1, 0, 0, 1, 1)
        #
        self.entry13 = Gtk.Entry()
        self.entry13.set_alignment(0)
        self.entry13.set_width_chars(40)
        grid3.attach(self.entry13, 1, 0, 1, 1)

        grid4 = Gtk.Grid()
        set_margins(grid4, 10)
        self.stack.add_named(grid4, QRType.EMAIL.name)
        label1 = Gtk.Label(_('Set email:'))
        label1.set_alignment(0, .5)
        grid4.attach(label1, 0, 0, 1, 1)

        self.entry14 = Gtk.Entry()
        self.entry14.set_alignment(0)
        self.entry14.set_width_chars(40)
        grid4.attach(self.entry14, 1, 0, 1, 1)

        grid5 = Gtk.Grid()
        set_margins(grid5, 10)
        self.stack.add_named(grid5, QRType.URL.name)
        label1 = Gtk.Label(_('Set url:'))
        label1.set_alignment(0, .5)
        grid5.attach(label1, 0, 0, 1, 1)

        self.entry15 = Gtk.Entry()
        self.entry15.set_alignment(0)
        self.entry15.set_width_chars(40)
        grid5.attach(self.entry15, 1, 0, 1, 1)

        grid6 = Gtk.Grid()
        set_margins(grid6, 10)
        self.stack.add_named(grid6, QRType.WIFI_LOGIN.name)
        label1 = Gtk.Label(_('SSID/Network name:'))
        label1.set_alignment(0, .5)
        grid6.attach(label1, 0, 0, 1, 1)

        self.entry161 = Gtk.Entry()
        self.entry161.set_alignment(0)
        self.entry161.set_width_chars(40)
        grid6.attach(self.entry161, 1, 0, 1, 1)

        label1 = Gtk.Label(_('Password:'******'Network type:'))
        label1.set_alignment(0, .5)
        grid6.attach(label1, 0, 2, 1, 1)
        self.liststore163 = Gtk.ListStore(str, str)
        self.liststore163.append([_('WEP'), 'WEP'])
        self.liststore163.append([_('WPA/WPA2'), 'WPA'])
        self.liststore163.append([_('No encryption'), 'nopass'])
        self.combobox163 = Gtk.ComboBox.new()
        self.combobox163.set_model(self.liststore163)
        cell163 = Gtk.CellRendererText()
        self.combobox163.pack_start(cell163, True)
        self.combobox163.add_attribute(cell163, 'text', 0)
        select_value_in_combo(self.combobox163, 'wpa')
        grid6.attach(self.combobox163, 1, 2, 1, 1)

        grid7 = Gtk.Grid()
        set_margins(grid7, 10)
        self.stack.add_named(grid7, QRType.SMS.name)

        label1 = Gtk.Label(_('Telephone Number:'))
        label1.set_alignment(0, .5)
        grid7.attach(label1, 0, 0, 1, 1)
        #
        self.entry171 = Gtk.Entry()
        self.entry171.set_alignment(0)
        self.entry171.set_width_chars(40)
        grid7.attach(self.entry171, 1, 0, 1, 1)
        #
        label1 = Gtk.Label(_('SMS Message:'))
        label1.set_alignment(0, .5)
        grid7.attach(label1, 0, 1, 1, 1)
        #
        scrolledwindow_sms = Gtk.ScrolledWindow()
        scrolledwindow_sms.set_hexpand(True)
        scrolledwindow_sms.set_vexpand(True)
        scrolledwindow_sms.set_shadow_type(type=Gtk.ShadowType.ETCHED_IN)
        scrolledwindow_sms.set_size_request(550, 550)
        grid7.attach(
            scrolledwindow_sms,
            0,
            2,
            2,
            2,
        )
        self.entry172 = Gtk.TextView()
        scrolledwindow_sms.add(self.entry172)

        grid8 = Gtk.Grid()
        set_margins(grid8, 10)
        self.stack.add_named(grid8, QRType.EMAIL_MESSAGE.name)

        label1 = Gtk.Label(_('Email:'))
        label1.set_alignment(0, .5)
        grid8.attach(label1, 0, 0, 1, 1)
        #
        self.entry181 = Gtk.Entry()
        self.entry181.set_alignment(0)
        self.entry181.set_width_chars(40)
        grid8.attach(self.entry181, 1, 0, 1, 1)
        #
        label1 = Gtk.Label(_('Subject:'))
        label1.set_alignment(0, .5)
        grid8.attach(label1, 0, 1, 1, 1)
        #
        self.entry182 = Gtk.Entry()
        self.entry182.set_alignment(0)
        self.entry182.set_width_chars(40)
        grid8.attach(self.entry182, 1, 1, 1, 1)
        #
        label1 = Gtk.Label(_('Body:'))
        label1.set_alignment(0, .5)
        grid8.attach(label1, 0, 2, 1, 1)
        #
        scrolledwindow_email = Gtk.ScrolledWindow()
        scrolledwindow_email.set_hexpand(True)
        scrolledwindow_email.set_vexpand(True)
        scrolledwindow_email.set_shadow_type(type=Gtk.ShadowType.ETCHED_IN)
        scrolledwindow_email.set_size_request(550, 300)
        grid8.attach(scrolledwindow_email, 0, 3, 2, 2)
        self.entry183 = Gtk.TextView()
        scrolledwindow_email.add(self.entry183)

        grid9 = Gtk.Grid()
        set_margins(grid9, 10)
        self.stack.add_named(grid9, QRType.VCARD.name)

        labels_card = {
            '01': _('Fist name'),
            '02': _('Last name'),
            '03': _('Job title'),
            '04': _('Telephone Number (work)'),
            '05': _('Fax Number (work)'),
            '06': _('Cell Phone'),
            '07': _('Email Address (work)'),
            '08': _('Website Address'),
            '09': _('Organization'),
            '10': _('Street Address (work)'),
            '11': _('City'),
            '12': _('State'),
            '13': _('Zip/Postcode'),
            '14': _('Country'),
            '15': _('Notes')
        }
        self.entries_vcard = {}
        for i, key in enumerate(sorted(labels_card.keys())):
            label1 = Gtk.Label(labels_card[key] + ':')
            label1.set_alignment(0, .5)
            grid9.attach(label1, 0, i, 1, 1)
            #
            self.entries_vcard[key] = Gtk.Entry()
            self.entries_vcard[key].set_alignment(0)
            self.entries_vcard[key].set_width_chars(40)
            grid9.attach(self.entries_vcard[key], 1, i, 1, 1)

        self.scrolled_code = Gtk.ScrolledWindow.new()
        self.scrolled_code.set_size_request(550, 550)
        self.main_stack.add_named(self.scrolled_code, 'Code')
        self.image = Gtk.Image()
        self.connect('key-release-event', self.on_key_release_event)
        self.scrolled_code.add_with_viewport(self.image)

        self.init_menu(hbox)
        self.init_headerbar()

        self.show_all()
        self.do_center()
Пример #17
0
    def __init__(self):
        super(Rpane_mapbox,
              self).__init__(orientation=Gtk.Orientation.VERTICAL)

        self.map = ogm.Map()
        self.pack_start(self.map, True, True, 0)

        self.btn_launch_site = Gtk.Button()
        launch_site_icon = Gio.ThemedIcon(name="go-home-symbolic")
        launch_site_image = Gtk.Image.new_from_gicon(launch_site_icon,
                                                     Gtk.IconSize.DND)

        self.lbl_coords = Gtk.Label()
        self.lbl_coords.set_text(
            'Latitud: (Haz click derecho en el mapa)\nLongitud: (Haz click derecho en el mapa)'
        )
        self.pack_start(self.lbl_coords, False, True, 0)

        self.btn_launch_site.set_image(launch_site_image)
        self.btn_launch_site.connect("clicked",
                                     self.on_btn_launch_site_clicked)
        self.pack_start(self.btn_launch_site, False, True, 0)

        self.grid_2nd_package = Gtk.Grid()
        self.pack_start(self.grid_2nd_package, False, True, 0)
        self.grid_2nd_package.set_column_homogeneous(True)

        v = "0"

        lbl_timer = Gtk.Label("TIMER")
        self.grid_2nd_package.attach(lbl_timer, 0, 0, 1, 1)
        self.lbl_vtimer = Gtk.Label(v)
        self.grid_2nd_package.attach(self.lbl_vtimer, 1, 0, 1, 1)

        lbl_gpsdia = Gtk.Label("DIA")
        lbl_gpsmes = Gtk.Label("MES")
        lbl_gpsanio = Gtk.Label("AÑO")
        self.grid_2nd_package.attach(lbl_gpsdia, 0, 1, 1, 1)
        self.grid_2nd_package.attach(lbl_gpsmes, 2, 1, 1, 1)
        self.grid_2nd_package.attach(lbl_gpsanio, 4, 1, 1, 1)
        self.lbl_vgpsdia = Gtk.Label(v)
        self.lbl_vgpsmes = Gtk.Label(v)
        self.lbl_vgpsanio = Gtk.Label(v)
        self.grid_2nd_package.attach(self.lbl_vgpsdia, 1, 1, 1, 1)
        self.grid_2nd_package.attach(self.lbl_vgpsmes, 3, 1, 1, 1)
        self.grid_2nd_package.attach(self.lbl_vgpsanio, 5, 1, 1, 1)

        lbl_gpshor = Gtk.Label("HORA")
        lbl_gpsmin = Gtk.Label("MIN")
        lbl_gpsseg = Gtk.Label("SEG")
        self.grid_2nd_package.attach(lbl_gpshor, 0, 2, 1, 1)
        self.grid_2nd_package.attach(lbl_gpsmin, 2, 2, 1, 1)
        self.grid_2nd_package.attach(lbl_gpsseg, 4, 2, 1, 1)
        self.lbl_vgpshor = Gtk.Label(v)
        self.lbl_vgpsmin = Gtk.Label(v)
        self.lbl_vgpsseg = Gtk.Label(v)
        self.grid_2nd_package.attach(self.lbl_vgpshor, 1, 2, 1, 1)
        self.grid_2nd_package.attach(self.lbl_vgpsmin, 3, 2, 1, 1)
        self.grid_2nd_package.attach(self.lbl_vgpsseg, 5, 2, 1, 1)

        lbl_alt1 = Gtk.Label("ALT1")
        lbl_alt2 = Gtk.Label("ALT2")
        lbl_gpsalt = Gtk.Label("ALTGPS")
        self.grid_2nd_package.attach(lbl_alt1, 0, 3, 1, 1)
        self.grid_2nd_package.attach(lbl_alt2, 1, 3, 1, 1)
        self.grid_2nd_package.attach(lbl_gpsalt, 2, 3, 1, 1)
        self.lbl_valt1 = Gtk.Label(v)
        self.lbl_valt2 = Gtk.Label(v)
        self.lbl_vgpsalt = Gtk.Label(v)
        self.grid_2nd_package.attach(self.lbl_valt1, 0, 4, 1, 1)
        self.grid_2nd_package.attach(self.lbl_valt2, 1, 4, 1, 1)
        self.grid_2nd_package.attach(self.lbl_vgpsalt, 2, 4, 1, 1)
Пример #18
0
    def __init__(self, parent=None, location=None, latitude=0, longitude=0):
        # ***************************************************************
        Gtk.Dialog.__init__(self, 'my-weather-indicator | ' + _('Where Am I'))
        self.set_modal(True)
        self.set_destroy_with_parent(True)
        self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
        self.add_button(Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)
        self.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
        # self.set_size_request(450, 350)
        self.connect('destroy', self.on_close_application)
        self.set_icon_from_file(comun.ICON)
        #
        self.lat = latitude
        self.lng = longitude
        self.locality = location
        #
        vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 5)
        self.get_content_area().add(vbox)
        #
        hbox = Gtk.Box.new(Gtk.Orientation.HORIZONTAL, 5)
        vbox.pack_start(hbox, False, False, 0)
        #
        self.entry1 = Gtk.Entry()
        self.entry1.set_width_chars(60)

        self.entry1.set_property('primary_icon_name', 'edit-find-symbolic')
        self.entry1.set_property('secondary_icon_name', 'edit-clear-symbolic')
        self.entry1.set_property('primary_icon_tooltip_text',
                                 _('Search location'))
        self.entry1.set_property('secondary_icon_tooltip_text',
                                 _('Clear location'))
        self.entry1.set_tooltip_text(_('Input the name of your city'))
        self.entry1.connect('icon-press', self.on_icon_press)
        self.entry1.connect('activate', self.on_button1_clicked)
        hbox.pack_start(self.entry1, True, True, 0)
        #
        button1 = Gtk.Button.new_with_label(_('Search'))
        button1.connect('clicked', self.on_button1_clicked)
        hbox.pack_start(button1, False, False, 0)
        #
        button2 = Gtk.Button.new_with_label(_('Find me'))
        button2.connect('clicked', self.on_button2_clicked)
        hbox.pack_start(button2, False, False, 0)
        self.expander = Gtk.Expander(label=_('Locations found'))
        self.expander.set_expanded(False)
        vbox.pack_start(self.expander, False, False, 0)
        #
        frame = Gtk.Frame()
        framebox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 50)
        framebox.add(frame)
        self.expander.add(framebox)
        self.expander.connect("notify::expanded", self.on_expander_expanded)
        #
        scrolledwindow0 = Gtk.ScrolledWindow()
        scrolledwindow0.set_policy(Gtk.PolicyType.AUTOMATIC,
                                   Gtk.PolicyType.AUTOMATIC)
        scrolledwindow0.set_shadow_type(Gtk.ShadowType.ETCHED_OUT)
        scrolledwindow0.set_size_request(450, 100)
        frame.add(scrolledwindow0)
        # city, county, country, latitude, longitude
        store = Gtk.ListStore(str, str, str, float, float)
        store.set_sort_column_id(2, Gtk.SortType.ASCENDING)
        self.treeview = Gtk.TreeView(model=store)
        self.treeview.set_reorderable(True)
        treeviewcolumn0 = Gtk.TreeViewColumn(_('City'),
                                             Gtk.CellRendererText(),
                                             text=0)
        treeviewcolumn0.set_reorderable(True)
        treeviewcolumn0.set_sort_column_id(0)
        treeviewcolumn1 = Gtk.TreeViewColumn(_('State'),
                                             Gtk.CellRendererText(),
                                             text=1)
        treeviewcolumn1.set_reorderable(True)
        treeviewcolumn1.set_sort_column_id(1)
        treeviewcolumn2 = Gtk.TreeViewColumn(_('Country'),
                                             Gtk.CellRendererText(),
                                             text=2)
        treeviewcolumn2.set_reorderable(True)
        treeviewcolumn2.set_sort_column_id(2)
        self.treeview.append_column(treeviewcolumn0)
        self.treeview.append_column(treeviewcolumn1)
        self.treeview.append_column(treeviewcolumn2)
        self.treeview.connect('cursor-changed', self.ontreeviewcursorchanged)
        scrolledwindow0.add(self.treeview)
        #
        #
        scrolledwindow = Gtk.ScrolledWindow()
        scrolledwindow.set_policy(Gtk.PolicyType.AUTOMATIC,
                                  Gtk.PolicyType.AUTOMATIC)
        scrolledwindow.set_shadow_type(Gtk.ShadowType.IN)
        vbox.pack_start(scrolledwindow, True, True, 0)
        #
        self.viewer = OsmGpsMap.Map()
        self.viewer.layer_add(
            OsmGpsMap.MapOsd(show_dpad=True,
                             show_zoom=True,
                             show_crosshair=True))
        # connect keyboard shortcuts
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.FULLSCREEN,
                                          Gdk.keyval_from_name("F11"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.UP,
                                          Gdk.keyval_from_name("Up"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.DOWN,
                                          Gdk.keyval_from_name("Down"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.LEFT,
                                          Gdk.keyval_from_name("Left"))
        self.viewer.set_keyboard_shortcut(OsmGpsMap.MapKey_t.RIGHT,
                                          Gdk.keyval_from_name("Right"))
        scrolledwindow.add(self.viewer)
        scrolledwindow.set_size_request(550, 550)

        #
        self.show_all()
        #
        self.set_wait_cursor()
        self.search_string = ''
        self.locality = ''
        print('============================')
        print(location, latitude, longitude)
        print('============================')
        if latitude and longitude:
            self.latitude = latitude
            self.longitude = longitude
            self.viewer.set_center_and_zoom(self.lat, self.lng, 14)
            if location is not None and len(location) > 0:
                self.locality = location
                print(1)
                self.entry1.set_text(location)
            else:
                print(2)
                self.do_search_location(latitude, longitude)
        else:
            self.search_location2()
        self.set_normal_cursor()