Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/calendario.py
blob: 32271d9c46b28476f1160b97fa242047eb84baee (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
229
230
231
232
233
234
235
# -*- coding: utf-8 -*-
#
#Copyright (C) 2010, Yader Velasquez
#
#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
import logging

from sugar.activity import activity

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

    def __init__(self, handle, create_jobject=True):
        ''' init class''' 
        activity.Activity.__init__(self, handle, False)
        #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()
        self._log = logging.getLogger('log principal')
        self.path = self.get_activity_root()
        
        

        ######################### 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_AUTOMATIC, 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.path)
        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(self.path)
        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(_('Efemerides:'))
        self.marco_efemeride.add(self.area_efem)
        self.marco_actividades = gtk.Frame(_('Actividades:'))
        self.marco_actividades.add(self.area_texto)

        #combobox
        self.combo = gtk.combo_box_new_text()
        self.combo.set_size_request(180, -1)
        self.combo.append_text(_('Matemática'))
        self.combo.append_text(_('Geografía'))
        self.combo.append_text(_('Ciencias'))
        self.combo.append_text(_('Español'))
        self.combo.append_text(_('Examen'))
        self.combo.append_text(_('Sin categoria'))
        self.combo.set_active(5) 
        
        #expander
        #self.categoria = gtk.Label(_("Categoria"))
        self.expandir = gtk.Expander(_('Expandir para mas opciones'))
        self.check_status = 0
        self.check = gtk.CheckButton(_('Marcar como importante'))
        self.expandir_h = gtk.HBox()
        self.expandir_h.pack_start(self.combo, False)
        self.expandir_h.pack_start(self.check)
        self.expandir.add(self.expandir_h)
        

        #containers
        self.contenedor_h = gtk.HBox()
        self.contenedor_vd = gtk.VBox()
        self.contenedor_vi = gtk.VBox()
        self.sub_contenedor_h = gtk.HBox()
        self.contenedor_extendido = 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)
        self.check.connect('toggled', self._check_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.contenedor_extendido, False)
        self.contenedor_extendido.pack_start(self.expandir)
        self.contenedor_vd.pack_start(self.sub_contenedor_h, False, padding = 5)
        
        self.sub_contenedor_h.pack_start(self.area_entrada)
        self.sub_contenedor_h.pack_start(self.botones_contenedor, False, padding = 3)
        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 _check_cb(self, widget, data=None):
        if self.check_status is 1:
            self.check_status = 0
        else:
            self.check_status = 1
        self._log.debug(self.check_status)

    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.path)
        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.path)
        self.modelo = crear_modelo(self.indice_dia, self.path)
        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)
        self.modelocombo = self.combo.get_model()
        self.index = self.combo.get_active()
        self.categoria = self.modelocombo[self.index][0]
        guardar_dato(self.indice_dia, self.cadena, self.categoria,\
                     self.check_status, self.path) 
        self.buffer.set_text(' ') 
        self.modelo = crear_modelo(self.indice_dia, self.path)
        self.actividades.set_model(self.modelo)   
        


    def _crear_columna(self):
        '''create the columns for the treeview'''
        self.celda = gtk.CellRendererText()
        self.numero = ('#')
        self.actividad = (_('Actividad'))
        self.categoria = (_('Categoria'))
        self.prioridad = (_('Prioridad'))
        
        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)
        self.columna = gtk.TreeViewColumn(self.categoria, self.celda, text = 2)
        self.actividades.append_column(self.columna)
        self.columna = gtk.TreeViewColumn(self.prioridad, self.celda, text = 3)
        self.actividades.append_column(self.columna)
  
    def close(self, skip_save=False):
        '''Override the close method so we don't try to
        create a Journal entry'''
        activity.Activity.close(self, True)

    def read_file(self, filepath):
        pass

    def write_file(self, filepath):
        pass