84 lines
2.4 KiB
Python
84 lines
2.4 KiB
Python
from kivy.app import App
|
|
from kivy.uix.screenmanager import ScreenManager, Screen, RiseInTransition
|
|
from kivy.properties import NumericProperty, StringProperty
|
|
from kivy.lang import Builder
|
|
from kivy_garden.mapview import MapView
|
|
from plyer import gps
|
|
from kivy.clock import mainthread
|
|
from kivy.utils import platform
|
|
|
|
|
|
|
|
class MapScreen(Screen):
|
|
hue = NumericProperty(0)
|
|
mapview = MapView(zoom=11, lat=50.6394, lon=3.057)
|
|
|
|
|
|
class CompassScreen(Screen):
|
|
hue = NumericProperty(0)
|
|
|
|
|
|
class FlockompassApp(App):
|
|
|
|
gps_location = StringProperty()
|
|
gps_status = StringProperty('Click Start to get GPS location updates')
|
|
|
|
def request_android_permissions(self):
|
|
from android.permissions import request_permissions, Permission
|
|
|
|
def callback(permissions, results):
|
|
if all([res for res in results]):
|
|
print("callback. All permissions granted.")
|
|
else:
|
|
print("callback. Some permissions refused.")
|
|
|
|
request_permissions([Permission.ACCESS_COARSE_LOCATION,
|
|
Permission.ACCESS_FINE_LOCATION],
|
|
callback)
|
|
|
|
@mainthread
|
|
def on_location(self, **kwargs):
|
|
self.gps_location = '\n'.join([
|
|
'{}={}'.format(k, v) for k, v in kwargs.items()])
|
|
|
|
@mainthread
|
|
def on_status(self, stype, status):
|
|
self.gps_status = 'type={}\n{}'.format(stype, status)
|
|
|
|
|
|
def build(self):
|
|
|
|
try:
|
|
gps.configure(on_location=self.on_location,
|
|
on_status=self.on_status)
|
|
except NotImplementedError:
|
|
import traceback
|
|
traceback.print_exc()
|
|
self.gps_status = 'GPS is not implemented for your platform'
|
|
|
|
if platform == "android":
|
|
print("gps.py: Android detected. Requesting permissions")
|
|
self.request_android_permissions()
|
|
|
|
root = ScreenManager(transition=RiseInTransition())
|
|
root.add_widget(MapScreen(name='map'))
|
|
root.add_widget(CompassScreen(name='compass'))
|
|
|
|
return root
|
|
|
|
|
|
if __name__ == '__main__':
|
|
FlockompassApp().run()
|
|
|
|
|
|
|
|
|
|
# Button:
|
|
# text: 'Use FallOutTransition'
|
|
# on_release: root.manager.transition = FallOutTransition()
|
|
|
|
# Button:
|
|
# text: 'Use RiseInTransition'
|
|
# on_release: root.manager.transition = RiseInTransition()
|
|
|