Functions | |
def | Command_Save_And_Execute (Command_TextObject text, Command command) |
Save the given command on the undo list then execute the command on the given text object. | |
None | Command_Operation_Replace (Command_TextObject source, str searchPattern, str replaceText) |
An operation to search and replace text in a Command_TextObject. | |
def | Command_Operation_Reverse (Command_TextObject source) |
An operation to reverse the characters in the given Command_TextObject. | |
None | Command_Undo (Command_TextObject text) |
Perform an undo on the given Command_TextObject, using the commands in the "global" undo list. | |
None | Command_ApplyReplaceCommand (Command_TextObject text, str searchPattern, str replaceText) |
Helper function to create a Command object that replaces text in the given Command_TextObject, adds the command to the undo list and then applies the command to the Command_TextObject. | |
None | Command_ApplyReverseCommand (Command_TextObject text) |
Helper function to create a Command object that reverses the order of the characters in the given Command_TextObject, adds the command to the undo list and then applies the command to the Command_TextObject. | |
def | Command_Exercise () |
Example of using the Command Pattern. | |
Variables | |
list | _commandUndoList = [] |
The list of commands applied. | |
None Command_ApplyReplaceCommand | ( | Command_TextObject | text, |
str | searchPattern, | ||
str | replaceText | ||
) |
Helper function to create a Command object that replaces text in the given Command_TextObject, adds the command to the undo list and then applies the command to the Command_TextObject.
Finally, it shows off what was done.
text | The Command_TextObject to affect. |
searchPattern | What to look for in the Command_TextObject. |
replaceText | What to replace the searchPattern with. |
Definition at line 89 of file command_exercise.py.
References DesignPatternExamples_python.command.command_exercise.Command_Save_And_Execute().
Referenced by DesignPatternExamples_python.command.command_exercise.Command_Exercise().
None Command_ApplyReverseCommand | ( | Command_TextObject | text | ) |
Helper function to create a Command object that reverses the order of the characters in the given Command_TextObject, adds the command to the undo list and then applies the command to the Command_TextObject.
Finally, it shows what was done.
text | The Command_TextObject to affect. |
Definition at line 105 of file command_exercise.py.
References DesignPatternExamples_python.command.command_exercise.Command_Save_And_Execute().
Referenced by DesignPatternExamples_python.command.command_exercise.Command_Exercise().
def Command_Exercise | ( | void | ) |
Example of using the Command Pattern.
The Command pattern is used to encapsulate an operation or command associated with an object so that the command can be applied to the object at a later time.
In this exercise, an undo list is implemented using instances of the Command class that associate commands defined in this file with a text object. The commands are applied to the text object in succession then effectively undone.
Definition at line 123 of file command_exercise.py.
References DesignPatternExamples_python.command.command_exercise.Command_ApplyReplaceCommand(), DesignPatternExamples_python.command.command_exercise.Command_ApplyReverseCommand(), and DesignPatternExamples_python.command.command_exercise.Command_Undo().
None Command_Operation_Replace | ( | Command_TextObject | source, |
str | searchPattern, | ||
str | replaceText | ||
) |
An operation to search and replace text in a Command_TextObject.
source | The Command_TextObject to affect. |
searchPattern | What to look for in the Command_TextObject. |
replaceText | What to replace the searchPattern with. |
Definition at line 34 of file command_exercise.py.
def Command_Operation_Reverse | ( | Command_TextObject | source | ) |
An operation to reverse the characters in the given Command_TextObject.
source | The Command_TextObject to affect. |
Definition at line 44 of file command_exercise.py.
def Command_Save_And_Execute | ( | Command_TextObject | text, |
Command | command | ||
) |
Save the given command on the undo list then execute the command on the given text object.
text | The Command_TextObject on which to apply the command. |
command | The Command object to apply to the text object. |
Definition at line 19 of file command_exercise.py.
Referenced by DesignPatternExamples_python.command.command_exercise.Command_ApplyReplaceCommand(), and DesignPatternExamples_python.command.command_exercise.Command_ApplyReverseCommand().
None Command_Undo | ( | Command_TextObject | text | ) |
Perform an undo on the given Command_TextObject, using the commands in the "global" undo list.
If the undo list is empty, nothing happens.
text | The Command_TextObject to affect. |
Definition at line 58 of file command_exercise.py.
Referenced by DesignPatternExamples_python.command.command_exercise.Command_Exercise().
|
protected |
The list of commands applied.
Definition at line 9 of file command_exercise.py.