use urllib2's opener instead of urllib
git-svn-id: http://www.neo1973-germany.de/svn@41 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
parent
2fca8a9974
commit
2707eac96e
1 changed files with 33 additions and 31 deletions
|
@ -32,42 +32,20 @@ import ecore.evas
|
||||||
from dbus import SystemBus, Interface
|
from dbus import SystemBus, Interface
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import urllib
|
from urllib2 import build_opener
|
||||||
|
|
||||||
class Tile(evas.Image):
|
|
||||||
def __init__(self, canvas):
|
|
||||||
evas.Image.__init__(self,canvas)
|
|
||||||
self.pass_events = True
|
|
||||||
self.show()
|
|
||||||
#we need this to store the original position while the zoom animations
|
|
||||||
self.position = (0,0)
|
|
||||||
|
|
||||||
def set_position(self, x, y):
|
|
||||||
self.position = (x,y)
|
|
||||||
self.move(x,y)
|
|
||||||
|
|
||||||
class Mark(evas.Image):
|
|
||||||
def __init__(self, canvas):
|
|
||||||
evas.Image.__init__(self,canvas)
|
|
||||||
self.pass_events = True
|
|
||||||
self.show()
|
|
||||||
#we need this to store the original position while the zoom animations
|
|
||||||
self.position = (0,0)
|
|
||||||
|
|
||||||
def set_position(self, x, y):
|
|
||||||
self.position = (x,y)
|
|
||||||
self.move(x,y)
|
|
||||||
|
|
||||||
class PylgrimMap(object):
|
class PylgrimMap(object):
|
||||||
|
def __init__(self):
|
||||||
|
self.opener = build_opener()
|
||||||
def download(self, x,y,z):
|
def download(self, x,y,z):
|
||||||
filename = "%d/%d/%d.png"%(z,x,y)
|
filename = "%d/%d/%d.png"%(z,x,y)
|
||||||
print 'download', filename
|
print 'download', filename
|
||||||
try:
|
try:
|
||||||
dirname = "%d/%d"%(z,x)
|
dirname = "%d/%d"%(z,x)
|
||||||
if not os.path.exists(dirname):
|
if not os.path.exists(dirname):
|
||||||
os.makedirs(dirname)
|
os.makedirs(dirname)
|
||||||
localFile = open(filename, 'w')
|
localFile = open(filename, 'w')
|
||||||
webFile = urllib.urlopen("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
|
webFile = self.opener.open("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
|
||||||
localFile.write(webFile.read())
|
localFile.write(webFile.read())
|
||||||
webFile.close()
|
webFile.close()
|
||||||
localFile.close()
|
localFile.close()
|
||||||
|
@ -76,9 +54,33 @@ class PylgrimMap(object):
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
os.unlink(filename)
|
os.unlink(filename)
|
||||||
|
|
||||||
|
|
||||||
class PylgrimView(edje.Edje, PylgrimMap):
|
class PylgrimView(edje.Edje, PylgrimMap):
|
||||||
|
class Tile(evas.Image):
|
||||||
|
def __init__(self, canvas):
|
||||||
|
evas.Image.__init__(self,canvas)
|
||||||
|
self.pass_events = True
|
||||||
|
self.show()
|
||||||
|
#we need this to store the original position while the zoom animations
|
||||||
|
self.position = (0,0)
|
||||||
|
|
||||||
|
def set_position(self, x, y):
|
||||||
|
self.position = (x,y)
|
||||||
|
self.move(x,y)
|
||||||
|
|
||||||
|
class Mark(evas.Image):
|
||||||
|
def __init__(self, canvas):
|
||||||
|
evas.Image.__init__(self,canvas)
|
||||||
|
self.pass_events = True
|
||||||
|
self.show()
|
||||||
|
#we need this to store the original position while the zoom animations
|
||||||
|
self.position = (0,0)
|
||||||
|
|
||||||
|
def set_position(self, x, y):
|
||||||
|
self.position = (x,y)
|
||||||
|
self.move(x,y)
|
||||||
|
|
||||||
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True):
|
def __init__(self, evas_canvas, filename, initial_lat, initial_lon, initial_zoom=10, offline=False, use_overlay=True):
|
||||||
|
PylgrimMap.__init__(self)
|
||||||
self.evas_canvas = evas_canvas
|
self.evas_canvas = evas_canvas
|
||||||
self.offline = offline
|
self.offline = offline
|
||||||
self.use_overlay = use_overlay
|
self.use_overlay = use_overlay
|
||||||
|
@ -151,7 +153,7 @@ class PylgrimView(edje.Edje, PylgrimMap):
|
||||||
self.set_current_tile(initial_lat, initial_lon, initial_zoom)
|
self.set_current_tile(initial_lat, initial_lon, initial_zoom)
|
||||||
|
|
||||||
'''
|
'''
|
||||||
self.marker = Mark(self.evas_canvas.evas_obj.evas)
|
self.marker = PylgrimView.Mark(self.evas_canvas.evas_obj.evas)
|
||||||
self.marker.file_set("blue-dot.png")
|
self.marker.file_set("blue-dot.png")
|
||||||
self.marker.lat = 49.073866
|
self.marker.lat = 49.073866
|
||||||
self.marker.lon = 8.184814
|
self.marker.lon = 8.184814
|
||||||
|
@ -165,7 +167,7 @@ class PylgrimView(edje.Edje, PylgrimMap):
|
||||||
self.marker.show()
|
self.marker.show()
|
||||||
'''
|
'''
|
||||||
|
|
||||||
ecore.timer_add(3, self.init_dbus)
|
#ecore.timer_add(3, self.init_dbus)
|
||||||
|
|
||||||
def init_dbus(self):
|
def init_dbus(self):
|
||||||
print 'LocationFeed init_dbus'
|
print 'LocationFeed init_dbus'
|
||||||
|
@ -262,7 +264,7 @@ class PylgrimView(edje.Edje, PylgrimMap):
|
||||||
self.icons = []
|
self.icons = []
|
||||||
#fill
|
#fill
|
||||||
for i in xrange((2*self.border_x+1)*(2*self.border_y+1)):
|
for i in xrange((2*self.border_x+1)*(2*self.border_y+1)):
|
||||||
self.icons.append(Tile(self.evas_canvas.evas_obj.evas))
|
self.icons.append(PylgrimView.Tile(self.evas_canvas.evas_obj.evas))
|
||||||
if not self.offline:
|
if not self.offline:
|
||||||
#add all tiles that are not yet downloaded to a list
|
#add all tiles that are not yet downloaded to a list
|
||||||
for i in xrange(2*self.border_x+1):
|
for i in xrange(2*self.border_x+1):
|
||||||
|
|
Loading…
Reference in a new issue