Advertisement
Guest User

main.py

a guest
May 21st, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.62 KB | None | 0 0
  1. #from kivy.lang import Builder
  2. from plyer import gps
  3. from kivy.app import App
  4. from kivy.properties import StringProperty
  5. from kivy.clock import Clock, mainthread
  6.  
  7. kv = '''
  8. BoxLayout:
  9.    orientation: 'vertical'
  10.  
  11.    Label:
  12.        text: app.gps_location
  13.  
  14.    Label:
  15.        text: app.gps_status
  16.  
  17.    BoxLayout:
  18.        size_hint_y: None
  19.        height: '48dp'
  20.        padding: '4dp'
  21.  
  22.        ToggleButton:
  23.            text: 'Start' if self.state == 'normal' else 'Stop'
  24.            on_state:
  25.                app.start(1000, 0) if self.state == 'down' else \
  26.                app.stop()
  27. '''
  28.  
  29.  
  30. class GpsTest(App):
  31.  
  32.     gps_location = StringProperty()
  33.     gps_status = StringProperty('Click Start to get GPS location updates')
  34.  
  35.     def build(self):
  36.         try:
  37.             gps.configure(on_location=self.on_location,
  38.                           on_status=self.on_status)
  39.         except NotImplementedError:
  40.             import traceback
  41.             traceback.print_exc()
  42.             self.gps_status = 'GPS is not implemented for your platform'
  43.  
  44.         return Builder.load_string(kv)
  45.  
  46.     def start(self, minTime, minDistance):
  47.         gps.start(minTime, minDistance)
  48.  
  49.     def stop(self):
  50.         gps.stop()
  51.  
  52.     @mainthread
  53.     def on_location(self, **kwargs):
  54.         self.gps_location = '\n'.join([
  55.             '{}={}'.format(k, v) for k, v in kwargs.items()])
  56.  
  57.     @mainthread
  58.     def on_status(self, stype, status):
  59.         self.gps_status = 'type={}\n{}'.format(stype, status)
  60.  
  61.     def on_pause(self):
  62.         gps.stop()
  63.         return True
  64.  
  65.     def on_resume(self):
  66.         gps.start(1000, 0)
  67.         pass
  68.  
  69.  
  70. if __name__ == '__main__':
  71.     GpsTest().run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement