<s> from muntjac . data . item import IItem , IPropertySetChangeEvent , IPropertySetChangeNotifier , IPropertySetChangeListener <EOL> from muntjac . util import EventObject <EOL> class PropertysetItem ( IItem , IPropertySetChangeNotifier ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . _map = dict ( ) <EOL> self . _list = list ( ) <EOL> self . _propertySetChangeListeners = list ( ) <EOL> self . _propertySetChangeCallbacks = dict ( ) <EOL> def getItemProperty ( self , idd ) : <EOL> """<STR_LIT>""" <EOL> return self . _map . get ( idd ) <EOL> def getItemPropertyIds ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . _list ) <EOL> def removeItemProperty ( self , idd ) : <EOL> """<STR_LIT>""" <EOL> if idd not in self . _map : <EOL> return False <EOL> del self . _map [ idd ] <EOL> self . _list . remove ( idd ) <EOL> self . fireItemPropertySetChange ( ) <EOL> return True <EOL> def addItemProperty ( self , idd , prop ) : <EOL> """<STR_LIT>""" <EOL> if idd is None : <EOL> raise ValueError , '<STR_LIT>' <EOL> if idd in self . _map : <EOL> return False <EOL> self . _map [ idd ] = prop <EOL> self . _list . append ( idd ) <EOL> self . fireItemPropertySetChange ( ) <EOL> return True <EOL> def __str__ ( self ) : <EOL> """<STR_LIT>""" <EOL> retValue = '<STR_LIT>' <EOL> for i , propertyId in enumerate ( self . getItemPropertyIds ( ) ) : <EOL> retValue += str ( self . getItemProperty ( propertyId ) ) <EOL> if i < len ( self . getItemPropertyIds ( ) ) - <NUM_LIT:1> : <EOL> retValue += '<STR_LIT:U+0020>' <EOL> return retValue <EOL> def addListener ( self , listener , iface = None ) : <EOL> """<STR_LIT>""" <EOL> if ( isinstance ( listener , IPropertySetChangeListener ) and <EOL> ( iface is None or <EOL> issubclass ( iface , IPropertySetChangeListener ) ) ) : <EOL> self . _propertySetChangeListeners . append ( listener ) <EOL> def addCallback ( self , callback , eventType = None , * args ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , IPropertySetChangeEvent ) : <EOL> self . _propertySetChangeCallbacks [ callback ] = args <EOL> else : <EOL> super ( PropertysetItem , self ) . addCallback ( callback , <EOL> eventType , * args ) <EOL> def removeListener ( self , listener , iface = None ) : <EOL> """<STR_LIT>""" <EOL> if ( isinstance ( listener , IPropertySetChangeListener ) and <EOL> ( iface is None or <EOL> issubclass ( iface , IPropertySetChangeListener ) ) ) : <EOL> if listener in self . _propertySetChangeListeners : <EOL> self . _propertySetChangeListeners . remove ( listener ) <EOL> def removeCallback ( self , callback , eventType = None ) : <EOL> if eventType is None : <EOL> eventType = callback . _eventType <EOL> if issubclass ( eventType , IPropertySetChangeEvent ) : <EOL> if callback in self . _propertySetChangeCallbacks : <EOL> del self . _propertySetChangeCallbacks [ callback ] <EOL> else : <EOL> super ( PropertysetItem , self ) . removeCallback ( callback , eventType ) <EOL> def fireItemPropertySetChange ( self ) : <EOL> """<STR_LIT>""" <EOL> event = PropertySetChangeEvent ( self ) <EOL> for listener in self . _propertySetChangeListeners : <EOL> listener . itemPropertySetChange ( event ) <EOL> for callback , args in self . _propertySetChangeCallbacks . iteritems ( ) : <EOL> callback ( event , * args ) <EOL> def getListeners ( self , eventType ) : <EOL> if issubclass ( eventType , IPropertySetChangeEvent ) : <EOL> return list ( self . _propertySetChangeListeners ) <EOL> return list ( ) <EOL> def getCallbacks ( self , eventType ) : <EOL> if issubclass ( eventType , IPropertySetChangeEvent ) : <EOL> return dict ( self . _propertySetChangeCallbacks ) <EOL> return dict ( ) <EOL> def clone ( self ) : <EOL> """<STR_LIT>""" <EOL> npsi = PropertysetItem ( ) <EOL> npsi . list = list ( self . _list ) if self . _list is not None else None <EOL> npsi . propertySetChangeListeners = list ( self . _propertySetChangeListeners ) <EOL> npsi . map = self . _map . copy ( ) <EOL> return npsi <EOL> def __eq__ ( self , obj ) : <EOL> if ( obj is None ) or ( not isinstance ( obj , PropertysetItem ) ) : <EOL> return False <EOL> other = obj <EOL> if other . _list != self . _list : <EOL> if other . _list is None : <EOL> return False <EOL> if not ( other . _list == self . _list ) : <EOL> return False <EOL> if other . _map != self . _map : <EOL> if other . _map is None : <EOL> return False <EOL> if other . _map != self . _map : <EOL> return False <EOL> if other . _propertySetChangeListeners != self . _propertySetChangeListeners : <EOL> thisEmpty = ( ( self . _propertySetChangeListeners is None ) <EOL> or len ( self . _propertySetChangeListeners ) == <NUM_LIT:0> ) <EOL> otherEmpty = ( ( other . propertySetChangeListeners is None ) <EOL> or len ( other . propertySetChangeListeners ) == <NUM_LIT:0> ) <EOL> if thisEmpty and otherEmpty : <EOL> return True <EOL> if otherEmpty : <EOL> return False <EOL> if ( other . propertySetChangeListeners != <EOL> self . _propertySetChangeListeners ) : <EOL> return False <EOL> return True <EOL> def __hash__ ( self ) : <EOL> return ( ( ( <NUM_LIT:0> if self . _list is None else hash ( self . _list ) ) <EOL> ^ ( <NUM_LIT:0> if self . _map is None else hash ( self . _map ) ) ) <EOL> ^ ( <NUM_LIT:0> if ( self . _propertySetChangeListeners is None ) <EOL> or ( len ( self . _propertySetChangeListeners ) == <NUM_LIT:0> ) <EOL> else hash ( self . _propertySetChangeListeners ) ) ) <EOL> class PropertySetChangeEvent ( EventObject , IItem , IPropertySetChangeEvent ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , source ) : <EOL> super ( PropertySetChangeEvent , self ) . __init__ ( source ) <EOL> def getItem ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . getSource ( ) </s>
