try to start make pylgrim a plugable module
git-svn-id: http://www.neo1973-germany.de/svn@23 46df4e5c-bc4e-4628-a0fc-830ba316316d
This commit is contained in:
parent
f8152a3649
commit
d21b40547e
2 changed files with 222 additions and 226 deletions
|
@ -4,7 +4,7 @@ fonts {
|
||||||
|
|
||||||
collections {
|
collections {
|
||||||
group {
|
group {
|
||||||
name: "main";
|
name: "pylgrim";
|
||||||
parts {
|
parts {
|
||||||
part {
|
part {
|
||||||
name: "background";
|
name: "background";
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#coding=utf8
|
#coding=utf8
|
||||||
|
|
||||||
'''
|
'''
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
|
@ -21,13 +20,6 @@
|
||||||
#TODO: add dynamic preloading
|
#TODO: add dynamic preloading
|
||||||
#TODO: add gps connection
|
#TODO: add gps connection
|
||||||
|
|
||||||
WIDTH = 480
|
|
||||||
HEIGHT = 640
|
|
||||||
|
|
||||||
TITLE = "pylgrim"
|
|
||||||
WM_NAME = "pylgrim"
|
|
||||||
WM_CLASS = "swallow"
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
from e_dbus import DBusEcoreMainLoop
|
from e_dbus import DBusEcoreMainLoop
|
||||||
|
@ -38,12 +30,11 @@ import edje.decorators
|
||||||
import ecore
|
import ecore
|
||||||
import ecore.evas
|
import ecore.evas
|
||||||
from dbus import SystemBus, Interface
|
from dbus import SystemBus, Interface
|
||||||
from optparse import OptionParser
|
|
||||||
import time
|
import time
|
||||||
import math
|
import math
|
||||||
import urllib
|
import urllib
|
||||||
|
|
||||||
class tile(evas.Image):
|
class Tile(evas.Image):
|
||||||
def __init__(self, canvas):
|
def __init__(self, canvas):
|
||||||
evas.Image.__init__(self,canvas)
|
evas.Image.__init__(self,canvas)
|
||||||
self.pass_events = True
|
self.pass_events = True
|
||||||
|
@ -55,7 +46,7 @@ class tile(evas.Image):
|
||||||
self.position = (x,y)
|
self.position = (x,y)
|
||||||
self.move(x,y)
|
self.move(x,y)
|
||||||
|
|
||||||
class mark(evas.Image):
|
class Mark(evas.Image):
|
||||||
def __init__(self, canvas):
|
def __init__(self, canvas):
|
||||||
evas.Image.__init__(self,canvas)
|
evas.Image.__init__(self,canvas)
|
||||||
self.pass_events = True
|
self.pass_events = True
|
||||||
|
@ -67,7 +58,99 @@ class mark(evas.Image):
|
||||||
self.position = (x,y)
|
self.position = (x,y)
|
||||||
self.move(x,y)
|
self.move(x,y)
|
||||||
|
|
||||||
class TestView(edje.Edje):
|
class Pylgrim(edje.Edje):
|
||||||
|
def __init__(self, filename, evas_canvas, offline=False):
|
||||||
|
self.evas_canvas = evas_canvas
|
||||||
|
self.offline = offline
|
||||||
|
|
||||||
|
edje.Edje.__init__(self, self.evas_canvas.evas_obj.evas, file=filename, group="pylgrim")
|
||||||
|
self.size = self.evas_canvas.evas_obj.evas.size
|
||||||
|
self.on_key_down_add(self.on_key_down)
|
||||||
|
self.on_key_up_add(self.on_key_up)
|
||||||
|
self.focus = True
|
||||||
|
self.evas_canvas.evas_obj.data["pylgrim"] = self
|
||||||
|
self.show()
|
||||||
|
|
||||||
|
#mouse position
|
||||||
|
self.x_pos, self.y_pos = (0,0)
|
||||||
|
|
||||||
|
#global variable for zooming
|
||||||
|
self.zoom_step = 0.0
|
||||||
|
|
||||||
|
#global list for tiles to download
|
||||||
|
self.tiles_to_download = []
|
||||||
|
self.tiles_to_download_total = 0
|
||||||
|
self.tiles_to_preload = []
|
||||||
|
|
||||||
|
#initial lat,lon,zoom
|
||||||
|
self.lat = 0
|
||||||
|
self.lon = 0
|
||||||
|
self.x = 0
|
||||||
|
self.y = 0
|
||||||
|
self.z = 0
|
||||||
|
self.offset_x = 0
|
||||||
|
self.offset_y = 0
|
||||||
|
|
||||||
|
self.icons = []
|
||||||
|
|
||||||
|
self.overlay = edje.Edje(self.evas_canvas.evas_obj.evas, file=filename, group='overlay')
|
||||||
|
self.overlay.size = self.evas_canvas.evas_obj.evas.size
|
||||||
|
self.overlay.layer = 2
|
||||||
|
self.evas_canvas.evas_obj.data["overlay"] = self.overlay
|
||||||
|
self.overlay.show()
|
||||||
|
|
||||||
|
self.progress_bg = evas.Rectangle(self.evas_canvas.evas_obj.evas)
|
||||||
|
self.progress_bg.geometry = 0,0,0,0
|
||||||
|
self.progress_bg.color = 255, 255, 255, 255
|
||||||
|
self.progress_bg.layer = 3
|
||||||
|
self.progress_bg.show()
|
||||||
|
|
||||||
|
self.progress = evas.Rectangle(self.evas_canvas.evas_obj.evas)
|
||||||
|
self.progress.geometry = 0,0,0,0
|
||||||
|
self.progress.color = 255, 0, 0, 255
|
||||||
|
self.progress.layer = 4
|
||||||
|
self.progress.show()
|
||||||
|
|
||||||
|
#calculate size of tile raster
|
||||||
|
self.border_x = int(math.ceil(self.size[0]/256.0))
|
||||||
|
self.border_y = int(math.ceil(self.size[1]/256.0))
|
||||||
|
|
||||||
|
self.mouse_down = False
|
||||||
|
|
||||||
|
self.animate = False
|
||||||
|
|
||||||
|
self.set_current_tile(49.009051, 8.402481, 13)
|
||||||
|
|
||||||
|
'''
|
||||||
|
self.marker = Mark(self.evas_canvas.evas_obj.evas)
|
||||||
|
self.marker.file_set("blue-dot.png")
|
||||||
|
self.marker.lat = 49.073866
|
||||||
|
self.marker.lon = 8.184814
|
||||||
|
self.marker.size_set(32,32)
|
||||||
|
self.marker.fill_set(0,0,32,32)
|
||||||
|
self.marker.x = (self.marker.lon+180)/360 * 2**self.z
|
||||||
|
self.marker.y = (1-math.log(math.tan(self.marker.lat*math.pi/180) + 1/math.cos(self.marker.lat*math.pi/180))/math.pi)/2 * 2**self.z
|
||||||
|
self.marker.offset_x, self.marker.offset_y = int((self.marker.x-int(self.marker.x))*256),int((self.marker.y-int(self.marker.y))*256)
|
||||||
|
self.marker.set_position(self.size[0]/2-16+256*(int(self.marker.x)-int(self.x))+self.marker.offset_x-self.offset_x, self.size[1]/2-32+256*(int(self.marker.y)-int(self.y))+self.marker.offset_y-self.offset_y)
|
||||||
|
self.marker.layer = 1
|
||||||
|
self.marker.show()
|
||||||
|
'''
|
||||||
|
|
||||||
|
ecore.timer_add(3, self.init_dbus)
|
||||||
|
|
||||||
|
def init_dbus(self):
|
||||||
|
print 'LocationFeed init_dbus'
|
||||||
|
try:
|
||||||
|
gps_obj = SystemBus(mainloop=DBusEcoreMainLoop()).get_object('org.mobile.gps', '/org/mobile/gps/RemoteObject')
|
||||||
|
gps_name = 'org.mobile.gps.RemoteInterface'
|
||||||
|
gps_obj.connect_to_signal("position", self.position, dbus_interface=gps_name)
|
||||||
|
self.gps_interface = Interface(gps_obj, gps_name)
|
||||||
|
#self.gps_interface.get_position()
|
||||||
|
return False
|
||||||
|
except Exception, e:
|
||||||
|
print 'LocationFeed', e
|
||||||
|
return True
|
||||||
|
|
||||||
def on_key_down(self, obj, event):
|
def on_key_down(self, obj, event):
|
||||||
if event.keyname in ("F6", "f"):
|
if event.keyname in ("F6", "f"):
|
||||||
self.evas_canvas.evas_obj.fullscreen = not self.evas_canvas.evas_obj.fullscreen
|
self.evas_canvas.evas_obj.fullscreen = not self.evas_canvas.evas_obj.fullscreen
|
||||||
|
@ -109,7 +192,6 @@ class TestView(edje.Edje):
|
||||||
self.init_redraw()
|
self.init_redraw()
|
||||||
self.update_coordinates()
|
self.update_coordinates()
|
||||||
|
|
||||||
|
|
||||||
def download(self, x,y,z):
|
def download(self, x,y,z):
|
||||||
try:
|
try:
|
||||||
webFile = urllib.urlopen("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
|
webFile = urllib.urlopen("http://a.tile.openstreetmap.org/%d/%d/%d.png"%(z,x,y))
|
||||||
|
@ -124,108 +206,6 @@ class TestView(edje.Edje):
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
print e
|
print e
|
||||||
|
|
||||||
def __init__(self):
|
|
||||||
self.options, self.args = myOptionParser(usage="usage: %prog [options]").parse_args()
|
|
||||||
|
|
||||||
edje.frametime_set(1.0 / self.options.fps)
|
|
||||||
|
|
||||||
self.evas_canvas = EvasCanvas(
|
|
||||||
fullscreen=not self.options.no_fullscreen,
|
|
||||||
engine=self.options.engine,
|
|
||||||
size=self.options.geometry
|
|
||||||
)
|
|
||||||
|
|
||||||
f = os.path.splitext(sys.argv[0])[0] + ".edj"
|
|
||||||
try:
|
|
||||||
edje.Edje.__init__(self, self.evas_canvas.evas_obj.evas, file=f, group="main")
|
|
||||||
except edje.EdjeLoadError, e:
|
|
||||||
raise SystemExit("error loading %s: %s" % (f, e))
|
|
||||||
self.size = self.evas_canvas.evas_obj.evas.size
|
|
||||||
self.on_key_down_add(self.on_key_down)
|
|
||||||
self.on_key_up_add(self.on_key_up)
|
|
||||||
self.focus = True
|
|
||||||
self.evas_canvas.evas_obj.data["main"] = self
|
|
||||||
self.show()
|
|
||||||
|
|
||||||
|
|
||||||
#mouse position
|
|
||||||
self.x_pos, self.y_pos = (0,0)
|
|
||||||
|
|
||||||
#global variable for zooming
|
|
||||||
self.zoom_step = 0.0
|
|
||||||
|
|
||||||
#global list for tiles to download
|
|
||||||
self.tiles_to_download = []
|
|
||||||
self.tiles_to_download_total = 0
|
|
||||||
self.tiles_to_preload = []
|
|
||||||
|
|
||||||
#initial lat,lon,zoom
|
|
||||||
self.lat = 0
|
|
||||||
self.lon = 0
|
|
||||||
self.x = 0
|
|
||||||
self.y = 0
|
|
||||||
self.z = 0
|
|
||||||
self.offset_x = 0
|
|
||||||
self.offset_y = 0
|
|
||||||
|
|
||||||
self.icons = []
|
|
||||||
|
|
||||||
self.overlay = edje.Edje(self.evas_canvas.evas_obj.evas, file=f, group='overlay')
|
|
||||||
self.overlay.size = self.evas_canvas.evas_obj.evas.size
|
|
||||||
self.overlay.layer = 2
|
|
||||||
self.evas_canvas.evas_obj.data["overlay"] = self.overlay
|
|
||||||
self.overlay.show()
|
|
||||||
|
|
||||||
self.progress_bg = evas.Rectangle(self.evas_canvas.evas_obj.evas)
|
|
||||||
self.progress_bg.geometry = 0,0,0,0
|
|
||||||
self.progress_bg.color = 255, 255, 255, 255
|
|
||||||
self.progress_bg.layer = 3
|
|
||||||
self.progress_bg.show()
|
|
||||||
|
|
||||||
self.progress = evas.Rectangle(self.evas_canvas.evas_obj.evas)
|
|
||||||
self.progress.geometry = 0,0,0,0
|
|
||||||
self.progress.color = 255, 0, 0, 255
|
|
||||||
self.progress.layer = 4
|
|
||||||
self.progress.show()
|
|
||||||
|
|
||||||
#calculate size of tile raster
|
|
||||||
self.border_x = int(math.ceil(self.size[0]/256.0))
|
|
||||||
self.border_y = int(math.ceil(self.size[1]/256.0))
|
|
||||||
|
|
||||||
self.mouse_down = False
|
|
||||||
|
|
||||||
self.animate = False
|
|
||||||
|
|
||||||
self.set_current_tile(49.009051, 8.402481, 13)
|
|
||||||
|
|
||||||
'''
|
|
||||||
self.marker = mark(self.evas_canvas.evas_obj.evas)
|
|
||||||
self.marker.file_set("blue-dot.png")
|
|
||||||
self.marker.lat = 49.073866
|
|
||||||
self.marker.lon = 8.184814
|
|
||||||
self.marker.size_set(32,32)
|
|
||||||
self.marker.fill_set(0,0,32,32)
|
|
||||||
self.marker.x = (self.marker.lon+180)/360 * 2**self.z
|
|
||||||
self.marker.y = (1-math.log(math.tan(self.marker.lat*math.pi/180) + 1/math.cos(self.marker.lat*math.pi/180))/math.pi)/2 * 2**self.z
|
|
||||||
self.marker.offset_x, self.marker.offset_y = int((self.marker.x-int(self.marker.x))*256),int((self.marker.y-int(self.marker.y))*256)
|
|
||||||
self.marker.set_position(self.size[0]/2-16+256*(int(self.marker.x)-int(self.x))+self.marker.offset_x-self.offset_x, self.size[1]/2-32+256*(int(self.marker.y)-int(self.y))+self.marker.offset_y-self.offset_y)
|
|
||||||
self.marker.layer = 1
|
|
||||||
self.marker.show()
|
|
||||||
'''
|
|
||||||
|
|
||||||
ecore.timer_add(3, self.init_dbus)
|
|
||||||
|
|
||||||
def init_dbus(self):
|
|
||||||
print 'LocationFeed init_dbus'
|
|
||||||
try:
|
|
||||||
gps_obj = SystemBus(mainloop=DBusEcoreMainLoop()).get_object('org.mobile.gps', '/org/mobile/gps/RemoteObject')
|
|
||||||
gps_name = 'org.mobile.gps.RemoteInterface'
|
|
||||||
gps_obj.connect_to_signal("position", self.position, dbus_interface=gps_name)
|
|
||||||
self.gps_interface = Interface(gps_obj, gps_name)
|
|
||||||
return False
|
|
||||||
except Exception, e:
|
|
||||||
print 'LocationFeed', e
|
|
||||||
return True
|
|
||||||
def position(self, content):
|
def position(self, content):
|
||||||
longitude = float(content.get('longitude', self.lat))
|
longitude = float(content.get('longitude', self.lat))
|
||||||
latitude = float(content.get('latitude', self.lon))
|
latitude = float(content.get('latitude', self.lon))
|
||||||
|
@ -263,8 +243,8 @@ class TestView(edje.Edje):
|
||||||
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(Tile(self.evas_canvas.evas_obj.evas))
|
||||||
if not self.options.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):
|
||||||
for j in xrange(2*self.border_y+1):
|
for j in xrange(2*self.border_y+1):
|
||||||
|
@ -408,40 +388,16 @@ class TestView(edje.Edje):
|
||||||
|
|
||||||
#self.marker.set_position(self.marker.pos[0]-delta_x,self.marker.pos[1]-delta_y)
|
#self.marker.set_position(self.marker.pos[0]-delta_x,self.marker.pos[1]-delta_y)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
WIDTH = 480
|
||||||
|
HEIGHT = 640
|
||||||
|
|
||||||
class EvasCanvas(object):
|
TITLE = "pylgrim"
|
||||||
def __init__(self, fullscreen, engine, size):
|
WM_NAME = "pylgrim"
|
||||||
if engine == "x11":
|
WM_CLASS = "swallow"
|
||||||
f = ecore.evas.SoftwareX11
|
|
||||||
elif engine == "x11-16":
|
|
||||||
if ecore.evas.engine_type_supported_get("software_x11_16"):
|
|
||||||
f = ecore.evas.SoftwareX11_16
|
|
||||||
else:
|
|
||||||
print "warning: x11-16 is not supported, fallback to x11"
|
|
||||||
f = ecore.evas.SoftwareX11
|
|
||||||
|
|
||||||
self.evas_obj = f(w=size[0], h=size[1])
|
|
||||||
self.evas_obj.callback_delete_request = self.on_delete_request
|
|
||||||
self.evas_obj.callback_resize = self.on_resize
|
|
||||||
|
|
||||||
self.evas_obj.title = TITLE
|
from optparse import OptionParser
|
||||||
self.evas_obj.name_class = (WM_NAME, WM_CLASS)
|
|
||||||
self.evas_obj.fullscreen = fullscreen
|
|
||||||
self.evas_obj.size = size
|
|
||||||
self.evas_obj.show()
|
|
||||||
|
|
||||||
def on_resize(self, evas_obj):
|
|
||||||
x, y, w, h = evas_obj.evas.viewport
|
|
||||||
size = (w, h)
|
|
||||||
for key in evas_obj.data.keys():
|
|
||||||
evas_obj.data[key].size = size
|
|
||||||
#calculate size of tile raster
|
|
||||||
evas_obj.data["main"].border_x = int(math.ceil(evas_obj.data["main"].size[0]/256.0))
|
|
||||||
evas_obj.data["main"].border_y = int(math.ceil(evas_obj.data["main"].size[1]/256.0))
|
|
||||||
evas_obj.data["main"].init_redraw()
|
|
||||||
|
|
||||||
def on_delete_request(self, evas_obj):
|
|
||||||
ecore.main_loop_quit()
|
|
||||||
|
|
||||||
class myOptionParser(OptionParser):
|
class myOptionParser(OptionParser):
|
||||||
def __init__(self, usage):
|
def __init__(self, usage):
|
||||||
|
@ -484,9 +440,49 @@ class myOptionParser(OptionParser):
|
||||||
raise optparse.OptionValueError("Invalid format for %s" % option)
|
raise optparse.OptionValueError("Invalid format for %s" % option)
|
||||||
parser.values.geometry = (w, h)
|
parser.values.geometry = (w, h)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
class EvasCanvas(object):
|
||||||
TestView()
|
def __init__(self, fullscreen, engine, size):
|
||||||
#dbus()
|
if engine == "x11":
|
||||||
|
f = ecore.evas.SoftwareX11
|
||||||
|
elif engine == "x11-16":
|
||||||
|
if ecore.evas.engine_type_supported_get("software_x11_16"):
|
||||||
|
f = ecore.evas.SoftwareX11_16
|
||||||
|
else:
|
||||||
|
print "warning: x11-16 is not supported, fallback to x11"
|
||||||
|
f = ecore.evas.SoftwareX11
|
||||||
|
|
||||||
|
self.evas_obj = f(w=size[0], h=size[1])
|
||||||
|
self.evas_obj.callback_delete_request = self.on_delete_request
|
||||||
|
self.evas_obj.callback_resize = self.on_resize
|
||||||
|
|
||||||
|
self.evas_obj.title = TITLE
|
||||||
|
self.evas_obj.name_class = (WM_NAME, WM_CLASS)
|
||||||
|
self.evas_obj.fullscreen = fullscreen
|
||||||
|
self.evas_obj.size = size
|
||||||
|
self.evas_obj.show()
|
||||||
|
|
||||||
|
def on_resize(self, evas_obj):
|
||||||
|
x, y, w, h = evas_obj.evas.viewport
|
||||||
|
size = (w, h)
|
||||||
|
for key in evas_obj.data.keys():
|
||||||
|
evas_obj.data[key].size = size
|
||||||
|
#calculate size of tile raster
|
||||||
|
evas_obj.data["pylgrim"].border_x = int(math.ceil(evas_obj.data["pylgrim"].size[0]/256.0))
|
||||||
|
evas_obj.data["pylgrim"].border_y = int(math.ceil(evas_obj.data["pylgrim"].size[1]/256.0))
|
||||||
|
evas_obj.data["pylgrim"].init_redraw()
|
||||||
|
|
||||||
|
def on_delete_request(self, evas_obj):
|
||||||
|
ecore.main_loop_quit()
|
||||||
|
|
||||||
|
options, args = myOptionParser(usage="usage: %prog [options]").parse_args()
|
||||||
|
edje.frametime_set(1.0 / options.fps)
|
||||||
|
evas_canvas = EvasCanvas(
|
||||||
|
fullscreen=not options.no_fullscreen,
|
||||||
|
engine=options.engine,
|
||||||
|
size=options.geometry
|
||||||
|
)
|
||||||
|
filename = os.path.splitext(sys.argv[0])[0] + ".edj"
|
||||||
|
Pylgrim(filename, evas_canvas, options.offline)
|
||||||
ecore.main_loop_begin()
|
ecore.main_loop_begin()
|
||||||
|
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in a new issue