Hi,
I am writing a small script that changes my pidgin status to away when I lock
my screen.I'm using the DBUS API for pidgin and gnome-screensaver.Here's the
code:
#!/usr/bin/env python
import dbus, gobject
from dbus.mainloop.glib import DBusGMainLoop
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService",
"/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
STATUS_AVAILABLE = 2
STATUS_AWAY = 5
ORIG_TYPE = 0
ORIG_MSG = ""
def my_func2(IsEnabled):
if IsEnabled:
ORIG_TYPE,ORIG_MSG = get_current()
set_status(STATUS_AWAY,"I'm not at my desk")
else:
set_status(ORIG_TYPE,ORIG_MSG)
def set_status(kind, message):
status = purple.PurpleSavedstatusNew("", kind)
purple.PurpleSavedstatusSetMessage(status, message)
purple.PurpleSavedstatusActivate(status)
def get_current():
typ = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())
current = purple.PurpleSavedstatusGetCurrent()
msg = purple.PurpleSavedstatusGetMessage(dbus.Int32(current))
return typ,msg
bus.add_signal_receiver(my_func2,
dbus_interface="org.gnome.ScreenSaver",
signal_name="SessionIdleChanged")
loop = gobject.MainLoop()
loop.run()
When I run it,it errors out at :
set_status(ORIG_TYPE,ORIG_MSG)
giving the error "UnboundLocalError: local variable 'ORIG_TYPE' referenced
before assignment" .This happens
Aren't ORIG_TYPE and ORIG_MSG global variables? Where am I going
wrong?Everything works fine if I set the arguments manually to the set_status
function.
Regards,
SZ
Get the name you always wanted with the new y7mail email address.
www.yahoo7.com.au/mail
--
http://mail.python.org/mailman/listinfo/python-list