<s> """<STR_LIT>""" <EOL> import dbus <EOL> EXPIRES_DEFAULT = - <NUM_LIT:1> <EOL> EXPIRES_NEVER = <NUM_LIT:0> <EOL> URGENCY_LOW = <NUM_LIT:0> <EOL> URGENCY_NORMAL = <NUM_LIT:1> <EOL> URGENCY_CRITICAL = <NUM_LIT:2> <EOL> urgency_levels = [ URGENCY_LOW , URGENCY_NORMAL , URGENCY_CRITICAL ] <EOL> initted = False <EOL> appname = "<STR_LIT>" <EOL> _have_mainloop = False <EOL> class UninittedError ( RuntimeError ) : <EOL> pass <EOL> class UninittedDbusObj ( object ) : <EOL> def __getattr__ ( self , name ) : <EOL> raise UninittedError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> dbus_iface = UninittedDbusObj ( ) <EOL> def init ( app_name , mainloop = None ) : <EOL> """<STR_LIT>""" <EOL> global appname , initted , dbus_iface , _have_mainloop <EOL> if mainloop == '<STR_LIT>' : <EOL> from dbus . mainloop . glib import DBusGMainLoop <EOL> mainloop = DBusGMainLoop ( ) <EOL> elif mainloop == '<STR_LIT>' : <EOL> from dbus . mainloop . qt import DBusQtMainLoop <EOL> mainloop = DBusQtMainLoop ( set_as_default = True ) <EOL> bus = dbus . SessionBus ( mainloop = mainloop ) <EOL> dbus_obj = bus . get_object ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> dbus_iface = dbus . Interface ( dbus_obj , <EOL> dbus_interface = '<STR_LIT>' ) <EOL> appname = app_name <EOL> initted = True <EOL> if mainloop or dbus . get_default_main_loop ( ) : <EOL> _have_mainloop = True <EOL> dbus_iface . connect_to_signal ( '<STR_LIT>' , _action_callback ) <EOL> dbus_iface . connect_to_signal ( '<STR_LIT>' , _closed_callback ) <EOL> return True <EOL> def is_initted ( ) : <EOL> """<STR_LIT>""" <EOL> return initted <EOL> def get_app_name ( ) : <EOL> """<STR_LIT>""" <EOL> return appname <EOL> def uninit ( ) : <EOL> """<STR_LIT>""" <EOL> global initted , dbus_iface , _have_mainloop <EOL> initted = False <EOL> _have_mainloop = False <EOL> dbus_iface = UninittedDbusObj ( ) <EOL> def get_server_caps ( ) : <EOL> """<STR_LIT>""" <EOL> return [ str ( x ) for x in dbus_iface . GetCapabilities ( ) ] <EOL> def get_server_info ( ) : <EOL> """<STR_LIT>""" <EOL> res = dbus_iface . GetServerInformation ( ) <EOL> return { '<STR_LIT:name>' : str ( res [ <NUM_LIT:0> ] ) , <EOL> '<STR_LIT>' : str ( res [ <NUM_LIT:1> ] ) , <EOL> '<STR_LIT:version>' : str ( res [ <NUM_LIT:2> ] ) , <EOL> '<STR_LIT>' : str ( res [ <NUM_LIT:3> ] ) , <EOL> } <EOL> notifications_registry = { } <EOL> def _action_callback ( nid , action ) : <EOL> nid , action = int ( nid ) , str ( action ) <EOL> n = notifications_registry [ nid ] <EOL> n . _action_callback ( action ) <EOL> def _closed_callback ( nid , reason ) : <EOL> nid , reason = int ( nid ) , int ( reason ) <EOL> n = notifications_registry [ nid ] <EOL> n . _closed_callback ( n ) <EOL> del notifications_registry [ nid ] <EOL> def no_op ( * args ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Notification ( object ) : <EOL> id = <NUM_LIT:0> <EOL> timeout = - <NUM_LIT:1> <EOL> _closed_callback = no_op <EOL> def __init__ ( self , summary , message = '<STR_LIT>' , icon = '<STR_LIT>' ) : <EOL> self . summary = summary <EOL> self . message = message <EOL> self . icon = icon <EOL> self . hints = { } <EOL> self . actions = { } <EOL> self . data = { } <EOL> def show ( self ) : <EOL> """<STR_LIT>""" <EOL> nid = dbus_iface . Notify ( appname , <EOL> self . id , <EOL> self . icon , <EOL> self . summary , <EOL> self . message , <EOL> self . _make_actions_array ( ) , <EOL> self . hints , <EOL> self . timeout , <EOL> ) <EOL> self . id = int ( nid ) <EOL> if _have_mainloop : <EOL> notifications_registry [ self . id ] = self <EOL> return True <EOL> def update ( self , summary , message = "<STR_LIT>" , icon = None ) : <EOL> """<STR_LIT>""" <EOL> self . summary = summary <EOL> self . message = message <EOL> if icon is not None : <EOL> self . icon = icon <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . id != <NUM_LIT:0> : <EOL> dbus_iface . CloseNotification ( self . id ) <EOL> def set_hint ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . hints [ key ] = value <EOL> set_hint_string = set_hint_int32 = set_hint_double = set_hint <EOL> def set_hint_byte ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . hints [ key ] = dbus . Byte ( value ) <EOL> def set_urgency ( self , level ) : <EOL> """<STR_LIT>""" <EOL> if level not in urgency_levels : <EOL> raise ValueError ( "<STR_LIT>" , level ) <EOL> self . set_hint_byte ( "<STR_LIT>" , level ) <EOL> def set_category ( self , category ) : <EOL> """<STR_LIT>""" <EOL> self . hints [ '<STR_LIT>' ] = category <EOL> def set_timeout ( self , timeout ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( timeout , int ) : <EOL> raise TypeError ( "<STR_LIT>" , timeout ) <EOL> self . timeout = timeout <EOL> def get_timeout ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . timeout <EOL> def add_action ( self , action , label , callback , user_data = None ) : <EOL> """<STR_LIT>""" <EOL> self . actions [ action ] = ( label , callback , user_data ) <EOL> def _make_actions_array ( self ) : <EOL> """<STR_LIT>""" <EOL> arr = [ ] <EOL> for action , ( label , callback , user_data ) in self . actions . items ( ) : <EOL> arr . append ( action ) <EOL> arr . append ( label ) <EOL> return arr <EOL> def _action_callback ( self , action ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> label , callback , user_data = self . actions [ action ] <EOL> except KeyError : <EOL> return <EOL> if user_data is None : <EOL> callback ( self , action ) <EOL> else : <EOL> callback ( self , action , user_data ) <EOL> def connect ( self , event , callback ) : <EOL> """<STR_LIT>""" <EOL> if event != '<STR_LIT>' : <EOL> raise ValueError ( "<STR_LIT>" , event ) <EOL> self . _closed_callback = callback <EOL> def set_data ( self , key , value ) : <EOL> """<STR_LIT>""" <EOL> self . data [ key ] = value <EOL> def get_data ( self , key ) : <EOL> """<STR_LIT>""" <EOL> return self . data [ key ] <EOL> def set_icon_from_pixbuf ( self , icon ) : <EOL> """<STR_LIT>""" <EOL> struct = ( <EOL> icon . get_width ( ) , <EOL> icon . get_height ( ) , <EOL> icon . get_rowstride ( ) , <EOL> icon . get_has_alpha ( ) , <EOL> icon . get_bits_per_sample ( ) , <EOL> icon . get_n_channels ( ) , <EOL> dbus . ByteArray ( icon . get_pixels ( ) ) <EOL> ) <EOL> self . hints [ '<STR_LIT>' ] = struct <EOL> def set_location ( self , x , y ) : <EOL> """<STR_LIT>""" <EOL> if ( not isinstance ( x , int ) ) or ( not isinstance ( y , int ) ) : <EOL> raise TypeError ( "<STR_LIT>" , ( x , y ) ) <EOL> self . hints [ '<STR_LIT:x>' ] = x <EOL> self . hints [ '<STR_LIT:y>' ] = y </s>
