Synopsis
Re-executes the last undone command or series of commands.
Syntax
redo() redo(count) redo(tag)
Description
The function arguments.
Argument | Description |
---|---|
count | The number of commands to redo (default is 1). |
tag | The name of a tag created with set_undo_tag. |
The redo command allows the user to re-execute one or more commands that have been undone via the undo command. If called without any arguments, the last command is redone. The redo functionality is extended by using tags and blocks, which are described below.
The undo command is used to undo the last command or series of commands.
Examples
Example 1
chips> set_frame(["bgcolor","red"]) chips> undo() chips> redo()
Make the frame background red, then undo and redo the command.
Example 2
chips> set_frame(["bgcolor","red"]) chips> set_frame(["bgcolor","orange"]) chips> set_frame(["bgcolor","yellow"]) chips> set_undo_tag("yellow") chips> set_frame(["bgcolor","green"]) chips> set_undo_tag("green") chips> set_frame(["bgcolor","blue"]) chips> undo("yellow") chips> undo(2) chips> redo("green")
A tag is added to the undo stack after the frame background color is set to yellow. The color is then changed to green and another tag is added. After changing the background color to blue, undo is called with the yellow tag. Undo is then called with the value "2" to return to the red background, which is two commands prior to the yellow tag. Calling redo with the green tag moves the state back to the green background.
Example 3
chips> add_contour([1,2,5,3,3,6,0,0,1],3,3) chips> open_undo_block() chips> set_preference("region.fill.style", "1") chips> add_region([1,1,2,2.32,2],[1.5,2,2,1,1],"fill.color=blue") chips> add_region([3,2.67,3],[1,2,2.2],"fill.color=lime") chips> add_label(1.7,1.7,r"\lambda") chips> close_undo_block() chips> undo() chips> redo()
Three commands - two add_region and one add_label - are marked as a block. The undo command undoes all three commands, then they are reinserted with redo.
The Undo and Redo Stacks
ChIPS maintains two stacks - an undo stack and a redo stack. When commands are executed, they are added to the undo stack. When undo is called, ChIPS pops the commands off the undo stack and pushes them onto the redo stack. Redoing the commands pops them off the redo stack and back onto the undo stack.
Redo only works if commands have been undone and exist in the redo stack. After an undo command, if any command is issued that gets added to the undo stack, the redo stack gets cleared and those undone actions are no longer available.
Note that not all commands may be undone, such as file commands (printing and saving). Commands which retrieve information (such as get_<attribute> or info) also cannot be undone.
Using tags, blocks, and buffers
Tags
A tag may be set to mark a point in the command history. The tag can later be used to undo and redo all commands back to that point. The command to create a tag is set_undo_tag(tagname). To remove an existing tag, use clear_undo_tag(tagname).
chips> set_undo_tag('plot1') ... chips> undo('plot1')
An undo tag may be added within a block, but is only valid until the block is closed.
Blocks
Multiple commands may be grouped together in blocks so that they are treated as a unit by the undo and redo commands. When an undo is issued on a block, all of the commands in the block are undone as a single step. A redo command can then reverse the block undo. The commands open_undo_block and close_undo_block are used to open and close the block. These commands are part of the advanced ChIPS module; refer to "ahelp chips" for information. To load the module:
from pychips.advanced import *
The commands are not grouped until the block is closed. If undo is called while a block is open, the last single command is undone.
Buffers
Multiple commands may be grouped together in buffers by the open_undo_buffer and close_undo_buffer commands. Buffers are similar to blocks, but the window display is not updated until the buffer is closed; block commands update the display as they are issued.
Additionally, the discard_undo_buffer command may be used instead of close_undo_buffer. This discard command allows the user to effectively undo all the commands in that were issued while the buffer was open, without leaving them on the undo stack.
As an example:
import pycrates import pychips import pychips.advanced as advanced import numpy as np # Allow the routine to be imported __all__ = ("shade_error_region", ) def error_region(filename): "The first 3 columns of file are assumed to be x, y, dy" cr = pycrates.read_file(filename) xcol = cr.get_column(0) ycol = cr.get_column(1) dycol = cr.get_column(2) # Column values x = xcol.values y = ycol.values dy = dycol.values # The vertexes of the histogram yl = y - dy yh = y + dy xr = np.append(x, x[::-1]) yr = np.append(yl, yh[::-1]) # Axis labels from column name and, if present, units xlbl = xcol.name if xcol.unit != '': xlbl += " ({})".format(xcol.unit) ylbl = ycol.name if ycol.unit != '': ylbl += " ({})".format(ycol.unit) advanced.open_undo_buffer() try: pychips.add_window(8, 6, 'inches') pychips.add_curve(x, y, dy) pychips.add_region(xr, yr, ['fill.style', 'solid']) pychips.set_plot_xlabel(xlbl) pychips.set_plot_ylabel(ylbl) pychips.set_plot_title(filename) except: # Throw away all the comands since the open buffer # call and re-raise the error advanced.discard_undo_buffer() raise else: # Code was successful, so close the block advanced.close_undo_buffer()
If saved to the file shade.py then an example of its use would be
chips> import shade chips> shade.error_region('tbl.dat') chips> chips-4> print(info()) Window [win1] Frame [frm1] Plot [plot1] (0.15,0.15) .. (0.90,0.90) Border bottom [bx1] top [bx2] left [by1] right [by2] Curve [crv1] X Axis [ax1] Y Axis [ay1] Region [reg1] chips> undo() chips> print(info()) None
Bugs
See the bugs pages on the ChIPS website for an up-to-date listing of known bugs.
See Also
- undo
- undo