Changeset 7

Show
Ignore:
Timestamp:
11/27/07 20:21:55 (1 year ago)
Author:
skit
Message:

Ajout des classes et interfaces suivantes :
* AbstractPlugin?
* ChannelExpert?
* PluginListener?
* PluginChannel?
* AbstractCommand?

Modification des noms de package : la première lettre d'un package est en majuscule.

Modification de certains import...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/Pyxoo/Commands/command.py

    r3 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
     24from Pyxoo.Log.stringifier import PyxooStringifier 
     25try: 
     26    from Pyxoo.Plugin.plugin import Plugin 
     27except(ImportError): 
     28    pass 
     29 
    2430class Command:     
    2531    """Command is the basic interface to encapsulate a request as an object,  
     
    3036        A concrete Command object always has execute() method that is called when an action occurs.""" 
    3137        raise NotImplementedError  
     38 
     39class AbstractCommand(Command): 
     40    __owner = None 
     41    def __init__(self): 
     42        raise NotImplementedError("AbstractCommand is an abstract class. It must be extented.") 
     43         
     44    def execute(self, event=None): 
     45        """execute(IEvent):void 
     46        A concrete Command object always has execute() method that is called when an action occurs.""" 
     47        raise NotImplementedError 
    3248     
     49    def getOwner(self): 
     50        """getOwner():Plugin""" 
     51        return self.__owner 
    3352     
     53    def setOwner(self, owner): 
     54        """setOwner(Plugin):void""" 
     55        if not isinstance(owner, Plugin): 
     56            raise TypeError("owner param must be a Plugin object") 
     57        self.__owner = owner 
     58         
     59    def getModelLocator(self): 
     60        """getModelLocator():ModelLocator""" 
     61        return self.getOwner().getModelLocator() 
     62     
     63    def getViewLocator(self): 
     64        """getViewLocator():ViewLocator""" 
     65        return self.getOwner().getViewLocator() 
     66     
     67    def _firePrivateEvent(self, event): 
     68        self.getOwner().firePrivateEvent(event) 
     69     
     70    def __str__(self): 
     71        """__str__():String 
     72        Returns the string representation of this instance.""" 
     73        return PyxooStringifier.stringify(self) 
     74     
     75 
    3476class MacroCommand(Command):   
    3577    """MacroCommand is the basic interface to handle several commands as one command."""  
  • trunk/src/Pyxoo/Commands/delegate.py

    r4 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.commands.command import Command 
    25 from Pyxoo.log.stringifier import PyxooStringifier 
    26 from Pyxoo.events.event import IEvent 
     24from Pyxoo.Commands.command import Command 
     25from Pyxoo.Log.stringifier import PyxooStringifier 
     26from Pyxoo.Events.event import IEvent 
    2727 
    2828class Delegate(Command, object):     
  • trunk/src/Pyxoo/Commands/frontcontroller.py

    r6 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.commands.locator import CommandLocator 
    25 from Pyxoo.events.broadcaster import EventBroadcaster 
    26 from Pyxoo.plugin.plugin import NullPlugin 
    27 from Pyxoo.utils import Type 
     24from Pyxoo.Commands.locator import CommandLocator 
     25from Pyxoo.Events.broadcaster import EventBroadcaster 
     26#from Pyxoo.Plugin import plugin 
     27import Pyxoo.Plugin 
     28from Pyxoo.Utils import Type 
     29from Pyxoo.Commands.command import AbstractCommand 
     30from Pyxoo.Log.stringifier import PyxooStringifier 
    2831 
    2932class FrontController: 
     
    4245            self.__eventBroadcaster = EventBroadcaster(owner) 
    4346        else: 
    44             self.__owner = NullPlugin() 
     47            self.__owner = Pyxoo.Plugin.plugin.NullPlugin() 
    4548            self.__eventBroadcaster = EventBroadcaster.getInstance() 
    4649        self.__eventBroadcaster.addListener(self) 
     
    6770            command = self.__commandLocator.locate(event.getEventType()) 
    6871            if Type.isClass(command): 
    69                 command().execute(event) 
     72                cmd = command() 
     73                if isinstance(cmd, AbstractCommand): 
     74                     cmd.setOwner(self.getOwner()) 
     75                cmd.execute(event) 
    7076            else: 
     77                if isinstance(command, AbstractCommand): 
     78                    if command.getOwner() is None: 
     79                        command.setOwner(self.getOwner()) 
    7180                command.execute(event) 
    7281         
  • trunk/src/Pyxoo/Commands/locator.py

    r6 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.core.locator import Locator 
    25 from Pyxoo.commands.command import Command 
    26 from Pyxoo.utils import Type 
     24from Pyxoo.Core.locator import Locator 
     25from Pyxoo.Commands.command import Command 
     26from Pyxoo.Utils import Type 
     27from Pyxoo.Log.stringifier import PyxooStringifier 
    2728 
    2829 
  • trunk/src/Pyxoo/Events/broadcaster.py

    r4 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.utils import Type 
    25 from Pyxoo.events.event import IEvent 
    26 from Pyxoo.exceptions import * 
    27 from Pyxoo.log.stringifier import PyxooStringifier 
    28 from Pyxoo.commands.delegate import Delegate 
     24from Pyxoo.Utils import Type 
     25from Pyxoo.Events.event import IEvent 
     26from Pyxoo.Exceptions import * 
     27from Pyxoo.Log.stringifier import PyxooStringifier 
     28from Pyxoo.Commands.delegate import Delegate 
    2929 
    3030class EventBroadcaster(object): 
  • trunk/src/Pyxoo/Events/channel.py

    r3 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.events.broadcaster import EventBroadcaster 
    25 from Pyxoo.log.stringifier import PyxooStringifier 
    26 from Pyxoo.utils import Type 
     24from Pyxoo.Events.broadcaster import EventBroadcaster 
     25from Pyxoo.Log.stringifier import PyxooStringifier 
     26from Pyxoo.Utils import Type 
    2727 
    2828class EventChannel: 
  • trunk/src/Pyxoo/Events/event.py

    r2 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.utils import Type 
    25 from Pyxoo.log.stringifier import PyxooStringifier 
     24from Pyxoo.Utils import Type 
     25from Pyxoo.Log.stringifier import PyxooStringifier 
    2626 
    2727class IEvent:   
  • trunk/src/Pyxoo/Events/timer.py

    r3 r7  
    2424 
    2525import threading,time 
    26 from Pyxoo.events.broadcaster import * 
    27 from Pyxoo.events.event import BasicEvent 
    28 from Pyxoo.utils import Type 
     26from Pyxoo.Events.broadcaster import * 
     27from Pyxoo.Events.event import BasicEvent 
     28from Pyxoo.Utils import Type 
    2929 
    3030UNLIMITED_REPEAT = -1 
  • trunk/src/Pyxoo/Log/loggers.py

    r2 r7  
    2121__author__  = Pyxoo.__author__ 
    2222 
    23 from Pyxoo.events.event import BasicEvent 
    24 from Pyxoo.events.channel import ChannelBroadcaster, EventChannel 
    25 from Pyxoo.log.loglevel import *     
    26 from Pyxoo.log.stringifier import PyxooStringifier 
    27 from Pyxoo.utils import Type 
     23from Pyxoo.Events.event import BasicEvent 
     24from Pyxoo.Events.channel import ChannelBroadcaster, EventChannel 
     25from Pyxoo.Log.loglevel import *     
     26from Pyxoo.Log.stringifier import PyxooStringifier 
     27from Pyxoo.Utils import Type 
    2828 
    2929 
  • trunk/src/Pyxoo/Log/loglevel.py

    r2 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.utils import Type 
    25 from Pyxoo.log.loggers import * 
    26 from Pyxoo.log.stringifier import PyxooStringifier 
     24from Pyxoo.Utils import Type 
     25from Pyxoo.Log.loggers import * 
     26from Pyxoo.Log.stringifier import PyxooStringifier 
    2727 
    2828MIN_VALUE, MAX_VALUE = 0, sys.maxint 
  • trunk/src/Pyxoo/Log/pyxoodebug.py

    r2 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.events.channel import EventChannel 
    25 from Pyxoo.log.loggers import Logger 
     24from Pyxoo.Events.channel import EventChannel 
     25from Pyxoo.Log.loggers import Logger 
    2626 
    2727 
  • trunk/src/Pyxoo/Model/locator.py

    r6 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.core.locator import Locator 
    25 from Pyxoo.model.model import Model 
    26 from Pyxoo.plugin.plugin import Plugin, NullPlugin 
     24from Pyxoo.Core.locator import Locator 
     25from Pyxoo.Model.model import Model 
     26from Pyxoo.Plugin.plugin import Plugin, NullPlugin 
    2727 
    2828class ModelLocator(Locator, object): 
  • trunk/src/Pyxoo/Plugin/plugin.py

    r6 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 try: 
    25     from Pyxoo.view.locator  import ViewLocator 
    26 except(ImportError): 
    27     pass 
    28 try: 
    29     from Pyxoo.model.locator import ModelLocator 
    30 except(ImportError): 
    31     pass 
    32 from Pyxoo.events.channel import ApplicationBroadcaster 
     24 
     25import Pyxoo.Model, Pyxoo.View, Pyxoo.Plugin 
     26 
     27from Pyxoo.Commands.frontcontroller import FrontController 
     28from Pyxoo.Events.channel import ApplicationBroadcaster 
     29from Pyxoo.Events.event import BasicEvent 
     30 
     31 
     32 
     33class PluginListener: 
     34    def onInitPlugin(self, event): 
     35        raise NotImplementedError 
     36     
     37    def onReleasePlugin(self, event): 
     38        raise NotImplementedError 
    3339 
    3440 
     
    6975     
    7076    def fireOnInitPlugin(self): 
     77        """fireOnInitPlugin():void""" 
    7178        pass 
    7279     
    7380    def fireOnReleasePlugin(self): 
     81        """fireOnReleasePlugin():void""" 
    7482        pass 
    7583            
    7684    def fireExternalEvent(self, event, eventChannel): 
     85        """fireExternalEvent(IEvent, EventChannel):void""" 
    7786        pass 
    7887     
    7988    def firePublicEvent(self, event): 
     89        """firePublicEvent(IEvent):void""" 
    8090        pass 
    8191     
    8292    def firePrivateEvent(self, event): 
     93        """firePrivateEvent(IEvent):void""" 
    8394        pass 
    8495         
    8596    def getChannel(self): 
     97        """getChannel():EventChannel""" 
    8698        return ApplicationBroadcaster.NO_CHANNEL 
    8799     
    88100    def getModelLocator(self): 
    89         return ModelLocator(self) 
     101        """getModelLocator():ModelLocator""" 
     102        return Pyxoo.Model.locator.ModelLocator(self) 
    90103     
    91104    def getViewLocator(self): 
    92         return ViewLocator(self)   
     105        """getViewLocator():ViewLocator""" 
     106        return Pyxoo.View.locator.ViewLocator(self)   
     107     
     108     
     109class AbstractPlugin(Plugin): 
     110    onInitPluginEVENT    = "onInitPlugin" 
     111    onReleasePluginEVENT = "onReleasePlugin" 
     112     
     113    def __init__(self): 
     114        """__init__()""" 
     115        self.__controller   = FrontController(self) 
     116        self.__modelLocator = Pyxoo.Model.locator.ModelLocator(self) 
     117        self.__viewLocator  = Pyxoo.View.locator.ViewLocator(self) 
     118         
     119        self.__ebExternal   = ApplicationBroadcaster() 
     120        self.__ebPublic     = ApplicationBroadcaster().getChannelDispatcher( self.getChannel(), self ) 
     121        self.__ebPrivate    = self.__controller.getBroadcaster() 
     122         
     123        if self.__ebPublic: 
     124            self.__ebPublic.addListener(self) 
     125             
     126    def fireOnInitPlugin(self): 
     127        """fireOnInitPlugin():void""" 
     128        self.firePublicEvent(BasicEvent(AbstractPlugin.onInitPluginEVENT)) 
     129     
     130    def fireOnReleasePlugin(self): 
     131        """fireOnReleasePlugin():void""" 
     132        self.firePublicEvent(BasicEvent(AbstractPlugin.onReleasePluginEVENT)) 
     133         
     134    def getChannel(self): 
     135        """getChannel():EventChannel""" 
     136        return Pyxoo.Plugin.channel.ChannelExpert().getChannel(self) 
     137     
     138    def getController(self): 
     139        """getController():FrontController""" 
     140        return self.__controller 
     141         
     142    def getModelLocator(self): 
     143        """getModelLocator():ModelLocator""" 
     144        return self.__modelLocator 
     145     
     146    def getViewLocator(self): 
     147        """getViewLocator():ViewLocator""" 
     148        return self.__viewLocator 
     149     
     150    def fireExternalEvent(self, event, eventChannel): 
     151        """fireExternalEvent(IEvent, EventChannel):void""" 
     152        if eventChannel != self.getChannel(): 
     153            self.__ebExternal.broadcastEvent(event, eventChannel) 
     154     
     155    def firePublicEvent(self, event): 
     156        """firePublicEvent(IEvent):void""" 
     157        if self.__ebPublic: 
     158            self.__ebPublic.broadcastEvent(event) 
     159     
     160    def firePrivateEvent(self, event): 
     161        """firePrivateEvent(IEvent):void""" 
     162        self.__ebPrivate.broadcastEvent(event) 
     163         
     164    def handleEvent(self, event=None): 
     165        """handleEvent(IEvent):void""" 
     166        pass 
     167     
     168    def release(self): 
     169        """release():void""" 
     170        self.__controller.release() 
     171        self.__modelLocator.release() 
     172        self.__viewLocator.release() 
     173        #TODO voir le BeanFactory 
     174         
     175        self.fireOnReleasePlugin() 
     176        self.__ebPrivate.removeAllListeners() 
     177        self.__ebPublic.removeAllListeners() 
     178         
     179        ApplicationBroadcaster().releaseChannelDispatcher(self.getChannel()) 
     180        ChannelExpert().releaseChannel(self) 
     181         
     182    def addListener(self, listener): 
     183        """addListener(PluginListener):boolean""" 
     184        if not isinstance(listener, PluginListener): 
     185            raise TypeError("listener param must be a PluginListener object") 
     186        if self.__ebPublic: 
     187            return self.__ebPublic.addListener(listener) 
     188        return False 
     189     
     190    def removeListener(self, listener): 
     191        """removeListener(PluginListener):boolean""" 
     192        if not isinstance(listener, PluginListener): 
     193            raise TypeError("listener param must be a PluginListener object") 
     194        if self.__ebPublic: 
     195            return self.__ebPublic.removeListener(listener) 
     196        return False 
     197     
     198    def addEventListener(self, type, listener, *args): 
     199        """addEventListener(String, PluginListener, ...):boolean""" 
     200        if self.__ebPublic: 
     201            return self.__ebPublic.addEventListener(self, type, listener, *args) 
     202        return False 
     203         
     204    def removeEventListener(self, type, listener): 
     205        """removeEventListener(String, PluginListener):boolean""" 
     206        if self.__ebPublic: 
     207            return self.__ebPublic.removeEventListener(type, listener) 
     208        return False 
  • trunk/src/Pyxoo/View/locator.py

    r6 r7  
    2222__author__  = Pyxoo.__author__ 
    2323 
    24 from Pyxoo.core.locator import Locator 
    25 from Pyxoo.view.view import View 
    26 from Pyxoo.plugin.plugin import Plugin, NullPlugin 
     24from Pyxoo.Core.locator import Locator 
     25from Pyxoo.View.view import View 
     26from Pyxoo.Plugin import plugin 
     27 
    2728 
    2829class ViewLocator(Locator, object): 
    2930    __M = dict() 
    3031     
    31     def __new__(cls, owner=NullPlugin()): 
     32    def __new__(cls, owner=plugin.NullPlugin()): 
    3233        if not cls.__M.__contains__(owner): 
    3334            tmp = object.__new__(cls, owner)  
     
    3637        return cls.__M.get(owner) 
    3738             
    38     def __init__(self, owner=NullPlugin()): 
     39    def __init__(self, owner=plugin.NullPlugin()): 
    3940        """__init__(Plugin) 
    4041        Constructs a ViewLocator implementation.""" 
    41         if not isinstance(owner, Plugin): 
     42        if not isinstance(owner, plugin.Plugin): 
    4243            raise TypeError("owner param must be a Plugin") 
    4344        self.__views = dict() 
  • trunk/test/commands/TestCommandLocator.py

    r6 r7  
    1919 
    2020import unittest 
    21 from Pyxoo.commands.command import Command 
    22 from Pyxoo.commands.locator import CommandLocator 
     21from Pyxoo.Commands.command import Command 
     22from Pyxoo.Commands.locator import CommandLocator 
    2323 
    2424class MyCommand1(Command): 
  • trunk/test/commands/TestDelegate.py

    r4 r7  
    2020import unittest 
    2121 
    22 from Pyxoo.commands.delegate import Delegate 
     22from Pyxoo.Commands.delegate import Delegate 
    2323 
    2424def myFunction(*args): 
  • trunk/test/commands/TestFrontController.py

    r6 r7  
    2020import unittest 
    2121 
    22 from Pyxoo.commands.frontcontroller import FrontController 
    23 from Pyxoo.plugin.plugin import NullPlugin, Plugin 
    24 from Pyxoo.events.broadcaster import EventBroadcaster 
    25 from Pyxoo.commands.command import Command 
    26 from Pyxoo.events.event import IntegerEvent 
     22from Pyxoo.Commands import frontcontroller 
     23from Pyxoo.Plugin import plugin 
     24from Pyxoo.Events.broadcaster import EventBroadcaster 
     25from Pyxoo.Commands.command import Command 
     26from Pyxoo.Events.event import IntegerEvent 
    2727 
    2828class MyCommand(Command): 
     
    3434class TestFrontController(unittest.TestCase): 
    3535    def setUp(self): 
    36         self.instance = FrontController() 
    37         self.aPlugin = Plugin() 
     36        self.instance = frontcontroller.FrontController() 
     37        self.aPlugin = plugin.Plugin() 
    3838         
    3939    def testGetOwner(self): 
    40         self.assertEquals(NullPlugin(), self.instance.getOwner()) 
    41         self.instance = FrontController(self.aPlugin) 
     40        self.assertEquals(plugin.NullPlugin(), self.instance.getOwner()) 
     41        self.instance = frontcontroller.FrontController(self.aPlugin) 
    4242        self.assertEquals(self.aPlugin, self.instance.getOwner()) 
    4343         
     
    4646        self.assertTrue(self.instance.getBroadcaster().isRegistered(self.instance)) 
    4747         
    48         self.instance = FrontController(self.aPlugin) 
     48        self.instance = frontcontroller.FrontController(self.aPlugin) 
    4949        self.assertNotEquals(EventBroadcaster.getInstance(), self.instance.getBroadcaster()) 
    5050        self.assertTrue(self.instance.getBroadcaster().isRegistered(self.instance)) 
  • trunk/test/events/TestApplicationBroadcaster.py

    r2 r7  
    2020import unittest 
    2121 
    22 from Pyxoo.events.channel import ApplicationBroadcaster, EventChannel 
    23 from Pyxoo.events.event   import IntegerEvent 
     22from Pyxoo.Events.channel import ApplicationBroadcaster, EventChannel 
     23from Pyxoo.Events.event   import IntegerEvent 
    2424 
    2525 
  • trunk/test/events/TestChannelBroadcaster.py

    r3 r7  
    1919import unittest 
    2020 
    21 from Pyxoo.events.broadcaster import * 
    22 from Pyxoo.events.event import * 
    23 from Pyxoo.events.channel import * 
     21from Pyxoo.Events.broadcaster import * 
     22from Pyxoo.Events.event import * 
     23from Pyxoo.Events.channel import * 
    2424 
    2525class MyListener: 
  • trunk/test/events/TestEventBroadcaster.py

    r4 r7  
    2323import unittest 
    2424 
    25 from Pyxoo.events.broadcaster import * 
    26 from Pyxoo.events.event import * 
    27 from Pyxoo.exceptions import * 
     25from Pyxoo.Events.broadcaster import * 
     26from Pyxoo.Events.event import * 
     27from Pyxoo.Exceptions import * 
    2828 
    2929class MyListener: 
  • trunk/test/events/TestTimer.py

    r3 r7  
    2020import unittest, time 
    2121 
    22 from Pyxoo.events.timer import * 
     22from Pyxoo.Events.timer import * 
    2323 
    2424class MyTimerListener(TimerListener): 
  • trunk/test/log/TestLogEvent.py

    r2 r7  
    1717 
    1818import unittest 
    19 from Pyxoo.log.loggers import LogEvent 
    20 import  Pyxoo.log.loglevel as loglevel 
     19from Pyxoo.Log.loggers import LogEvent 
     20import  Pyxoo.Log.loglevel as loglevel 
    2121 
    2222class TestLogEvent(unittest.TestCase): 
  • trunk/test/log/TestLogLevel.py

    r2 r7  
    1818 
    1919import unittest 
    20 from Pyxoo.log.loglevel import * 
     20from Pyxoo.Log.loglevel import * 
    2121 
    2222class TestLogLevel(unittest.TestCase): 
  • trunk/test/log/TestLogger.py

    r3 r7  
    1818import unittest 
    1919 
    20 from Pyxoo.log.loggers import Logger, ILogListener 
    21 from Pyxoo.events.channel import EventChannel 
    22 from Pyxoo.log.loglevel import * 
     20from Pyxoo.Log.loggers import Logger, ILogListener 
     21from Pyxoo.Events.channel import EventChannel 
     22from Pyxoo.Log.loglevel import * 
    2323 
    2424 
  • trunk/test/model/TestModelLocator.py

    r6 r7  
    2121 
    2222 
    23 from Pyxoo.model.model import Model 
    24 from Pyxoo.model.locator import ModelLocator 
    25 from Pyxoo.plugin.plugin import Plugin 
     23from Pyxoo.Model.model import Model 
     24from Pyxoo.Model.locator import ModelLocator 
     25from Pyxoo.Plugin.plugin import Plugin 
    2626 
    2727class TestModelLocator(unittest.TestCase): 
  • trunk/test/utils/TestType.py

    r3 r7  
    1717# 
    1818 
    19 __version__ = "0.1" 
    20 __author__  = "Alexis Couronne - http://www.skitoo.org" 
    2119 
    2220import unittest,sys 
    23 from Pyxoo.utils import Type 
     21 
     22from Pyxoo.Utils import Type 
    2423 
    2524class A: 
  • trunk/test/view/TestViewLocator.py

    r6 r7  
    2121 
    2222 
    23 from Pyxoo.view.view import View 
    24 from Pyxoo.view.locator import ViewLocator 
    25 from Pyxoo.plugin.plugin import Plugin 
     23from Pyxoo.View.view import View 
     24from Pyxoo.View.locator import ViewLocator 
     25from Pyxoo.Plugin.plugin import Plugin 
    2626 
    2727class TestViewLocator(unittest.TestCase):