Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/CeibalNotifica.py
diff options
context:
space:
mode:
authorflavio <fdanesse@gmail.com>2012-04-11 19:04:41 (GMT)
committer flavio <fdanesse@gmail.com>2012-04-11 19:04:41 (GMT)
commit56811517bc85b6d64ed752c0400803a47eb7c9a8 (patch)
tree25e420e38a626b34a83c918c8658a09a96ed92c9 /CeibalNotifica.py
Ceibal Notifica
Diffstat (limited to 'CeibalNotifica.py')
-rw-r--r--CeibalNotifica.py262
1 files changed, 262 insertions, 0 deletions
diff --git a/CeibalNotifica.py b/CeibalNotifica.py
new file mode 100644
index 0000000..ddccc08
--- /dev/null
+++ b/CeibalNotifica.py
@@ -0,0 +1,262 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Autor: Flavio Danesse - fdanesse@activitycentral.com
+'''
+La idea es hacer una aplicación que sea capaz de mostrar todos los mensajes, no importa su prioridad.
+La aplicación se llevará a cabo tanto en el azúcar y el Gnome y debe ser capaz de:
+- Muestra todos los mensajes activos
+- Filtrar y ordenar los mensajes por prioridad, fecha o tipo de mensajes'''
+
+import shelve
+import sqlite3
+import time
+import datetime
+import os
+import gtk
+import sys
+import gobject
+import string
+
+from store import *
+
+BASE = os.path.dirname(__file__)
+
+class CeibalNotifica(gtk.Window):
+ def __init__(self):
+ super(CeibalNotifica, self).__init__()
+ self.set_title("CeibalNotifica")
+ self.set_icon_from_file(os.path.join(BASE, "Iconos", "ceibal.png"))
+ self.set_resizable(True)
+ self.set_size_request(640, 480)
+ self.set_border_width(2)
+ self.set_position(gtk.WIN_POS_CENTER)
+ #self.modify_bg(gtk.STATE_NORMAL, G.GRIS)
+
+ self.notify_store = None
+ self.store = None
+ self.text_buffer = None
+ self.text_view = None
+
+ self.set_layout()
+
+ self.show_all()
+
+ self.connect("delete_event", self.delete_event)
+ self.notify_store.connect("set_notify", self.set_notify)
+
+ self.load_notify()
+
+ def set_layout(self):
+ self.text_buffer = gtk.TextBuffer()
+ self.text_view = gtk.TextView(buffer = self.text_buffer)
+ hpanel = gtk.HPaned()
+
+ self.notify_store = Notify_Store()
+ self.store = Store(db_filename = "prueba.db")
+ scroll = gtk.ScrolledWindow()
+ scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ scroll.add_with_viewport(self.notify_store)
+ hpanel.pack1(scroll, resize = False, shrink = True)
+
+ scroll = gtk.ScrolledWindow()
+ scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
+ scroll.add_with_viewport(self.text_view)
+ hpanel.pack2(scroll, resize = False, shrink = False)
+ hpanel.show_all()
+
+ self.add(hpanel)
+
+ def set_notify(self, widget, text):
+ self.text_buffer.set_text(text)
+
+ def load_notify(self):
+ notificaciones = self.store.db.get_messages([])
+ self.notify_store.clear()
+ for notif in notificaciones:
+ self.notify_store.add_notify(notif)
+
+ def delete_event(self, widget, event):
+ self.salir()
+ return False
+ def salir(self, widget = None):
+ sys.exit(0)
+
+
+class Notify_Store(gtk.TreeView):
+ __gsignals__ = {"set_notify":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, ))}
+ def __init__(self):
+ gtk.TreeView.__init__(self)
+ self.set_property("rules-hint", True)
+ # self.connect("row-activated", self.callback_activated, None)
+ self.add_events(gtk.gdk.BUTTON2_MASK)
+ #self.connect("button-press-event", self.handler_click)
+
+ self.modelo = gtk.ListStore (gobject.TYPE_STRING,
+ gobject.TYPE_STRING, gobject.TYPE_STRING,
+ gobject.TYPE_STRING, gobject.TYPE_STRING)
+
+ self.set_model(self.modelo)
+ render = gtk.CellRendererText()
+ columna = gtk.TreeViewColumn ("Notificaciones:", render, text=0)
+ self.append_column(columna)
+
+ render = gtk.CellRendererText()
+ columna = gtk.TreeViewColumn("text", render, text=1)
+ columna.set_property('visible', False)
+ self.append_column(columna)
+
+ render = gtk.CellRendererText()
+ columna = gtk.TreeViewColumn("launched", render, text=2)
+ columna.set_property('visible', False)
+ self.append_column(columna)
+
+ render = gtk.CellRendererText()
+ columna = gtk.TreeViewColumn("expires", render, text=3)
+ columna.set_property('visible', False)
+ self.append_column(columna)
+
+ render = gtk.CellRendererText()
+ columna = gtk.TreeViewColumn("type", render, text=4)
+ columna.set_property('visible', False)
+ self.append_column(columna)
+ self.show_all()
+
+ self.treeselection = self.get_selection()
+ self.treeselection.set_mode(gtk.SELECTION_SINGLE)
+ # conecta a una funcion que manejará las selecciones
+ self.treeselection.set_select_function(self.func_selecciones, self.modelo, True)
+
+ def clear(self):
+ self.modelo.clear()
+ def add_notify(self, notify):
+ notify = [notify['title'], notify['text'], notify['launched'], notify['expires'], notify['type']]
+ iter = self.modelo.append(notify)
+
+ def func_selecciones(self, selection, model, path, is_selected, user_data):
+ # Control de selecciones sobre treestore
+ # print selection, model, path, is_selected, user_data
+ iter = self.modelo.get_iter(path)
+ self.emit("set_notify", self.modelo.get_value(iter, 1))
+ #direccion = self.modelo.get_value(iter, 2)
+ #self.preview.control_preview(direccion)
+ return True # Debe devolver True
+
+ def callback_activated (self, treeview, path, view_column, user_param1):
+ pass
+ # print treeview, path, view_column, user_param1
+ # Cuando se hace doble click sobre una fila
+ '''
+ # Obtengo el valor almacenado
+ iter = treeview.modelo.get_iter(path)
+ valor = treeview.modelo.get_value(iter, 2)
+
+ if os.path.isdir(os.path.join(valor)):
+ # Si representa a un directorio
+ if treeview.row_expanded(path):
+ # Si está expandida, colapsarla
+ treeview.collapse_row(path)
+ elif not treeview.row_expanded(path):
+ # Si no está expandida, expandirla
+ treeview.expand_to_path(path)
+ elif os.path.isfile(os.path.join(valor)):
+ # Si representa a un archivo
+ pass'''
+
+ def handler_click(self, widget, event):
+ pass
+ # reacciona a los clicks sobre las filas de tresstore
+ # print widget, event
+ '''
+ boton = event.button
+ pos = (event.x, event.y)
+ tiempo = event.time
+ # widget es TreeView widget.get_name()
+ # Obteniendo datos a partir de coordenadas de evento
+ path, columna, xdefondo, ydefondo= widget.get_path_at_pos(int(pos[0]), int(pos[1]))
+ # TreeView.get_path_at_pos(event.x, event.y) devuelve:
+ # * La ruta de acceso en el punto especificado (x, y), en relación con las coordenadas widget
+ # * El gtk.TreeViewColumn en ese punto
+ # * La coordenada X en relación con el fondo de la celda
+ # * La coordenada Y en relación con el fondo de la celda
+ if boton == 1:
+ return
+ elif boton == 3:
+ # Abrir menu - popup pasando el path de la fila seleccionada
+ self.crear_menu_emergente(boton, pos, tiempo, path)
+ return
+ elif boton == 2:
+ return'''
+
+ '''
+ def crear_menu_emergente(self, boton, pos, tiempo, path):
+ # un menu para agregar o eliminar radios de la base de datos
+ menu= gtk.Menu()
+ iter= self.modelo.get_iter(path)
+ direccion= self.modelo.get_value(iter, 2)
+ # verificamos los permisos del archivo o directorio
+ lectura, escritura, ejecucion= self.manejadordearchivos.verificar_permisos(direccion)
+
+ # Items del menu
+ if lectura: #and not os.path.ismount(os.path.join(direccion)):
+ copiar = gtk.MenuItem("Copiar")
+ menu.append(copiar)
+ copiar.connect_object("activate", self.seleccionar_origen, path, "Copiar")
+
+ if escritura and not os.path.ismount(os.path.join(direccion)):
+ borrar = gtk.MenuItem("Borrar")
+ menu.append(borrar)
+ borrar.connect_object("activate", self.seleccionar_origen, path, "Borrar")
+
+ if escritura and (os.path.isdir(os.path.join(direccion)) or os.path.ismount(os.path.join(direccion))) \
+ and (self.direccion_seleccionada != None or self.direccion_seleccionada_para_cortar != None):
+ pegar = gtk.MenuItem("Pegar")
+ menu.append(pegar)
+ pegar.connect_object("activate", self.seleccionar_origen, path, "Pegar")
+
+ if escritura and (os.path.isdir(os.path.join(direccion)) or os.path.isfile(os.path.join(direccion))):
+ cortar = gtk.MenuItem("Cortar")
+ menu.append(cortar)
+ cortar.connect_object("activate", self.seleccionar_origen, path, "Cortar")
+
+ if escritura and (os.path.isdir(os.path.join(direccion)) or os.path.ismount(os.path.join(direccion))):
+ nuevodirectorio = gtk.MenuItem("Crear Directorio")
+ menu.append(nuevodirectorio)
+ nuevodirectorio.connect_object("activate", self.seleccionar_origen, path, "Crear Directorio")
+
+ menu.show_all()
+ #popup(parent_menu_shell, parent_menu_item, func, button, activate_time, data=None)
+ gtk.Menu.popup(menu, None, None, None, boton, tiempo)'''
+
+if __name__=="__main__":
+ CeibalNotifica()
+ gtk.main()
+
+'''
+# Archivo notificaciones # http://docs.python.org/library/shelve.html
+filename = os.path.join('/tmp', 'notify_0')
+d = shelve.open(filename)
+d['id'] = 0
+d['title'] = "Prueba Titulo"
+d['text'] = "Prueba Texto"
+d['priority'] = 1
+d['launched'] = datetime.date(1972, 6, 21)
+d['expires'] = datetime.date(2012, 6, 21)
+d['type'] = "Prueba tipo"
+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.close()
+
+store = Store(db_filename="prueba.db")
+mensaje = store.db.get_messages([])
+print mensaje'''
+