Python + Statusbar + Osso? (or DBUS)
Since the last question which got my statusbar (and taskbar) applet in python working:
http://www.internettablettalk.com/fo...ad.php?t=22857
The following is recognized but the callback never occurs (though it will in a stand-alone):
Code:
#!/usr/bin/env python2.5
import pygtk
import gtk
import hildondesktop
import os
import osso
active = 1
class statusbar_applet(hildondesktop.StatusbarItem):
def __init__(self):
hildondesktop.StatusbarItem.__init__(self)
self.button = gtk.Button()
self.button.set_image(gtk.image_new_from_stock(gtk.STOCK_NO, gtk.ICON_SIZE_MENU))
self.button.set_name("one")
self.button.set_size_request(40,40)
self.add(self.button)
self.show_all()
osso_c = osso.Context("minigpsd-statusbar", "0.5", False)
device = osso.DeviceState(osso_c)
device.set_device_state_callback(self.state_cb, system_inactivity=1, user_data=None)
def state_cb(shutdown, save_unsaved_data, memory_low, system_inactivity,
message, userdat):
global active
self.button.set_image(gtk.image_new_from_stock(gtk.STOCK_YES, gtk.ICON_SIZE_MENU))
active += 1
if system_inactivity:
os.system( "touch /tmp/inactive &" )
else:
os.system( "touch /tmp/active &" )
return False
def hd_plugin_get_objects():
plugin = statusbar_applet()
with sdsc.desktop
Code:
[Desktop Entry]
Name=CallbackTest
Type=python
X-Path=sdsc
This is the original that works. (Maybe it is python 2.5?)
Code:
#!/usr/bin/python2.5
import osso
import gobject
def state_cb(shutdown, save_unsaved_data, memory_low, system_inactivity,
message, loop):
print "System Inactivity: ", system_inactivity
return False
def main():
loop = gobject.MainLoop()
osso_c = osso.Context("osso_test_device_on", "0.5", False)
device = osso.DeviceState(osso_c)
device.set_device_state_callback(state_cb, system_inactivity=True, user_data=None)
print 'start'
loop.run()
print 'end'
device.set_device_state_callback(None)
if __name__ == "__main__":
main()
---------------------------------
Original request about dbus:
I've run into a problem trying to use dbus. Basically I need to determine when the screen is off or the tablet is inactive, some fairly standard dbus calls. The problem is the mainloop. This is the minimalist working dbus snippet:
Code:
#!/usr/bin/env python2.5
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
import dbus
import gobject
def handler(self,sender=None):
print "screen:" + sender
def handler2(self,sender=None):
print "inactivity:" + sender
dbus_loop = gobject.MainLoop()
bus = dbus.SessionBus()
obj = bus.get_object('com.nokia.mce', '/com/nokia/mce/signal')
iface1 = dbus.Interface(obj, 'com.nokia.mce.signal')
iface1.connect_to_signal("display_status_ind", self.handler)
iface2 = dbus.Interface(obj, 'com.nokia.mce.signal')
iface2.connect_to_signal("system_inactivity_ind", self.handler2)
dbus_loop.run()
I suspect the Python-hildon-desktop stuff has its own idea of a mainloop or whatever else, so when I try to integrate this (place the above code at the obvious places in the statusbar example), I don't get any events (maybe of any kind).
Could someone help, maybe with something that changes the statusbar icon from a stock yes to no when the screen dims and back when it goes on?
|