Changeset 29
- Timestamp:
- 02/29/08 08:20:45 (10 months ago)
- Files:
-
- project/trunk/src/pyxoo/command.py (modified) (1 diff)
- project/trunk/src/pyxoo/core.py (modified) (6 diffs)
- project/trunk/src/pyxoo/event.py (modified) (11 diffs)
- project/trunk/src/pyxoo/exceptions.py (modified) (2 diffs)
- project/trunk/src/pyxoo/plugin.py (modified) (5 diffs)
- project/trunk/src/pyxoo/utils/interface.py (modified) (4 diffs)
- project/trunk/src/pyxoo/view.py (modified) (4 diffs)
- project/trunk/test/commands/TestFrontController.py (modified) (1 diff)
- project/trunk/test/events/TestChannelBroadcaster.py (modified) (1 diff)
- project/trunk/test/events/TestEventBroadcaster.py (modified) (5 diffs)
- project/trunk/test/plugin/TestAbstractPlugin.py (added)
- project/trunk/test/view/TestViewLocator.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
project/trunk/src/pyxoo/command.py
r26 r29 518 518 """ 519 519 Registers the passed-in command to be triggered at each time 520 the controller will receive an event of type eventName >.520 the controller will receive an event of type eventName. 521 521 522 522 If there is already a class or a command associated with the passed-in project/trunk/src/pyxoo/core.py
r26 r29 172 172 self.register( key, value ) 173 173 174 def matchType( self, object):174 def matchType( self, object ): 175 175 """ 176 176 Verify that the passed-in object type match the current … … 181 181 return isinstance( object, self.getType() ) or object is None 182 182 183 def getType( self):183 def getType( self ): 184 184 """ 185 185 Return the class type of elements in this container. … … 191 191 return self.__type 192 192 193 def isTyped( self):193 def isTyped( self ): 194 194 """ 195 195 Returns true if this container perform a verification … … 231 231 return self.__eventBroadcaster.removeEventListener( eventType, listener ) 232 232 233 def getKeys( self):233 def getKeys( self ): 234 234 """ 235 235 Returns an list view of the keys contained in this locator. … … 238 238 return self._elements.getKeys() 239 239 240 def getValues( self):240 def getValues( self ): 241 241 """ 242 242 Returns an list view of the values contained in this locator. … … 254 254 255 255 256 257 class Accessor( pyxoo.utils.Interface ): 258 """ 259 The Accessor interface defines common rules 260 to create abstract access to properties or methods of an 261 object. That interface allow tweens to get and set both 262 properties and methods of an object in a transparent way. 263 264 An Accessor could access to only one property or 265 getter/setter pair of methods for an object. To access many 266 properties/methods in one time see the AccessorComposer 267 interface. 268 269 In order to the accessor to get or set value with methods, an accessor 270 must know both getter and setter methods name. If one of these information 271 is not available, the accessor must throw an exception in order to prevent 272 the tween to work on unavailable data. 273 274 There isn't any method to dynamically bind an accessor to a new property or 275 a new getter/setter pair of method. You have to create a new accessor if you 276 need to change the property you want to access. 277 278 Note : Of course, only public members of the target object could be accessed 279 by an accessor instance. 280 """ 281 282 def getValue( self ): 283 """ 284 Retreives the value from the target property. 285 If the type of the data stored by this object is not 286 a number type, the call must fail with an exception. 287 @rtype: int, float, long 288 @return: current value stored in the target property 289 @raise TypeError: The target getter method doesn't return a number. 290 """ 291 292 def setValue( self, value ): 293 """ 294 Defines the new value for the target property. 295 If the type of the data stored by this object is not 296 a number type, the call must fail with an exception. 297 @param value: new numeric value for the target property 298 @type value: int, float, long 299 """ 300 301 def getTarget( self ): 302 """ 303 Returns the target object onto which this accessor operate. 304 @rtype: Object 305 @return: the object onto which this accessor operate 306 """ 307 308 def getGetterHelper( self ): 309 """ 310 Returns the string name of the getter access used 311 by this accessor to retreive data from its target object. 312 @rtype: String 313 @return: the string name of the getter access used by this accessor 314 """ 315 316 def getSetterHelper( self ): 317 """ 318 Returns the string name of the setter access used 319 by this accessor to defines new data to its target object. 320 @rtype: String 321 @return: the string name of the setter access used by this accessor 322 """ 323 324 325 class MethodAccessor( Accessor ): 326 """ 327 The MethodAccessor provides read and write access 328 to the specified method of an object. 329 """ 330 331 def __init__( self, target, setter, getter ): 332 """ 333 Creates a new MethodAccessor instance which 334 allow access to the specified getter and 335 setter methods of the passed-in object. 336 @param target: object onto which access methods 337 @type target: Object 338 @param setter: name of the setter method on the object 339 @type setter: String 340 @param getter: name of the getter method on the object 341 @type getter: String 342 @raise pyxoo.exceptions.NullPointerException: Can't create an accessor on a null object 343 @raise pyxoo.exceptions.NoSuchMethodException: There is no setter method of the specified name 344 @raise pyxoo.exceptions.NoSuchMethodException: There is no getter method of the specified name 345 """ 346 if not target: 347 raise pyxoo.exceptions.NullPointerException( "Can't create an accessor on a null object" ) 348 elif not hasattr( target, setter ): 349 raise pyxoo.exceptions.NoSuchMethodException( "%s doesn't own any setter method called '%s'"%( target, setter ) ) 350 elif not hasattr( target, getter ): 351 raise pyxoo.exceptions.NoSuchMethodException( "%s doesn't own any getter method called '%s'"%( target, getter ) ) 352 self.__target = target 353 self.__setter = setter 354 self.__getter = getter 355 self.__Fsetter = getattr( target, setter ) 356 self.__Fgetter = getattr( target, getter ) 357 358 def getValue ( self ): 359 """ 360 Retreives the value from the target property. 361 If the type of the data stored by this object is not 362 a number type, the call must fail with an exception. 363 @rtype: int, float, long 364 @return: current value stored in the target property 365 @raise TypeError: The target getter method doesn't return a number. 366 """ 367 n = self.__Fgetter() 368 if not pyxoo.utils.Type.isNumber( n ): 369 raise TypeError( "%s.%s() doesn't return a number"%( self.__target, self.__getter ) ) 370 return n 371 372 def setValue( self, value ): 373 """ 374 Defines the new value for the target property. 375 If the type of the data stored by this object is not 376 a number type, the call must fail with an exception. 377 @param value: new numeric value for the target property 378 @type value: int, float, long 379 """ 380 self.__Fsetter( value ) 381 382 def getTarget( self ): 383 """ 384 Returns the target object onto which this accessor operate. 385 @rtype: Object 386 @return: the object onto which this accessor operate 387 """ 388 return self.__target 389 390 def getGetterHelper( self ): 391 """ 392 Returns the string name of the getter access used 393 by this accessor to retreive data from its target object. 394 @rtype: String 395 @return: the string name of the getter access used by this accessor 396 """ 397 return self.__getter 398 399 def getSetterHelper( self ): 400 """ 401 Returns the string name of the setter access used 402 by this accessor to defines new data to its target object. 403 @rtype: String 404 @return: the string name of the setter access used by this accessor 405 """ 406 return self.__setter 407 408 def __str__( self ): 409 """__str__():String 410 Returns the string representation of this instance.""" 411 return pyxoo.utils.PyxooStringifier.stringify( self ) 412 413 414 class PropertyAccessor( Accessor ): 415 """ 416 The PropertyAccessor provides read and write access 417 to the specified property of an object. 418 """ 419 def __init__( self, target, property ): 420 if not target: 421 raise pyxoo.exceptions.NullPointerException( "Can't create an accessor on a null object" ) 422 elif not hasattr( target, property ): 423 raise pyxoo.exceptions.NoSuchFieldException( "%s doesn't own any property called '%s'"%( target, property ) ) 424 self.__target = target 425 self.__property = property 426 427 428 def getValue( self ): 429 """ 430 Retreives the value from the target property. 431 If the type of the data stored by this object is not 432 a number type, the call must fail with an exception. 433 @rtype: int, float, long 434 @return: current value stored in the target property 435 @raise TypeError: The target getter method doesn't return a number. 436 """ 437 n = getattr( self.__target, self.__property ) 438 if not pyxoo.utils.Type.isNumber( n ): 439 raise TypeError( "%s.%s() doesn't return a number"%( self.__target, self.__getter ) ) 440 return n 441 442 def setValue( self, value ): 443 """ 444 Defines the new value for the target property. 445 If the type of the data stored by this object is not 446 a number type, the call must fail with an exception. 447 @param value: new numeric value for the target property 448 @type value: int, float, long 449 """ 450 451 setattr( self.__target, self.__property, value ) 452 453 def getTarget( self ): 454 """ 455 Returns the target object onto which this accessor operate. 456 @rtype: Object 457 @return: the object onto which this accessor operate 458 """ 459 return self.__target 460 461 def getGetterHelper( self ): 462 """ 463 Returns the string name of the getter access used 464 by this accessor to retreive data from its target object. 465 @rtype: String 466 @return: the string name of the getter access used by this accessor 467 """ 468 return self.__property 469 470 def getSetterHelper( self ): 471 """ 472 Returns the string name of the setter access used 473 by this accessor to defines new data to its target object. 474 @rtype: String 475 @return: the string name of the setter access used by this accessor 476 """ 477 return self.__property 478 479 def getProperty( self ): 480 """ 481 Returns the property's name onto which this accessor operate. 482 """ 483 return self.__property 484 485 def __str__( self ): 486 """__str__():String 487 Returns the string representation of this instance.""" 488 return pyxoo.utils.PyxooStringifier.stringify( self ) 489 490 491 class AccessorFactory: 492 """ 493 A factory for Accessor and AccessorComposer creation. 494 With the AccessorFactory, you don't have to know if you attempt to 495 access to a property or to a method. The creational methods of the factory 496 will return the corresponding concret accessor. 497 """ 498 499 @classmethod 500 def getAccessor( cls, target , setter, getter=None ): 501 """ 502 Returns an accessor object for the passed-in property or methods of the 503 specified target object. The concret type of the accessor cannot be 504 known before the call, as for any other factories. 505 506 In the case of accessing to method member, the setter and 507 getter arguments must be set. 508 @param target: the object onto which access member(s) 509 @type target: Object 510 @param setter: name of the setter property on the target 511 @type setter: String 512 @param getter: name of the getter property on the target, used only if the setter property is a function 513 @type getter: String 514 @rtype: pyxoo.core.Accessor 515 @raise pyxoo.exceptions.NullPointerException: Can't create an accessor on a null object 516 @raise pyxoo.exceptions.NoSuchFieldException: The target object doesn't own any field named as setter 517 @raise pyxoo.exceptions.NoSuchMethodExceptio: There'is no getter method to associate with the corresponding setter 518 """ 519 if not target: 520 raise pyxoo.exceptions.NullPointerException( "Can't create an accessor on a null object" ) 521 if not hasattr( target, setter ): 522 raise pyxoo.exceptions.NoSuchFieldException( "%s doesn't own any property called '%s'"%( target, setter ) ) 523 elif callable( getattr( target, setter ) ): 524 if not getter or not hasattr( target, getter ): 525 raise pyxoo.exceptions.NoSuchMethodException( "%s doesn't own any getter method named %s"%( target, getter ) ) 526 return MethodAccessor( target, setter, getter ) 527 else: 528 return PropertyAccessor( target, setter ) 529 530 project/trunk/src/pyxoo/event.py
r23 r29 143 143 parameter. 144 144 """ 145 if target is None:self._ _target = self146 else:self._ _target = target145 if target is None:self._target = self 146 else:self._target = target 147 147 self.setListenerType( listenerType ) 148 148 self.__init() … … 367 367 if not isinstance( event, IEvent ): 368 368 raise TypeError( "event param must be an instance of IEvent class." ) 369 if pyxoo.utils.Type.isNone( event.getTarget()):370 event.setTarget( self._ _target )369 if not event.getTarget(): 370 event.setTarget( self._target ) 371 371 if self.hasListenerCollection( event.getType() ): 372 self._ _broadcast( self.getListenerCollection( event.getType() ), event )373 self._ _broadcast( self.__listeners, event )372 self._broadcast( self.getListenerCollection( event.getType() ), event ) 373 self._broadcast( self.__listeners, event ) 374 374 375 def __broadcast( self, listeners, event ): 375 def _broadcast( self, listeners, event ): 376 eventType = event.getType() 376 377 for listener in listeners: 377 if hasattr( listener, event .getType() ) and callable( getattr( listener, event.getType()) ):378 getattr( listener, event .getType())( event )378 if hasattr( listener, eventType ) and callable( getattr( listener, eventType ) ): 379 getattr( listener, eventType )( event ) 379 380 elif hasattr( listener, "handleEvent" ) and callable( getattr( listener, "handleEvent" ) ): 380 381 listener.handleEvent( event ) 381 382 else: 382 raise pyxoo.exceptions.UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( event .getType(), listener.__class__.__name__ ) )383 raise pyxoo.exceptions.UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( eventType, listener.__class__.__name__ ) ) 383 384 384 385 def __storeRef( self, type, listener ): … … 711 712 if privateAccess is not self.__PRIVATE: 712 713 raise IllegalAccessException( "Constructor of ApplicationBroadcaster is private." ) 713 ChannelBroadcaster.__init__( self, _InternalBroadcaster, ApplicationBroadcaster.SYSTEM_CHANNEL )714 ChannelBroadcaster.__init__( self, pyxoo.plugin.PluginBroadcaster, ApplicationBroadcaster.SYSTEM_CHANNEL ) 714 715 715 716 def getChannelDispatcher( self, eventChannel=None, owner=None ): … … 729 730 730 731 731 class _InternalBroadcaster( EventBroadcaster ): 732 733 def __broadcast( self, listeners, event ): 732 class _InternalBroadcaster( EventBroadcaster ): 733 def _broadcast( self, listeners, event ): 734 734 for listener in listeners: 735 if hasattr( listener, event.getType() ) and callable( getattr( listener, event.getType() ) ) and event.getTarget() != listener: 736 getattr( listener, event.getType() )( event ) 737 elif hasattr( listener, "handleEvent" ) and callable( getattr( listener, "handleEvent" ) ): 738 listener.handleEvent( event ) 739 else: 740 raise UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( event.getType(), listener.__class__.__name__ ) ) 741 735 try: 736 if listener != event.getTarget(): 737 getattr( listener, event.getType() )( event ) 738 except (AttributeError, TypeError): 739 try: 740 listener.handleEvent( event ) 741 except (AttributeError, TypeError): 742 raise pyxoo.exceptions.UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( event.getType(), listener.__class__.__name__ ) ) 742 743 743 744 … … 815 816 class BooleanEvent( BasicEvent ): 816 817 """BooleanEvent defines specific event structure to work with Boolean value""" 817 def __init__( self, eventType, value ):818 def __init__( self, eventType, target=None, value=None ): 818 819 """__init__(String, Boolean) 819 820 Constructs a new BooleanEvent instance.""" 820 BasicEvent.__init__( self, eventType )821 BasicEvent.__init__( self, eventType, target ) 821 822 if not Type.isBoolean( value ): 822 823 raise TypeError( "value must be a boolean" ) … … 832 833 class IntegerEvent( BasicEvent ): 833 834 """IntegerEvent defines specific event structure to work with Integer value""" 834 def __init__( self, eventType, value ):835 def __init__( self, eventType, target=None, value=None ): 835 836 """Constructs a new IntegerEvent instance.""" 836 BasicEvent.__init__( self, eventType )837 if not pyxoo.utils.Type.isInt( value ):837 BasicEvent.__init__( self, eventType, target ) 838 if value is not None and not pyxoo.utils.Type.isInt( value ): 838 839 raise TypeError( "value must be an integer" ) 839 840 self.__integer = value … … 847 848 class LongEvent( BasicEvent ): 848 849 """LongEvent defines specific event structure to work with Long Integer value""" 849 def __init__( self, eventType, value ):850 def __init__( self, eventType, target=None, value=None ): 850 851 """Constructs a new IntegerEvent instance.""" 851 BasicEvent.__init__( self, eventType )852 BasicEvent.__init__( self, eventType, target ) 852 853 if not pyxoo.utils.Type.isLong( value ): 853 854 raise TypeError( "value must be a long integer" ) … … 862 863 class FloatEvent( BasicEvent ): 863 864 """FloatEvent defines specific event structure to work with Float value""" 864 def __init__( self, eventType, value ):865 def __init__( self, eventType, target=None, value=None ): 865 866 """Constructs a new FloatEvent instance.""" 866 BasicEvent.__init__( self, eventType )867 BasicEvent.__init__( self, eventType, target ) 867 868 if not Type.isFloat( value ): 868 869 raise TypeError( "value must be a float" ) … … 877 878 class StringEvent( BasicEvent ): 878 879 """StringEvent defines specific event structure to work with String value""" 879 def __init__( self, eventType, value ):880 def __init__( self, eventType, target=None, value=None ): 880 881 """Constructs a new StringEvent instance.""" 881 BasicEvent.__init__( self, eventType )882 if notType.isString( value ):882 BasicEvent.__init__( self, eventType, target ) 883 if value and not pyxoo.utils.Type.isString( value ): 883 884 raise TypeError( "value must be a String" ) 884 885 self.__string = value … … 892 893 class ValueObjectEvent( BasicEvent ): 893 894 """ValueObjectEvent defines specific event structure to work with ValueObject value""" 894 def __init__( self, eventType, value ):895 def __init__( self, eventType, target=None, value=None ): 895 896 """Constructs a new ValueObjectEvent instance.""" 896 BasicEvent.__init__( self, eventType )897 BasicEvent.__init__( self, eventType, target ) 897 898 if not isinstance( value, ValueObject ): 898 899 raise TypeError( "value must be a ValueObject" ) … … 964 965 time.sleep( self.__delay ) 965 966 966 def start( self):967 def start( self ): 967 968 self.__running = True 968 threading.Thread.start( self)969 threading.Thread.start( self ) 969 970 970 971 def stop( self ): project/trunk/src/pyxoo/exceptions.py
r25 r29 11 11 12 12 class NoSuchElementException( Exception ): 13 pass 14 15 class NoSuchMethodException( Exception ): 16 pass 17 18 class NoSuchFieldException( Exception ): 19 pass 20 21 class IndexOutOfBoundsException( Exception ): 13 22 pass 14 23 … … 32 41 pass 33 42 34 35 43 class NullPointerException( Exception ): 36 44 pass project/trunk/src/pyxoo/plugin.py
r26 r29 43 43 self.__modelLocator = pyxoo.model.ModelLocator.getInstance( self ) 44 44 self.__viewLocator = pyxoo.view.ViewLocator.getInstance( self ) 45 46 self.__ebExternal = pyxoo.event.ApplicationBroadcaster.getInstance() 45 47 46 self.__ebPublic = pyxoo.event.ApplicationBroadcaster.getInstance().getChannelDispatcher( self.getChannel(), self ) 48 self.__ebPrivate = pyxoo.event.EventBroadcaster( self ) 49 self.__ebPrivate.addListener( self.__controller ) 50 47 51 48 if self.__ebPublic: 52 49 self.__ebPublic.addListener( self ) … … 79 76 """fireExternalEvent(IEvent, EventChannel):void""" 80 77 if eventChannel != self.getChannel(): 81 self.__ebExternal.broadcastEvent( event, eventChannel )78 pyxoo.event.ApplicationBroadcaster.getInstance().broadcastEvent( event, eventChannel ) 82 79 83 80 def firePublicEvent( self, event ): 84 81 """firePublicEvent(IEvent):void""" 85 82 if self.__ebPublic: 86 self.__ebPublic. broadcastEvent( event)83 self.__ebPublic.firePublicEvent( event, self ) 87 84 88 85 def firePrivateEvent( self, event ): 89 86 """firePrivateEvent(IEvent):void""" 90 self.__ ebPrivate.broadcastEvent( event )87 self.__controller.handleEvent( event ) 91 88 92 89 def handleEvent( self, event=None ): … … 135 132 return self.__ebPublic.removeEventListener( type, listener ) 136 133 return False 137 134 135 138 136 class PluginChannel( pyxoo.event.EventChannel ): 139 137 __instances = pyxoo.utils.HashMap() … … 228 226 229 227 230 231 232 228 class NullPlugin( Plugin ): 233 229 __instance = None … … 277 273 """getViewLocator():ViewLocator""" 278 274 return pyxoo.view.ViewLocator.getInstance( self ) 275 276 277 class PluginBroadcaster( pyxoo.event.EventBroadcaster ): 278 279 def firePublicEvent(self, event, owner): 280 if not event.getTarget(): 281 event.setTarget( self._target ) 282 eventType = event.getType() 283 if self.hasListenerCollection( eventType ): 284 for listener in self.getListenerCollection( eventType ): 285 if listener != owner: 286 if hasattr( listener, eventType ) and callable( getattr( listener, eventType ) ): 287 getattr( listener, eventType )( event ) 288 elif hasattr( listener, "handleEvent" ) and callable( getattr( listener, "handleEvent" ) ): 289 listener.handleEvent( event ) 290 else: 291 raise pyxoo.exceptions.UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( eventType, listener.__class__.__name__ ) ) 292 for listener in self.getListenerCollection(): 293 if listener != owner: 294 if hasattr( listener, eventType ) and callable( getattr( listener, eventType ) ): 295 getattr( listener, eventType )( event ) 296 elif hasattr( listener, "handleEvent" ) and callable( getattr( listener, "handleEvent" ) ): 297 listener.handleEvent( event ) 298 else: 299 raise pyxoo.exceptions.UnsupportedOperationError( "EventBroadcaster.broadcastEvent() failed, you must implement '%s' method in '%s' class."%( eventType, listener.__class__.__name__ ) ) 300 301 302 project/trunk/src/pyxoo/utils/interface.py
r25 r29 13 13 def __init__( self, name, parents, attributs ): 14 14 if len( parents ) == 0:return 15 self.__ name = name15 self.__interfaceName = name 16 16 self.__parents = list( parents ) 17 17 self.__attributs = attributs … … 26 26 if type( att ) == types.FunctionType: 27 27 if self.__isInterface and att.__name__ == "__init__": 28 raise pyxoo.exceptions.UnsupportedOperationError( "'" + self.__ name + "' is an interface. It can not contain constructor." )28 raise pyxoo.exceptions.UnsupportedOperationError( "'" + self.__interfaceName + "' is an interface. It can not contain constructor." ) 29 29 self.__methods[att.__name__] = att 30 30 … … 48 48 try: 49 49 if self.__methods[parent_method_name].func_code.co_argcount != parent_method.func_code.co_argcount: 50 raise NotImplementedError( "'" + self.__ name + "' class implement '" + parent.getInterfaceName() + "' interface but " + parent_method.__name__ + str( parent_method.func_code.co_varnames ) + " method is not implemented." )50 raise NotImplementedError( "'" + self.__interfaceName + "' class implement '" + parent.getInterfaceName() + "' interface but " + parent_method.__name__ + str( parent_method.func_code.co_varnames ) + " method is not implemented." ) 51 51 except( KeyError ): 52 raise NotImplementedError( "'" + self.__ name + "' class implement '" + parent.getInterfaceName() + "' interface but " + parent_method.__name__ + str( parent_method.func_code.co_varnames ) + " method is not implemented." )52 raise NotImplementedError( "'" + self.__interfaceName + "' class implement '" + parent.getInterfaceName() + "' interface but " + parent_method.__name__ + str( parent_method.func_code.co_varnames ) + " method is not implemented." ) 53 53 54 54 def getInterfaceName( self ): 55 return self.__ name55 return self.__interfaceName 56 56 57 57 def getParents( self ): … … 68 68 69 69 def __str__(self): 70 return self.__ name70 return self.__interfaceName 71 71 72 72 project/trunk/src/pyxoo/view.py
r25 r29 11 11 __owner = None 12 12 __name = None 13 onInitEVENT = "onInit" 14 onReleaseEVENT = "onRelease" 13 15 14 16 def __init__( self, owner=None, name=None ): … … 23 25 24 26 def onInit( self ): 25 """onInit():void""" 26 pass 27 """ 28 """ 29 self.notifyChanged( pyxoo.event.StringEvent( AbstractView.onInitEVENT, self, self.getName() ) ) 27 30 31 def onRelease(self): 32 """ 33 """ 34 self.notifyChanged( pyxoo.event.StringEvent( AbstractView.onReleaseEVENT, self, self.getName() ) ) 35 28 36 def notifyChanged( self, event ): 29 37 """notifyChanged(IEvent):void""" … … 34 42 self._getBroadcaster().removeAllListeners() 35 43 pyxoo.view.ViewLocator.getInstance( self.getOwner() ).unregister( self.getName() ) 44 self.onRelease() 45 self.__name = None 36 46 37 47 def getOwner( self ): … … 57 67 raise TypeError( "name param must be a String" ) 58 68 locator = pyxoo.view.ViewLocator.getInstance( self.getOwner() ) 59 if name and not locator.isRegistered( name ): 60 if locator.isRegistered( self.getName() ): 69 if name and not locator.isRegistered( name ): 70 if locator.isRegistered( self.getName() ): 61 71 locator.unregister( self.getName() ) 62 if locator.register( name, self ):63 self.__name = name72 locator.register( name, self ) 73 self.__name = name 64 74 65 75 def addListener( self, listener ): project/trunk/test/commands/TestFrontController.py
r26 r29 39 39 40 40 def testHandleEvent( self ): 41 event = pyxoo.event.IntegerEvent( "azerty", 100 )41 event = pyxoo.event.IntegerEvent( "azerty", None, 100 ) 42 42 command = MyCommand() 43 43 self.instance.pushCommandInstance( "azerty", command ) project/trunk/test/events/TestChannelBroadcaster.py
r21 r29 33 33 self.instance = pyxoo.event.ChannelBroadcaster( None, self.channel1 ) 34 34 self.type = "notify" 35 self.event = pyxoo.event.IntegerEvent( self.type, 1 )35 self.event = pyxoo.event.IntegerEvent( self.type, None, 1 ) 36 36 self.listener = self 37 37 self.__model = 0 project/trunk/test/events/TestEventBroadcaster.py
r21 r29 152 152 def testBroadcastEvent( self ): 153 153 self.instance.addEventListener( self.eventType, self ) 154 myEvent = pyxoo.event.IntegerEvent( self.eventType, 1 )154 myEvent = pyxoo.event.IntegerEvent( self.eventType, None, 1 ) 155 155 self.instance.broadcastEvent( myEvent ) 156 156 self.assertEquals( myEvent.getTarget(), self.instance ) … … 158 158 class A:pass 159 159 a = A() 160 myEvent = pyxoo.event.IntegerEvent( self.eventType, 0 )160 myEvent = pyxoo.event.IntegerEvent( self.eventType, None, 0 ) 161 161 myEvent.setTarget( a ) 162 162 self.instance.broadcastEvent( myEvent ) … … 165 165 def testBroadcastEventFail( self ): 166 166 self.instance.addListener( self ) 167 event = pyxoo.event.IntegerEvent( "coucou", 0 )167 event = pyxoo.event.IntegerEvent( "coucou", None, 0 ) 168 168 self.assertRaises( pyxoo.exceptions.UnsupportedOperationError, self.instance.broadcastEvent, event ) 169 169 170 170 def testAnotherBroadcastEvent( self ): 171 171 self.instance.addListener( self ) 172 myEvent = pyxoo.event.IntegerEvent( self.eventType, 10 )172 myEvent = pyxoo.event.IntegerEvent( self.eventType, None, 10 ) 173 173 self.instance.broadcastEvent( myEvent ) 174 174 self.assertEquals( myEvent.getTarget(), self.instance ) … … 189 189 self.assertTrue( self.instance.isRegistered( myFunction, "coucou" ) ) 190 190 191 myEvent = pyxoo.event.IntegerEvent( self.eventType, 10 )191 myEvent = pyxoo.event.IntegerEvent( self.eventType, None, 10 ) 192 192 self.instance.broadcastEvent( myEvent ) 193 193 self.assertEquals( self.instance, myEvent.getTarget() ) … … 200 200 self.assertTrue( self.instance.isRegistered( myFunction, "coucou" ) ) 201 201 self.assertTrue( self.instance.removeEventListener( "coucou", myFunction ) ) 202 myEvent = pyxoo.event.IntegerEvent( self.eventType, 0 )202 myEvent = pyxoo.event.IntegerEvent( self.eventType, None, 0 ) 203 203 self.instance.broadcastEvent( myEvent ) 204 204 self.assertEquals( 0, myEvent.getInteger() ) project/trunk/test/view/TestViewLocator.py
r24 r29 52 52 def testUnregisterView( self ): 53 53 self.instance.register( "v1", self.view ) 54 self.instance.register( "v2", pyxoo.view.AbstractView() ) 54 view = pyxoo.view.AbstractView() 55 self.instance.register( "v2", view ) 55 56 self.assertTrue( self.instance.isRegistered( "v1" ) ) 56 57 self.assertTrue( self.instance.isRegistered( "v2" ) ) … … 58 59 self.assertFalse( self.instance.isRegistered( "v1" ) ) 59 60 self.assertTrue( self.instance.isRegistered( "v2" ) ) 61 62 self.assertRaises( pyxoo.exceptions.NoSuchElementException, self.instance.locate, "v1" ) 63 self.assertEquals( view, self.instance.locate( "v2" ) ) 60 64 61 65 def testLocate( self ):
