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.
Help request: getting step-by-step user touch input while rendering scene
-
Hello all,
I'm new to python programming, but am looking for a way to:
- iterate through dictionary keys, asking users to select a map location for the key
- map the new location.x, location.y values to the dictionary
- Select the next dictionary key and continue to map new x, y values until complete.
It's the last item I'm having a problem with. The script (below) either locks on the first key, or whips through all keys incredibly quickly. Can anyone help? Thanks!
city_list = {'city name' : [x, y]}
import math, random import city_list from scene import * city_dict = city_list.city_dict class MyScene (Scene): def draw (self): background(0, 0, 0) fill(1, 0, 0) image('_ACKS_ipad_map',0,50) for key in city_dict: text('Please select '+str(key)+' on the map',font_name='Helvetica',font_size=15,x=10,y=30,alignment=6) if len(self.touches) ==0: return if len(self.touches) ==1: location = self.touches.values()[0].location city_dict[key][0] = location.x city_dict[key][1] = location.y text(str(city_dict[key]),font_name='Helvetica',font_size=15,x=10,y=10,alignment=6) break run(MyScene())
-
Hello all,
It took me a week, but is figured out what I was doing wrong. It was a mix of not understanding exactly how scenes render and how that loop effects other functions and some errors on how I was trying to handle local variables in loops. The finished script is up on Github. https://gist.github.com/8077804
Script to identify the coordinates for locations on an image map by having the user tap on the appropriate locations and saving the results into a dictionary that can be called by another script.
Requires an initial dictionary with at least the location name as a key and x, y coordinates as list values 0 and 1.
Cheers!
-
See the gist comments for some ideas...
Writing the file with "r+" instead of "w" did not make much sense to me.<br />
Adding sublayers to the root_layer simplifies the update() and draw() code.<br />
Reused the city_dict for data storage so new_list could be eliminated.<br />
Added reading and writing to a .json file which is a more standard approach than using city_list.py as a data file.<br />
(I could never really figure out how to create the city_list.py file in a way that would work with the main file.) -
Hi there,
Thank you very much for the advice. I love Python, but it can be hard to figure out all the different options in Python and the best way of doing things.
I use the R+ option because I had to reuse the single file multiple times to get it right. :-) The dictionaries actually dictionary lists, with the list values being the X coordinates, Y coordinates, population, tribal affiliation and leader. Example:
city_dict = {'Corinium': [398.0, 456.5, 74, 'Bubroci', 'Eriadacus'], 'Aquae Solis': [343.5, 364.0, 249, 'Belgae', 'Ambiorix'], 'Durobrivae': [806.0, 365.0, 159, 'Caantii', 'Cingetorix'], 'Anderida': [830.5, 231.0, 249, 'Caantii', 'Segovax'], ...
I finished up the final map reader file as well, and posted it on GitHub. As always, any advice or suggestions would be fantastic. https://gist.github.com/Cgeist7/8129983
Thanks all!
CG7