diff options
author | flavio <fdanesse@gmail.com> | 2012-04-25 23:02:01 (GMT) |
---|---|---|
committer | flavio <fdanesse@gmail.com> | 2012-04-25 23:02:01 (GMT) |
commit | 1440258b5c6e4c49c6462cbef8d75770c16770b6 (patch) | |
tree | feb0b042c44c883b2dbe8ccc0c0d38ec731fe085 /CeibalNotifica.py | |
parent | 8b3669916ca63b9b4237eaddd369d0dd80dbd767 (diff) |
Agrego Barra de estado y Marcas para Favoritos
Diffstat (limited to 'CeibalNotifica.py')
-rw-r--r-- | CeibalNotifica.py | 178 |
1 files changed, 105 insertions, 73 deletions
diff --git a/CeibalNotifica.py b/CeibalNotifica.py index 2669dc7..e86b350 100644 --- a/CeibalNotifica.py +++ b/CeibalNotifica.py @@ -1,18 +1,22 @@ #!/usr/bin/python # -*- coding: utf-8 -*- -# Plan Ceibal - Uruguay -# 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: -- Mostrar todos los mensajes activos. -- Filtrar y ordenar los mensajes por prioridad, -fecha o tipo de mensajes. -''' +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import shelve import os @@ -21,7 +25,9 @@ import sys import gobject from store import * BASE = os.path.dirname(__file__) - +pixbuf1 = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(BASE, "Iconos", "ceibal-gris.png"), 32,32) +pixbuf2 = gtk.gdk.pixbuf_new_from_file_at_size(os.path.join(BASE, "Iconos", "ceibal.png"), 32,32) + class CeibalNotifica(gtk.Window): def __init__(self): super(CeibalNotifica, self).__init__() @@ -31,92 +37,97 @@ class CeibalNotifica(gtk.Window): self.set_size_request(640, 480) self.set_border_width(2) self.set_position(gtk.WIN_POS_CENTER) - self.text_buffer = None self.text_view = None self.store = None self.listore_model = None self.modelsort = None self.notify_store = None - self.info_label = None - + self.info_toolbar = None self.set_layout() self.show_all() - self.connect("delete_event", self.delete_event) self.notify_store.connect("show_notify", self.show_notify) self.notify_store.connect("delete_notify", self.delete_notify) self.notify_store.connect("marcar_notify", self.marcar_notify) self.load_notify() - self.notify_store.columns_autosize() 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) self.text_view.set_editable(False) hpanel = gtk.HPaned() - 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 = True) - vbox = gtk.VBox() - self.info_label = gtk.Label("") + self.info_toolbar = Toolbar() vbox.pack_start(hpanel, True, True, 0) - vbox.pack_start(self.info_label, False, False, 0) - + vbox.pack_start(self.info_toolbar, False, False, 0) hpanel.show_all() self.add(vbox) def show_notify(self, widget, text, info): self.text_buffer.set_text(text) - self.info_label.set_text(info) + self.info_toolbar.set_text(info) def delete_notify(self, widget, path): iter = widget.get_model().get_iter(path) - id_registro = int(widget.get_model().get_value(iter, 0)) + id_registro = int(widget.get_model().get_value(iter, 1)) self.store.db.remove_message(id_registro) iter = self.listore_model.get_iter(path) self.listore_model.remove(iter) - self.text_buffer.set_text('') - self.info_label.set_text('') + self.update_view() def marcar_notify(self, widget, path): iter = widget.get_model().get_iter(path) - id_registro = int(widget.get_model().get_value(iter, 0)) + id_registro = int(widget.get_model().get_value(iter, 1)) marca = not self.store.db.is_fav(id_registro) self.store.db.set_fav(id_registro, fav=marca) iter = self.listore_model.get_iter(path) - self.listore_model.set_value(iter, 7, int(self.store.db.is_fav(id_registro))) - self.info_label.set_text('') - + fav = self.store.db.is_fav(id_registro) + self.listore_model.set_value(iter, 8, fav) + self.update_view() + + def update_view(self): + path = self.notify_store.get_path_selected() + if path == None: path = 0 + self.notify_store.treeselection.select_path(path) + try: + iter = self.listore_model.get_iter(path) + if self.listore_model.get_value(iter, 8): + self.listore_model.set_value(iter, 0, pixbuf2) + else: + self.listore_model.set_value(iter, 0, pixbuf1) + except: + self.text_buffer.set_text('') + self.info_toolbar.set_text('') + def load_notify(self): notificaciones = self.store.db.get_messages([]) self.listore_model.clear() - self.text_buffer.set_text('') - self.info_label.set_text('') for notif in notificaciones: 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']] + mark = pixbuf1 + if bool(notify['fav']): mark = pixbuf2 + notify = [mark, notify['id'], notify['priority'], notify['title'], notify['text'], + notify['launched'], notify['expires'], notify['type'], bool(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) + il = self.modelsort.convert_child_iter_to_iter(None, io) + sel.select_iter(il) def delete_event(self, widget, event): self.salir() @@ -127,15 +138,12 @@ class CeibalNotifica(gtk.Window): class ListoreModel(gtk.ListStore): def __init__(self): - gtk.ListStore.__init__(self, gobject.TYPE_STRING, + gtk.ListStore.__init__(self, gtk.gdk.Pixbuf, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING, - gobject.TYPE_STRING) + gobject.TYPE_STRING, gobject.TYPE_BOOLEAN) -''' -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, gobject.TYPE_STRING)), @@ -151,22 +159,28 @@ class Notify_Store(gtk.TreeView): self.set_headers_clickable(True) self.set_columns() self.show_all() - self.treeselection = self.get_selection() self.treeselection.set_mode(gtk.SELECTION_SINGLE) self.treeselection.set_select_function(self.func_selections, self.get_model(), True) def set_columns(self): - 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, 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, False)) + self.append_column(self.make_column_mark('', 0, True)) + self.append_column(self.make_column('id', 1, False)) + self.append_column(self.make_column('Prioridad', 2, True)) + self.append_column(self.make_column('Título', 3, True)) + self.append_column(self.make_column('Notificación', 4, False)) + self.append_column(self.make_column('Lanzamiento', 5, False)) + self.append_column(self.make_column('Expira', 6, True)) + self.append_column(self.make_column('Tipo', 7, True)) + self.append_column(self.make_column('Favorito', 8, False)) + def make_column_mark(self, text, index, visible): + render = gtk.CellRendererPixbuf() + column = gtk.TreeViewColumn(text, render, pixbuf = index) + column.set_property("visible", visible) + return column + def make_column(self, text, index, visible): render = gtk.CellRendererText() column = gtk.TreeViewColumn(text, render, text=index) @@ -176,10 +190,10 @@ class Notify_Store(gtk.TreeView): def func_selections(self, selection, model, path, is_selected, user_data): iter = self.get_model().get_iter(path) - texto = self.get_model().get_value(iter, 3) - nid = self.get_model().get_value(iter, 0) - lanzamiento = self.get_model().get_value(iter, 4) - fav = bool(int(self.get_model().get_value(iter, 7))) + texto = self.get_model().get_value(iter, 4) + nid = self.get_model().get_value(iter, 1) + lanzamiento = self.get_model().get_value(iter, 5) + fav = self.get_model().get_value(iter, 8) info = "id: %s Lanzamiento: %s Favorito: %s" % (nid, lanzamiento, fav) self.emit("show_notify", texto, info) return True @@ -206,34 +220,52 @@ class Notify_Store(gtk.TreeView): menu.append(eliminar) eliminar.connect_object("activate", self.emit_delete_notify, path) iter = self.get_model().get_iter(path) - fav = bool(int(self.get_model().get_value(iter, 7))) + fav = self.get_model().get_value(iter, 8) marcar = gtk.MenuItem("Marcar Como Favorito.") if fav: marcar = gtk.MenuItem("Desmarcar Como Favorito.") menu.append(marcar) marcar.connect_object("activate", self.emit_marcar_notify, path) menu.show_all() gtk.Menu.popup(menu, None, None, None, boton, tiempo) - + + def get_path_selected(self): + (model, iter) = self.get_selection().get_selected() + path = None + if iter: + treemodelrow = model[iter] + path = treemodelrow.path + return path + def emit_delete_notify(self, path): self.emit("delete_notify", path) def emit_marcar_notify(self, path): self.emit("marcar_notify", path) +class Toolbar(gtk.Toolbar): + def __init__(self): + gtk.Toolbar.__init__(self) + self.modify_bg(gtk.STATE_NORMAL, + gtk.gdk.Color(0, 0, 0, 1)) + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_size_request(0, -1) + separator.set_expand(True) + self.insert(separator, -1) + item = gtk.ToolItem() + self.info_label = gtk.Label("") + self.info_label.modify_fg(gtk.STATE_NORMAL, + gtk.gdk.Color(65535, 65535, 65535,1)) + self.info_label.show() + item.add(self.info_label) + self.insert(item, -1) + separator = gtk.SeparatorToolItem() + separator.props.draw = False + separator.set_size_request(0, -1) + separator.set_expand(True) + self.insert(separator, -1) + def set_text(self, text=""): + self.info_label.set_text(text) + 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['fav'] = 0 -d.close() -''' |