define source in items own kv files. implement basic gps permissions

This commit is contained in:
Daniel afx 2020-10-14 20:47:43 +03:00
parent 32d59cbd87
commit 586732dce1
6 changed files with 64 additions and 9 deletions

View file

@ -1,6 +1,7 @@
#:import MapView kivy_garden.mapview.MapView
#:import GpsBlinker gpsblinker.GpsBlinker
#:include gpsblinker.kv
#:include treemarker.kv
<ForestMapView>:
lat: 42.131331

View file

@ -41,7 +41,7 @@ class ForestMapView(MapView):
# Create TreeMarker
name = tree[0]
lat, lon = tree[1], tree[2]
treemarker = TreeMarker(lat=lat, lon=lon, source='assets/images/markers/tree.png')
treemarker = TreeMarker(lat=lat, lon=lon)
treemarker.tree_data = treemarker
# Add TreeMarker to the map

View file

@ -1,12 +1,66 @@
from kivy.app import App
from kivy.utils import platform
from kivymd.uix.dialog import MDDialog
class GpsHelper():
has_centered_map = False
def run(self):
# Start blinking the GpsBlinker
# Get a reference to GpsBlinker, then call blink()
#gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
#gps_blinker = App.get_running_app().root.ids.forestmapview.ids.blinker
#gps_blinker.blink()
# Request permission on Android
pass
# Request permissions on Android
if platform == 'android':
from android.permissions import Permission, request_permissions
def callback(permission, results):
if all([res for res in results]):
print("Got all permissions")
from plyer import gps
gps.configure(on_location=self.update_blinker_position,
on_status=self.on_auth_status)
gps.start(minTime=1000, minDistance=0)
else:
print("Did not get all permissions")
request_permissions([Permission.ACCESS_COARSE_LOCATION,
Permission.ACCESS_FINE_LOCATION], callback)
# Configure GPS
if platform == 'ios':
from plyer import gps
gps.configure(on_location=self.update_blinker_position,
on_status=self.on_auth_status)
gps.start(minTime=1000, minDistance=0)
def update_blinker_position(self, *args, **kwargs):
my_lat = kwargs['lat']
my_lon = kwargs['lon']
print("GPS POSITION", my_lat, my_lon)
# Update GpsBlinker position
gps_blinker = App.get_running_app().root.ids.mapview.ids.blinker
gps_blinker.lat = my_lat
gps_blinker.lon = my_lon
# Center map on gps
if not self.has_centered_map:
map = App.get_running_app().root.ids.mapview
map.center_on(my_lat, my_lon)
self.has_centered_map = True
def on_auth_status(self, general_status, status_message):
if general_status == 'provider-enabled':
pass
else:
self.open_gps_access_popup()
def open_gps_access_popup(self):
dialog = MDDialog(title="GPS Error", text="You need to enable GPS access for the app to function properly")
dialog.size_hint = [.8, .8]
dialog.pos_hint = {'center_x': .5, 'center_y': .5}
dialog.open()

View file

@ -2,4 +2,4 @@
ForestMapView:
orientation: 'vertical'
id: mapview
id: forestmapview

View file

@ -8,4 +8,4 @@ class TreeMarker(MapMarkerPopup):
# Open the TreePopupMenu
menu = TreePopupMenu(self.tree_data)
menu.size_hint = [.8, .9]
menu.open()
menu.open()

View file

@ -1,9 +1,9 @@
from kivymd.uix.dialog2 import ListMDDialog
class TreePopupMenu(ListMDDialog):
class TreePopupMenu(ListMDDialog):
def __init__(self, tree_data):
super().__init__()
# Set all of the fields of tree data
#headers = "Name,Lat,Lon,Description"
#headers = headers.split(',')
@ -14,4 +14,4 @@ class TreePopupMenu(ListMDDialog):
for i in range(len(headers)):
attribute_name = headers[i]
attribute_value = tree_data[i]
setattr(self, attribute_name, attribute_value)
setattr(self, attribute_name, attribute_value)