Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/calendario.py
blob: c3ea062e07e4a9c90da122ed711363c60a37d15f (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
# -*- coding: utf-8 -*-
#
#Copyright (C) 2010, Yader Velasquez
#Copyright (C) 2010, Marcelo Gutierrez
#
#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 3 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, see <http://www.gnu.org/licenses/>.

from gettext import gettext as _
from fecha import FechaUnix, FechaNormal 
from archivo import crear_modelo, abrir_efemeride, guardar_dato, borrar_dato
import gtk

from sugar.activity import activity

class CalendarioActivity(activity.Activity):
    '''the sugar class'''

    def __init__(self, handle):
        ''' init class'''
        super(CalendarioActivity, self).__init__(handle)
        self.set_title(_('Calendario'))
        barra_herramientas = activity.ActivityToolbox(self)
        self.set_toolbox(barra_herramientas)
        barra_herramientas.show()
        self.fecha_normal = FechaNormal()

        ######################### set interface ########################

        #calendar
        self.calendario = gtk.Calendar()    
        self.fecha = _('Hoy es ') + self.fecha_normal.fecha_actual()
        self.texto_fecha = gtk.Label(self.fecha)     

        #daily activities
        self.area_texto = gtk.ScrolledWindow() 
        self.area_texto.set_shadow_type(gtk.SHADOW_IN)
        self.area_texto.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
         

        self.lista_fecha_t = self.calendario.get_date()
        self.indice_dia_t = FechaUnix(self.lista_fecha_t)
        
        self.modelo = crear_modelo(self.indice_dia_t.fecha_unix())
        self.actividades = gtk.TreeView(self.modelo)
        self.area_texto.add(self.actividades)
        self._crear_columna()

        #ephemeris 

        self.area_efem = gtk.ScrolledWindow()
        self.area_efem.set_shadow_type(gtk.SHADOW_IN)
        self.area_efem.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
        self.buffer = gtk.TextBuffer()
        
        #ephemeris files
        
        self.texto = abrir_efemeride()
        if self.texto.has_key(self.fecha_normal.fecha_especial()):  
            self.buffer.set_text(self.texto[self.fecha_normal.fecha_especial()])
        
        else:
            self.buffer.set_text('Hoy no se celebra ninguna efemeride')
        
        self.efemeride = gtk.TextView(self.buffer) 
        self.efemeride.set_editable(False)
        self.efemeride.set_cursor_visible(False)
        self.area_efem.add(self.efemeride)

        #text input
        self.area_entrada = gtk.ScrolledWindow()
        self.area_entrada.set_shadow_type(gtk.SHADOW_OUT)
        self.area_entrada.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.entrada = gtk.TextView()
        self.entrada.set_size_request(0, 80) 
        self.area_entrada.add(self.entrada)       

        #buttons
        self.boton1 = gtk.Button(_('Ingresar'))
        self.boton2 = gtk.Button(_('Borrar'))

        #frames
        self.marco_efemeride = gtk.Frame(_('La efemeride del día de hoy es:'))
        self.marco_efemeride.add(self.area_efem)
        self.marco_actividades = gtk.Frame(_('Tus actividades para hoy son:'))
        self.marco_actividades.add(self.area_texto)

        #containers
        self.contenedor_h = gtk.HBox()
        self.contenedor_vd = gtk.VBox()
        self.contenedor_vi = gtk.VBox()
        self.sub_contenedor_h = gtk.HBox()
        self.botones_contenedor = gtk.VBox()

        #callbacks
        self.calendario.connect('day_selected', self._dia_selec_cb)
        self.boton1.connect('clicked', self._nuevo_ingreso_cb)
        self.boton2.connect('clicked', self._borrar_fila_cb)
       
        ########################### Add Blocks ################################
        self.contenedor_h.pack_start(self.contenedor_vi, False, padding = 5)
        
        self.contenedor_vi.pack_start(self.texto_fecha, False, padding = 5)
        self.contenedor_vi.pack_start(self.calendario, False, padding = 5)
        self.contenedor_vi.pack_start(self.marco_efemeride, padding = 5)
        
        self.contenedor_h.pack_start(self.contenedor_vd, padding = 5)
        
        self.contenedor_vd.pack_start(self.marco_actividades)
        self.contenedor_vd.pack_start(self.sub_contenedor_h, False, padding = 15)
        
        self.sub_contenedor_h.pack_start(self.area_entrada)
        self.sub_contenedor_h.pack_start(self.botones_contenedor, False)
        self.botones_contenedor.pack_start(self.boton1)
        self.botones_contenedor.pack_start(self.boton2)
        
        self.set_canvas(self.contenedor_h)
        self.contenedor_h.show_all()

    def _dia_selec_cb(self, widget, data=None):
        '''when a date is selected'''
        self.lista_fecha = self.calendario.get_date()
        self.indice_dia = FechaUnix(self.lista_fecha)
        self.modelo = crear_modelo(self.indice_dia.fecha_unix())
        self.actividades.set_model(self.modelo)

    def _borrar_fila_cb(self, widget, data=None):
        '''deleted the selected row'''
        self.seleccion = self.actividades.get_selection()
        self.model, self.iter = self.seleccion.get_selected()
        self.enlace = self.modelo.get_path(self.iter)
        self.lista_fecha = self.calendario.get_date()
        self.indice_dia = FechaUnix(self.lista_fecha)  
        self.indice_dia = self.indice_dia.fecha_unix()
        borrar_dato(self.indice_dia, self.enlace)
        self.modelo = crear_modelo(self.indice_dia)
        self.actividades.set_model(self.modelo) 
   
    def _nuevo_ingreso_cb(self, widget, data=None):
        '''when the user clicked on the save button, 
        the content is added to a python object and
        is saved in a file'''
        self.lista_fecha = self.calendario.get_date()
        self.indice_dia = FechaUnix(self.lista_fecha)
        self.indice_dia = self.indice_dia.fecha_unix()
        self.buffer = self.entrada.get_buffer()
        self.inicio, self.final = self.buffer.get_bounds()
        self.cadena = self.buffer.get_text(self.inicio, self.final, False)
        guardar_dato(self.indice_dia, self.cadena) 
        self.buffer.set_text(' ') 
        self.modelo = crear_modelo(self.indice_dia)
        self.actividades.set_model(self.modelo)   
        


    def _crear_columna(self):
        '''create the columns for the treeview'''
        self.celda = gtk.CellRendererText()
        self.numero = (_('Numero de actividad'))
        self.actividad = (_('Actividades para hoy'))
        
        self.columna = gtk.TreeViewColumn(self.numero, self.celda, text = 0)
        self.actividades.append_column(self.columna)
        
        self.columna = gtk.TreeViewColumn(self.actividad, self.celda, text = 1)
        self.actividades.append_column(self.columna)
   

    def read_file(self, filepath):
        pass

    def write_file(self, filepath):
        pass