Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/archivo.py
blob: 55507bf7efba22cc881b408b50316968dcf8fc34 (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
# -*- 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/>.

import gtk
import pickle
import gobject
from gettext import gettext as _

def indice_entero(cadena):
    '''return an int from a string with tuple sintax'''
    cadena = cadena.replace('(','')
    cadena = cadena.replace(',','')
    cadena = cadena.replace(')','')
    return int(cadena)

def crear_modelo(indice):
    '''create the liststore model for the main block'''
    archivo = open('files/actividades.pkl', 'rb')
    dia = pickle.load(archivo)
    contar = 1
    modelo = gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING)
    
    if dia.has_key(indice): 
        for activ in dia[indice]:
            modelo.append([contar, activ]) 
            contar += 1
    else :
        vacio = (_('no hay actividades para el día de hoy'))
        modelo.append([0,vacio])
    
    archivo.close()
    return modelo

def abrir_efemeride():
    '''open the ephemeris file and return a data dictionary'''
    archivo = open('files/efemerides.pkl', 'rb')
    texto = pickle.load(archivo)
    return texto

def guardar_dato(indice, contenido):
    '''save the content in a file, add the content to a dictionary->list'''
    indice = str(indice)
    f = open('files/actividades.pkl', 'rb+wb')
    dia = pickle.load(f)
    if dia.has_key(indice) is False:
        dia[indice] = []
    dia[indice].append(contenido)
    f.seek(0)
    pickle.dump(dia, f)
    f.flush()
    f.close()

def borrar_dato(indice,indice_lista):
    '''delete the selected content'''
    indice_lista = str(indice_lista)
    indice = str(indice)
    indice_lista = indice_entero(indice_lista)
    f = open('files/actividades.pkl', 'rb+wb')
    dia = pickle.load(f)
    del dia[indice][indice_lista]
    f.seek(0)
    pickle.dump(dia, f)
    f.flush()
    f.close()