Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoryaderv <yajosev@gmail.com>2011-03-15 16:23:39 (GMT)
committer yaderv <yajosev@gmail.com>2011-03-15 16:23:39 (GMT)
commit3f2915558d5d60b5dca115876087068a4372683c (patch)
treed5007bf70435e0488148563aaa539a40a65aada9
parentc3fe565683236c9c0f738af0120c1c589b1c4e2a (diff)
imported phrases
-rw-r--r--archivo.py33
-rw-r--r--calendario.py38
-rw-r--r--fecha.py3
3 files changed, 56 insertions, 18 deletions
diff --git a/archivo.py b/archivo.py
index 23dff84..73e7f13 100644
--- a/archivo.py
+++ b/archivo.py
@@ -71,26 +71,36 @@ def crear_modelo(indice, path):
archivo.close()
return modelo
-def comprobar_efemeride(path):
+def comprobar_archivo(path, archivo):
'''Return true if the ephemeris database exists,
else return false'''
- path = path + '/data/efemerides.pkl'
+ if archivo is 'efemeride':
+ path = path + '/data/efemerides.pkl'
+ elif archivo is 'frase':
+ path = path + '/data/frase.pkl'
+
if not os.path.exists(path):
return False
else:
return True
-def abrir_efemeride(path):
+def abrir_archivo(path, archivo):
'''open the ephemeris file and return a data dictionary'''
- path = path + '/data/efemerides.pkl'
+ if archivo is 'efemeride':
+ path = path + '/data/efemerides.pkl'
+ elif archivo is 'frase':
+ path = path + '/data/frase.pkl'
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'
+def guardar_archivo(path, file_name, archivo):
+ '''import, convert and save a new ephemeris/phrases database'''
+ if archivo is 1:
+ path = path + '/data/efemerides.pkl'
+ elif archivo is 2:
+ path = path + '/data/frase.pkl'
di = {}
archivo = open(file_name, 'r')
lines = archivo.readlines()
@@ -99,8 +109,13 @@ def guardar_efemeride(path, file_name):
for j in range(30, len(current_text),30):
current_text = current_text[:j] + '\n' + current_text[j:]
- current_id = lines[i][0 : 8]
- di[current_id] = current_text
+ if archivo is 1:
+ current_id = lines[i][0 : 8]
+ else:
+ current_id = lines[i][0 : 2]
+
+ di[current_id] = current_text
+ _log.debug(di[current_id])
file_new = open(path, 'wb')
pickle.dump(di,file_new)
file_new.close()
diff --git a/calendario.py b/calendario.py
index e6cc36e..94dea53 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_efemeride, guardar_dato, borrar_dato, comprobar_efemeride, dict_meses, borrar_dict_meses
+from archivo import crear_modelo, abrir_archivo, guardar_archivo, guardar_dato, borrar_dato, comprobar_archivo, dict_meses, borrar_dict_meses
import gtk
import pango
import logging
@@ -92,9 +92,10 @@ class CalendarioActivity(activity.Activity):
self.area_efem.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.buffer = gtk.TextBuffer()
- #ephemeris files
- if comprobar_efemeride(self.path):
- self.texto = abrir_efemeride(self.path)
+ #ephemeris file
+ if comprobar_archivo(self.path, 'efemeride'):
+ self.texto = abrir_archivo(self.path, 'efemeride')
+ self._log.debug(self.texto)
if self.fecha_normal.fecha_especial() in self.texto:
self.buffer.set_text(self.texto[self.fecha_normal.fecha_especial()])
@@ -115,6 +116,17 @@ class CalendarioActivity(activity.Activity):
self.area_frase.set_shadow_type(gtk.SHADOW_IN)
self.area_frase.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.buffer = gtk.TextBuffer()
+ #phrase file
+ if comprobar_archivo(self.path, 'frase'):
+ self.texto = abrir_archivo(self.path, 'frase')
+ self._log.debug(self.texto)
+ if self.fecha_normal.numero_semana() in self.texto:
+ self.buffer.set_text(self.texto[self.fecha_normal.numero_semana()])
+
+ else:
+ self.buffer.set_text(_('There\'s not phrases'))
+ else:
+ self.buffer.set_text(_('There\'s not phrases imported'))
self.frases = gtk.TextView(self.buffer)
self.frases.set_editable(False)
self.frases.set_cursor_visible(False)
@@ -175,7 +187,16 @@ class CalendarioActivity(activity.Activity):
#file
self.archivo = gtk.FileChooserWidget()
self.archivo.set_current_folder('/media')
- self.archivo.set_extra_widget(self.boton3)
+ self.combo_archivo = gtk.combo_box_new_text()
+ self.combo_archivo.set_size_request(180, -1)
+ self.combo_archivo.append_text(_('Ephemeris'))
+ self.combo_archivo.append_text(_('Phrases'))
+ self.combo_archivo.set_active(1)
+
+ self.botones = gtk.HBox()
+ self.botones.pack_start(self.combo_archivo, False)
+ self.botones.pack_start(self.boton3)
+ self.archivo.set_extra_widget(self.botones)
#containers
self.contenedor_h = gtk.HBox()
@@ -358,10 +379,12 @@ class CalendarioActivity(activity.Activity):
self.set_canvas(self.contenedor_h)
def _importar_archivo_cb(self, widget, data=None):
- '''import a file to ephemeris'''
+ '''import a file to phrase/ephemeris'''
+ self.modelo_archivo = self.combo_archivo.get_model()
+ self.index_archivo = self.combo_archivo.get_active()
self.uri = self.archivo.get_uri()
self.uri = self.uri[7:]
- guardar_efemeride(self.path, self.uri)
+ guardar_archivo(self.path, self.uri, self.index_archivo + 1)
def _editar_cb(self, widget, data=None):
'''edit row'''
@@ -380,7 +403,6 @@ class CalendarioActivity(activity.Activity):
self.progre.set_active(True)
self.check_editar = True
-
def _crear_columna(self):
'''create the columns for the treeview'''
self.celda = gtk.CellRendererText()
diff --git a/fecha.py b/fecha.py
index afe76ab..abb3878 100644
--- a/fecha.py
+++ b/fecha.py
@@ -55,8 +55,9 @@ class FechaNormal(object):
be use it like a dicctionary key
in the format day/month/year'''
return self.fecha.strftime("%d/%m/%y")
+
def numero_semana(self):
'''return the number of the current week'''
self.esta_semana = date.today()
self.semana = date.isocalendar(self.esta_semana)
- return int(self.semana[1])
+ return str(self.semana[1])