1

I have a program with a map on a canvas. When I scroll over the map it displays on the screen the longitude and latitude of where the mouse pointer is located, updated realtime. As well, when I move the mouse it show the sunrise, sunset, moonrise, moonset, and moon phase for where I am at on the screen. Everything is working fine except ephem obviously doesn't update real time.

This is the ephem specific part of the code that is run everytime the mouse is moved.

self.maploc.lat, self.maploc.lon = str(py), str(px)
sr = str(self.maploc.next_rising(ephem.Sun()
ss = str(self.maploc.next_setting(ephem.Sun()))
snr = sr.split(' ')
sns = ss.split(' ')
self.maploc.lat, self.maploc.lon = str(py), str(px)
mr = str(self.maploc.next_rising(ephem.Moon()))
ms = str(self.maploc.next_setting(ephem.Moon()))
mn = ephem.Moon()
mn.compute(self.maploc)
mnr = mr.split(' ')
mns = ms.split(' ')

I would think running the mn.compute(self.maploc) would do a complete update of the map coordinates but it doesn't. Granted yesterday as I started tinkering with this idea I noticed it didn't seem to be doing live updating with the sunrise times either.

How do I get real time updating or can I with ephem.

If I run the program the moon phase will always stay the same until I close out the program and restart the program.

confused
  • 1,283
  • 6
  • 21
  • 37

1 Answers1

0

You might need to reset the maploc’s date, otherwise its routines like next_rising() will probably just compute times based on the date it got when you created it.

from ephem import now
...
self.maploc.date = now()

That is how you can update the maploc to start thinking about calculations from a new date and time. Good luck!

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147