command.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » command.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from historyUtils import *

class Command(object):
    """
    @author P. Dabrowski <przemek.dabrowski@destroy-display.com> (15.11.2005)
    This class is a part of the history system of PyUt.
    Every action that needs to be redone/undone should have an associated
    command. This class is to be considered as an abstract class.
    """
    
    def __init__(self):
        """
        Constructor.
        Notes : each Command should have at least one constructor with the
        same profile (no params), because it's this constructor that will
        be called when the history manager will do a unserialization.
        """

        #group to which the command is added. Init when added to a group
        self._group = None

    #>------------------------------------------------------------------------
       
    def serialize(self):
        """
        @return a string representation of the command in view to store it
        in a file. This method must be redifined in all subclasses in that
        way :
            return Command.serialize + (MyCommand's serialized informations)
            
        Notes : use makeValuatedToken() from historyUtils for each value
        you want to serialize, so that you can use the getTokenValue to get
        back the string representation of this value for the unserialization.
        """

        #return the module name and class name in view to read them during
        #the unserialization and get the right constructor.
        return (makeValuatedToken(COMMAND_MODULE_ID, str(self.__module__)) +
                makeValuatedToken(COMMAND_CLASS_ID, str(self.__class__.__name__)))
        
    #>------------------------------------------------------------------------
    
    def unserialize(self, serializedInfos):
        """
        (Abstract) Here should be assigned values to the informations needed
        by the command (see also getTokenValue in historyUtils).
        @serializedInfos String :   string from which whe have to extract
                                    the informations needed to set up
                                    the command.
        """
        
        pass

    #>------------------------------------------------------------------------

    def execute(self):
        """
        Do exactly the same as redo(), but is added for context clearness.
        It should be called instead of redo when we execute for the first time
        the command outside the history. It should be also called in the undo
        method of the contrary command (for e.g. : createItem.undo() calls
        deleteItem.execute() and deleteItem.undo() calls createItem.execute())
        """
        
        self.redo()
    #>------------------------------------------------------------------------
    
    def redo(self):
        """
        (Abstract)Here should be implemented the code to redo the associated
        action
        """
        pass

    #>------------------------------------------------------------------------

    def undo(self):
        """
        here should be implemented the code to undo the associated action. If
        there is a contrary command, use its execute() method.
        """
        pass

    #>------------------------------------------------------------------------

    def getGroup(self):
        """
        @return the group (CommandGroup) to which belongs the command 
        """

        return self._group

    #>------------------------------------------------------------------------

    def setGroup(self, group):
        """
        Set the group to which belongs the command. Avoid to call this method,
        because it is called automaticaly when the command is added to a group.
        @param group (CommandGroup) : group to which the command belongs.
        """

        self._group = group
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.