diff options
author | flavio <fdanesse@gmail.com> | 2012-10-22 22:49:46 (GMT) |
---|---|---|
committer | flavio <fdanesse@gmail.com> | 2012-10-22 22:49:46 (GMT) |
commit | bea7e9041a7dbde5832e1d0a0f8897276dd621e3 (patch) | |
tree | 5cdc436e456b4445adb61a83efc094781fb55f05 | |
parent | 8aa2f60cc446f39f7f55a486f0c1d116a02befb1 (diff) |
Corrección de Tabulaciones
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | GnomeMoonActivity.py | 399 | ||||
-rw-r--r-- | MoonGlobals.py | 308 | ||||
-rw-r--r-- | Moonwidgets.py | 932 | ||||
-rw-r--r-- | SugarMoonActivity.py | 602 | ||||
-rw-r--r-- | setup.py | 46 |
6 files changed, 1207 insertions, 1081 deletions
@@ -1,3 +1,4 @@ *.pyc *.pyo +*.bak *.??~ diff --git a/GnomeMoonActivity.py b/GnomeMoonActivity.py index 3bf6239..206e035 100755 --- a/GnomeMoonActivity.py +++ b/GnomeMoonActivity.py @@ -41,198 +41,211 @@ SECONDS_PER_DAY = 86400.0 format = "%Y-%m-%d %H:%M" class MoonActivity(gtk.Window): - def __init__(self): - gtk.Window.__init__(self) - self.set_title(_("Luna")) - self.set_icon_from_file(os.path.join(MG.ICONOS,"luna-ico.png")) - self.set_resizable(True) - self.set_size_request(MG.WIDTH, MG.HEIGHT) - self.set_position(gtk.WIN_POS_CENTER) - self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.main_view = None - self.mooncalendar = None - self.info_panel = None - self.info = None - self.luna_hoy = None - self.label_emisferio = None - self.aspectframe = None - self.bufferinfo = None - - self.set_layout() - - self.show_all() - self.realize() - self.maximize() - - self.connect("delete_event", self.delete_event) - self.luna_hoy.connect("expose_event", self.repaint) - - self.actualizador = gobject.timeout_add(1000, self.handle) - - def set_layout(self): - anio, mes, fecha, hora = MG.get_date_time_now() - self.luna_hoy = CalendarButton(anio, mes, fecha, hora) - self.mooncalendar = MoonCalendar() - self.aspectframe = gtk.AspectFrame() - self.aspectframe.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.aspectframe.add(self.luna_hoy) - - cajabase = gtk.VBox() - self.main_view = gtk.HBox() - cajabase.pack_end(self.main_view, True, True, 5) - - view_tool_bar = gtk.Toolbar() - view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - cajabase.pack_start(view_tool_bar, False, False, 0) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.toggle_grid_clicked, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", _(""), "",boton, self.toggle_hemisphere_clicked, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.switch_calendar_luna, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.label_emisferio = gtk.Label() - view_tool_bar.append_widget(self.label_emisferio, None, None) - self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - self.label_emisferio.show() - - view_tool_bar.show_all() - - info_scroll = gtk.ScrolledWindow() - info_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - self.info_panel = gtk.VBox() - self.info = gtk.TextView() - self.info.set_property("sensitive", False) - self.info.set_border_window_size(gtk.TEXT_WINDOW_TOP, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 10) - self.info_panel.pack_start(self.info, False, False, 0) - info_scroll.add_with_viewport(self.info_panel) - - self.main_view.pack_start(info_scroll, False, False, 5) - self.main_view.pack_end(self.aspectframe, True, True, 5) - self.add(cajabase) - - self.bufferinfo = gtk.TextBuffer() - self.info.set_buffer(self.bufferinfo) - self.mooncalendar.set_mes(anio, mes, fecha, hora) - self.update_text_information_view() - - def toggle_grid_clicked(self, widget= None): - self.luna_hoy.toggle_grid_clicked() - self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) - - def toggle_hemisphere_clicked(self, widget= None): - self.luna_hoy.toggle_hemisphere_clicked() - self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) - - def switch_calendar_luna(self, widget): - if self.mooncalendar in self.aspectframe.get_children(): - self.aspectframe.remove(self.mooncalendar) - self.aspectframe.add(self.luna_hoy) - self.luna_hoy.show_all() - elif self.luna_hoy in self.aspectframe.get_children(): - self.aspectframe.remove(self.luna_hoy) - self.aspectframe.add(self.mooncalendar) - self.mooncalendar.show_all() - self.show_all() - self.realize() - - def handle(self): - self.update_text_information_view() - if self.luna_hoy in self.aspectframe.get_children(): - self.luna_hoy.actualizar() - return True - - def repaint(self, widget= None, event= None): - x,y,w,h= self.luna_hoy.get_allocation() - anchoboton, altoboton = (w,h) - tamanioboton = min( [anchoboton,altoboton] ) - self.luna_hoy.repaint(tamanioboton) - - def delete_event(self, widget, event, data=None): - sys.exit(0) - return False - - def update_text_information_view(self): - anio, mes, fecha, hora = MG.get_date_time_now() - hoy = "%s-%s-%s %s" % (anio, mes, fecha, hora) - ahora = time.mktime(time.strptime(hoy, MG.format)) - - self.luna_hoy.data_model.update_moon_calculations(ahora) - - information = "" - information += "%s:\n\n" % (_("Today's Moon Information")) - information += "%s\n\n" % (MG.get_date_time()) - information += "%s:\n%s\n\n" % (_("Phase"), self.luna_hoy.data_model.moon_phase_name(self.luna_hoy.data_model.phase_of_moon)) - information += "%s:\n%.2f (%s)\n\n" % (_("Julian Date"), self.luna_hoy.data_model.julian_date, _("astronomical")) - - information += "%s:\n" % (_("Age")) - dias = self.luna_hoy.data_model.days_old - horas = self.luna_hoy.data_model.hours_old - minutos = self.luna_hoy.data_model.minutes_old - information += "%i %s, %i %s, %i %s.\n\n" % (dias, _("days"), horas, _("hours"), minutos, _("minutes")) - - phase = self.luna_hoy.data_model.phase_of_moon * 100 - lunation = self.luna_hoy.data_model.lunation - information += "%s:\n" % (_("Lunation")) - information += "%.2f%s %s %d.\n\n" % (phase, "%", _("through lunation"), lunation) - - information += "%s:\n" % (_("Surface Visibility")) - information += "%.0f%s (%s)\n\n" % (self.luna_hoy.data_model.percent_of_full_moon * 100, "%", _("estimated")) - - #information += _("Surface Visibility:\n%.0f%% (estimated)\n\n") % (self.luna_hoy.data_model.percent_of_full_moon * 100) - - selen = {'deg':self.luna_hoy.data_model.selenographic_deg, 'westOrEast':self.luna_hoy.data_model.west_or_east, - 'riseOrSet':self.luna_hoy.data_model.rise_or_set} - information += _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % selen - - full = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_full_moon_date)), - 'days':self.luna_hoy.data_model.days_until_full_moon} - information += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % full - - new = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_new_moon_date)), - 'days':self.luna_hoy.data_model.days_until_new_moon} - information += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % new - - lunare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_lunar_eclipse_date)), - 'days':self.luna_hoy.data_model.days_until_lunar_eclipse} - information += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % lunare - - solare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_solar_eclipse_date)), - 'days':self.luna_hoy.data_model.days_until_solar_eclipse} - information += _("Next Solar eclipse:\n%(date)s in %(days).0f days") % solare - - self.bufferinfo.set_text(information) - self.label_emisferio.set_text( " %s: %s" % (_("Vista Hemisferio"),_(self.luna_hoy.hemisphere_view)) ) + + def __init__(self): + + gtk.Window.__init__(self) + + self.set_title(_("Luna")) + self.set_icon_from_file(os.path.join(MG.ICONOS,"luna-ico.png")) + self.set_resizable(True) + self.set_size_request(MG.WIDTH, MG.HEIGHT) + self.set_position(gtk.WIN_POS_CENTER) + self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.main_view = None + self.mooncalendar = None + self.info_panel = None + self.info = None + self.luna_hoy = None + self.label_emisferio = None + self.aspectframe = None + self.bufferinfo = None + + self.set_layout() + + self.show_all() + self.realize() + self.maximize() + + self.connect("delete_event", self.delete_event) + self.luna_hoy.connect("expose_event", self.repaint) + + self.actualizador = gobject.timeout_add(1000, self.handle) + + def set_layout(self): + + anio, mes, fecha, hora = MG.get_date_time_now() + self.luna_hoy = CalendarButton(anio, mes, fecha, hora) + self.mooncalendar = MoonCalendar() + self.aspectframe = gtk.AspectFrame() + self.aspectframe.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.aspectframe.add(self.luna_hoy) + + cajabase = gtk.VBox() + self.main_view = gtk.HBox() + cajabase.pack_end(self.main_view, True, True, 5) + + view_tool_bar = gtk.Toolbar() + view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + cajabase.pack_start(view_tool_bar, False, False, 0) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.toggle_grid_clicked, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", _(""), "",boton, self.toggle_hemisphere_clicked, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.switch_calendar_luna, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.label_emisferio = gtk.Label() + view_tool_bar.append_widget(self.label_emisferio, None, None) + self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + self.label_emisferio.show() + + view_tool_bar.show_all() + + info_scroll = gtk.ScrolledWindow() + info_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + self.info_panel = gtk.VBox() + self.info = gtk.TextView() + self.info.set_property("sensitive", False) + self.info.set_border_window_size(gtk.TEXT_WINDOW_TOP, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 10) + self.info_panel.pack_start(self.info, False, False, 0) + info_scroll.add_with_viewport(self.info_panel) + + self.main_view.pack_start(info_scroll, False, False, 5) + self.main_view.pack_end(self.aspectframe, True, True, 5) + self.add(cajabase) + + self.bufferinfo = gtk.TextBuffer() + self.info.set_buffer(self.bufferinfo) + self.mooncalendar.set_mes(anio, mes, fecha, hora) + self.update_text_information_view() + + def toggle_grid_clicked(self, widget= None): + + self.luna_hoy.toggle_grid_clicked() + self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) + + def toggle_hemisphere_clicked(self, widget= None): + + self.luna_hoy.toggle_hemisphere_clicked() + self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) + + def switch_calendar_luna(self, widget): + + if self.mooncalendar in self.aspectframe.get_children(): + self.aspectframe.remove(self.mooncalendar) + self.aspectframe.add(self.luna_hoy) + self.luna_hoy.show_all() + + elif self.luna_hoy in self.aspectframe.get_children(): + self.aspectframe.remove(self.luna_hoy) + self.aspectframe.add(self.mooncalendar) + self.mooncalendar.show_all() + + self.show_all() + self.realize() + + def handle(self): + + self.update_text_information_view() + if self.luna_hoy in self.aspectframe.get_children(): + self.luna_hoy.actualizar() + + return True + + def repaint(self, widget= None, event= None): + + x,y,w,h= self.luna_hoy.get_allocation() + anchoboton, altoboton = (w,h) + tamanioboton = min( [anchoboton,altoboton] ) + self.luna_hoy.repaint(tamanioboton) + + def delete_event(self, widget, event, data=None): + sys.exit(0) + return False + + def update_text_information_view(self): + + anio, mes, fecha, hora = MG.get_date_time_now() + hoy = "%s-%s-%s %s" % (anio, mes, fecha, hora) + ahora = time.mktime(time.strptime(hoy, MG.format)) + + self.luna_hoy.data_model.update_moon_calculations(ahora) + + information = "" + information += "%s:\n\n" % (_("Today's Moon Information")) + information += "%s\n\n" % (MG.get_date_time()) + information += "%s:\n%s\n\n" % (_("Phase"), self.luna_hoy.data_model.moon_phase_name(self.luna_hoy.data_model.phase_of_moon)) + information += "%s:\n%.2f (%s)\n\n" % (_("Julian Date"), self.luna_hoy.data_model.julian_date, _("astronomical")) + + information += "%s:\n" % (_("Age")) + dias = self.luna_hoy.data_model.days_old + horas = self.luna_hoy.data_model.hours_old + minutos = self.luna_hoy.data_model.minutes_old + information += "%i %s, %i %s, %i %s.\n\n" % (dias, _("days"), horas, _("hours"), minutos, _("minutes")) + + phase = self.luna_hoy.data_model.phase_of_moon * 100 + lunation = self.luna_hoy.data_model.lunation + information += "%s:\n" % (_("Lunation")) + information += "%.2f%s %s %d.\n\n" % (phase, "%", _("through lunation"), lunation) + + information += "%s:\n" % (_("Surface Visibility")) + information += "%.0f%s (%s)\n\n" % (self.luna_hoy.data_model.percent_of_full_moon * 100, "%", _("estimated")) + + #information += _("Surface Visibility:\n%.0f%% (estimated)\n\n") % (self.luna_hoy.data_model.percent_of_full_moon * 100) + + selen = {'deg':self.luna_hoy.data_model.selenographic_deg, 'westOrEast':self.luna_hoy.data_model.west_or_east, + 'riseOrSet':self.luna_hoy.data_model.rise_or_set} + information += _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % selen + + full = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_full_moon_date)), + 'days':self.luna_hoy.data_model.days_until_full_moon} + information += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % full + + new = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_new_moon_date)), + 'days':self.luna_hoy.data_model.days_until_new_moon} + information += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % new + + lunare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_lunar_eclipse_date)), + 'days':self.luna_hoy.data_model.days_until_lunar_eclipse} + information += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % lunare + + solare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_solar_eclipse_date)), + 'days':self.luna_hoy.data_model.days_until_solar_eclipse} + information += _("Next Solar eclipse:\n%(date)s in %(days).0f days") % solare + + self.bufferinfo.set_text(information) + self.label_emisferio.set_text( " %s: %s" % (_("Vista Hemisferio"),_(self.luna_hoy.hemisphere_view)) ) if __name__=="__main__": - MoonActivity() - gtk.main() + MoonActivity() + gtk.main() diff --git a/MoonGlobals.py b/MoonGlobals.py index 3096b18..0122fc5 100644 --- a/MoonGlobals.py +++ b/MoonGlobals.py @@ -86,7 +86,7 @@ new_moon_array = ("2008-01-08 11:37_", "2008-02-07 03:44A", "2008-03-07 17:14_", "2015-01-20 13:14_", "2015-02-18 23:47_", "2015-03-20 09:36T", "2015-04-18 18:57_", "2015-05-18 04:13_", "2015-06-16 14:05_", "2015-07-16 01:24_", "2015-08-14 14:54_", "2015-09-13 06:41P", "2015-10-13 00:06_", "2015-11-11 17:47_", "2015-12-11 10:29_", - + "2016-01-10 01:30_", "2016-02-08 14:39_", "2016-03-09 01:54T", "2016-04-07 11:24_", "2016-05-06 19:30_", "2016-06-05 03:00_", "2016-07-04 11:01_", "2016-08-02 20:45_", "2016-09-01 09:03A", "2016-10-01 00:12_", "2016-10-30 17:38_", "2016-11-29 12:18_", @@ -251,179 +251,189 @@ last_quarter_array = ("2008-01-30 05:03", "2008-02-29 02:18", "2008-03-29 21:47" "2018-12-29 09:34") def next_full_moon_sec_at_time(now): - # Return seconds to the next Full Moon. - for date_string in full_moon_array: - next = time.mktime(time.strptime(date_string[:-1], format)) - if next >= now: - break - return next - now + # Return seconds to the next Full Moon. + for date_string in full_moon_array: + next = time.mktime(time.strptime(date_string[:-1], format)) + if next >= now: + break + return next - now def next_new_moon_sec_at_time(now): - # Return seconds to the next New Moon. - for date_string in new_moon_array: - next = time.mktime(time.strptime(date_string[:-1], format)) - if next >= now: - break - return next - now + # Return seconds to the next New Moon. + for date_string in new_moon_array: + next = time.mktime(time.strptime(date_string[:-1], format)) + if next >= now: + break + return next - now def next_quarter_moon_sec_at_time(now): - # Return seconds to the next Quater Moon phase (could be First or Last). - for date_string in first_quarter_array: - next1 = time.mktime(time.strptime(date_string, format)) - if next1 >= now: - break - for date_string in last_quarter_array: - next2 = time.mktime(time.strptime(date_string, format)) - if next2 >= now: - break - next = min(next1, next2) - return next - now + # Return seconds to the next Quater Moon phase (could be First or Last). + for date_string in first_quarter_array: + next1 = time.mktime(time.strptime(date_string, format)) + if next1 >= now: + break + for date_string in last_quarter_array: + next2 = time.mktime(time.strptime(date_string, format)) + if next2 >= now: + break + next = min(next1, next2) + return next - now def last_full_moon_sec_at_time(now): - # Return (positive) seconds since the last Full Moon. - for date_string in full_moon_array: - then = time.mktime(time.strptime(date_string[:-1], format)) - if then >= now: - break - last = then - return now - last + # Return (positive) seconds since the last Full Moon. + for date_string in full_moon_array: + then = time.mktime(time.strptime(date_string[:-1], format)) + if then >= now: + break + last = then + return now - last def last_new_moon_sec_at_time(now): - # Return (positive) seconds since the last New Moon. - for date_string in new_moon_array: - then = time.mktime(time.strptime(date_string[:-1], format)) - if then >= now: - break - last = then - return now - last + # Return (positive) seconds since the last New Moon. + for date_string in new_moon_array: + then = time.mktime(time.strptime(date_string[:-1], format)) + if then >= now: + break + last = then + return now - last def last_quarter_moon_sec_at_time(now): - # Return (positive) seconds to the last Quater Moon phase (could be First or Last). - for date_string in first_quarter_array: - then = time.mktime(time.strptime(date_string, format)) - if then >= now: - break - last1 = then - for date_string in last_quarter_array: - then = time.mktime(time.strptime(date_string, format)) - if then >= now: - break - last2 = then - last = max(last1, last2) - return now - last + # Return (positive) seconds to the last Quater Moon phase (could be First or Last). + for date_string in first_quarter_array: + then = time.mktime(time.strptime(date_string, format)) + if then >= now: + break + last1 = then + for date_string in last_quarter_array: + then = time.mktime(time.strptime(date_string, format)) + if then >= now: + break + last2 = then + last = max(last1, last2) + return now - last def lunation_at_time(now): - # Return lunation number, 0 started on Dec 18, 1922, current data set starts as 2008 - lunation = 1051 - for date_string in new_moon_array: - next = time.mktime(time.strptime(date_string[:-1], format)) - if next >= now: - break - lunation += 1 - return lunation + # Return lunation number, 0 started on Dec 18, 1922, current data set starts as 2008 + lunation = 1051 + for date_string in new_moon_array: + next = time.mktime(time.strptime(date_string[:-1], format)) + if next >= now: + break + lunation += 1 + return lunation def next_lunar_eclipse_sec_at_time(now): - # Return (positive) seconds to the next Lunar eclipe or -1. - for date_string in full_moon_array: - if date_string[-1:] != "_": - next = time.mktime(time.strptime(date_string[:-1], format)) - if next >= now: - return next - now - return -1 + # Return (positive) seconds to the next Lunar eclipe or -1. + for date_string in full_moon_array: + if date_string[-1:] != "_": + next = time.mktime(time.strptime(date_string[:-1], format)) + if next >= now: + return next - now + return -1 def last_lunar_eclipse_sec_at_time(now): - # Return (positive) seconds to the last Lunar eclipe or -1. - last = -1 - for date_string in full_moon_array: - if date_string[-1:] != "_": - then = time.mktime(time.strptime(date_string[:-1], format)) - if then >= now: - break - last = then - if last == -1: - return -1 - else: - return now - last + # Return (positive) seconds to the last Lunar eclipe or -1. + last = -1 + for date_string in full_moon_array: + if date_string[-1:] != "_": + then = time.mktime(time.strptime(date_string[:-1], format)) + if then >= now: + break + last = then + if last == -1: + return -1 + else: + return now - last def next_solar_eclipse_sec_at_time(now): - # Return (positive) seconds to the next Solar eclipe or -1. - for date_string in new_moon_array: - if date_string[-1:] != "_": - next = time.mktime(time.strptime(date_string[:-1], format)) - if next >= now: - return next - now - return -1 + # Return (positive) seconds to the next Solar eclipe or -1. + for date_string in new_moon_array: + if date_string[-1:] != "_": + next = time.mktime(time.strptime(date_string[:-1], format)) + if next >= now: + return next - now + return -1 def correct_for_tz_and_dst(date_sec_of_event): - # Time-zone and/or daylight-saving correction (internal data is UTC). - if time.daylight == 0 or time.localtime(date_sec_of_event)[8] == 0: - # Time-zone correction - return time.timezone - else: - # Time-zone & daylight saving correction - return time.altzone + # Time-zone and/or daylight-saving correction (internal data is UTC). + if time.daylight == 0 or time.localtime(date_sec_of_event)[8] == 0: + # Time-zone correction + return time.timezone + else: + # Time-zone & daylight saving correction + return time.altzone def RecalcularFase(the_date): - # Una fecha representada en segundos. Ejem: - # format = "%Y-%m-%d %H:%M" - # fecha = time.mktime(time.strptime("2012-06-21 15:00", format)) - last_new_moon_sec = last_new_moon_sec_at_time(the_date) - next_new_moon_sec = next_new_moon_sec_at_time(the_date) - last_full_moon_sec = last_full_moon_sec_at_time(the_date) - next_full_moon_sec = next_full_moon_sec_at_time(the_date) - last_quarter_moon_sec = last_quarter_moon_sec_at_time(the_date) - next_quarter_moon_sec = next_quarter_moon_sec_at_time(the_date) - phase_of_moon = None - # Calculate phase percent of Moon based on nearest two data values - if next_full_moon_sec <= next_new_moon_sec: - if next_quarter_moon_sec <= next_full_moon_sec: - phase_of_moon = (last_new_moon_sec / (last_new_moon_sec + next_quarter_moon_sec)) * 0.25 - else: - phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_full_moon_sec)) * 0.25 + 0.25 - else: - if next_quarter_moon_sec <= next_new_moon_sec: - phase_of_moon = (last_full_moon_sec / (last_full_moon_sec + next_quarter_moon_sec)) * 0.25 + 0.5 - else: - phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_new_moon_sec)) * 0.25 + 0.75 - return phase_of_moon + # Una fecha representada en segundos. Ejem: + # format = "%Y-%m-%d %H:%M" + # fecha = time.mktime(time.strptime("2012-06-21 15:00", format)) + last_new_moon_sec = last_new_moon_sec_at_time(the_date) + next_new_moon_sec = next_new_moon_sec_at_time(the_date) + last_full_moon_sec = last_full_moon_sec_at_time(the_date) + next_full_moon_sec = next_full_moon_sec_at_time(the_date) + last_quarter_moon_sec = last_quarter_moon_sec_at_time(the_date) + next_quarter_moon_sec = next_quarter_moon_sec_at_time(the_date) + phase_of_moon = None + + # Calculate phase percent of Moon based on nearest two data values + if next_full_moon_sec <= next_new_moon_sec: + if next_quarter_moon_sec <= next_full_moon_sec: + phase_of_moon = (last_new_moon_sec / (last_new_moon_sec + next_quarter_moon_sec)) * 0.25 + + else: + phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_full_moon_sec)) * 0.25 + 0.25 + + else: + if next_quarter_moon_sec <= next_new_moon_sec: + phase_of_moon = (last_full_moon_sec / (last_full_moon_sec + next_quarter_moon_sec)) * 0.25 + 0.5 + + else: + phase_of_moon = (last_quarter_moon_sec / (last_quarter_moon_sec + next_new_moon_sec)) * 0.25 + 0.75 + + return phase_of_moon def get_date_time(): - # Devolución tipo: Lunes 5 de Febrero de 2012 - dias= [] - for d in calendar.day_name: - if d: dias.append(d) - meses= [] - for m in calendar.month_name: - if m: meses.append(m) - t= time.localtime() - anio= t.tm_year - mes= meses[t.tm_mon -1] - fecha= t.tm_mday - dia= dias[t.tm_wday]#[t.tm_wday -1] - hora= t.tm_hour - minutos= t.tm_min - segundos= t.tm_sec - fecha= "%s %s de %s de %s" % (dia, fecha, mes, anio) - hora= "%s:%s:%s" % (hora, minutos, segundos) - return "%s %s" % (fecha, hora) + # Devolución tipo: Lunes 5 de Febrero de 2012 + dias= [] + + for d in calendar.day_name: + if d: dias.append(d) + + meses= [] + + for m in calendar.month_name: + if m: meses.append(m) + + t= time.localtime() + anio= t.tm_year + mes= meses[t.tm_mon -1] + fecha= t.tm_mday + dia= dias[t.tm_wday]#[t.tm_wday -1] + hora= t.tm_hour + minutos= t.tm_min + segundos= t.tm_sec + fecha= "%s %s de %s de %s" % (dia, fecha, mes, anio) + hora= "%s:%s:%s" % (hora, minutos, segundos) + return "%s %s" % (fecha, hora) def get_date_time_now(): - # Devolución tipo: año, mes, dia, hora (hora es string, los demás son enteros) - t= time.localtime() - anio= t.tm_year - mes = t.tm_mon - fecha= t.tm_mday - hora= t.tm_hour - minutos= t.tm_min - hora= "%s:%s" % (hora, minutos) - return (anio, mes, fecha, hora) + + # Devolución tipo: año, mes, dia, hora (hora es string, los demás son enteros) + t= time.localtime() + anio= t.tm_year + mes = t.tm_mon + fecha= t.tm_mday + hora= t.tm_hour + minutos= t.tm_min + hora= "%s:%s" % (hora, minutos) + return (anio, mes, fecha, hora) def get_semanas_del_mes(anio, mes): - # Devuelve una lista de semanas. - # Cada semana es una lista con las fechas del mes que le corresponde. - # Cada semana comienza en lunes. - # Las fechas 0 corresponden al mes pasado o al siguiente. - calendario= calendar.Calendar() - semanas= calendario.monthdayscalendar(anio, mes) - return semanas - + + # Devuelve una lista de semanas. + # Cada semana es una lista con las fechas del mes que le corresponde. + # Cada semana comienza en lunes. + # Las fechas 0 corresponden al mes pasado o al siguiente. + calendario= calendar.Calendar() + semanas= calendario.monthdayscalendar(anio, mes) + return semanas diff --git a/Moonwidgets.py b/Moonwidgets.py index 7a1c233..2281916 100644 --- a/Moonwidgets.py +++ b/Moonwidgets.py @@ -35,254 +35,299 @@ from gettext import gettext as _ import MoonGlobals as MG class CalendarButton(gtk.EventBox): - __gsignals__ = {"clicked":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), - "clickederecho":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} - def __init__(self, anio, mes, d, hora): - gtk.EventBox.__init__(self) - self.set_visible_window(True) - self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK | - gtk.gdk.POINTER_MOTION_MASK | gtk.gdk.ENTER_NOTIFY_MASK | gtk.gdk.LEAVE_NOTIFY_MASK) - - self.imagen_size = 50 - self.image_pixmap = None - self.moon_stamp = gtk.gdk.pixbuf_new_from_file(os.path.join(MG.ICONOS,"moon.jpg")) - self.image = gtk.Image() - self.fixed = gtk.Fixed() - - self.hemisphere_view = _('Sur') - self.show_grid = False - - self.fixed.put(self.image, 0, 0) - - self.add(self.fixed) - self.show_all() - - self.anio, self.mes, self.dia, self.hora = anio, mes, d, hora - self.hoy = "%s-%s-%s %s" % (self.anio, self.mes, self.dia, self.hora) - if self.dia > 0: - self.ahora = time.mktime(time.strptime(self.hoy, MG.format)) - #self.data_model.update_moon_calculations(ahora) # para recalcular la fase - self.data_model = DataModel(self.ahora) - dias= [] - for d in calendar.day_name: - if d: dias.append(d) - meses= [] - for m in calendar.month_name: - if m: meses.append(m) - t = time.strptime(self.hoy, MG.format) - mes= meses[t.tm_mon -1] - dia= dias[t.tm_wday] - fecha= "%s %s de %s de %s" % (dia, self.dia, mes, self.anio) - self.set_tooltip(fecha) - label = gtk.Label(str(self.dia)) - label.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - self.fixed.put(label, 0, 0) - - self.connect("button_press_event", self.button_press) - self.connect("button_release_event", self.button_release) - self.connect("enter-notify-event", self.enter_notify_event) - self.connect("leave-notify-event", self.leave_notify_event) - - # --------------------------- EVENTOS -------------------------- - def button_release(self, widget, event): - pass - def leave_notify_event(self, widget, event): - pass - def enter_notify_event(self, widget, event): - pass - def button_press(self, widget, event): - if event.button == 1: - self.emit("clicked", event) - if event.button == 3: - self.emit("clickederecho", event) - # --------------------------- EVENTOS -------------------------- - - # --------------------------- SETEOS --------------------------- - def set_tooltip(self, texto): - tooltips = gtk.Tooltips() - tooltips.set_tip(self, texto, tip_private=None) - # --------------------------- SETEOS --------------------------- - - def toggle_grid_clicked(self, widget= None): - if self.show_grid == True: - self.show_grid = False - else: - self.show_grid = True - - def toggle_hemisphere_clicked(self, widget= None): - if self.hemisphere_view == _('Norte'): - self.hemisphere_view = _('Sur') - else: - self.hemisphere_view = _('Norte') - - def repaint(self, tamanioboton): - if tamanioboton != self.imagen_size: - self.imagen_size = tamanioboton - if self.dia > 0: - self.actualizar() - - def actualizar(self): - if self.dia <= 0: return - self.image_pixmap = gtk.gdk.Pixmap(self.window, self.imagen_size, self.imagen_size) - gc = self.image_pixmap.new_gc(foreground=MG.BACKGROUND) - self.image.set_from_pixmap(self.image_pixmap, None) - - self.image_pixmap.draw_rectangle(gc, True, 0, 0, self.imagen_size, self.imagen_size) - - # Create a 1bit shadow mask - mask_pixmap = gtk.gdk.Pixmap(None, self.imagen_size, self.imagen_size, depth=1) - kgc = mask_pixmap.new_gc(foreground=MG.BACKGROUND) - wgc = mask_pixmap.new_gc(foreground=MG.FOREGROUND) - - mask_pixmap.draw_rectangle(kgc, True, 0, 0, self.imagen_size, self.imagen_size) - mask_pixmap = self.draw_fase_moon(mask_pixmap, kgc, wgc) - maskgc = self.image_pixmap.new_gc(clip_mask=mask_pixmap) - - moon_pixbuf = self.moon_stamp.scale_simple(self.imagen_size, self.imagen_size, gtk.gdk.INTERP_BILINEAR) - - # Composite bright Moon image and semi-transparant Moon for shadow detail - dark_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.imagen_size, self.imagen_size) - dark_pixbuf.fill(0x00000000) - - uno = (self.data_model.next_lunar_eclipse_sec == -1 and self.data_model.last_lunar_eclipse_sec > 7200) - dos = (self.data_model.next_lunar_eclipse_sec > 7200 and self.data_model.last_lunar_eclipse_sec == -1) - tres = min([self.data_model.next_lunar_eclipse_sec, self.data_model.last_lunar_eclipse_sec]) > 7200 - - if uno or dos or tres: #print "Normal Moon phase render" - moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, 127) - self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) # parte oscura - self.image_pixmap.draw_pixbuf(maskgc, moon_pixbuf, 0, 0, 0, 0) # parte iluminada - - else: #print "Reddening eclipse effect, 2hrs (7200sec) before and after (by masking out green & blue)" - if self.data_model.next_lunar_eclipse_sec == -1: - eclipse_alpha = self.data_model.last_lunar_eclipse_sec / 7200.0 * 256 - elif self.data_model.last_lunar_eclipse_sec == -1: - eclipse_alpha = self.data_model.next_lunar_eclipse_sec / 7200.0 * 256 - else: - eclipse_alpha = min([self.data_model.next_lunar_eclipse_sec, - self.data_model.last_lunar_eclipse_sec]) / 7200.0 * 256 - - moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, - 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, int(196 - eclipse_alpha / 2)) - - self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) - - dark_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.imagen_size, self.imagen_size) - moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, - 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, int(eclipse_alpha)) - rgc = self.image_pixmap.new_gc(foreground=MG.BLUEGREENMASK, function=gtk.gdk.AND) - self.image_pixmap.draw_rectangle(rgc, True, 0, 0, self.imagen_size, self.imagen_size) - self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) - - if self.hemisphere_view == _('Sur'): - #print "Rotate final image for a view from Norte or Sur hemisphere" - rot_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.imagen_size, self.imagen_size) - rot_pixbuf.get_from_drawable(self.image_pixmap, self.image_pixmap.get_colormap(), 0, 0, 0, 0, -1, -1) - rot_pixbuf = rot_pixbuf.rotate_simple(gtk.gdk.PIXBUF_ROTATE_UPSIDEDOWN) - self.image_pixmap.draw_pixbuf(gc, rot_pixbuf, 0, 0, 0, 0) - - if self.show_grid: self.draw_grid(_("SNWE")) - else: - if self.show_grid: self.draw_grid(_("NSEW")) - - def draw_grid(self, compass_text): - # Draw Selenographic grid line data. - rgc = self.image_pixmap.new_gc(foreground=MG.RED) - bgc = self.image_pixmap.new_gc(foreground=MG.BLUE) - wgc = self.image_pixmap.new_gc(foreground=MG.FOREGROUND) - pango_layout = self.image.create_pango_layout("") - pango_layout.set_text("0°") - self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, self.imagen_size/2, 24, 22) - self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, self.imagen_size/2, pango_layout) - pango_layout.set_text("30°") - self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.5), 36, 22) - self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.5), 36, 22) - self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.5), pango_layout) - self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.5), pango_layout) - pango_layout.set_text("60°") - self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.15), 36, 22) - self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.85), 36, 22) - self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.15), pango_layout) - self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.85), pango_layout) - pango_layout.set_text("30°") - self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 0.48) + 2, self.imagen_size/2, 36, 22) - self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 1.52) + 2, self.imagen_size/2, 36, 22) - self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 0.48) + 2, self.imagen_size/2, pango_layout) - self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 1.52) + 2, self.imagen_size/2, pango_layout) - pango_layout.set_text("60°") - self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 0.15) + 2, self.imagen_size/2, 36, 22) - self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 1.85) + 2, self.imagen_size/2, 36, 22) - self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 0.15) + 2, self.imagen_size/2, pango_layout) - self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 1.85) + 2, self.imagen_size/2, pango_layout) - for i in (-1, 0, 1): - self.image_pixmap.draw_line(rgc, self.imagen_size/2 + i, 0, self.imagen_size/2 + i, self.imagen_size) - self.image_pixmap.draw_arc(rgc, False, int(self.imagen_size/2 * 0.15) + i, 0, - self.imagen_size - int(self.imagen_size * 0.15), self.imagen_size, 0, 360*64) - self.image_pixmap.draw_arc(rgc, False, int(self.imagen_size/2 * 0.48) + i, 0, - self.imagen_size - int(self.imagen_size * 0.48) , self.imagen_size, 0, 360*64) - for i in (-1, 0, 1): - self.image_pixmap.draw_line(bgc, 0, self.imagen_size/2 + i, self.imagen_size, self.imagen_size/2 + i) - self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 0.5) + i, - self.imagen_size - int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 0.5) + i) - self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 1.5) + i, - self.imagen_size - int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 1.5) + i) - self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 0.15) + i, - self.imagen_size - int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 0.15) + i) - self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 1.85) + i, - self.imagen_size - int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 1.85) + i) - - pango_layout.set_text(_("Latitude")) - self.image_pixmap.draw_layout(bgc, 15, self.imagen_size - 48 - 15, pango_layout) - pango_layout.set_text(_("Longitude")) - self.image_pixmap.draw_layout(rgc, 15, self.imagen_size - 24 - 15, pango_layout) - - # Compass - # TODO: fix string index to support multi-byte texts - for i in (-1, 0, 1): - self.image_pixmap.draw_line(rgc, 22 + 15, 48 + 15 + i, 68 + 15, 48 + 15 + i) - for i in (-1, 0, 1): - self.image_pixmap.draw_line(bgc, 45 + 15 + i, 24 + 15, 45 + 15 + i, 68 + 15) - pango_layout.set_text(compass_text[0]) - self.image_pixmap.draw_layout(bgc, 38 + 15, 15, pango_layout) - pango_layout.set_text(compass_text[1]) - self.image_pixmap.draw_layout(bgc, 38 + 15, 72 + 15, pango_layout) - pango_layout.set_text(compass_text[2]) - self.image_pixmap.draw_layout(rgc, 72 + 15, 36 + 15, pango_layout) - pango_layout.set_text(compass_text[3]) - self.image_pixmap.draw_layout(rgc, 15, 36 + 15, pango_layout) - - def draw_fase_moon(self, mask_pixmap, kgc, wgc): - if self.data_model.phase_of_moon <= .25: - #print "New Moon to First Quarter" - phase_shadow_adjust = self.data_model.phase_of_moon - abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) - arc_scale = int(self.imagen_size * (1 - (phase_shadow_adjust * 4))) - mask_pixmap.draw_rectangle(wgc, True, self.imagen_size/2 + 1, 0, self.imagen_size/2, self.imagen_size - 1) - mask_pixmap.draw_arc(kgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 17280, 11520) - elif self.data_model.phase_of_moon <= .5: - #print "First Quarter to Full Moon" - phase_shadow_adjust = self.data_model.phase_of_moon + abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) - arc_scale = int(self.imagen_size * ((phase_shadow_adjust - .25) * 4)) - mask_pixmap.draw_rectangle(wgc, True, self.imagen_size/2, 0, self.imagen_size/2, self.imagen_size) - mask_pixmap.draw_arc(wgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 5760, 11520) - elif self.data_model.phase_of_moon <= .75: - #print "Full Moon to Last Quarter" - phase_shadow_adjust = self.data_model.phase_of_moon - abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) - arc_scale = int(self.imagen_size * (1 - ((phase_shadow_adjust - .5) * 4))) - mask_pixmap.draw_rectangle(wgc, True, 0, 0, self.imagen_size/2 + 1, self.imagen_size) - mask_pixmap.draw_arc(wgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 17280, 11520) - else: - #print "Last Quarter to New Moon" - phase_shadow_adjust = self.data_model.phase_of_moon + abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) - arc_scale = int(self.imagen_size * ((phase_shadow_adjust - .75) * 4)) - mask_pixmap.draw_rectangle(wgc, True, 0, 0, self.imagen_size/2, self.imagen_size) # mitad de luna blanca - mask_pixmap.draw_arc(kgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 5760, 11520) - return mask_pixmap + + __gsignals__ = { + "clicked":(gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, )), + "clickederecho":(gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))} + + def __init__(self, anio, mes, d, hora): + + gtk.EventBox.__init__(self) + + self.set_visible_window(True) + self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.add_events( + gtk.gdk.BUTTON_PRESS_MASK | + gtk.gdk.BUTTON_RELEASE_MASK | + gtk.gdk.POINTER_MOTION_MASK | + gtk.gdk.ENTER_NOTIFY_MASK | + gtk.gdk.LEAVE_NOTIFY_MASK) + + self.imagen_size = 50 + self.image_pixmap = None + icono = os.path.join(MG.ICONOS,"moon.jpg") + self.moon_stamp = gtk.gdk.pixbuf_new_from_file(icono) + self.image = gtk.Image() + self.fixed = gtk.Fixed() + + self.hemisphere_view = _('Sur') + self.show_grid = False + + self.fixed.put(self.image, 0, 0) + + self.add(self.fixed) + self.show_all() + + self.anio, self.mes, self.dia, self.hora = anio, mes, d, hora + self.hoy = "%s-%s-%s %s" % (self.anio, self.mes, self.dia, self.hora) + + if self.dia > 0: + self.ahora = time.mktime(time.strptime(self.hoy, MG.format)) + #self.data_model.update_moon_calculations(ahora) # para recalcular la fase + self.data_model = DataModel(self.ahora) + dias= [] + + for d in calendar.day_name: + if d: dias.append(d) + + meses= [] + + for m in calendar.month_name: + if m: meses.append(m) + + t = time.strptime(self.hoy, MG.format) + mes= meses[t.tm_mon -1] + dia= dias[t.tm_wday] + fecha= "%s %s de %s de %s" % (dia, self.dia, mes, self.anio) + self.set_tooltip(fecha) + label = gtk.Label(str(self.dia)) + label.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + self.fixed.put(label, 0, 0) + + self.connect("button_press_event", self.button_press) + self.connect("button_release_event", self.button_release) + self.connect("enter-notify-event", self.enter_notify_event) + self.connect("leave-notify-event", self.leave_notify_event) + + # --------------------------- EVENTOS -------------------------- + def button_release(self, widget, event): + pass + + def leave_notify_event(self, widget, event): + pass + + def enter_notify_event(self, widget, event): + pass + + def button_press(self, widget, event): + + if event.button == 1: + self.emit("clicked", event) + + if event.button == 3: + self.emit("clickederecho", event) + # --------------------------- EVENTOS -------------------------- + + # --------------------------- SETEOS --------------------------- + def set_tooltip(self, texto): + + tooltips = gtk.Tooltips() + tooltips.set_tip(self, texto, tip_private=None) + # --------------------------- SETEOS --------------------------- + + def toggle_grid_clicked(self, widget= None): + + if self.show_grid == True: + self.show_grid = False + else: + self.show_grid = True + + def toggle_hemisphere_clicked(self, widget= None): + + if self.hemisphere_view == _('Norte'): + self.hemisphere_view = _('Sur') + + else: + self.hemisphere_view = _('Norte') + + def repaint(self, tamanioboton): + + if tamanioboton != self.imagen_size: + self.imagen_size = tamanioboton + + if self.dia > 0: + self.actualizar() + + def actualizar(self): + + if self.dia <= 0: return + + self.image_pixmap = gtk.gdk.Pixmap(self.window, self.imagen_size, self.imagen_size) + gc = self.image_pixmap.new_gc(foreground=MG.BACKGROUND) + self.image.set_from_pixmap(self.image_pixmap, None) + + self.image_pixmap.draw_rectangle(gc, True, 0, 0, self.imagen_size, self.imagen_size) + + # Create a 1bit shadow mask + mask_pixmap = gtk.gdk.Pixmap(None, self.imagen_size, self.imagen_size, depth=1) + kgc = mask_pixmap.new_gc(foreground=MG.BACKGROUND) + wgc = mask_pixmap.new_gc(foreground=MG.FOREGROUND) + + mask_pixmap.draw_rectangle(kgc, True, 0, 0, self.imagen_size, self.imagen_size) + mask_pixmap = self.draw_fase_moon(mask_pixmap, kgc, wgc) + maskgc = self.image_pixmap.new_gc(clip_mask=mask_pixmap) + + moon_pixbuf = self.moon_stamp.scale_simple(self.imagen_size, self.imagen_size, gtk.gdk.INTERP_BILINEAR) + + # Composite bright Moon image and semi-transparant Moon for shadow detail + dark_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.imagen_size, self.imagen_size) + dark_pixbuf.fill(0x00000000) + + uno = (self.data_model.next_lunar_eclipse_sec == -1 and self.data_model.last_lunar_eclipse_sec > 7200) + dos = (self.data_model.next_lunar_eclipse_sec > 7200 and self.data_model.last_lunar_eclipse_sec == -1) + tres = min([self.data_model.next_lunar_eclipse_sec, self.data_model.last_lunar_eclipse_sec]) > 7200 + + if uno or dos or tres: #print "Normal Moon phase render" + moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, 127) + self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) # parte oscura + self.image_pixmap.draw_pixbuf(maskgc, moon_pixbuf, 0, 0, 0, 0) # parte iluminada + + else: #print "Reddening eclipse effect, 2hrs (7200sec) before and after (by masking out green & blue)" + if self.data_model.next_lunar_eclipse_sec == -1: + eclipse_alpha = self.data_model.last_lunar_eclipse_sec / 7200.0 * 256 + + elif self.data_model.last_lunar_eclipse_sec == -1: + eclipse_alpha = self.data_model.next_lunar_eclipse_sec / 7200.0 * 256 + + else: + eclipse_alpha = min([self.data_model.next_lunar_eclipse_sec, + self.data_model.last_lunar_eclipse_sec]) / 7200.0 * 256 + + moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, + 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, int(196 - eclipse_alpha / 2)) + + self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) + + dark_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, self.imagen_size, self.imagen_size) + moon_pixbuf.composite(dark_pixbuf, 0, 0, self.imagen_size, self.imagen_size, + 0, 0, 1, 1, gtk.gdk.INTERP_BILINEAR, int(eclipse_alpha)) + rgc = self.image_pixmap.new_gc(foreground=MG.BLUEGREENMASK, function=gtk.gdk.AND) + self.image_pixmap.draw_rectangle(rgc, True, 0, 0, self.imagen_size, self.imagen_size) + self.image_pixmap.draw_pixbuf(gc, dark_pixbuf, 0, 0, 0, 0) + + if self.hemisphere_view == _('Sur'): + #print "Rotate final image for a view from Norte or Sur hemisphere" + rot_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, self.imagen_size, self.imagen_size) + rot_pixbuf.get_from_drawable(self.image_pixmap, self.image_pixmap.get_colormap(), 0, 0, 0, 0, -1, -1) + rot_pixbuf = rot_pixbuf.rotate_simple(gtk.gdk.PIXBUF_ROTATE_UPSIDEDOWN) + self.image_pixmap.draw_pixbuf(gc, rot_pixbuf, 0, 0, 0, 0) + + if self.show_grid: self.draw_grid(_("SNWE")) + + else: + if self.show_grid: self.draw_grid(_("NSEW")) + + def draw_grid(self, compass_text): + + # Draw Selenographic grid line data. + rgc = self.image_pixmap.new_gc(foreground=MG.RED) + bgc = self.image_pixmap.new_gc(foreground=MG.BLUE) + wgc = self.image_pixmap.new_gc(foreground=MG.FOREGROUND) + pango_layout = self.image.create_pango_layout("") + pango_layout.set_text("0°") + self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, self.imagen_size/2, 24, 22) + self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, self.imagen_size/2, pango_layout) + pango_layout.set_text("30°") + self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.5), 36, 22) + self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.5), 36, 22) + self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.5), pango_layout) + self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.5), pango_layout) + pango_layout.set_text("60°") + self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.15), 36, 22) + self.image_pixmap.draw_rectangle(bgc, True, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.85), 36, 22) + self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 0.15), pango_layout) + self.image_pixmap.draw_layout(wgc, self.imagen_size/2 + 2, int(self.imagen_size/2 * 1.85), pango_layout) + pango_layout.set_text("30°") + self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 0.48) + 2, self.imagen_size/2, 36, 22) + self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 1.52) + 2, self.imagen_size/2, 36, 22) + self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 0.48) + 2, self.imagen_size/2, pango_layout) + self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 1.52) + 2, self.imagen_size/2, pango_layout) + pango_layout.set_text("60°") + self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 0.15) + 2, self.imagen_size/2, 36, 22) + self.image_pixmap.draw_rectangle(rgc, True, int(self.imagen_size/2 * 1.85) + 2, self.imagen_size/2, 36, 22) + self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 0.15) + 2, self.imagen_size/2, pango_layout) + self.image_pixmap.draw_layout(wgc, int(self.imagen_size/2 * 1.85) + 2, self.imagen_size/2, pango_layout) + + for i in (-1, 0, 1): + self.image_pixmap.draw_line(rgc, self.imagen_size/2 + i, 0, self.imagen_size/2 + i, self.imagen_size) + self.image_pixmap.draw_arc(rgc, False, int(self.imagen_size/2 * 0.15) + i, 0, + self.imagen_size - int(self.imagen_size * 0.15), self.imagen_size, 0, 360*64) + self.image_pixmap.draw_arc(rgc, False, int(self.imagen_size/2 * 0.48) + i, 0, + self.imagen_size - int(self.imagen_size * 0.48) , self.imagen_size, 0, 360*64) + + for i in (-1, 0, 1): + self.image_pixmap.draw_line(bgc, 0, self.imagen_size/2 + i, self.imagen_size, self.imagen_size/2 + i) + self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 0.5) + i, + self.imagen_size - int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 0.5) + i) + self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 1.5) + i, + self.imagen_size - int(self.imagen_size/2 * 0.15), int(self.imagen_size/2 * 1.5) + i) + self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 0.15) + i, + self.imagen_size - int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 0.15) + i) + self.image_pixmap.draw_line(bgc, int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 1.85) + i, + self.imagen_size - int(self.imagen_size/2 * 0.5), int(self.imagen_size/2 * 1.85) + i) + + pango_layout.set_text(_("Latitude")) + self.image_pixmap.draw_layout(bgc, 15, self.imagen_size - 48 - 15, pango_layout) + pango_layout.set_text(_("Longitude")) + self.image_pixmap.draw_layout(rgc, 15, self.imagen_size - 24 - 15, pango_layout) + + # Compass + # TODO: fix string index to support multi-byte texts + for i in (-1, 0, 1): + self.image_pixmap.draw_line(rgc, 22 + 15, 48 + 15 + i, 68 + 15, 48 + 15 + i) + + for i in (-1, 0, 1): + self.image_pixmap.draw_line(bgc, 45 + 15 + i, 24 + 15, 45 + 15 + i, 68 + 15) + + pango_layout.set_text(compass_text[0]) + self.image_pixmap.draw_layout(bgc, 38 + 15, 15, pango_layout) + pango_layout.set_text(compass_text[1]) + self.image_pixmap.draw_layout(bgc, 38 + 15, 72 + 15, pango_layout) + pango_layout.set_text(compass_text[2]) + self.image_pixmap.draw_layout(rgc, 72 + 15, 36 + 15, pango_layout) + pango_layout.set_text(compass_text[3]) + self.image_pixmap.draw_layout(rgc, 15, 36 + 15, pango_layout) + + def draw_fase_moon(self, mask_pixmap, kgc, wgc): + + if self.data_model.phase_of_moon <= .25: + #print "New Moon to First Quarter" + phase_shadow_adjust = self.data_model.phase_of_moon - abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) + arc_scale = int(self.imagen_size * (1 - (phase_shadow_adjust * 4))) + mask_pixmap.draw_rectangle(wgc, True, self.imagen_size/2 + 1, 0, self.imagen_size/2, self.imagen_size - 1) + mask_pixmap.draw_arc(kgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 17280, 11520) + + elif self.data_model.phase_of_moon <= .5: + #print "First Quarter to Full Moon" + phase_shadow_adjust = self.data_model.phase_of_moon + abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) + arc_scale = int(self.imagen_size * ((phase_shadow_adjust - .25) * 4)) + mask_pixmap.draw_rectangle(wgc, True, self.imagen_size/2, 0, self.imagen_size/2, self.imagen_size) + mask_pixmap.draw_arc(wgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 5760, 11520) + + elif self.data_model.phase_of_moon <= .75: + #print "Full Moon to Last Quarter" + phase_shadow_adjust = self.data_model.phase_of_moon - abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) + arc_scale = int(self.imagen_size * (1 - ((phase_shadow_adjust - .5) * 4))) + mask_pixmap.draw_rectangle(wgc, True, 0, 0, self.imagen_size/2 + 1, self.imagen_size) + mask_pixmap.draw_arc(wgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 17280, 11520) + + else: + #print "Last Quarter to New Moon" + phase_shadow_adjust = self.data_model.phase_of_moon + abs(math.sin(self.data_model.phase_of_moon * math.pi * 4) / 18.0) + arc_scale = int(self.imagen_size * ((phase_shadow_adjust - .75) * 4)) + mask_pixmap.draw_rectangle(wgc, True, 0, 0, self.imagen_size/2, self.imagen_size) # mitad de luna blanca + mask_pixmap.draw_arc(kgc, True, self.imagen_size/2 - int(arc_scale / 2), 0, arc_scale, self.imagen_size, 5760, 11520) + + return mask_pixmap class DataModel(): + def __init__(self, ahora): - self.ahora = ahora + + self.ahora = ahora self.new_moon_array = MG.new_moon_array self.full_moon_array = MG.full_moon_array self.first_quarter_array = MG.first_quarter_array @@ -307,12 +352,13 @@ class DataModel(): self.days_until_solar_eclipse = None self.next_solar_eclipse_date = None - self.phase_of_moon = None + self.phase_of_moon = None - self.update_moon_calculations(self.ahora) + self.update_moon_calculations(self.ahora) def update_moon_calculations(self, the_date): - self.ahora = the_date + + self.ahora = the_date # Generate all Moon data ready for display. last_new_moon_sec = MG.last_new_moon_sec_at_time(the_date) next_new_moon_sec = MG.next_new_moon_sec_at_time(the_date) @@ -321,7 +367,7 @@ class DataModel(): last_quarter_moon_sec = MG.last_quarter_moon_sec_at_time(the_date) next_quarter_moon_sec = MG.next_quarter_moon_sec_at_time(the_date) - self.phase_of_moon = MG.RecalcularFase(the_date) + self.phase_of_moon = MG.RecalcularFase(the_date) # Generate interesting human readable values self.percent_of_full_moon = (math.cos(((self.phase_of_moon + .5) / .5 * math.pi)) + 1) * .5 @@ -349,217 +395,259 @@ class DataModel(): selenographic_tmp = 270 + (self.phase_of_moon * 360) if selenographic_tmp >= 360: selenographic_tmp -= 360 + if selenographic_tmp >= 270: selenographic_tmp -= 360 + elif selenographic_tmp >= 180: selenographic_tmp -= 180 + elif selenographic_tmp >= 90: selenographic_tmp -= 180 + selenographic_tmp = -selenographic_tmp + if selenographic_tmp < 0: self.west_or_east = _("west") + else: self.west_or_east = _("east") + self.selenographic_deg = abs(selenographic_tmp) + if self.phase_of_moon >= .5: self.rise_or_set = _("Sunset") + else: self.rise_or_set = _("Sunrise") def moon_phase_name(self, phase_of_moon): + # Return the moon image name for a given phase value. if phase_of_moon >= 0 and phase_of_moon < 0.025: return _("New Moon") + elif phase_of_moon >= 0.025 and phase_of_moon < 0.225: return _("Waxing Crescent") + elif phase_of_moon >= 0.225 and phase_of_moon < 0.275: return _("First Quarter") + elif phase_of_moon >= 0.275 and phase_of_moon < 0.475: return _("Waxing Gibbous") + elif phase_of_moon >= 0.475 and phase_of_moon < 0.525: return _("Full Moon") + elif phase_of_moon >= 0.525 and phase_of_moon < 0.735: return _("Waning Gibbous") + elif phase_of_moon >= 0.735 and phase_of_moon < 0.775: return _("Last Quarter") + elif phase_of_moon >= 0.775 and phase_of_moon < 0.975: return _("Waning Crescent") + else: return _("New Moon") class MoonCalendar(gtk.AspectFrame): - def __init__(self): - gtk.AspectFrame.__init__(self) - self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.anio = None - self.mes = None - self.fecha = None - self.hora = None - self.semanas = None - - self.label_mes = None - self.matriz = None - - self.layout() - - def layout(self): - base = gtk.VBox() - caja_control = gtk.HBox() - - view_tool_bar = gtk.Toolbar() - view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'flecha-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.anterior, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - caja_control.pack_start(view_tool_bar, False, False, 0) - - self.label_mes = gtk.Label() - self.label_mes.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.label_mes.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - self.label_mes.show() - - caja_control.pack_start(self.label_mes, True, True, 0) - - view_tool_bar = gtk.Toolbar() - view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'flecha-ico.svg'), 32, 32) - pixbuf= pixbuf.flip(1) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.siguiente, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - caja_control.pack_end(view_tool_bar, False, False, 0) - - caja_dias = gtk.HBox() - for dia in [_("Lun"), _("Mar"), _("Mie"), _("Jue"), _("Vie"), _("Sáb"), _("Dom")]: - label = gtk.Label(dia) - label.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - caja_dias.pack_start(label, True, True, 0) - - self.matriz = MatrizMoonCalendar() - - base.pack_start(caja_control, False, False, 0) - base.pack_start(caja_dias, False, False, 5) - base.pack_start(self.matriz, True, True, 5) - - self.add(base) - self.show_all() - - def anterior(self, widget= None): - if self.mes == 1: - self.mes = 12 - self.anio -= 1 - else: - self.mes -= 1 - self.set_mes(self.anio, self.mes, self.fecha, self.hora) - self.show_all() - - def siguiente(self, widget= None): - if self.mes == 12: - self.mes = 1 - self.anio += 1 - else: - self.mes += 1 - self.set_mes(self.anio, self.mes, self.fecha, self.hora) - self.show_all() - - def set_mes(self, anio, mes, fecha, hora): - self.anio, self.mes, self.fecha, self.hora = (anio, mes, 1, hora) - self.matriz.set_mes(self.anio, self.mes, self.fecha, self.hora) - dias= [] - for d in calendar.day_name: - if d: dias.append(d) - self.hoy = "%s-%s-%s %s" % (self.matriz.anio, self.matriz.mes, self.matriz.fecha, self.matriz.hora) - meses= [] - for m in calendar.month_name: - if m: meses.append(m) - t = time.strptime(self.hoy, MG.format) - mes= meses[t.tm_mon -1] - dia= dias[t.tm_wday] - self.label_mes.set_text("%s %s" % (_(mes), self.matriz.anio)) - - def toggle_grid_clicked(self, widget= None, actualizar= False): - for linea in self.matriz.calendarbuttons: - for boton in linea: - boton.toggle_grid_clicked() - if actualizar: boton.actualizar() - - def toggle_hemisphere_clicked(self, widget= None, actualizar= False): - for linea in self.matriz.calendarbuttons: - for boton in linea: - boton.toggle_hemisphere_clicked() - if actualizar: boton.actualizar() + + def __init__(self): + + gtk.AspectFrame.__init__(self) + + self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.anio = None + self.mes = None + self.fecha = None + self.hora = None + self.semanas = None -class MatrizMoonCalendar(gtk.EventBox): - def __init__(self): - gtk.EventBox.__init__(self) - self.set_visible_window(True) - self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.fixed = gtk.Fixed() - self.add(self.fixed) - self.show_all() - - self.anio = None - self.mes = None - self.fecha = None - self.hora = None - self.semanas = [] - - self.fixes = [] - self.calendarbuttons = [] - self.tamanioboton = 0 - self.connect("expose_event", self.repaint) - - def repaint(self, widget= None, event= None): - if not self.fixes: return - x,y,w,h= self.get_allocation() - anchoboton = w/len(self.fixes[0]) - altoboton = h/len(self.fixes) - tamanioboton = min( [anchoboton,altoboton] ) - if self.tamanioboton != tamanioboton: - self.tamanioboton = tamanioboton - posy = 0 - for fixed in self.fixes: - self.fixed.move(fixed, 0, posy) - posy += self.tamanioboton - posx = 0 - for fixed in self.fixes: - for boton in self.calendarbuttons[self.fixes.index(fixed)]: - fixed.move(boton, posx, 0) - boton.repaint(self.tamanioboton) - posx += self.tamanioboton - posx = 0 - - def set_mes(self, anio, mes, fecha, hora): - self.anio, self.mes, self.fecha, self.hora = anio, mes, fecha, hora - self.fixes = [] - self.calendarbuttons = [] - self.semanas = MG.get_semanas_del_mes(anio, mes) - for child in self.fixed.get_children(): - self.fixed.remove(child) - child.destroy() - for sem in self.semanas: - listadias = [] - fixed = gtk.Fixed() - self.fixes.append(fixed) - self.fixed.put(fixed, 0,0) - for dia in sem: - boton = CalendarButton(self.anio, self.mes, dia, self.hora) - listadias.append(boton) - fixed.put(boton, 0,0) - self.calendarbuttons.append(listadias) + self.label_mes = None + self.matriz = None + + self.layout() + + def layout(self): + + base = gtk.VBox() + caja_control = gtk.HBox() + + view_tool_bar = gtk.Toolbar() + view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'flecha-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.anterior, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + caja_control.pack_start(view_tool_bar, False, False, 0) + + self.label_mes = gtk.Label() + self.label_mes.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.label_mes.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + self.label_mes.show() + + caja_control.pack_start(self.label_mes, True, True, 0) + + view_tool_bar = gtk.Toolbar() + view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'flecha-ico.svg'), 32, 32) + pixbuf= pixbuf.flip(1) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.siguiente, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + caja_control.pack_end(view_tool_bar, False, False, 0) + + caja_dias = gtk.HBox() + + for dia in [_("Lun"), _("Mar"), _("Mie"), _("Jue"), _("Vie"), _("Sáb"), _("Dom")]: + label = gtk.Label(dia) + label.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + caja_dias.pack_start(label, True, True, 0) + + self.matriz = MatrizMoonCalendar() + + base.pack_start(caja_control, False, False, 0) + base.pack_start(caja_dias, False, False, 5) + base.pack_start(self.matriz, True, True, 5) + + self.add(base) + self.show_all() + + def anterior(self, widget= None): + + if self.mes == 1: + self.mes = 12 + self.anio -= 1 + + else: + self.mes -= 1 + + self.set_mes(self.anio, self.mes, self.fecha, self.hora) + self.show_all() + + def siguiente(self, widget= None): + + if self.mes == 12: + self.mes = 1 + self.anio += 1 + + else: + self.mes += 1 + + self.set_mes(self.anio, self.mes, self.fecha, self.hora) + self.show_all() + + def set_mes(self, anio, mes, fecha, hora): + + self.anio, self.mes, self.fecha, self.hora = (anio, mes, 1, hora) + self.matriz.set_mes(self.anio, self.mes, self.fecha, self.hora) + dias= [] + + for d in calendar.day_name: + if d: dias.append(d) + + self.hoy = "%s-%s-%s %s" % (self.matriz.anio, self.matriz.mes, self.matriz.fecha, self.matriz.hora) + meses= [] + + for m in calendar.month_name: + if m: meses.append(m) + + t = time.strptime(self.hoy, MG.format) + mes= meses[t.tm_mon -1] + dia= dias[t.tm_wday] + self.label_mes.set_text("%s %s" % (_(mes), self.matriz.anio)) + + def toggle_grid_clicked(self, widget= None, actualizar= False): + + for linea in self.matriz.calendarbuttons: + + for boton in linea: + boton.toggle_grid_clicked() + if actualizar: boton.actualizar() + + def toggle_hemisphere_clicked(self, widget= None, actualizar= False): + + for linea in self.matriz.calendarbuttons: + for boton in linea: + boton.toggle_hemisphere_clicked() + if actualizar: boton.actualizar() +class MatrizMoonCalendar(gtk.EventBox): + + def __init__(self): + + gtk.EventBox.__init__(self) + + self.set_visible_window(True) + self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.fixed = gtk.Fixed() + self.add(self.fixed) + self.show_all() + + self.anio = None + self.mes = None + self.fecha = None + self.hora = None + self.semanas = [] + + self.fixes = [] + self.calendarbuttons = [] + self.tamanioboton = 0 + self.connect("expose_event", self.repaint) + + def repaint(self, widget= None, event= None): + + if not self.fixes: return + x,y,w,h= self.get_allocation() + anchoboton = w/len(self.fixes[0]) + altoboton = h/len(self.fixes) + tamanioboton = min( [anchoboton,altoboton] ) + if self.tamanioboton != tamanioboton: + self.tamanioboton = tamanioboton + posy = 0 + for fixed in self.fixes: + self.fixed.move(fixed, 0, posy) + posy += self.tamanioboton + posx = 0 + for fixed in self.fixes: + for boton in self.calendarbuttons[self.fixes.index(fixed)]: + fixed.move(boton, posx, 0) + boton.repaint(self.tamanioboton) + posx += self.tamanioboton + posx = 0 + + def set_mes(self, anio, mes, fecha, hora): + + self.anio, self.mes, self.fecha, self.hora = anio, mes, fecha, hora + self.fixes = [] + self.calendarbuttons = [] + self.semanas = MG.get_semanas_del_mes(anio, mes) + for child in self.fixed.get_children(): + self.fixed.remove(child) + child.destroy() + for sem in self.semanas: + listadias = [] + fixed = gtk.Fixed() + self.fixes.append(fixed) + self.fixed.put(fixed, 0,0) + for dia in sem: + boton = CalendarButton(self.anio, self.mes, dia, self.hora) + listadias.append(boton) + fixed.put(boton, 0,0) + self.calendarbuttons.append(listadias) +
\ No newline at end of file diff --git a/SugarMoonActivity.py b/SugarMoonActivity.py index 6637606..0c21693 100644 --- a/SugarMoonActivity.py +++ b/SugarMoonActivity.py @@ -48,297 +48,311 @@ except (ImportError, AttributeError): import simplejson as json class MoonActivity(activity.Activity): - def __init__(self, handle): - activity.Activity.__init__(self, handle, True) - self.set_title(_("Luna")) - self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.main_view = None - self.mooncalendar = None - self.info_panel = None - self.info = None - self.luna_hoy = None - self.label_emisferio = None - self.aspectframe = None - self.bufferinfo = None - - self.activity_state = {} - self.max_participants = 1 - - self.set_layout() - - self.show_all() - self.realize() - self.maximize() - - self.connect("delete_event", self.delete_event) - self.luna_hoy.connect("expose_event", self.repaint) - - self.actualizador = gobject.timeout_add(1000, self.handle) - - def set_layout(self): - anio, mes, fecha, hora = MG.get_date_time_now() - self.luna_hoy = CalendarButton(anio, mes, fecha, hora) - self.mooncalendar = MoonCalendar() - self.aspectframe = gtk.AspectFrame() - self.aspectframe.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.aspectframe.add(self.luna_hoy) - - cajabase = gtk.VBox() - self.main_view = gtk.HBox() - cajabase.pack_end(self.main_view, True, True, 5) - - try: # Sugar 86 en adelante - from sugar.graphics.toolbarbox import ToolbarBox - from sugar.activity.widgets import StopButton - from sugar.activity.widgets import ActivityToolbarButton - - toolbox = ToolbarBox() - activity_button = ActivityToolbarButton(self) - activity_button.show() - toolbox.toolbar.insert(activity_button, 0) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - toolbox.toolbar.insert(boton, -1) - boton.connect("clicked", self.toggle_grid_clicked) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - toolbox.toolbar.insert(boton, -1) - boton.connect("clicked", self.toggle_hemisphere_clicked) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - toolbox.toolbar.insert(boton, -1) - boton.connect("clicked", self.switch_calendar_luna) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.label_emisferio = gtk.Label() - item = gtk.ToolItem() - item.add(self.label_emisferio) - toolbox.toolbar.insert(item, -1) - self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - self.label_emisferio.show() - - separator = gtk.SeparatorToolItem() - separator.props.draw = False - separator.set_size_request(0, -1) - separator.set_expand(True) - toolbox.toolbar.insert(separator, -1) - - toolbox.toolbar.insert(StopButton(self), -1) - - self.set_toolbar_box(toolbox) - toolbox.show_all() - - except: # Hasta Sugar 84 - view_tool_bar = gtk.Toolbar() - view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.toggle_grid_clicked, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", _(""), "",boton, self.toggle_hemisphere_clicked, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - boton = gtk.ToggleToolButton() - pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) - imagen = gtk.Image() - imagen.set_from_pixbuf(pixbuf) - boton.set_icon_widget(imagen) - imagen.show() - boton.show() - view_tool_bar.append_item("", "", "",boton, self.switch_calendar_luna, user_data=None) - boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - - self.label_emisferio = gtk.Label() - view_tool_bar.append_widget(self.label_emisferio, None, None) - self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) - self.label_emisferio.show() - - view_tool_bar.show_all() - toolbox = activity.ActivityToolbox(self) - toolbox.add_toolbar(_("Luna"), view_tool_bar) - self.set_toolbox(toolbox) - toolbox.show() - - info_scroll = gtk.ScrolledWindow() - info_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) - self.info_panel = gtk.VBox() - self.info = gtk.TextView() - self.info.set_property("sensitive", False) - self.info.set_border_window_size(gtk.TEXT_WINDOW_TOP, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 10) - self.info.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 10) - self.info_panel.pack_start(self.info, False, False, 0) - info_scroll.add_with_viewport(self.info_panel) - - event = gtk.EventBox() - event.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) - event.add(self.aspectframe) - self.main_view.pack_start(info_scroll, False, False, 5) - self.main_view.pack_end(event, True, True, 5) - self.set_canvas(cajabase) - - self.bufferinfo = gtk.TextBuffer() - self.info.set_buffer(self.bufferinfo) - self.mooncalendar.set_mes(anio, mes, fecha, hora) - self.update_text_information_view() - - self.activity_state['hemisphereView'] = self.luna_hoy.hemisphere_view - self.activity_state['showGrid'] = self.luna_hoy.show_grid - self.read_and_parse_prefs(os.environ['SUGAR_ACTIVITY_ROOT'] + '/data/defaults') - - def toggle_grid_clicked(self, widget= None): - self.luna_hoy.toggle_grid_clicked() - self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) - - def toggle_hemisphere_clicked(self, widget= None): - self.luna_hoy.toggle_hemisphere_clicked() - self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) - - def switch_calendar_luna(self, widget): - if self.mooncalendar in self.aspectframe.get_children(): - self.aspectframe.remove(self.mooncalendar) - self.aspectframe.add(self.luna_hoy) - self.luna_hoy.show_all() - elif self.luna_hoy in self.aspectframe.get_children(): - self.aspectframe.remove(self.luna_hoy) - self.aspectframe.add(self.mooncalendar) - self.mooncalendar.show_all() - self.show_all() - self.realize() - - def handle(self): - self.update_text_information_view() - if self.luna_hoy in self.aspectframe.get_children(): - self.luna_hoy.actualizar() - return True - - def repaint(self, widget= None, event= None): - x,y,w,h= self.luna_hoy.get_allocation() - anchoboton, altoboton = (w,h) - tamanioboton = min( [anchoboton,altoboton] ) - self.luna_hoy.repaint(tamanioboton) - - def delete_event(self, widget, event, data=None): - sys.exit(0) - return False - - def update_text_information_view(self): - anio, mes, fecha, hora = MG.get_date_time_now() - hoy = "%s-%s-%s %s" % (anio, mes, fecha, hora) - ahora = time.mktime(time.strptime(hoy, MG.format)) - - self.luna_hoy.data_model.update_moon_calculations(ahora) - - information = "" - information += "%s:\n\n" % (_("Today's Moon Information")) - information += "%s\n\n" % (MG.get_date_time()) - information += "%s:\n%s\n\n" % (_("Phase"), self.luna_hoy.data_model.moon_phase_name(self.luna_hoy.data_model.phase_of_moon)) - information += "%s:\n%.2f (%s)\n\n" % (_("Julian Date"), self.luna_hoy.data_model.julian_date, _("astronomical")) - - information += "%s:\n" % (_("Age")) - dias = self.luna_hoy.data_model.days_old - horas = self.luna_hoy.data_model.hours_old - minutos = self.luna_hoy.data_model.minutes_old - information += "%i %s, %i %s, %i %s.\n\n" % (dias, _("days"), horas, _("hours"), minutos, _("minutes")) - - phase = self.luna_hoy.data_model.phase_of_moon * 100 - lunation = self.luna_hoy.data_model.lunation - information += "%s:\n" % (_("Lunation")) - information += "%.2f%s %s %d.\n\n" % (phase, "%", _("through lunation"), lunation) - - information += "%s:\n" % (_("Surface Visibility")) - information += "%.0f%s (%s)\n\n" % (self.luna_hoy.data_model.percent_of_full_moon * 100, "%", _("estimated")) - - #information += _("Surface Visibility:\n%.0f%% (estimated)\n\n") % (self.luna_hoy.data_model.percent_of_full_moon * 100) - - selen = {'deg':self.luna_hoy.data_model.selenographic_deg, 'westOrEast':self.luna_hoy.data_model.west_or_east, - 'riseOrSet':self.luna_hoy.data_model.rise_or_set} - information += _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % selen - - full = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_full_moon_date)), - 'days':self.luna_hoy.data_model.days_until_full_moon} - information += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % full - - new = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_new_moon_date)), - 'days':self.luna_hoy.data_model.days_until_new_moon} - information += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % new - - lunare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_lunar_eclipse_date)), - 'days':self.luna_hoy.data_model.days_until_lunar_eclipse} - information += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % lunare - - solare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_solar_eclipse_date)), - 'days':self.luna_hoy.data_model.days_until_solar_eclipse} - information += _("Next Solar eclipse:\n%(date)s in %(days).0f days") % solare - - self.bufferinfo.set_text(information) - self.label_emisferio.set_text( " %s: %s" % (_("Vista Hemisferio"),_(self.luna_hoy.hemisphere_view)) ) - - def read_and_parse_prefs(self, file_path): - try: - read_file = open(file_path, 'r') - self.activity_state = json.loads(read_file.read()) - if self.activity_state.has_key('hemisphereView'): - self.luna_hoy.hemisphere_view = self.activity_state['hemisphereView'] - if self.activity_state.has_key('showGrid'): - self.luna_hoy.show_grid = self.activity_state['showGrid'] - read_file.close() - except: - pass - - def read_file(self, file_path): - self.read_and_parse_prefs(file_path) - - def write_file(self, file_path): - self.activity_state['hemisphereView'] = self.luna_hoy.hemisphere_view - self.activity_state['showGrid'] = self.luna_hoy.show_grid - serialised_data = json.dumps(self.activity_state) - to_journal = file(file_path, 'w') - try: - to_journal.write(serialised_data) - finally: - to_journal.close() - to_persistent_fs = file(os.environ['SUGAR_ACTIVITY_ROOT'] + '/data/defaults', 'w') - try: - to_persistent_fs.write(serialised_data) - finally: - to_persistent_fs.close() - + + def __init__(self, handle): + + activity.Activity.__init__(self, handle, True) + + self.set_title(_("Luna")) + self.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.main_view = None + self.mooncalendar = None + self.info_panel = None + self.info = None + self.luna_hoy = None + self.label_emisferio = None + self.aspectframe = None + self.bufferinfo = None + + self.activity_state = {} + self.max_participants = 1 + + self.set_layout() + + self.show_all() + self.realize() + self.maximize() + + self.connect("delete_event", self.delete_event) + self.luna_hoy.connect("expose_event", self.repaint) + + self.actualizador = gobject.timeout_add(1000, self.handle) + + def set_layout(self): + + anio, mes, fecha, hora = MG.get_date_time_now() + self.luna_hoy = CalendarButton(anio, mes, fecha, hora) + self.mooncalendar = MoonCalendar() + self.aspectframe = gtk.AspectFrame() + self.aspectframe.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.aspectframe.add(self.luna_hoy) + + cajabase = gtk.VBox() + self.main_view = gtk.HBox() + cajabase.pack_end(self.main_view, True, True, 5) + + try: # Sugar 86 en adelante + from sugar.graphics.toolbarbox import ToolbarBox + from sugar.activity.widgets import StopButton + from sugar.activity.widgets import ActivityToolbarButton + + toolbox = ToolbarBox() + activity_button = ActivityToolbarButton(self) + activity_button.show() + toolbox.toolbar.insert(activity_button, 0) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + toolbox.toolbar.insert(boton, -1) + boton.connect("clicked", self.toggle_grid_clicked) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + toolbox.toolbar.insert(boton, -1) + boton.connect("clicked", self.toggle_hemisphere_clicked) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'calendario-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + toolbox.toolbar.insert(boton, -1) + boton.connect("clicked", self.switch_calendar_luna) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.label_emisferio = gtk.Label() + item = gtk.ToolItem() + item.add(self.label_emisferio) + toolbox.toolbar.insert(item, -1) + self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + self.label_emisferio.show() + + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_size_request(0, -1) + separator.set_expand(True) + toolbox.toolbar.insert(separator, -1) + + toolbox.toolbar.insert(StopButton(self), -1) + + self.set_toolbar_box(toolbox) + toolbox.show_all() + + except: # Hasta Sugar 84 + view_tool_bar = gtk.Toolbar() + view_tool_bar.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.toggle_grid_clicked, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'hemi-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", _(""), "",boton, self.toggle_hemisphere_clicked, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + boton = gtk.ToggleToolButton() + pixbuf= gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(MG.ICONOS,'grid-ico.svg'), 32, 32) + imagen = gtk.Image() + imagen.set_from_pixbuf(pixbuf) + boton.set_icon_widget(imagen) + imagen.show() + boton.show() + view_tool_bar.append_item("", "", "",boton, self.switch_calendar_luna, user_data=None) + boton.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + + self.label_emisferio = gtk.Label() + view_tool_bar.append_widget(self.label_emisferio, None, None) + self.label_emisferio.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + self.label_emisferio.modify_fg(gtk.STATE_NORMAL, MG.FOREGROUND) + self.label_emisferio.show() + + view_tool_bar.show_all() + toolbox = activity.ActivityToolbox(self) + toolbox.add_toolbar(_("Luna"), view_tool_bar) + self.set_toolbox(toolbox) + toolbox.show() + + info_scroll = gtk.ScrolledWindow() + info_scroll.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC) + self.info_panel = gtk.VBox() + self.info = gtk.TextView() + self.info.set_property("sensitive", False) + self.info.set_border_window_size(gtk.TEXT_WINDOW_TOP, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_RIGHT, 10) + self.info.set_border_window_size(gtk.TEXT_WINDOW_BOTTOM, 10) + self.info_panel.pack_start(self.info, False, False, 0) + info_scroll.add_with_viewport(self.info_panel) + + event = gtk.EventBox() + event.modify_bg(gtk.STATE_NORMAL, MG.BACKGROUND) + event.add(self.aspectframe) + self.main_view.pack_start(info_scroll, False, False, 5) + self.main_view.pack_end(event, True, True, 5) + self.set_canvas(cajabase) + + self.bufferinfo = gtk.TextBuffer() + self.info.set_buffer(self.bufferinfo) + self.mooncalendar.set_mes(anio, mes, fecha, hora) + self.update_text_information_view() + + self.activity_state['hemisphereView'] = self.luna_hoy.hemisphere_view + self.activity_state['showGrid'] = self.luna_hoy.show_grid + self.read_and_parse_prefs(os.environ['SUGAR_ACTIVITY_ROOT'] + '/data/defaults') + + def toggle_grid_clicked(self, widget= None): + + self.luna_hoy.toggle_grid_clicked() + self.mooncalendar.toggle_grid_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) + + def toggle_hemisphere_clicked(self, widget= None): + + self.luna_hoy.toggle_hemisphere_clicked() + self.mooncalendar.toggle_hemisphere_clicked(widget= None, actualizar = self.mooncalendar in self.aspectframe.get_children()) + + def switch_calendar_luna(self, widget): + + if self.mooncalendar in self.aspectframe.get_children(): + self.aspectframe.remove(self.mooncalendar) + self.aspectframe.add(self.luna_hoy) + self.luna_hoy.show_all() + elif self.luna_hoy in self.aspectframe.get_children(): + self.aspectframe.remove(self.luna_hoy) + self.aspectframe.add(self.mooncalendar) + self.mooncalendar.show_all() + self.show_all() + self.realize() + + def handle(self): + + self.update_text_information_view() + if self.luna_hoy in self.aspectframe.get_children(): + self.luna_hoy.actualizar() + return True + + def repaint(self, widget= None, event= None): + + x,y,w,h= self.luna_hoy.get_allocation() + anchoboton, altoboton = (w,h) + tamanioboton = min( [anchoboton,altoboton] ) + self.luna_hoy.repaint(tamanioboton) + + def delete_event(self, widget, event, data=None): + + sys.exit(0) + return False + + def update_text_information_view(self): + + anio, mes, fecha, hora = MG.get_date_time_now() + hoy = "%s-%s-%s %s" % (anio, mes, fecha, hora) + ahora = time.mktime(time.strptime(hoy, MG.format)) + + self.luna_hoy.data_model.update_moon_calculations(ahora) + + information = "" + information += "%s:\n\n" % (_("Today's Moon Information")) + information += "%s\n\n" % (MG.get_date_time()) + information += "%s:\n%s\n\n" % (_("Phase"), self.luna_hoy.data_model.moon_phase_name(self.luna_hoy.data_model.phase_of_moon)) + information += "%s:\n%.2f (%s)\n\n" % (_("Julian Date"), self.luna_hoy.data_model.julian_date, _("astronomical")) + + information += "%s:\n" % (_("Age")) + dias = self.luna_hoy.data_model.days_old + horas = self.luna_hoy.data_model.hours_old + minutos = self.luna_hoy.data_model.minutes_old + information += "%i %s, %i %s, %i %s.\n\n" % (dias, _("days"), horas, _("hours"), minutos, _("minutes")) + + phase = self.luna_hoy.data_model.phase_of_moon * 100 + lunation = self.luna_hoy.data_model.lunation + information += "%s:\n" % (_("Lunation")) + information += "%.2f%s %s %d.\n\n" % (phase, "%", _("through lunation"), lunation) + + information += "%s:\n" % (_("Surface Visibility")) + information += "%.0f%s (%s)\n\n" % (self.luna_hoy.data_model.percent_of_full_moon * 100, "%", _("estimated")) + + #information += _("Surface Visibility:\n%.0f%% (estimated)\n\n") % (self.luna_hoy.data_model.percent_of_full_moon * 100) + + selen = {'deg':self.luna_hoy.data_model.selenographic_deg, 'westOrEast':self.luna_hoy.data_model.west_or_east, + 'riseOrSet':self.luna_hoy.data_model.rise_or_set} + information += _(u"Selenographic Terminator Longitude:\n%(deg).1f\u00b0%(westOrEast)s (%(riseOrSet)s)\n\n") % selen + + full = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_full_moon_date)), + 'days':self.luna_hoy.data_model.days_until_full_moon} + information += _("Next Full Moon:\n%(date)s in %(days).0f days\n\n") % full + + new = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_new_moon_date)), + 'days':self.luna_hoy.data_model.days_until_new_moon} + information += _("Next New Moon:\n%(date)s in %(days).0f days\n\n") % new + + lunare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_lunar_eclipse_date)), + 'days':self.luna_hoy.data_model.days_until_lunar_eclipse} + information += _("Next Lunar eclipse:\n%(date)s in %(days).0f days\n\n") % lunare + + solare = {'date':time.strftime(MG.LOCALE_DATE_FORMAT, time.localtime(self.luna_hoy.data_model.next_solar_eclipse_date)), + 'days':self.luna_hoy.data_model.days_until_solar_eclipse} + information += _("Next Solar eclipse:\n%(date)s in %(days).0f days") % solare + + self.bufferinfo.set_text(information) + self.label_emisferio.set_text( " %s: %s" % (_("Vista Hemisferio"),_(self.luna_hoy.hemisphere_view)) ) + + def read_and_parse_prefs(self, file_path): + + try: + read_file = open(file_path, 'r') + self.activity_state = json.loads(read_file.read()) + if self.activity_state.has_key('hemisphereView'): + self.luna_hoy.hemisphere_view = self.activity_state['hemisphereView'] + if self.activity_state.has_key('showGrid'): + self.luna_hoy.show_grid = self.activity_state['showGrid'] + read_file.close() + except: + pass + + def read_file(self, file_path): + + self.read_and_parse_prefs(file_path) + + def write_file(self, file_path): + + self.activity_state['hemisphereView'] = self.luna_hoy.hemisphere_view + self.activity_state['showGrid'] = self.luna_hoy.show_grid + serialised_data = json.dumps(self.activity_state) + to_journal = file(file_path, 'w') + try: + to_journal.write(serialised_data) + finally: + to_journal.close() + to_persistent_fs = file(os.environ['SUGAR_ACTIVITY_ROOT'] + '/data/defaults', 'w') + try: + to_persistent_fs.write(serialised_data) + finally: + to_persistent_fs.close() +
\ No newline at end of file @@ -9,29 +9,29 @@ import commands from distutils.core import setup -setup(name="MoonActivity", - version= "1", - author= "Gary C. Martin", - author_email= "gary@garycmartin.com", - url= "", - license= "GPL3", +setup(name="MoonActivity", + version= "1", + author= "Gary C. Martin", + author_email= "gary@garycmartin.com", + url= "", + license= "GPL3", - scripts= ["MoonActivity", "MoonActivityUninstall"], + scripts= ["MoonActivity", "MoonActivityUninstall"], - py_modules= ['GnomeMoonActivity', 'Moonwidgets', 'MoonActivityUninstall', 'MoonGlobals'], + py_modules= ['GnomeMoonActivity', 'Moonwidgets', 'MoonActivityUninstall', 'MoonGlobals'], - data_files= [('/usr/share/applications/', ['MoonActivity.desktop']), ('', ['MoonActivityUninstall.py']), - ('po', ['po/da.po', 'po/nl.po', - 'po/hy.po', 'po/pa.po', 'po/pap.po', 'po/hi.po', 'po/templates.po', 'po/km.po', 'po/en_US.po', 'po/tyv.po', - 'po/ha.po', 'po/na.po', 'po/yo.po', 'po/bs.po', 'po/pis.po', 'po/ta.po', 'po/af.po', 'po/nah.po', 'po/ig.po', - 'po/hus.po', 'po/fi.po', 'po/fil.po', 'po/tzo.po', 'po/moon.pot', 'po/en_GB.po', 'po/cs.po', 'po/fa_AF.po', - 'po/wa.po', 'po/it.po', 'po/kn.po', 'po/tvl.po', 'po/ro.po', 'po/ff.po', 'po/ar.po', 'po/pseudo.po', - 'po/ak.po', 'po/hu.po', 'po/ug.po', 'po/fa.po', 'po/sw.po', 'po/mr.po', 'po/sv.po', 'po/quz.po', 'po/th.po', - 'po/zh_TW.po', 'po/sm.po', 'po/bg.po', 'po/dz.po', 'po/ko.po', 'po/uk.po', 'po/ne.po', 'po/sr.po', 'po/mn.po', - 'po/lv.po', 'po/ja.po', 'po/son.po', 'po/mg.po', 'po/fr.po', 'po/zh_CN.po', 'po/si.po', 'po/sl.po', 'po/zh_HK.po', - 'po/vi.po', 'po/te.po', 'po/tr.po', 'po/ru.po', 'po/ps.po', 'po/ca.po', 'po/ml.po', 'po/nn.po', 'po/ht.po', 'po/tzm.po', - 'po/id.po', 'po/mk.po', 'po/he.po', 'po/ku.po', 'po/gu.po', 'po/sd.po', 'po/pt.po', 'po/cpp.po', 'po/kos.po', - 'po/ar_SY.po', 'po/nb.po', 'po/bn.po', 'po/POTFILES.in', 'po/tpi.po', 'po/ton.po', 'po/bn_IN.po', 'po/sk.po', - 'po/es.po', 'po/rw.po', 'po/el.po', 'po/am.po', 'po/ur.po', 'po/mvo.po', 'po/pt_BR.po', 'po/pl.po', 'po/aym.po', - 'po/sq.po', 'po/ms.po', 'po/st.po', 'po/lt.po', 'po/de.po', 'po/is.po', 'po/en.po']), ('Iconos', ['Iconos/grid-ico.svg', - 'Iconos/luna-ico.png', 'Iconos/calendario-ico.svg', 'Iconos/flecha-ico.svg', 'Iconos/moon.jpg', 'Iconos/hemi-ico.svg'])]) + data_files= [('/usr/share/applications/', ['MoonActivity.desktop']), ('', ['MoonActivityUninstall.py']), + ('po', ['po/da.po', 'po/nl.po', + 'po/hy.po', 'po/pa.po', 'po/pap.po', 'po/hi.po', 'po/templates.po', 'po/km.po', 'po/en_US.po', 'po/tyv.po', + 'po/ha.po', 'po/na.po', 'po/yo.po', 'po/bs.po', 'po/pis.po', 'po/ta.po', 'po/af.po', 'po/nah.po', 'po/ig.po', + 'po/hus.po', 'po/fi.po', 'po/fil.po', 'po/tzo.po', 'po/moon.pot', 'po/en_GB.po', 'po/cs.po', 'po/fa_AF.po', + 'po/wa.po', 'po/it.po', 'po/kn.po', 'po/tvl.po', 'po/ro.po', 'po/ff.po', 'po/ar.po', 'po/pseudo.po', + 'po/ak.po', 'po/hu.po', 'po/ug.po', 'po/fa.po', 'po/sw.po', 'po/mr.po', 'po/sv.po', 'po/quz.po', 'po/th.po', + 'po/zh_TW.po', 'po/sm.po', 'po/bg.po', 'po/dz.po', 'po/ko.po', 'po/uk.po', 'po/ne.po', 'po/sr.po', 'po/mn.po', + 'po/lv.po', 'po/ja.po', 'po/son.po', 'po/mg.po', 'po/fr.po', 'po/zh_CN.po', 'po/si.po', 'po/sl.po', 'po/zh_HK.po', + 'po/vi.po', 'po/te.po', 'po/tr.po', 'po/ru.po', 'po/ps.po', 'po/ca.po', 'po/ml.po', 'po/nn.po', 'po/ht.po', 'po/tzm.po', + 'po/id.po', 'po/mk.po', 'po/he.po', 'po/ku.po', 'po/gu.po', 'po/sd.po', 'po/pt.po', 'po/cpp.po', 'po/kos.po', + 'po/ar_SY.po', 'po/nb.po', 'po/bn.po', 'po/POTFILES.in', 'po/tpi.po', 'po/ton.po', 'po/bn_IN.po', 'po/sk.po', + 'po/es.po', 'po/rw.po', 'po/el.po', 'po/am.po', 'po/ur.po', 'po/mvo.po', 'po/pt_BR.po', 'po/pl.po', 'po/aym.po', + 'po/sq.po', 'po/ms.po', 'po/st.po', 'po/lt.po', 'po/de.po', 'po/is.po', 'po/en.po']), ('Iconos', ['Iconos/grid-ico.svg', + 'Iconos/luna-ico.png', 'Iconos/calendario-ico.svg', 'Iconos/flecha-ico.svg', 'Iconos/moon.jpg', 'Iconos/hemi-ico.svg'])]) |