Simulation of mouse button click --- how?

I am looking at how I can perform an "Undo" operation when using wxPython (2.8.12.1) as follows:

* User moves the mouse over a grid of cells displayed on the screen.
* The Left Button is clicked at a specific location, an event is fired, and it's bound function is executed, which changes the state of the grid of cells (e.g shapes displayed change). The state change depends on the location of mouse when the click occurred.
* This bound function saves (in a stack) a set of parameters that are necessary to recover the state of the grid of cells before the mouse click (e.g. location of the mouse click in the grid of cells, shapes, etc.).
* The "Undo" button (widget in a panel) is now clicked on, and it's bound function will pop the last set of parameters in this state recovery stack.
* These parameters are then used to simulate the last mouse click at a specific location, which will undo the effect of the last mouse click. That is, the displayed grid of cells will now appear as they were before the last mouse click --- previous state recovered.

Notes: 1) This "Undo" operation can be applied repeatedly until the state recovery stack is empty, 2) The bound method for the mouse click must be executed (or code that gives the identical results) to recover the state of the grid of cells, 3) The code has been written so that a mouse click at a specific location causes a state change and if this is followed by a mouse click at the same location, the state will be recovered (state flip-flop approach that is location dependent).

Finally, my question --- how can I use wxPython to simulate a mouse click at a specific location in the displayed cell grid?

You probably do not want to do it at the level of widgets and mouse or keyboard events. Rather your undo/redo stack should focus on the changes to the data model (or other program state) and just have your UI widgets be able to display the current state, whatever it may be.

When I've done things like this before I usually have a hierarchy of Command classes of various types, (add item, remove item, move item left, etc.) and then everything that the user can do is first turned into a Command object of the appropriate type and then the command object is the one that actually performs the change with a Do() method, and finally that command object is put on the undo-redo stack. The Command objects also know how to undo their own actions and so performing a series of undo's is a simple matter of grabbing the next item from the stack, calling its Undo method and moving the stack pointer to the next item. (They are not popped from the stack in case the user wants to Redo.) Each of the commands basically just changes the program's data or state in some way and then sends the appropriate messages to the widgets involved telling them to adjust themselves to the new data or state.

···

On 3/1/12 8:53 AM, Virgil Stokes wrote:

I am looking at how I can perform an "Undo" operation when using
wxPython (2.8.12.1) as follows:

* User moves the mouse over a grid of cells displayed on the screen.
* The Left Button is clicked at a specific location, an event is fired,
and it's bound function is executed, which changes the state of the grid
of cells (e.g shapes displayed change). The state change depends on the
location of mouse when the click occurred.
* This bound function saves (in a stack) a set of parameters that are
necessary to recover the state of the grid of cells before the mouse
click (e.g. location of the mouse click in the grid of cells, shapes,
etc.).
* The "Undo" button (widget in a panel) is now clicked on, and it's
bound function will pop the last set of parameters in this state
recovery stack.
* These parameters are then used to simulate the last mouse click at a
specific location, which will undo the effect of the last mouse click.
That is, the displayed grid of cells will now appear as they were before
the last mouse click --- previous state recovered.

Notes: 1) This "Undo" operation can be applied repeatedly until the
state recovery stack is empty, 2) The bound method for the mouse click
must be executed (or code that gives the identical results) to recover
the state of the grid of cells, 3) The code has been written so that a
mouse click at a specific location causes a state change and if this is
followed by a mouse click at the same location, the state will be
recovered (state flip-flop approach that is location dependent).

Finally, my question --- how can I use wxPython to simulate a mouse
click at a specific location in the displayed cell grid?

--
Robin Dunn
Software Craftsman

I am looking at how I can perform an "Undo" operation when using
wxPython (2.8.12.1) as follows:

* User moves the mouse over a grid of cells displayed on the screen.
* The Left Button is clicked at a specific location, an event is fired,
and it's bound function is executed, which changes the state of the grid
of cells (e.g shapes displayed change). The state change depends on the
location of mouse when the click occurred.
* This bound function saves (in a stack) a set of parameters that are
necessary to recover the state of the grid of cells before the mouse
click (e.g. location of the mouse click in the grid of cells, shapes,
etc.).
* The "Undo" button (widget in a panel) is now clicked on, and it's
bound function will pop the last set of parameters in this state
recovery stack.
* These parameters are then used to simulate the last mouse click at a
specific location, which will undo the effect of the last mouse click.
That is, the displayed grid of cells will now appear as they were before
the last mouse click --- previous state recovered.

Notes: 1) This "Undo" operation can be applied repeatedly until the
state recovery stack is empty, 2) The bound method for the mouse click
must be executed (or code that gives the identical results) to recover
the state of the grid of cells, 3) The code has been written so that a
mouse click at a specific location causes a state change and if this is
followed by a mouse click at the same location, the state will be
recovered (state flip-flop approach that is location dependent).

Finally, my question --- how can I use wxPython to simulate a mouse
click at a specific location in the displayed cell grid?

You probably do not want to do it at the level of widgets and mouse or keyboard events. Rather your undo/redo stack should focus on the changes to the data model (or other program state) and just have your UI widgets be able to display the current state, whatever it may be.

I like this suggestion, Robin --- simple and clean --- makes more sense that what I had planned

When I've done things like this before I usually have a hierarchy of Command classes of various types, (add item, remove item, move item left, etc.) and then everything that the user can do is first turned into a Command object of the appropriate type and then the command object is the one that actually performs the change with a Do() method, and finally that command object is put on the undo-redo stack. The Command objects also know how to undo their own actions and so performing a series of undo's is a simple matter of grabbing the next item from the stack, calling its Undo method and moving the stack pointer to the next item. (They are not popped from the stack in case the user wants to Redo.) Each of the commands basically just changes the program's data or state in some way and then sends the appropriate messages to the widgets involved telling them to adjust themselves to the new data or state.

Yes, I will now focus on this approach which seems to be much more sensible.

Thanks for pointing me in the right direction :slight_smile:

--V

···

On 01-Mar-2012 18:41, Robin Dunn wrote:

On 3/1/12 8:53 AM, Virgil Stokes wrote: