Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2012-04-25 14:18:29 (GMT)
committer flavio <fdanesse@gmail.com>2012-04-25 14:18:29 (GMT)
commit40c72c67b36bd80a4dd936a8bc889526dd62b2af (patch)
tree1382e02285863833dce1eb916b57377107d24d68
parentef0afced91216be8953a7ee05516c4d1f729d82f (diff)
Correcciones y Agrego Eliminar Registro
-rw-r--r--CeibalNotifica.py63
-rw-r--r--base.py26
-rw-r--r--prueba.dbbin2048 -> 2048 bytes
-rw-r--r--store.py17
4 files changed, 60 insertions, 46 deletions
diff --git a/CeibalNotifica.py b/CeibalNotifica.py
index 396e3de..18d949d 100644
--- a/CeibalNotifica.py
+++ b/CeibalNotifica.py
@@ -19,14 +19,10 @@ import os
import gtk
import sys
import gobject
-
from store import *
-
BASE = os.path.dirname(__file__)
-
class CeibalNotifica(gtk.Window):
-
def __init__(self):
super(CeibalNotifica, self).__init__()
self.set_title("Ceibal Notifica")
@@ -38,7 +34,7 @@ class CeibalNotifica(gtk.Window):
self.text_buffer = None
self.text_view = None
-
+ self.store = None
self.listore_model = None
self.modelsort = None
self.notify_store = None
@@ -60,6 +56,7 @@ class CeibalNotifica(gtk.Window):
self.text_buffer = gtk.TextBuffer()
self.text_view = gtk.TextView(buffer=self.text_buffer)
+ self.text_view.set_editable(False)
hpanel = gtk.HPaned()
self.store = Store(db_filename="prueba.db")
@@ -81,12 +78,14 @@ class CeibalNotifica(gtk.Window):
def delete_notify(self, widget, path):
iter = widget.get_model().get_iter(path)
- id_registro = widget.get_model().get_value(iter, 0)
- print "Eliminar item", id_registro
+ id_registro = int(widget.get_model().get_value(iter, 0))
+ self.store.db.remove_message(id_registro)
+ self.load_notify()
def load_notify(self):
notificaciones = self.store.db.get_messages([])
self.listore_model.clear()
+ self.text_buffer.set_text('')
for notif in notificaciones:
self.add_notify(notif)
@@ -105,7 +104,6 @@ class CeibalNotifica(gtk.Window):
def salir(self, widget=None):
sys.exit(0)
-
class ListoreModel(gtk.ListStore):
def __init__(self):
gtk.ListStore.__init__(self, gobject.TYPE_STRING,
@@ -117,15 +115,12 @@ class ListoreModel(gtk.ListStore):
'''
set_fav(self, id_msg, fav=True) marcará favorito.
remove_message(self, id_msg) borra un registro en la base.'''
-
-
class Notify_Store(gtk.TreeView):
__gsignals__ = {"show_notify": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (gobject.TYPE_STRING, )),
"delete_notify": (gobject.SIGNAL_RUN_FIRST,
gobject.TYPE_NONE, (gobject.TYPE_PYOBJECT, ))}
-
- def __init__(self, model):
+ def __init__(self, model):
gtk.TreeView.__init__(self, model)
self.set_property("rules-hint", True)
self.add_events(gtk.gdk.BUTTON2_MASK)
@@ -140,14 +135,14 @@ class Notify_Store(gtk.TreeView):
self.get_model(), True)
def set_columns(self):
- self.append_column(self.make_column('id', 0, True))
+ self.append_column(self.make_column('id', 0, False))
self.append_column(self.make_column('Prioridad', 1, True))
self.append_column(self.make_column('Título', 2, True))
- self.append_column(self.make_column('Notificación', 3, True))
- self.append_column(self.make_column('Lanzamiento', 4, True))
+ self.append_column(self.make_column('Notificación', 3, False))
+ self.append_column(self.make_column('Lanzamiento', 4, False))
self.append_column(self.make_column('Expira', 5, True))
self.append_column(self.make_column('Tipo', 6, True))
- self.append_column(self.make_column('Favorito', 7, True))
+ self.append_column(self.make_column('Favorito', 7, False))
def make_column(self, text, index, visible):
render = gtk.CellRendererText()
@@ -165,14 +160,17 @@ class Notify_Store(gtk.TreeView):
boton = event.button
pos = (int(event.x), int(event.y))
tiempo = event.time
- path, col, x, y = widget.get_path_at_pos(pos[0], pos[1])
- if boton == 1:
- return
- elif boton == 3:
- self.get_menu(boton, pos, tiempo, path)
- return
- elif boton == 2:
- return
+ try:
+ path, col, x, y = widget.get_path_at_pos(pos[0], pos[1])
+ if boton == 1:
+ return
+ elif boton == 3:
+ self.get_menu(boton, pos, tiempo, path)
+ return
+ elif boton == 2:
+ return
+ except:
+ pass
def get_menu(self, boton, pos, tiempo, path):
menu = gtk.Menu()
@@ -202,19 +200,4 @@ d['expires'] = datetime.date(2012, 6, 21)
d['type'] = "Prueba tipo"
d['fav'] = 0
d.close()
-
-filename = os.path.join('/tmp', 'notify_1')
-d = shelve.open(filename)
-d['id'] = 1
-d['title'] = "Prueba Titulo1"
-d['text'] = "Prueba Texto1"
-d['priority'] = 1
-d['launched'] = datetime.date(1972, 6, 21)
-d['expires'] = datetime.date(2013, 6, 21)
-d['type'] = "Prueba tipo1"
-d['fav'] = 1
-d.close()
-
-store = Store(db_filename="prueba.db")
-mensaje = store.db.get_messages([])
-print mensaje'''
+'''
diff --git a/base.py b/base.py
index 58930f9..0638617 100644
--- a/base.py
+++ b/base.py
@@ -41,6 +41,32 @@ d['type'] = "Prueba tipo1"
d['fav'] = 1
d.close()
+filename = os.path.join('/tmp', 'notify_2')
+d = shelve.open(filename)
+d['id'] = 2
+d['title'] = "Nueva Imagen Para tu xo"
+d['text'] = '''Está disponible la nueva imagen para tu XO!
+Para tenerla entrar al sitio www.ceibal.edu.uy'''
+d['priority'] = 0
+d['launched'] = datetime.date(1972, 6, 21)
+d['expires'] = datetime.date(2013, 6, 21)
+d['type'] = "Actualización"
+d['fav'] = 1
+d.close()
+
+filename = os.path.join('/tmp', 'notify_3')
+d = shelve.open(filename)
+d['id'] = 3
+d['title'] = "Actividades"
+d['text'] = '''En setiembre se viene la Liga de Primavera de Cazaproblemas.
+En breve podrás inscribirte y participar por grandes premios'''
+d['priority'] = 3
+d['launched'] = datetime.date(1972, 6, 21)
+d['expires'] = datetime.date(2013, 6, 21)
+d['type'] = "Actividades"
+d['fav'] = 0
+d.close()
+
store = Store(xmlpath='/tmp', db_filename="prueba.db")
mensaje = store.db.get_messages([])
print mensaje
diff --git a/prueba.db b/prueba.db
index b1347f2..720ed41 100644
--- a/prueba.db
+++ b/prueba.db
Binary files differ
diff --git a/store.py b/store.py
index 76b486c..6075c4e 100644
--- a/store.py
+++ b/store.py
@@ -15,11 +15,18 @@ import shelve
# for future releases
#from xml.dom import minidom
+init_db = """
+CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,
+title VARCHAR(30) NOT NULL ON CONFLICT REPLACE DEFAULT '',
+text TEXT NOT NULL ON CONFLICT REPLACE DEFAULT '',
+priority INTEGER NOT NULL,
+launched DATE NOT NULL ON CONFLICT REPLACE DEFAULT 00000000,
+expires DATETIME,
+type VARCHAR(15) NOT NULL ON CONFLICT REPLACE DEFAULT '',
+fav INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT 0 ); """
class Db:
def __init__(self, db_filename=None):
- init_db = """
-CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(30) NOT NULL ON CONFLICT REPLACE DEFAULT '',text TEXT NOT NULL ON CONFLICT REPLACE DEFAULT '', priority INTEGER NOT NULL, launched DATE NOT NULL ON CONFLICT REPLACE DEFAULT 00000000,expires DATETIME, type VARCHAR(15) NOT NULL ON CONFLICT REPLACE DEFAULT '',fav INTEGER NOT NULL ON CONFLICT REPLACE DEFAULT 0 ); """
if db_filename:
self._db_filename = db_filename
else:
@@ -61,7 +68,7 @@ CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(3
c = con.cursor()
c.execute('BEGIN TRANSACTION')
try:
- c.execute('delete from notifications where id=%i' % id)
+ c.execute('delete from notifications where id=%i' % id_msg)
except sqlite3.IntegrityError, e:
print "Error al eliminar datos: %s" % str(e)
c.execute('END TRANSACTION')
@@ -74,7 +81,7 @@ CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(3
c = con.cursor()
c.execute('BEGIN TRANSACTION')
try:
- c.execute('update notifications set fav=%i where id=%i' % (int(fav), id))
+ c.execute('update notifications set fav=%i where id=%i' % (int(fav), id_msg))
except sqlite3.IntegrityError, e:
print "Error al eliminar datos: %s" % str(e)
c.execute('END TRANSACTION')
@@ -130,9 +137,7 @@ CREATE TABLE IF NOT EXISTS notifications (id INTEGER PRIMARY KEY,title VARCHAR(3
return output
"""
-
class Store:
-
def __init__(self, xmlpath=None, db_filename=None):
self.db = Db(db_filename)
# Borro todas las notificaciones que ya expiraron