Geography : first try for gobject introspection. partial map, no zoom, no menu, ...

svn: r20280
This commit is contained in:
Serge Noiraud
2012-08-28 20:30:31 +00:00
parent fe38fb66fc
commit 6227383508
12 changed files with 86 additions and 59 deletions

View File

@ -30,7 +30,7 @@
import gen.lib import gen.lib
import os import os
from gen.const import HOME_DIR from gen.const import HOME_DIR
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -93,18 +93,18 @@ map_title = {
} }
map_type = { map_type = {
OPENSTREETMAP : osmgpsmap.SOURCE_OPENSTREETMAP, OPENSTREETMAP : osmgpsmap.MapSource_t.OPENSTREETMAP,
OPENSTREETMAP_RENDERER : osmgpsmap.SOURCE_OPENSTREETMAP_RENDERER, OPENSTREETMAP_RENDERER : osmgpsmap.MapSource_t.OPENSTREETMAP_RENDERER,
OPENAERIALMAP : osmgpsmap.SOURCE_OPENAERIALMAP, OPENAERIALMAP : osmgpsmap.MapSource_t.OPENAERIALMAP,
MAPS_FOR_FREE : osmgpsmap.SOURCE_MAPS_FOR_FREE, MAPS_FOR_FREE : osmgpsmap.MapSource_t.MAPS_FOR_FREE,
GOOGLE_STREET : osmgpsmap.SOURCE_GOOGLE_STREET, GOOGLE_STREET : osmgpsmap.MapSource_t.GOOGLE_STREET,
GOOGLE_SATELLITE : osmgpsmap.SOURCE_GOOGLE_SATELLITE, GOOGLE_SATELLITE : osmgpsmap.MapSource_t.GOOGLE_SATELLITE,
GOOGLE_HYBRID : osmgpsmap.SOURCE_GOOGLE_HYBRID, GOOGLE_HYBRID : osmgpsmap.MapSource_t.GOOGLE_HYBRID,
VIRTUAL_EARTH_STREET : osmgpsmap.SOURCE_VIRTUAL_EARTH_STREET, VIRTUAL_EARTH_STREET : osmgpsmap.MapSource_t.VIRTUAL_EARTH_STREET,
VIRTUAL_EARTH_SATELLITE : osmgpsmap.SOURCE_VIRTUAL_EARTH_SATELLITE, VIRTUAL_EARTH_SATELLITE : osmgpsmap.MapSource_t.VIRTUAL_EARTH_SATELLITE,
VIRTUAL_EARTH_HYBRID : osmgpsmap.SOURCE_VIRTUAL_EARTH_HYBRID, VIRTUAL_EARTH_HYBRID : osmgpsmap.MapSource_t.VIRTUAL_EARTH_HYBRID,
YAHOO_STREET : osmgpsmap.SOURCE_YAHOO_STREET, YAHOO_STREET : osmgpsmap.MapSource_t.YAHOO_STREET,
YAHOO_SATELLITE : osmgpsmap.SOURCE_YAHOO_SATELLITE, YAHOO_SATELLITE : osmgpsmap.MapSource_t.YAHOO_SATELLITE,
YAHOO_HYBRID : osmgpsmap.SOURCE_YAHOO_HYBRID, YAHOO_HYBRID : osmgpsmap.MapSource_t.YAHOO_HYBRID,
} }

View File

@ -61,11 +61,11 @@ import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class DateLayer(GObject.GObject, osmgpsmap.GpsMapLayer): class DateLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display the two extreme dates on the top left of the view This is the layer used to display the two extreme dates on the top left of the view
""" """

View File

@ -51,11 +51,11 @@ _LOG = logging.getLogger("maps.dummylayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class DummyLayer(GObject.GObject, osmgpsmap.GpsMapLayer): class DummyLayer(GObject.GObject, osmgpsmap.MapLayer):
def __init__(self): def __init__(self):
""" """
Initialize the dummy layer Initialize the dummy layer

View File

@ -51,11 +51,11 @@ _LOG = logging.getLogger("maps.dummynogps")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class DummyMapNoGpsPoint(osmgpsmap.GpsMap): class DummyMapNoGpsPoint(osmgpsmap.Map):
def do_draw_gps_point(self, drawable): def do_draw_gps_point(self, drawable):
pass pass

View File

@ -57,7 +57,7 @@ from gen.config import config
from gui.editors import EditPlace, EditEvent, EditFamily, EditPerson from gui.editors import EditPlace, EditEvent, EditFamily, EditPerson
from gui.selectors.selectplace import SelectPlace from gui.selectors.selectplace import SelectPlace
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
import constants import constants
from osmGps import OsmGps from osmGps import OsmGps
from selectionlayer import SelectionLayer from selectionlayer import SelectionLayer
@ -529,6 +529,8 @@ class GeoGraphyView(OsmGps, NavigationView):
""" """
Is this marker in the visible area ? Is this marker in the visible area ?
""" """
return True
# BUG here : how to replace that ?
bbox = self.osm.get_bbox() bbox = self.osm.get_bbox()
s_lon = lon + 10.0 s_lon = lon + 10.0
s_lat = lat + 10.0 s_lat = lat + 10.0
@ -579,8 +581,15 @@ class GeoGraphyView(OsmGps, NavigationView):
We must use function called by timeout to force map updates. We must use function called by timeout to force map updates.
""" """
level_start = self.osm.props.zoom level_start = self.osm.props.zoom
p1lat, p1lon = self.begin_selection.get_degrees() # BUG here : how to replace that ?
p2lat, p2lon = self.end_selection.get_degrees() #p1lat = p1lon = 0.0
#p1lat, p1lon = self.begin_selection.get_degrees(p1lat, p1lon)
#print p1lat, p1lon
#p2lat, p2lon = self.end_selection.get_degrees(0.0, 0.0)
p1lat = self.begin_selection.rlat
p1lon = self.begin_selection.rlon
p2lat = self.end_selection.rlat
p2lon = self.end_selection.rlon
lat = p1lat + ( p2lat - p1lat ) / 2 lat = p1lat + ( p2lat - p1lat ) / 2
lon = p1lon + ( p2lon - p1lon ) / 2 lon = p1lon + ( p2lon - p1lon ) / 2
# We center the map on the center of the region # We center the map on the center of the region
@ -609,9 +618,9 @@ class GeoGraphyView(OsmGps, NavigationView):
signminlat = _get_sign(self.minlat) signminlat = _get_sign(self.minlat)
signmaxlon = _get_sign(self.maxlon) signmaxlon = _get_sign(self.maxlon)
signmaxlat = _get_sign(self.maxlat) signmaxlat = _get_sign(self.maxlat)
current = osmgpsmap.point_new_degrees(self.minlat, self.minlon) current = osmgpsmap.MapPoint.new_degrees(self.minlat, self.minlon)
self.end_selection = current self.end_selection = current
current = osmgpsmap.point_new_degrees(self.maxlat, self.maxlon) current = osmgpsmap.MapPoint.new_degrees(self.maxlat, self.maxlon)
self.begin_selection = current self.begin_selection = current
if signminlon == signmaxlon: if signminlon == signmaxlon:
maxlong = abs(abs(self.minlon) - abs(self.maxlon)) maxlong = abs(abs(self.minlon) - abs(self.maxlon))

View File

@ -60,11 +60,11 @@ import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class LifeWayLayer(GObject.GObject, osmgpsmap.GpsMapLayer): class LifeWayLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display tracks or the life way for one or several This is the layer used to display tracks or the life way for one or several
individuals. individuals.

View File

@ -68,11 +68,11 @@ _LOG = logging.getLogger("GeoGraphy.markerlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class MarkerLayer(GObject.GObject, osmgpsmap.GpsMapLayer): class MarkerLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display the markers. This is the layer used to display the markers.
""" """

View File

@ -28,7 +28,7 @@
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
import os import os
import gobject from gi.repository import GObject
import operator import operator
from math import * from math import *
@ -46,7 +46,8 @@ _LOG = logging.getLogger("maps.messagelayer")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gdk from gi.repository import Gdk
from gi.repository import Cairo #from gi.repository import Cairo
import cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -61,11 +62,11 @@ from gi.repository import Cairo
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class MessageLayer(gobject.GObject, osmgpsmap.GpsMapLayer): class MessageLayer(GObject.GObject, osmgpsmap.MapLayer):
""" """
This is the layer used to display messages over the map This is the layer used to display messages over the map
""" """
@ -73,7 +74,7 @@ class MessageLayer(gobject.GObject, osmgpsmap.GpsMapLayer):
""" """
Initialize the layer Initialize the layer
""" """
gobject.GObject.__init__(self) GObject.GObject.__init__(self)
self.message = [] self.message = []
self.color = "black" self.color = "black"
self.font = "Arial" self.font = "Arial"
@ -163,5 +164,5 @@ class MessageLayer(gobject.GObject, osmgpsmap.GpsMapLayer):
""" """
return False return False
gobject.type_register(MessageLayer) GObject.type_register(MessageLayer)

View File

@ -45,6 +45,7 @@ _LOG = logging.getLogger("maps.osmgps")
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
@ -70,7 +71,7 @@ from gui.dialog import ErrorDialog
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
@ -134,9 +135,9 @@ class OsmGps():
if 0: if 0:
self.osm = DummyMapNoGpsPoint() self.osm = DummyMapNoGpsPoint()
else: else:
self.osm = osmgpsmap.GpsMap(tile_cache=tiles_path, self.osm = osmgpsmap.Map(tile_cache=tiles_path,
map_source=constants.map_type[map_type]) map_source=constants.map_type[map_type])
current_map = osmgpsmap.GpsMapOsd( show_dpad=False, show_zoom=True) current_map = osmgpsmap.MapOsd( show_dpad=False, show_zoom=True)
self.end_selection = None self.end_selection = None
self.osm.layer_add(current_map) self.osm.layer_add(current_map)
self.osm.layer_add(DummyLayer()) self.osm.layer_add(DummyLayer())
@ -145,7 +146,7 @@ class OsmGps():
self.marker_layer = self.add_marker_layer() self.marker_layer = self.add_marker_layer()
self.date_layer = self.add_date_layer() self.date_layer = self.add_date_layer()
self.message_layer = self.add_message_layer() self.message_layer = self.add_message_layer()
self.cross_map = osmgpsmap.GpsMapOsd( show_crosshair=False) self.cross_map = osmgpsmap.MapOsd( show_crosshair=False)
self.set_crosshair(config.get("geography.show_cross")) self.set_crosshair(config.get("geography.show_cross"))
self.osm.set_center_and_zoom(config.get("geography.center-lat"), self.osm.set_center_and_zoom(config.get("geography.center-lat"),
config.get("geography.center-lon"), config.get("geography.center-lon"),
@ -246,9 +247,14 @@ class OsmGps():
""" """
Moving during selection Moving during selection
""" """
current = osmgpsmap.point_new_degrees(0.0, 0.0) # BUG here : how to replace that ?
osmmap.convert_screen_to_geographic(int(event.x), int(event.y), current) #current = osmgpsmap.MapPoint.new_degrees(0.0, 0.0)
lat, lon = current.get_degrees() current = osmgpsmap.MapPoint.new_degrees(int(event.x), int(event.y))
# BUG here : how to replace that ?
#osmmap.convert_screen_to_geographic(int(event.x), int(event.y), current)
#lat, lon = current.get_degrees()
lat = current.rlat
lon = current.rlon
if self.zone_selection: if self.zone_selection:
# We draw a rectangle to show the selected region. # We draw a rectangle to show the selected region.
layer = self.get_selection_layer() layer = self.get_selection_layer()
@ -302,10 +308,18 @@ class OsmGps():
mouse button 2 : begin zone selection mouse button 2 : begin zone selection
mouse button 3 : call the menu mouse button 3 : call the menu
""" """
lat, lon = self.osm.get_event_location(event).get_degrees() # BUG here : how to replace that ?
current = osmgpsmap.point_new_degrees(0.0, 0.0) #lat, lon = self.osm.get_event_location(event).get_degrees()
osm.convert_screen_to_geographic(int(event.x), int(event.y), current) lat = self.osm.get_event_location(event).rlat
lat, lon = current.get_degrees() lon = self.osm.get_event_location(event).rlon
current = osmgpsmap.MapPoint.new_degrees(0.0, 0.0)
# BUG here : how to replace that ?
#osm.convert_screen_to_geographic(int(event.x), int(event.y), current)
current = osm.convert_screen_to_geographic(int(event.x), int(event.y))
# BUG here : how to replace that ?
#lat, lon = current.get_degrees()
lat = current.rlat
lon = current.rlon
if event.button == 1: if event.button == 1:
if self.end_selection is not None: if self.end_selection is not None:
self.activate_selection_zoom(osm, event) self.activate_selection_zoom(osm, event)

View File

@ -51,11 +51,11 @@ _LOG = logging.getLogger("maps.selectionlayer")
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
try: try:
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
except: except:
raise raise
class SelectionLayer(GObject.GObject, osmgpsmap.GpsMapLayer): class SelectionLayer(GObject.GObject, osmgpsmap.MapLayer):
def __init__(self): def __init__(self):
""" """
Initialize thz selection layer Initialize thz selection layer

View File

@ -35,16 +35,17 @@ try :
if Gtk.get_major_version() >= 3: if Gtk.get_major_version() >= 3:
OSMGPSMAP = False OSMGPSMAP = False
NEWGTK = True NEWGTK = True
if not NEWGTK: if NEWGTK:
# current osmgpsmap does not support GTK3 # current osmgpsmap support GTK3
import osmgpsmap from gi.repository import OsmGpsMap as osmgpsmap
print "OsmGpsMap version : ", osmgpsmap._version
OSMGPSMAP = True OSMGPSMAP = True
if osmgpsmap.__version__ < '0.7.0': if osmgpsmap._version < '1.0':
OSMGPSMAP = False OSMGPSMAP = False
import logging import logging
logging.warning( _("WARNING: osmgpsmap module not loaded. " logging.warning( _("WARNING: osmgpsmap module not loaded. "
"osmgpsmap must be >= 0.7.0. yours is %s") % "osmgpsmap must be >= 1.0. yours is %s") %
osmgpsmap.__version__) osmgpsmap._version)
except: except:
OSMGPSMAP = False OSMGPSMAP = False
import logging import logging

View File

@ -33,6 +33,7 @@ Geography for one person and all his descendant
from gen.ggettext import gettext as _ from gen.ggettext import gettext as _
import operator import operator
from gi.repository import Gtk from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject from gi.repository import GObject
import time import time
import threading import threading
@ -520,11 +521,12 @@ class GeoMoves(GeoGraphyView):
death = high_date death = high_date
new_list.append([level, plxp, birth, death]) new_list.append([level, plxp, birth, death])
pidx = 0; pidx = 0;
try: color = Gdk.color_parse(color)
color = Gdk.color_parse(color) #try:
except: # color = Gdk.color_parse(color)
# We have already a Gdk.color #except:
pass # # We have already a Gdk.color
# pass
for (level, plxp, birth, death) in sorted(new_list, key=operator.itemgetter(0,2)): for (level, plxp, birth, death) in sorted(new_list, key=operator.itemgetter(0,2)):
if index == int(self._config.get("geography.maximum_generations")): if index == int(self._config.get("geography.maximum_generations")):
break break