.. wxPython Phoenix documentation This file was generated by Phoenix's sphinx generator and associated tools, do not edit by hand. Copyright: (c) 2011-2025 by Total Control Software License: wxWindows License .. include:: headings.inc .. _wx.CommandProcessor: ========================================================================================================================================== |phoenix_title| **wx.CommandProcessor** ========================================================================================================================================== :ref:`wx.CommandProcessor` is a class that maintains a history of Commands, with undo/redo functionality built-in. Derive a new class from this if you want different behaviour. .. seealso:: :ref:`CommandProcessor Overview `, :ref:`wx.Command` | |class_hierarchy| Class Hierarchy ================================= .. raw:: html

Inheritance diagram of CommandProcessor

| |method_summary| Methods Summary ================================ ================================================================================ ================================================================================ :meth:`~wx.CommandProcessor.__init__` Constructor. :meth:`~wx.CommandProcessor.CanRedo` Returns ``True`` if the currently-active command can be redone, ``False`` otherwise. :meth:`~wx.CommandProcessor.CanUndo` Returns ``True`` if the currently-active command can be undone, ``False`` otherwise. :meth:`~wx.CommandProcessor.ClearCommands` Deletes all commands in the list and sets the current command pointer to nullptr. :meth:`~wx.CommandProcessor.GetCommands` Returns the list of commands. :meth:`~wx.CommandProcessor.GetCurrentCommand` Returns the current command. :meth:`~wx.CommandProcessor.GetEditMenu` Returns the edit menu associated with the command processor. :meth:`~wx.CommandProcessor.GetMaxCommands` Returns the maximum number of commands that the command processor stores. :meth:`~wx.CommandProcessor.GetRedoAccelerator` Returns the string that will be appended to the Redo menu item. :meth:`~wx.CommandProcessor.GetRedoMenuLabel` Returns the string that will be shown for the redo menu item. :meth:`~wx.CommandProcessor.GetUndoAccelerator` Returns the string that will be appended to the Undo menu item. :meth:`~wx.CommandProcessor.GetUndoMenuLabel` Returns the string that will be shown for the undo menu item. :meth:`~wx.CommandProcessor.Initialize` Initializes the command processor, setting the current command to the last in the list (if any), and updating the edit menu (if one has been specified). :meth:`~wx.CommandProcessor.IsDirty` Returns a boolean value that indicates if changes have been made since the last save operation. :meth:`~wx.CommandProcessor.MarkAsSaved` You must call this method whenever the project is saved if you plan to use :meth:`~CommandProcessor.IsDirty` . :meth:`~wx.CommandProcessor.Redo` Executes (redoes) the current command (the command that has just been undone if any). :meth:`~wx.CommandProcessor.SetEditMenu` Tells the command processor to update the Undo and Redo items on this menu as appropriate. :meth:`~wx.CommandProcessor.SetMenuStrings` Sets the menu labels according to the currently set menu and the current command state. :meth:`~wx.CommandProcessor.SetRedoAccelerator` Sets the string that will be appended to the Redo menu item. :meth:`~wx.CommandProcessor.SetUndoAccelerator` Sets the string that will be appended to the Undo menu item. :meth:`~wx.CommandProcessor.Store` Just store the command without executing it. :meth:`~wx.CommandProcessor.Submit` Submits a new command to the command processor. :meth:`~wx.CommandProcessor.Undo` Undoes the last command executed. ================================================================================ ================================================================================ | |property_summary| Properties Summary ===================================== ================================================================================ ================================================================================ :attr:`~wx.CommandProcessor.Commands` See :meth:`~wx.CommandProcessor.GetCommands` :attr:`~wx.CommandProcessor.CurrentCommand` See :meth:`~wx.CommandProcessor.GetCurrentCommand` :attr:`~wx.CommandProcessor.EditMenu` See :meth:`~wx.CommandProcessor.GetEditMenu` and :meth:`~wx.CommandProcessor.SetEditMenu` :attr:`~wx.CommandProcessor.MaxCommands` See :meth:`~wx.CommandProcessor.GetMaxCommands` :attr:`~wx.CommandProcessor.RedoAccelerator` See :meth:`~wx.CommandProcessor.GetRedoAccelerator` and :meth:`~wx.CommandProcessor.SetRedoAccelerator` :attr:`~wx.CommandProcessor.RedoMenuLabel` See :meth:`~wx.CommandProcessor.GetRedoMenuLabel` :attr:`~wx.CommandProcessor.UndoAccelerator` See :meth:`~wx.CommandProcessor.GetUndoAccelerator` and :meth:`~wx.CommandProcessor.SetUndoAccelerator` :attr:`~wx.CommandProcessor.UndoMenuLabel` See :meth:`~wx.CommandProcessor.GetUndoMenuLabel` ================================================================================ ================================================================================ | |api| Class API =============== .. class:: wx.CommandProcessor(Object) **Possible constructors**:: CommandProcessor(maxCommands=-1) -> None CommandProcessor is a class that maintains a history of Commands, with undo/redo functionality built-in. .. method:: __init__(self, maxCommands=-1) Constructor. :param `maxCommands`: May be set to a positive integer to limit the number of commands stored to it, otherwise (and by default) the list of commands can grow arbitrarily. :type `maxCommands`: int :rtype: `None` .. method:: CanRedo(self) Returns ``True`` if the currently-active command can be redone, ``False`` otherwise. :rtype: `bool` .. method:: CanUndo(self) Returns ``True`` if the currently-active command can be undone, ``False`` otherwise. :rtype: `bool` .. method:: ClearCommands(self) Deletes all commands in the list and sets the current command pointer to nullptr. :rtype: `None` .. method:: GetCommands(self) Returns the list of commands. :rtype: `CommandList` .. method:: GetCurrentCommand(self) Returns the current command. :rtype: :ref:`wx.Command` .. method:: GetEditMenu(self) Returns the edit menu associated with the command processor. :rtype: :ref:`wx.Menu` .. method:: GetMaxCommands(self) Returns the maximum number of commands that the command processor stores. :rtype: `int` .. method:: GetRedoAccelerator(self) Returns the string that will be appended to the Redo menu item. :rtype: `str` .. method:: GetRedoMenuLabel(self) Returns the string that will be shown for the redo menu item. :rtype: `str` .. method:: GetUndoAccelerator(self) Returns the string that will be appended to the Undo menu item. :rtype: `str` .. method:: GetUndoMenuLabel(self) Returns the string that will be shown for the undo menu item. :rtype: `str` .. method:: Initialize(self) Initializes the command processor, setting the current command to the last in the list (if any), and updating the edit menu (if one has been specified). :rtype: `None` .. method:: IsDirty(self) Returns a boolean value that indicates if changes have been made since the last save operation. This only works if :meth:`MarkAsSaved` is called whenever the project is saved. :rtype: `bool` .. method:: MarkAsSaved(self) You must call this method whenever the project is saved if you plan to use :meth:`IsDirty` . :rtype: `None` .. method:: Redo(self) Executes (redoes) the current command (the command that has just been undone if any). :rtype: `bool` .. method:: SetEditMenu(self, menu) Tells the command processor to update the Undo and Redo items on this menu as appropriate. Set this to nullptr if the menu is about to be destroyed and command operations may still be performed, or the command processor may try to access an invalid pointer. :param `menu`: :type `menu`: wx.Menu :rtype: `None` .. method:: SetMenuStrings(self) Sets the menu labels according to the currently set menu and the current command state. :rtype: `None` .. method:: SetRedoAccelerator(self, accel) Sets the string that will be appended to the Redo menu item. :param `accel`: :type `accel`: string :rtype: `None` .. method:: SetUndoAccelerator(self, accel) Sets the string that will be appended to the Undo menu item. :param `accel`: :type `accel`: string :rtype: `None` .. method:: Store(self, command) Just store the command without executing it. The command is stored in the history list, and the associated edit menu (if any) updated appropriately. :param `command`: :type `command`: wx.Command :rtype: `None` .. method:: Submit(self, command, storeIt=True) Submits a new command to the command processor. The command processor calls :meth:`wx.Command.Do` to execute the command; if it succeeds, the command is stored in the history list, and the associated edit menu (if any) updated appropriately. If it fails, the command is deleted immediately. Once :meth:`Submit` has been called, the passed command should not be deleted directly by the application. :param `command`: The command to submit :type `command`: wx.Command :param `storeIt`: Indicates whether the successful command should be stored in the history list. :type `storeIt`: bool :rtype: `bool` .. method:: Undo(self) Undoes the last command executed. :rtype: `bool` .. attribute:: Commands See :meth:`~wx.CommandProcessor.GetCommands` .. attribute:: CurrentCommand See :meth:`~wx.CommandProcessor.GetCurrentCommand` .. attribute:: EditMenu See :meth:`~wx.CommandProcessor.GetEditMenu` and :meth:`~wx.CommandProcessor.SetEditMenu` .. attribute:: MaxCommands See :meth:`~wx.CommandProcessor.GetMaxCommands` .. attribute:: RedoAccelerator See :meth:`~wx.CommandProcessor.GetRedoAccelerator` and :meth:`~wx.CommandProcessor.SetRedoAccelerator` .. attribute:: RedoMenuLabel See :meth:`~wx.CommandProcessor.GetRedoMenuLabel` .. attribute:: UndoAccelerator See :meth:`~wx.CommandProcessor.GetUndoAccelerator` and :meth:`~wx.CommandProcessor.SetUndoAccelerator` .. attribute:: UndoMenuLabel See :meth:`~wx.CommandProcessor.GetUndoMenuLabel`