Python Geosystem / KML / Google Earth
Hi, I have used some time to look around the internet, but seems not to get me further, therefore i think i would ask in here :) I would like to add an overlay picture in google maps, ny add it to KML file, that part i think i know how to do. What i have issues with is to calculate the 4 corners of the picture. If o know the center lat/lon and i want to add the picture (10m x 10m) with this position in the middle of the picture? Also how to know how many pixels this picture have to be... maybe the ratio is enough and then it will scale it automatic. I think this is mainly a issues of understanding the geo system, but also how to code it, what libraries are smartest to use etc. Hope you can help me in any direction :) /Kasper -- https://mail.python.org/mailman/listinfo/python-list
Hi! i need some help with a program in python on Raspberry pi3.
every time i run the program i get this messeage: Traceback (most recent call last): File "smartmirror.py", line 159, in get_weather temprature2 = "%S%S" % (str(int(weather_obj['currently']['temperature'])), degree_sign) KeyError: 'currently' Error: 'currently'. Cannot get weather. How do i fix that? Here is the program: # smartmirror.py # requirements # requests, feedparser, traceback, Pillow from Tkinter import * import locale import threading import time import requests import json import traceback import feedparser from PIL import Image, ImageTk from contextlib import contextmanager LOCALE_LOCK = threading.Lock() ui_locale = '' # e.g. 'fr_FR' fro French, '' as default time_format = 24 # 12 or 24 date_format = "%b %d, %Y" # check python doc for strftime() for options news_country_code = 'nb' weather_api_token = '16dc67b56f94f8083b1afed7e69c5dc1' # create account at https://darksky.net/dev/ weather_lang = 'nb' # see https://darksky.net/dev/docs/forecast for full list of language parameters values weather_unit = 'nb' # see https://darksky.net/dev/docs/forecast for full list of unit parameters values latitude = (59.1311800) # Set this if IP location lookup does not work for you (must be a string) longitude = (10.2166500) # Set this if IP location lookup does not work for you (must be a string) xlarge_text_size = 94 large_text_size = 48 medium_text_size = 28 small_text_size = 18 @contextmanager def setlocale(name): #thread proof function to work with locale with LOCALE_LOCK: saved = locale.setlocale(locale.LC_ALL) try: yield locale.setlocale(locale.LC_ALL, name) finally: locale.setlocale(locale.LC_ALL, saved) # maps open weather icons to # icon reading is not impacted by the 'lang' parameter icon_lookup = { 'clear-day': "assets/Sun.png", # clear sky day 'wind': "assets/Wind.png", #wind 'cloudy': "assets/Cloud.png", # cloudy day 'partly-cloudy-day': "assets/PartlySunny.png", # partly cloudy day 'rain': "assets/Rain.png", # rain day 'snow': "assets/Snow.png", # snow day 'snow-thin': "assets/Snow.png", # sleet day 'fog': "assets/Haze.png", # fog day 'clear-night': "assets/Moon.png", # clear sky night 'partly-cloudy-night': "assets/PartlyMoon.png", # scattered clouds night 'thunderstorm': "assets/Storm.png", # thunderstorm 'tornado': "assests/Tornado.png",# tornado 'hail': "assests/Hail.png" # hail } class Clock(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') # initialize time label self.time1 = '' self.timeLbl = Label(self, font=('Helvetica', large_text_size), fg="white", bg="black") self.timeLbl.pack(side=TOP, anchor=E) # initialize day of week self.day_of_week1 = '' self.dayOWLbl = Label(self, text=self.day_of_week1, font=('Helvetica', small_text_size), fg="white", bg="black") self.dayOWLbl.pack(side=TOP, anchor=E) # initialize date label self.date1 = '' self.dateLbl = Label(self, text=self.date1, font=('Helvetica', small_text_size), fg="white", bg="black") self.dateLbl.pack(side=TOP, anchor=E) self.tick() def tick(self): with setlocale(ui_locale): if time_format == 12: time2 = time.strftime('%I:%M %p') #hour in 12h format else: time2 = time.strftime('%H:%M') #hour in 24h format day_of_week2 = time.strftime('%A') date2 = time.strftime(date_format) # if time string has changed, update it if time2 != self.time1: self.time1 = time2 self.timeLbl.config(text=time2) if day_of_week2 != self.day_of_week1: self.day_of_week1 = day_of_week2 self.dayOWLbl.config(text=day_of_week2) if date2 != self.date1: self.date1 = date2 self.dateLbl.config(text=date2) # calls itself every 200 milliseconds # to update the time display as needed # could use >200 ms, but display gets jerky self.timeLbl.after(200, self.tick) class Weather(Frame): def __init__(self, parent, *args, **kwargs): Frame.__init__(self, parent, bg='black') self.temperature = '' self.forecast = '' self.location = '' self.currently = '' self.icon = '' self.degreeFrm = Frame(self, bg="black") self.degreeFrm.pack(side=TOP, anchor=W) self.temperatureLbl = Label(self.degreeFrm, font=('Helvetica', xlarge_text_size), fg="white", bg="black") self.temperatureLbl.pack(side=LEFT, anchor=N) self.iconLbl = Label(self.degreeFrm, bg="black") self.iconLbl.pack(side=LEFT, anchor=N, padx=20) self.currentlyLbl = Label(self, font=('Helvetica', medium_text_size), fg="white", bg="black")
Re: I need help with a game in (turtle graphics - python)
Thanks! This helped me! -- https://mail.python.org/mailman/listinfo/python-list
I need help with a game in (turtle graphics - python)
Hi! How can i make the score stop blinking and how can i make a high score table, in this game made with python? (this game is made on a Macbook) (there are some files in the game that i don't haven't copied into this file! like pyth.GIF) #turtle game (take down the yellow astroides 1v1) import turtle import math import random import os #asks for players name print("player 1 uses W,A,S,D and player 2 are using arrow Up, Down, Left, Right.") print("write player 1's name") name1 = input() print("write player 2's name") name2 = input() #set up screen wn = turtle.Screen() wn.bgcolor("black") wn.bgpic("pyth.GIF") #borders mypen = turtle.Turtle() mypen.penup() mypen.setposition(-300,-300) mypen.pendown() mypen.pensize(3) mypen.color("white") mypen.left(90) mypen.forward(600) mypen.right(90) mypen.forward(600) mypen.right(90) mypen.forward(600) mypen.right(90) mypen.forward(600) mypen.hideturtle() #creates the scores score1 = 0 score2 = 0 #create player 1 player = turtle.Turtle() player.color("blue") player.shape("triangle") player.penup() player.speed(0) player.setposition(285, 285) #create player 2 player2 = turtle.Turtle() player2.color("white") player2.shape("triangle") player2.penup() player2.speed(0) player2.setposition(-285, -285) #creats goals maxGoals = 1 goals = [] for count in range(maxGoals): goals.append(turtle.Turtle()) goals[count].color("yellow") goals[count].shape("circle") goals[count].penup() goals[count].speed(0) goals[count].setposition(random.randint(-290, 290), random.randint(-290, 290)) #set speed variable speed = 3 #define functions def turnleft(): player.left(30) def turnright(): player.right(30) def turnright2(): player2.right(30) def turnleft2(): player2.left(30) def up(): player.forward(50) def up2(): player2.forward(50) def down(): player.right(180) def down2(): player2.right(180) def speedup(): global speed speed += 1 def stop(): global speed speed = 0 def reset(): goals[count].setposition(random.randint(-290, 290), random.randint(-290, 290)) player.setposition(random.randint(-290, 290), random.randint(-290, 290)) player2.setposition(random.randint(-290, 290), random.randint(-290, 290)) def isCollision(t1, t2): d = math.sqrt(math.pow(t1.xcor()-t2.xcor(),2) + math.pow(t1.ycor()-t2.ycor(),2)) if d < 20: return True else: return False #set keyboard bindings turtle.listen() turtle.onkey(turnleft, "a") turtle.onkey(turnleft2, "Left") turtle.onkey(turnright, "d") turtle.onkey(turnright2, "Right") turtle.onkey(speedup, "o") turtle.onkey(stop, "b") turtle.onkey(down, "s") turtle.onkey(down2, "Down") turtle.onkey(up, "w") turtle.onkey(up2, "Up") turtle.onkey(reset, "r") while True: player.forward(speed) player2.forward(speed) #boundary checking player if player.xcor() > 290 or player.xcor() < -290: player.right(180) os.system("afplay bing.mp3&") #boundary Checking player if player.ycor() > 290 or player.ycor() < -290: player.right(180) os.system("afplay bing.mp3&") #boundary checking player2 if player2.xcor() > 290 or player2.xcor() < -290: player2.right(180) os.system("afplay bing.mp3&") #boundary Checking player2 if player2.ycor() > 290 or player2.ycor() < -290: player2.right(180) os.system("afplay bing.mp3&") #boundary checking if goals[count].xcor() > 290 or goals[count].xcor() < -290: goals[count].right(180) os.system("afplay bing.mp3&") #boundary Checking if goals[count].ycor() > 290 or goals[count].ycor() < -290: goals[count].right(180) os.system("afplay bing.mp3&") #move ball for count in range(maxGoals): goals[count].forward(1) #collision checking with goals if isCollision(player, goals[count]): goals[count].setposition(random.randint(-300, 300), random.randint(-300, 300)) goals[count].right(random.randint(0,360)) os.system("afplay yes.mp3&") score1 += 2 speed += 0.5 #collision checking with goals if isCollision(player2, goals[count]): goals[count].setposition(random.randint(-300, 300), random.randint(-300, 300)) goals[count].right(random.randint(0,360)) os.system("afplay yes.mp3&") score2 += 2 speed += 0.5 #collision checking with player 2 if isCollision(player, player2): player.setposition(random.randint(-300, 300), random.randint(-290, 290)) player.right(random.randint(0,360)) os.system("afplay yes.mp3&") score1 -= 1 speed += 0.5 if isCollision(player2, player):
COM Server - COMTYPES / PYTHONCOM
Hello all, I have some major problems with something i am not good at :( I have come to a situation where i have to add a COM server in my python code the get access to it from Labview Teststand. Firs i have tried with pythoncom/wincom and got it almost working, it registered and i could look it up in the windows COM data list. But this combination do not register coclasses: Coclasses are not registered (that is, RegisterTypeLib does not write any values to the CLSID key of the coclass). http://docs.activestate.com/activepython/2.6/pywin32/pythoncom__RegisterTypeLib_meth.html IDL File: http://pastebin.com/WGCMmzHv And here the code: http://pastebin.com/44t45tPj my reference: https://chromium.googlesource.com/chromium/deps/python_26/+/cd4a3da8f0f0806bec98a40d80484f2362908250/Lib/site-packages/win32com/test/pippo_server.py - Then i started by using COMTYPES, but this do not at all register into the COM catalog on windows - both solutions i can connect to from another python. here is my code - IDL is the same. http://pastebin.com/ke5V5ZbY How do i continue so i can use this server from Teststand or any other windows program?? I really hope some can give me an example or help me in what is wrong - i think it is quite close... Thank you -- https://mail.python.org/mailman/listinfo/python-list
data visualization - graph
Hi, I am looking for a solution to graph charts from real time measurements on the web like: http://pvoutput.org/intraday.jsp?id=16919sid=14707gs=1dxa=1dt=20150715 I have some solar systems i like to save data into an sql database - and then i like to have some web service where i can select which data to see and compare and zoom in/ out etc. I like to do it in Python - but maybe some else also? Also i like as much as possible in some library / packages.. Any one who has experience? best regards /Kasper -- https://mail.python.org/mailman/listinfo/python-list
Re: PyEval_GetLocals and unreferenced variables
I'm not sure how you think you're adding a local from C code. If you're using PyEval_GetLocals(), that only gives you a dict containing a *copy* of the locals; modifying that dict doesn't change the locals in the function's frame. That may have been the design plan, but in Python 2.7.6, I definitely am able to inject locals via PyEval_GetLocals() and have them be visible both from the C and Python side; see also http://stackoverflow.com/questions/22276502/create-python-object-in-local-scope-from-within-c If the bytecode of the nested function doesn't reference a given variable in the outer function, it doesn't get passed in. Ok, that's good to know because it rules out doing this without having an explicit reference to the variable in the inner scope. Thanks. Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list
Re: PyEval_GetLocals and unreferenced variables
def fun(): cfun_that_creates_q_in_local_scope() def fun2(): cfun_that_wants_to_see_if_q_is_available() So the Python side actually doesn't see 'q' directly at all. I think you will need to elaborate. Ok, here goes (and thanks for listening). The behaviour of the C side is determined by certain settings/preferences. I want these settings to respect the Python scope. I could in principle decide to make these settings a proper Python object, and ask the user to create one and pass it along at every C-function call. Something like def fun(): settings = Cpp_Options() settings.set_some_flag() cfun(settings, ...) def fun2(): settings = Cpp_Options(settings) settings.set_some_other_flag() cfun(settings, ...) Then Python would automatically take care of the scope of 'settings'. However, this is difficult for the user to keep track of. So my idea was to allow for def fun(): set_some_flag() cfun(...) def fun2(): set_some_other_flag() cfun(...) I let the C side create a Cpp_Options object on the locals stack behind the scenes, and the 'cfun()' function takes it from there directly, without requiring the user to pass it. Much easier for the user. This works, but the problem is that the C side does not see the settings that were created in fun() when it gets called from fun2(). In fun2(), the locals do not contain objects constructed earlier in fun(), unless the Python side explicitly refers to them. So adding a line settings.do_something() inside fun2() would work and forces Python to pull the settings object created in fun() into scope, but that sort of defeats the purpose. Hence my question: how can I ask, purely on the C side, for Python to pull objects into the local frame? Final note: I am actually trying to make this look as close as possible to an older custom-built language, which didn't require passing the settings object either, so it's kinda important to make the user feel 'at home'. Hope this makes it more clear, thanks for your patience. Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list
PyEval_GetLocals and unreferenced variables
I have a question about PyEval_GetLocals(). The normal behaviour of PyEval_GetLocals(), and in fact of the locals() function in Python itself, is to return a list which includes only those variables which are actually referenced in the local scope. Example: def fun(): q=3 def fun2(): print(locals()) fun2() fun() will print {} because q has not been referenced in fun2(). On the other hand, if you do def fun(): q=3 def fun2(): print(q) print(locals()) fun2() fun() you will instead get {'q': 3} as output. All fine and understood. My question: I want to call a C function inside fun2(), which I want to give access to the 'q' variable in the fun() scope, _without_ there being any reference to 'q' in the python code itself. That is, I want to do: def fun(): q=3 def fun2(): cfun() fun2() fun() and access 'q' inside the C-function cfun(). If I simply let it call PyEval_GetLocals, then the result will again not contain q. Is there any way in which I can convince python to pull 'q' into the local scope from within my C code? Thanks! Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list
Re: PyEval_GetLocals and unreferenced variables
def fun(): q=3 def fun2(): cfun() fun2() fun() and access 'q' inside the C-function cfun(). If I simply let it call PyEval_GetLocals, then the result will again not contain q. Is there any way in which I can convince python to pull 'q' into the local scope from within my C code? Wouldn't this be a little surprising? Why not simply pass q as a parameter? I agree that in this example that would be the natural thing to do. My case is more tricky though: I have something like def fun(): cfun_that_creates_q_in_local_scope() def fun2(): cfun_that_wants_to_see_if_q_is_available() So the Python side actually doesn't see 'q' directly at all. I am willing to elaborate on this if you want (I have fairly good reasons to do things this way, mostly having to do with historical constraints of an older C library that I cannot avoid), but it requires more space. Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list
Re: PyEval_GetLocals and unreferenced variables
To be honest, that's just made it even more weird :) You're creating something in a local namespace that the Python compiler isn't aware of. Yes, I agree that retrieving the locals with PyEval_GetLocals and then sticking something in there on the C side is weird. I wouldn't say that the Python compiler is not aware of it though (I could ask my question purely in Python: how do I check in the scope of fun2 whether 'q' is available in the outer scope without actually using it). I wonder, would a 'nonlocal q' declaration inside fun2 affect things any? Yes, that pulls in 'q', but I would like to do that 'nonlocal q' on the C side. If I have to write 'nonlocal q' inside fun2 then I can also pull in 'q' using any other reference to 'q'. Otherwise, maybe there's some completely different way to transfer information around. Using locals in this way seems fraught with peril. There might very well be... Cheers, Kasper -- https://mail.python.org/mailman/listinfo/python-list
lambda - strange behavior
I was playing around with lambda functions, but I cannot seem to fully grasp them. I was running the script below in Python 2.7.5, and it doesn't do what I want it to. Are lambda functions really supposed to work that way. How do I make it work as I intend? f = [] for n in range(5): f.append( lambda x: x*n ) assert( f[4](2) == 8 ) assert( f[3](3) == 9 ) assert( f[2](2) == 4 ) assert( f[1](8) == 8 ) assert( f[0](2) == 0 ) -- https://mail.python.org/mailman/listinfo/python-list
Re: HID Feature Raport, Linux
Den onsdag den 18. september 2013 12.10.29 UTC+2 skrev Anssi Saari: Hi, I have been using pywinusb.hid for a hid unit, using only feature reports. I like to get this code to run on raspbian PI, but i can not fint a good library to support HID/feature reports? I am a USB newbie Can anyone help me, or point me in a direction to send/recieve feature reports without HID support? I believe pyusb with libusb or libusbx would work. There's a summary of the alternatives at http://mcuee.blogspot.fi/2011/04/python-and-usb-hid-device.html if that helps. Hi, Thx, i have been looking at this... but could not fint the way to send feature reports, does anyone have an example? Kasper -- https://mail.python.org/mailman/listinfo/python-list
HID Feature Raport, Linux
Hi, I have been using pywinusb.hid for a hid unit, using only feature reports. I like to get this code to run on raspbian PI, but i can not fint a good library to support HID/feature reports? I am a USB newbie Can anyone help me, or point me in a direction to send/recieve feature reports without HID support? Br. Kasper -- https://mail.python.org/mailman/listinfo/python-list
[issue4344] crash upon launch
New submission from kasper [EMAIL PROTECTED]: Hi I'm new at programming and have chosen to start with python, and so I have installed python 2.6, and played around with it a little. However, a problem has occured: yesterday when i tried to run the program - pythonwin editor 2.6.0 - a crash occured immediately upon launch. All i do is start up the program, and while trying to open, the program crashes, and a windows error window pops up, telling me that 'the program has encountered an error, and will now exit' - not telling me anything useful about what kind of error has occured, or why. As usual, the windows errorreport is of no use. And so I have little idea of what causes the crash, but I do have a suspicion that the .dll mfc90.dll might be a part of the problem, since it is mentioned in the beginning of the errorreport. Looking forward to hear from you. Kasper -- components: Windows messages: 76006 nosy: source.mod severity: normal status: open title: crash upon launch type: crash versions: Python 2.6 ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4344 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4344] crash upon launch
kasper [EMAIL PROTECTED] added the comment: i got it from this URL, which i believe is indeed not phoney: http://www.activestate.com/store/productdetail.aspx?prdGuid=b08b04e0-6872-4d9d-a722-7a0c2dea2758 it's their own homepage. would you happen to know why this happens? the problem occurs eventhough i uninstall and reinstall the program. same error, only mentioning that mfc90.dll. ___ Python tracker [EMAIL PROTECTED] http://bugs.python.org/issue4344 ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
Re: page faults when spawning subprocesses
Dave Kirby wrote: 5) WTF can I do about it? Maybe using vfork rather than fork would help. But I'm not sure that will work as intended when there are multiple threads, in fact I'm not sure fork will work either. You could have fork racing against another thread being in a critical region thus duplicating the memory map at some point where some data structures are in an inconsistent state and apparently locked by some thread existing in the parent. A possible solution would be to use fork to create two processes before creating any threads. Have the communicate over pipes or sockets when new processes are to be created. Then one process can create all the threads you need, and the other can fork off children. Even in that case vfork may come in handy. If you dislike the semantics of vfork, but still want the parent to block until the child has called execve, then you can do so manually using a pipe. Create the pipe before calling fork, in parent process you close write end and try to read from the pipe, in child process you close read end and mark write end close on exec. When exec succeeds, the pipe is closed and parent gets EOF. (I have tried some of this in C, but I must admit, I don't know if it can be done in Python as well.) -- Kasper Dupont Note to self: Don't try to allocate 256000 pages with GFP_KERNEL on x86. -- http://mail.python.org/mailman/listinfo/python-list