diff options
-rwxr-xr-x | MANIFEST | 4 | ||||
-rw-r--r-- | archivo.py | 48 | ||||
-rw-r--r-- | calendario.py | 43 |
3 files changed, 64 insertions, 31 deletions
@@ -8,5 +8,5 @@ calendario.py po/Calendario.pot activity/activity.info activity/icono_calendario.svg -.calendario.py.swp -efe.pkl + + @@ -66,22 +66,48 @@ def crear_modelo(indice, path): archivo.close() return modelo -def abrir_efemeride(path): - '''open the ephemeris file and return a data dictionary''' +def comprobar_efemeride(path): + '''test is the ephemeri file exists''' path = path + '/data/efemerides.pkl' if not os.path.exists(path): - _log.debug('THE FILE EFEMERIDES DID NOT EXISTS') - archivo = open(path, 'wb') - texto = {} - pickle.dump(texto, archivo) - archivo.close() + return False else: - _log.debug('THE FILE EPHEMERIS EXISTS') - archivo = open(path, 'rb') - texto = pickle.load(archivo) - archivo.close() + return True + +def abrir_efemeride(path): + '''open the ephemeris file and return a data dictionary''' + path = path + '/data/efemerides.pkl' + #if not os.path.exists(path): + # _log.debug('THE FILE EFEMERIDES DID NOT EXISTS') + # archivo = open(path, 'wb') + # texto = {} + # pickle.dump(texto, archivo) + # archivo.close() + #else: + _log.debug('THE FILE EPHEMERIS EXISTS') + archivo = open(path, 'rb') + texto = pickle.load(archivo) + archivo.close() return texto +def guardar_efemeride(path, file_name): + '''import, convert and save a new ephemeris database''' + path = path + '/data/efemerides/pkl' + di = {} + file = open(file_name, 'r') + lines = file.readlines() + for i in range(len(lines)): + current_text = lines[i][10 : len(lines[i]) - 2] + + for j in range(30, len(current_text),30): + current_text = current_text[:j] + '\n' + current_text[j + 1 :] + current_id = lines[i][0 : 8] + di[current_id] = current_text + file_new = open(path, 'wb') + pickle.dump(di,file_new) + file_new.close() + file.close() + def guardar_dato(indice, contenido, categoria, bolean, path): '''save the content in a file, add the content to a dictionary->list''' path = path + '/data/actividades.pkl' diff --git a/calendario.py b/calendario.py index bcca924..9cdc211 100644 --- a/calendario.py +++ b/calendario.py @@ -17,7 +17,7 @@ from gettext import gettext as _ from fecha import FechaUnix, FechaNormal -from archivo import crear_modelo, abrir_efemeride, guardar_dato, borrar_dato +from archivo import crear_modelo, abrir_efemeride, guardar_efemeride, guardar_dato, borrar_dato, comprobar_efemeride import gtk import logging @@ -84,14 +84,15 @@ class CalendarioActivity(activity.Activity): 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()]) + if comprobar_efemeride(self.path): + 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(_('Sin efemerides')) else: - self.buffer.set_text(_('Sin efemerides')) - + self.buffer.set_text(_('No ha importado ninguna efemeride')) self.efemeride = gtk.TextView(self.buffer) self.efemeride.set_editable(False) self.efemeride.set_cursor_visible(False) @@ -108,7 +109,8 @@ class CalendarioActivity(activity.Activity): #buttons self.boton1 = gtk.Button(_('Ingresar')) self.boton2 = gtk.Button(_('Borrar')) - + self.boton3 = gtk.Button(_('Importar efemeride')) + #frames self.marco_efemeride = gtk.Frame(_('Efemerides:')) self.marco_efemeride.add(self.area_efem) @@ -135,6 +137,10 @@ class CalendarioActivity(activity.Activity): self.expandir_h.pack_start(self.check) self.expandir.add(self.expandir_h) + #file + self.archivo = gtk.FileChooserWidget() + self.archivo.set_current_folder('/media') + self.archivo.set_extra_widget(self.boton3) #containers self.contenedor_h = gtk.HBox() @@ -148,6 +154,7 @@ class CalendarioActivity(activity.Activity): 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.boton3.connect('clicked', self._importar_archivo_cb) self.check.connect('toggled', self._check_cb) ########################### Add Blocks ################################ @@ -171,6 +178,7 @@ class CalendarioActivity(activity.Activity): self.set_canvas(self.contenedor_h) self.contenedor_h.show_all() + self.archivo.show_all() def _check_cb(self, widget, data=None): if self.check_status is 1: @@ -221,19 +229,18 @@ class CalendarioActivity(activity.Activity): def _importar_cb(self, widget, data=None): '''change to the import view''' - self._remover() - + self.set_canvas(self.archivo) + def _calendario_cb(self, widget, data=None): '''change to the calendar view''' - self._remover() - self.contenedor_h.pack_start(self.contenedor_vi, False, padding = 5) - self.contenedor_h.pack_start(self.contenedor_vd, padding = 5) + self.set_canvas(self.contenedor_h) - def _remover(self): - '''remove all the element of the view''' - self.elementos = self.contenedor_h.get_children() - for i in self.elementos: - self.contenedor_h.remove(i) + def _importar_archivo_cb(self, widget, data=None): + '''import a file to ephemeris''' + self.uri = self.archivo.get_uri() + self.uri = uri[7:] + self._log.debug(self.uri) + guardar_efemeride(self.path, self.uri) def _crear_columna(self): '''create the columns for the treeview''' |