From 1d9947fee7ccb66b685f8f68a3717915b34789a9 Mon Sep 17 00:00:00 2001 From: flavio Date: Mon, 23 Apr 2012 20:49:16 +0000 Subject: Se agrega TreeModelSort --- diff --git a/CeibalNotifica.py b/CeibalNotifica.py index 4279474..952a90b 100644 --- a/CeibalNotifica.py +++ b/CeibalNotifica.py @@ -1,12 +1,18 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Autor: Flavio Danesse - fdanesse@activitycentral.com +# Plan Ceibal - Uruguay +# 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 sugar como en Gnome y debe ser capaz de: +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 sugar como en Gnome y +debe ser capaz de: - Mostrar todos los mensajes activos. -- Filtrar y ordenar los mensajes por prioridad, fecha o tipo de mensajes.''' +- Filtrar y ordenar los mensajes por prioridad, + fecha o tipo de mensajes. +''' import shelve import sqlite3 @@ -25,7 +31,7 @@ BASE = os.path.dirname(__file__) class CeibalNotifica(gtk.Window): def __init__(self): super(CeibalNotifica, self).__init__() - self.set_title("CeibalNotifica") + self.set_title("Ceibal Notifica") self.set_icon_from_file(os.path.join(BASE, "Iconos", "ceibal.png")) self.set_resizable(True) self.set_size_request(640, 480) @@ -33,26 +39,29 @@ class CeibalNotifica(gtk.Window): 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.listore_model = None + self.modelsort = None + self.notify_store = 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.listore_model = ListoreModel() + self.modelsort = gtk.TreeModelSort(self.listore_model) + self.notify_store = Notify_Store(self.modelsort) + 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) @@ -72,124 +81,72 @@ class CeibalNotifica(gtk.Window): def load_notify(self): notificaciones = self.store.db.get_messages([]) - self.notify_store.clear() + self.listore_model.clear() for notif in notificaciones: - self.notify_store.add_notify(notif) + self.add_notify(notif) + def add_notify(self, notify): + notify = [notify['id'], notify['priority'], notify['title'], notify['text'], + notify['launched'], notify['expires'], notify['type'], notify['fav']] + io = self.modelsort.get_model().append(notify) + sel = self.notify_store.get_selection() + i1 = self.modelsort.convert_child_iter_to_iter(None, io) + sel.select_iter(i1) + def delete_event(self, widget, event): self.salir() return False def salir(self, widget = None): sys.exit(0) + +class ListoreModel(gtk.ListStore): + def __init__(self): + gtk.ListStore.__init__(self, gobject.TYPE_STRING, + gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, + gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, + gobject.TYPE_STRING) + ''' 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__ = {"set_notify":(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (gobject.TYPE_STRING, ))} - def __init__(self): - gtk.TreeView.__init__(self) + def __init__(self, model): + gtk.TreeView.__init__(self, model) 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, 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("id", render, text=0) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("priority", render, text=1) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("title", render, text=2) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("text", render, text=3) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("launched", render, text=4) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("expires", render, text=5) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("type", render, text=6) - columna.set_property('visible', True) - self.append_column(columna) - - render = gtk.CellRendererText() - columna = gtk.TreeViewColumn("fav", render, text=7) - columna.set_property('visible', True) - self.append_column(columna) + # self.connect("row-activated", self.callback_activated, None) + # self.connect("button-press-event", self.handler_click) + self.set_columns() 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): - '''solo priority no se recupera.''' - notify = [notify['id'], notify['priority'], notify['title'], notify['text'], - notify['launched'], notify['expires'], notify['type'], notify['fav']] - iter = self.modelo.append(notify) - + self.treeselection.set_select_function(self.func_selecciones, self.get_model(), True) + + def set_columns(self): + # self.append_column(self.make_column('Notificaciones', 0, True)) + self.append_column(self.make_column('id', 0, True)) + 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('Expira', 5, True)) + self.append_column(self.make_column('Tipo', 6, True)) + self.append_column(self.make_column('Favorito', 7, True)) + + def make_column(self, text, index, visible): + print text, index + render = gtk.CellRendererText() + column = gtk.TreeViewColumn(text, render, text=index) + column.set_sort_column_id(index) + column.set_property('visible', visible) + return column + 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, 3)) - #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 + iter = self.get_model().get_iter(path) + self.emit("set_notify", self.get_model().get_value(iter, 3)) + return True if __name__=="__main__": CeibalNotifica() @@ -224,4 +181,3 @@ d.close() store = Store(db_filename="prueba.db") mensaje = store.db.get_messages([]) print mensaje''' - -- cgit v0.9.1