Perhaps a very very late reaction.. but... I just bought an iPad pro 12’’ with Apple pencil and came up with the same question because I am working towards an application that enables you to draw musical scores. The ‘Pencil Script’ works indeed and my God what a possibilities! Hands-off Pythonista...
Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Posts made by lenoirmind
-
RE: pressure / apple pencil data in touch event object?
-
Unable to use location.reverse_geocode inside a scene/layer
Hello all,
First of: what an inspiring app Pythonista is! I am a developer, though Python is pretty new to me. But I am a quick learner and start to really enjoy Python.
I run into a strange problem and I do not really understand what I am doing wrong or what might go wrong.
I've succesfully made simple sketching application based on the scene module elaborating on the 'example with layers'
I've also succeeded in using the location module and retrieve my current location and made pythonista show me the address of my current location in the console.
But when I try to use the same location code to retrieve and display my current addres in the scene mode, in either the console (displayed after closing the scene) or using the text() command in the scene, I only get 'none' as a result. Retrieving the gps coordinated does work from within a scene. But location.reverse_gecode does not.
Did anyone run into this as well?
Thanks in advance for the time and effort helping me out here...
-
RE: Unable to use location.reverse_geocode inside a scene/layer
Thanks to your script example I found a strange anomaly, dgelessus!
It took my quite a while to figure this out and it is due to similar strange behavior I've seen wehen working in a PHP based project, where I found out that the contents of variables seemed to be updated in a different fashion when FIRST printing the values of these variables to stdout and THEN access the values of these variables to print them elsewhere - eg on a screenIn your code example at http://pastebin.com/ZAWiaGGm you've used this construction:
location.start_updates() self.loc = location.get_location() print(self.loc) location.stop_updates()
I've modified your code so the draw() method displays the value of the self.loc variable on the canvas as well as in the interpreter. As you've noticed, the interpreter's values are correctly updated. The values within the scene are not.
After some experimentation I've noticed the "print(self.loc))" line in your code and I got this "PHP problem hunch". I've added the same print() line in my Scenes based script and lo and behold! The location values are now correctly updated within the Scene's draw loop!
With your original script with the three buttons you can see the same behavior. If you comment out the 'print(self.loc)' line, you'll notice the values printed on the screen canvas are not updated. As soon as you uncomment the print() line, the values are correctly updated.
I've added my modifications here:
import console
import locationfrom scene import *
running = True
testaddr = {'Street': 'Infinite Loop', 'City': 'Cupertino', 'Country': 'USA'}
testcoords = (())def geocode():
testcoords = location.geocode(testaddr)class MainScene (Scene):
def init(self):
self.btn = 0
self.loc = ''def setup(self): # This will be called before the first frame is drawn. pass def draw(self): # This will be called for every frame (typically 60 times per second). background(0, 0, 0) # draw wannabe buttons fill(0, 0, 1) rect(0, 0, 200, 200) # add continuous polling of location. Not so economic, but only for this testing case location.start_updates() self.loc = location.get_location() # make sure to add this print statement: comment this line to see the update of the self.loc value fail. print(self.loc) location.stop_updates() # if we've successfully obtained our location, display it in the scene in all it's floating number glory if self.loc: mylocation = '%.9f, %.9f, %d' % (self.loc['longitude'], self.loc['latitude'], self.loc['timestamp']) stroke(1,1,1) text(mylocation, 'Helvetica', 20, 100, 10, 6) # Draw a red circle for every finger that touches the screen: fill(1, 0, 0) for touch in self.touches.values(): ellipse(touch.location.x - 50, touch.location.y - 50, 100, 100) def touch_began(self, touch): # determines touched "button" if touch.location.x < 200: if touch.location.y < 200: self.btn = 1 elif touch.location.y < 400: self.btn = 2 elif touch.location.y < 600: self.btn = 3 def touch_moved(self, touch): pass def touch_ended(self, touch): stroke(1,1,1) # runs the tapped button's corresponding function if self.btn == 1: text('button 1', 'Helvetica', 20, 100, 200, 6) self.dumploc() elif self.btn == 2: text('button 2', 'Helvetica', 20, 100, 300, 6) self.dumpaddr() elif self.btn == 3: text('button 3', 'Helvetica', 20, 100, 400, 6) self.geocode() self.btn = 0 def dumploc(self): location.start_updates() self.loc = location.get_location() print(self.loc) location.stop_updates() def dumpaddr(self): self.addr = location.reverse_geocode(self.loc) print(self.addr) def geocode(self): geocode() print(testcoords)
run(MainScene())
Though this perhaps doesn't solve the reverse_geocode issue, it does solve continuous update issue I've ran into.
Not sure I understand why this happens, but I am happy that I found a workaround for the continuous location update issue. If I find a gap in my schedule I will dive into the reverse_geocode issue.
Thanks for your input!
-
RE: Location timestamp always the same
Hello both. I found the same issue as well.
Both in a Scene based script and a script in the interpreter, I can't get the location module to update within a loop.
I am not sure if this could be an iOS "feature" that limits Pythonista's continuous sensing possibilities in a way. Would be great through if it would be possible to sense the location within a loop.
-
RE: Unable to use location.reverse_geocode inside a scene/layer
Thanks for your time, both dgelessus snd ccc
Agree.
Location.geocode seems to work perfectly within a scene running. at least in my app. Only problem might be if you'd want to display the changing address in the scene while walking around using location.reverse_geocode.
but there may be workarounds for that as well - different rev_gecode services?
anyway... in my view this is exactly why i really like pythonista!
-
RE: Unable to use location.reverse_geocode inside a scene/layer
that, in a way is good news.
I would be glad to help out here, but my knowledge about Python is not sufficient yet.
Something with assignment and retrieval of global variables and class and/or function scopes within the scene module?
I've had similar problems in php/java based systems when juggling with packages and static (global) variables and static class variables.