enable.tools.pyface.commands module

Enable Commands

This module provides pyface.undo.abstract_command.AbstractCommand subclasses for common component manipulations, such as moving, resizing and setting attribute values.

class enable.tools.pyface.commands.ComponentCommand(component, **traits)[source]

Bases: pyface.undo.abstract_command.AbstractCommand

Abstract command which operates on a Component

component = Instance(Component)

The component the command is being performed on.

component_name = Unicode

An appropriate name for the component that can be used by the command. The default is the class name, split into words.

class enable.tools.pyface.commands.MoveCommand(component, new_position=None, previous_position=None, **traits)[source]

Bases: enable.tools.pyface.commands.ComponentCommand

A command that moves a component

This handles the logic of moving a component and merging successive moves. This class provides _change_position and _merge_data methods that subclasses can override to change the move behaviour in a uniform way for undo and redo operations.

Parameters
  • component (Component instance) – The component being moved.

  • new_position (tuple of (x, y)) – The tuple representing the new position.

  • previous_position (tuple of (x, y)) – The tuple representing the previous position.

  • **traits – Any other trait values that need to be passed in at creation time.

  • new_position argument is the same as the data trait on the (The) –

  • If both are provided (class.) –

  • new_position value is used. (the) –

data = Tuple

The new position of the component as a tuple (x, y).

do()[source]

This is called by the command stack to do the command and to return any value. The command must save any state necessary for the ‘redo()’ and ‘undo()’ methods to work. The class’s __init__() must also ensure that deep copies of any arguments are made if appropriate. It is guaranteed that this will only ever be called once and that it will be called before any call to ‘redo()’ or ‘undo()’.

merge(other)[source]

This is called by the command stack to try and merge another command with this one. True is returned if the commands were merged. ‘other’ is the command that is about to be executed. If the commands are merged then ‘other’ will discarded and not placed on the command stack. A subsequent undo or redo of this modified command must have the same effect as the two original commands.

mergeable = Bool

whether additional moves can be merged or if the move is finished.

previous_position = Tuple

The old position of the component as a tuple (x, y).

redo()[source]

This is called by the command stack to redo the command. Any returned value will replace the value that the command stack references from the original call to ‘do()’ or previous call to ‘redo()’.

undo()[source]

This is called by the command stack to undo the command.

class enable.tools.pyface.commands.ResizeCommand(component, new_rectangle=None, previous_rectangle=None, **traits)[source]

Bases: enable.tools.pyface.commands.ComponentCommand

Command for resizing a component

This handles the logic of moving a component and merging successive moves. This class provides _change_rectangle and _merge_data methods that subclasses can override to change the reszie behaviour in a uniform way for undo and redo operations.

Parameters
  • component (Component instance) – The component being moved.

  • new_rectangle (tuple of (x, y, w, h)) – The rectangle representing the new position and bounds.

  • previous_rectangle (tuple of (x, y, w, h)) – The rectangle representing the previous position and bounds.

  • **traits – Any other trait values that need to be passed in at creation time.

  • new_rectangle argument is the same as the data trait on the (The) –

  • If both are provided (class.) –

  • new_rectangle value is used. (the) –

data = Tuple

The new rectangle of the component as a tuple (x, y, width, height).

do()[source]

This is called by the command stack to do the command and to return any value. The command must save any state necessary for the ‘redo()’ and ‘undo()’ methods to work. The class’s __init__() must also ensure that deep copies of any arguments are made if appropriate. It is guaranteed that this will only ever be called once and that it will be called before any call to ‘redo()’ or ‘undo()’.

merge(other)[source]

This is called by the command stack to try and merge another command with this one. True is returned if the commands were merged. ‘other’ is the command that is about to be executed. If the commands are merged then ‘other’ will discarded and not placed on the command stack. A subsequent undo or redo of this modified command must have the same effect as the two original commands.

mergeable = Bool

whether additional resizes can be merged or if the resize is finished.

classmethod move_command(component, new_position, previous_position=None, **traits)[source]

Factory that creates a ResizeCommand implementing a move operation

This allows a MoveTool to create move commands that can be easily merged with resize commands.

previous_rectangle = Tuple

The old rectangle of the component as a tuple (x, y, width, height).

redo()[source]

This is called by the command stack to redo the command. Any returned value will replace the value that the command stack references from the original call to ‘do()’ or previous call to ‘redo()’.

undo()[source]

This is called by the command stack to undo the command.