diff options
author | flavio <fdanesse@gmail.com> | 2012-04-23 23:04:45 (GMT) |
---|---|---|
committer | flavio <fdanesse@gmail.com> | 2012-04-23 23:04:45 (GMT) |
commit | 49c217933a96a9880f15094086528ac7419111ef (patch) | |
tree | 0432329a4e55eabf2ed471637e7e31cee23b8e07 | |
parent | 1d9947fee7ccb66b685f8f68a3717915b34789a9 (diff) |
Correcciones, y se agrega interfaz en click derecho sobre item en treestore, para eliminar registro, falta funcionalidad para esto último.
-rw-r--r-- | CeibalNotifica.py | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/CeibalNotifica.py b/CeibalNotifica.py index 952a90b..57da2c4 100644 --- a/CeibalNotifica.py +++ b/CeibalNotifica.py @@ -15,14 +15,10 @@ debe ser capaz de: ''' import shelve -import sqlite3 -import time -import datetime import os import gtk import sys import gobject -import string from store import * @@ -37,7 +33,6 @@ class CeibalNotifica(gtk.Window): 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.text_buffer = None self.text_view = None @@ -50,9 +45,12 @@ class CeibalNotifica(gtk.Window): self.show_all() self.connect("delete_event", self.delete_event) - self.notify_store.connect("set_notify", self.set_notify) + self.notify_store.connect("show_notify", self.show_notify) + self.notify_store.connect("delete_notify", self.delete_notify) self.load_notify() + self.notify_store.columns_autosize() + def set_layout(self): self.listore_model = ListoreModel() self.modelsort = gtk.TreeModelSort(self.listore_model) @@ -76,9 +74,14 @@ class CeibalNotifica(gtk.Window): self.add(hpanel) - def set_notify(self, widget, text): + def show_notify(self, widget, text): self.text_buffer.set_text(text) + 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 + def load_notify(self): notificaciones = self.store.db.get_messages([]) self.listore_model.clear() @@ -102,30 +105,34 @@ class CeibalNotifica(gtk.Window): 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, 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, ))} + __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): gtk.TreeView.__init__(self, model) self.set_property("rules-hint", True) self.add_events(gtk.gdk.BUTTON2_MASK) - # self.connect("row-activated", self.callback_activated, None) - # self.connect("button-press-event", self.handler_click) + self.connect("button-press-event", self.handle_click) + 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_selecciones, self.get_model(), True) + self.treeselection.set_select_function(self.func_selections, + 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)) @@ -136,18 +143,41 @@ class Notify_Store(gtk.TreeView): 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): + def func_selections(self, selection, model, path, is_selected, user_data): iter = self.get_model().get_iter(path) - self.emit("set_notify", self.get_model().get_value(iter, 3)) + self.emit("show_notify", self.get_model().get_value(iter, 3)) return True + def handle_click(self, widget, event): + 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 + + def get_menu(self, boton, pos, tiempo, path): + menu = gtk.Menu() + eliminar = gtk.MenuItem("Eliminar Notificación.") + menu.append(eliminar) + eliminar.connect_object("activate", self.emit_delete_notify, path) + menu.show_all() + gtk.Menu.popup(menu, None, None, None, boton, tiempo) + + def emit_delete_notify(self, path): + self.emit("delete_notify", path) + if __name__=="__main__": CeibalNotifica() gtk.main() |