map goes to current lat-lon if no destination set

This commit is contained in:
rgarcia-herrera 2020-08-10 21:20:19 -05:00
parent f85ba17996
commit dd2c675146
2 changed files with 22 additions and 46 deletions

View File

@ -50,7 +50,7 @@
ActionButton:
important: True
text: 'set destination'
on_press: root.manager.current = 'map'; app.cambia()
on_press: root.manager.current = 'map';
Button:

66
main.py
View File

@ -19,49 +19,26 @@ from pprint import pprint
class MapScreen(Screen):
def cambia(self):
print(self.app_label)
if self.app_label == 'ms hola':
self.app_label = 'ms adios'
else:
self.app_label = 'ms hola'
print(self.app_label)
pass
class CompassScreen(Screen):
def cambia(self):
print(self.app_label)
if self.app_label == 'cs hola':
self.app_label = 'cs adios'
else:
self.app_label = 'cs hola'
print(self.app_label)
pass
class FlockompassApp(App):
class PruebitaApp(App):
gps_data = DictProperty()
session_data = DictProperty()
def dump(self, dt):
print(dt, self.gps_data, self.session_data)
def set_destination(self):
self.session_data['lat'] = self.ms.ids.centermark.lat
self.session_data['lon'] = self.ms.ids.centermark.lon
def cambia(self):
print(self.app_label)
if self.app_label == 'hola':
self.app_label = 'adios'
else:
self.app_label = 'hola'
print(self.app_label)
self.session_data['dest_lat'] = self.ms.ids.centermark.lat
self.session_data['dest_lon'] = self.ms.ids.centermark.lon
self.ms.ids.mapview.center_on(self.session_data['dest_lat'],
self.session_data['dest_lon'])
def request_android_permissions(self):
from android.permissions import request_permissions, Permission
@ -76,7 +53,6 @@ class PruebitaApp(App):
Permission.ACCESS_FINE_LOCATION],
callback)
def gps_start(self, minTime, minDistance):
gps.start(minTime, minDistance)
@ -91,17 +67,24 @@ class PruebitaApp(App):
self.gps_start(1000, 0)
@mainthread
def on_location(self, **kwargs):
def on_location(self, **kwargs):
self.gps_data = kwargs
if ('dest_lat' not in self.session_data
and
'dest_lon' not in self.session_data):
self.session_data['dest_lat'] = self.gps_data['lat']
self.session_data['dest_lon'] = self.gps_data['lon']
self.ms.ids.mapview.center_on(self.session_data['dest_lat'],
self.session_data['dest_lon'])
def build(self):
# start GPS
try:
gps.configure(on_location=self.on_location)
#on_status=self.on_status)
except NotImplementedError:
import traceback
traceback.print_exc()
@ -110,30 +93,23 @@ class PruebitaApp(App):
if platform == "android":
print("gps.py: Android detected. Requesting permissions")
self.request_android_permissions()
self.gps_start(1000, 0)
# setup app screens
screen_manager = ScreenManager(transition=RiseInTransition())
self.ms = MapScreen(name='map')
self.ms.app_label = 'ms hola'
screen_manager.add_widget(self.ms)
self.cs = CompassScreen(name='compass')
self.cs.app_label = 'cs hola'
screen_manager.add_widget(self.cs)
self.app_label = 'hola'
Clock.schedule_interval(self.dump, 2.0)
return screen_manager
if __name__ == '__main__':
app = PruebitaApp()
app = FlockompassApp()
app.run()