Skip to content

Instantly share code, notes, and snippets.

@segphault
Created April 4, 2010 19:10
Show Gist options
  • Save segphault/355627 to your computer and use it in GitHub Desktop.
Save segphault/355627 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import gtk, dbus, dbus.service, sqlite3
from dbus.mainloop.glib import DBusGMainLoop
DB_FILENAME = "/home/segphault/test.sqlite"
DBusGMainLoop(set_as_default=True)
class Notifier(dbus.service.Object):
__dbus_object_path__ = "/net/phault/Test"
def __init__(self):
self.bus = dbus.SessionBus()
bus_name = dbus.service.BusName("net.phault.Test", bus=self.bus)
dbus.service.Object.__init__(self, bus_name, self.__dbus_object_path__)
@dbus.service.signal(dbus_interface="net.phault.Test")
def OnRowInserted(self, id, text):
print "Row inserted:", id, text
NOTIFY = Notifier()
db = sqlite3.connect(DB_FILENAME)
db.create_function("notify", 2, NOTIFY.OnRowInserted)
cur = db.cursor()
cur.executescript("""
CREATE TABLE test (id INTEGER PRIMARY KEY, value TEXT);
CREATE TRIGGER InsertNotification AFTER INSERT ON test
BEGIN
SELECT notify(NEW.id, NEW.value);
END;
INSERT INTO test VALUES(NULL, "This is a test");
""")
db.commit()
db.close()
gtk.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment