Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/GnomeMoonActivity.py
blob: d55bb753107262144531289c525fecfb37281709 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2008 Gary C. Martin

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

# Activity web site: http://wiki.laptop.org/go/Moon
# Created: Febuary 2008
# Author: gary@garycmartin.com
# Home page: http://www.garycmartin.com/

#	Febrero 2012
# Correcciones, Simplificación y Reestructuración Modular:
# Desarrollo de CalendarButton + MoonCalendar:
# Instalador y Portado a gnome:
#	Flavio Danesse <fdanesse@gmail.com> CeibalJAM! - Uruguay - Activity Central
# Traducciones a Español:
# 	Ana Cichero <ana.cichero@gmail.com> CeibalJAM! - Uruguay

import gtk, pygtk, time, math, gobject, sys
from gettext import gettext as _
import MoonGlobals as MG
from Moonwidgets import *

IMAGE_SIZE = 726
HALF_SIZE = IMAGE_SIZE / 2
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.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.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 += _("Today's Moon Information\n\n")
		information += "%s\n\n" % (MG.get_date_time())
		information += _("Phase:\n%s\n\n") % (self.luna_hoy.data_model.moon_phase_name(self.luna_hoy.data_model.phase_of_moon))
		information += _("Julian Date:\n%.2f (astronomical)\n\n") % (self.luna_hoy.data_model.julian_date)

		tiempo = {'days':self.luna_hoy.data_model.days_old,
		'hours':self.luna_hoy.data_model.hours_old, 'minutes':self.luna_hoy.data_model.minutes_old}
		information += _("Age:\n%(days).0f days, %(hours).0f hours, %(minutes).0f minutes\n\n") % tiempo

		lunacion = {'phase':self.luna_hoy.data_model.phase_of_moon * 100, 'lunation':self.luna_hoy.data_model.lunation}
		information += _("Lunation:\n%(phase).2f%% through lunation %(lunation)d\n\n") % lunacion
		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
		text = gtk.TextBuffer()
		text.set_text(information)
		self.info.set_buffer(text)
		self.label_emisferio.set_text( "%s: %s" % (_("Vista Hemisferio"),_(self.luna_hoy.hemisphere_view)) )

if __name__=="__main__":
	MoonActivity()
	gtk.main()