dgelessus

SceneLocTest.py

Mar 19th, 2014
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import console, location
  2. from scene import *
  3.  
  4. running = True
  5. testaddr = {'Street': 'Infinite Loop', 'City': 'Cupertino', 'Country': 'USA'}
  6. testcoords = (())
  7.  
  8. def geocode():
  9.     testcoords = location.geocode(testaddr)
  10.  
  11. class MainScene (Scene):
  12.     def __init__(self):
  13.         self.btn = 0
  14.    
  15.     def setup(self):
  16.         # This will be called before the first frame is drawn.
  17.         pass
  18.    
  19.     def draw(self):
  20.         # This will be called for every frame (typically 60 times per second).
  21.         background(0, 0, 0)
  22.        
  23.         # draw wannabe buttons
  24.         fill(0, 0, 1)
  25.         rect(0, 0, 200, 200)
  26.         fill(0, 1, 0)
  27.         rect(0, 200, 200, 200)
  28.         fill(1, 1, 0)
  29.         rect(0, 400, 200, 200)
  30.        
  31.         # Draw a red circle for every finger that touches the screen:
  32.         fill(1, 0, 0)
  33.         for touch in self.touches.values():
  34.             ellipse(touch.location.x - 50, touch.location.y - 50, 100, 100)
  35.    
  36.     def touch_began(self, touch):
  37.         # determines touched "button"
  38.         if touch.location.x < 200:
  39.             if touch.location.y < 200:
  40.                 self.btn = 1
  41.             elif touch.location.y < 400:
  42.                 self.btn = 2
  43.             elif touch.location.y < 600:
  44.                 self.btn = 3
  45.    
  46.     def touch_moved(self, touch):
  47.         pass
  48.  
  49.     def touch_ended(self, touch):
  50.         # runs the tapped button's corresponding function
  51.         if self.btn == 1:
  52.             self.dumploc()
  53.         elif self.btn == 2:
  54.             self.dumpaddr()
  55.         elif self.btn == 3:
  56.             self.geocode()
  57.         self.btn = 0
  58.    
  59.     def dumploc(self):
  60.         location.start_updates()
  61.         self.loc = location.get_location()
  62.         print(self.loc)
  63.         location.stop_updates()
  64.    
  65.     def dumpaddr(self):
  66.         self.addr = location.reverse_geocode(self.loc)
  67.         print(self.addr)
  68.    
  69.     def geocode(self):
  70.         geocode()
  71.         print(testcoords)
  72.  
  73. run(MainScene())
RAW Paste Data