<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:verdana,helvetica,sans-serif;font-size:8pt"><br>Hi,<br><br>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:<br><br><font size="3"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">#!/usr/bin/env python</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">import dbus, gobject</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">from dbus.mainloop.glib import DBusGMainLoop</span><br style="font-family: Courier
 New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">bus = dbus.SessionBus()</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")</span><br style="font-family: Courier
 New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">STATUS_AVAILABLE = 2</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">STATUS_AWAY = 5</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">ORIG_TYPE = 0</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">ORIG_MSG = ""</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br
 style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">def my_func2(IsEnabled):</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    if IsEnabled:</span><br style="color: rgb(255, 0, 0); font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="color: rgb(255, 0, 0); font-family: Courier New,courier,monaco,monospace,sans-serif;">        ORIG_TYPE,ORIG_MSG = get_current()    </span><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">            </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span
 style="font-family: Courier New,courier,monaco,monospace,sans-serif;">        set_status(STATUS_AWAY,"I'm not at my desk")</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    else:</span><br style="color: rgb(0, 0, 0); font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="color: rgb(255, 0, 0); font-family: Courier New,courier,monaco,monospace,sans-serif;">        set_status(ORIG_TYPE,ORIG_MSG)    </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">def set_status(kind, message):</span><br style="font-family: Courier
 New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">        </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    status = purple.PurpleSavedstatusNew("", kind)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    purple.PurpleSavedstatusSetMessage(status, message)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">   
     purple.PurpleSavedstatusActivate(status)</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">def get_current():</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    typ = purple.PurpleSavedstatusGetType(purple.PurpleSavedstatusGetCurrent())</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    current = purple.PurpleSavedstatusGetCurrent()</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family:
 Courier New,courier,monaco,monospace,sans-serif;">    msg = purple.PurpleSavedstatusGetMessage(dbus.Int32(current))</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    return typ,msg</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">    </span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">bus.add_signal_receiver(my_func2,</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier
 New,courier,monaco,monospace,sans-serif;">                        dbus_interface="org.gnome.ScreenSaver",</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">                        signal_name="SessionIdleChanged")</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span style="font-family: Courier New,courier,monaco,monospace,sans-serif;">loop = gobject.MainLoop()</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"><span
 style="font-family: Courier New,courier,monaco,monospace,sans-serif;">loop.run()</span><br style="font-family: Courier New,courier,monaco,monospace,sans-serif;"></font><br><br>When I run it,it errors out at :<br><br><span style="color: rgb(255, 0, 0);">        set_status(ORIG_TYPE,ORIG_MSG)    <br><span style="color: rgb(17, 17, 17);"><br>giving the error "UnboundLocalError: local variable 'ORIG_TYPE' referenced before assignment" .This happens </span><br></span><div> </div>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.<br><br>Regards,<br>SZ<br><div><br></div></div><br>







      <hr size=1>
Get the name you always wanted with the <a href="http://au.rd.yahoo.com/mail/taglines/au/y7mail/default/*http://au.mail.yahoo.com/?p1=ni&p2=general&p3=tagline&p4=other" target=_blank>new y7mail email address</a>.</body></html>