My app needs too calculation for each wx.EVT_MOVE event, so I'd like to
save the entire mouse state in some kind of data structure/class and
then add it to a collections.deque for processing during wx.EVT_IDLE
events. I feel like I'm "recreating the wheel" as it seems to me that
someone has probably already done this.
I'd like to save all the mouse-related event.* attributes, too. Is the
event object store-able as-is, or is it reused for every event ? Do I
have to, instead, extract every event attribute individually and save
them one-by-one ?
The event object passed to the handler will be destroyed after control returns to where the event was sent from, so you will need to copy the values you are interested in from the event object.
I have attached a class that outlines what I think needs to be done, but
I am hoping this has already been implemented, which seems like it would
save me a lot of work.
Unless you really do need to be able to store both the current and previous positions in a single object, you can just use the wx.MouseState class instead. (Wouldn't it make more sense to have the previous position just be the previous state object in the list?)
In wxPython 2.9 the wx.MouseEvent derives from wx.MouseState, so they are *very* compatible but it also exists in 2.8 and should work just fine. Here is what the C++/SWIG declaration of the class looks like in 2.8. As you can see there is a convenient property defined for each of the attributes, so writing a bit of code to transplant values from a wx.MouseEvent to an instance of wx.MouseState should be trivial:
class wxMouseState
{
public:
wxMouseState();
~wxMouseState();
wxCoord GetX();
wxCoord GetY();
bool LeftDown();
bool MiddleDown();
bool RightDown();
bool ControlDown();
bool ShiftDown();
bool AltDown();
bool MetaDown();
bool CmdDown();
void SetX(wxCoord x);
void SetY(wxCoord y);
void SetLeftDown(bool down);
void SetMiddleDown(bool down);
void SetRightDown(bool down);
void SetControlDown(bool down);
void SetShiftDown(bool down);
void SetAltDown(bool down);
void SetMetaDown(bool down);
%pythoncode {
x = property(GetX, SetX)
y = property(GetY, SetY)
leftDown = property(LeftDown, SetLeftDown)
middleDown = property(MiddleDown, SetMiddleDown)
rightDown = property(RightDown, SetRightDown)
controlDown = property(ControlDown, SetControlDown)
shiftDown = property(ShiftDown, SetShiftDown)
altDown = property(AltDown, SetAltDown)
metaDown = property(MetaDown, SetMetaDown)
cmdDown = property(CmdDown)
}
};
···
On 8/3/11 10:52 AM, Ray Pasco wrote:
--
Robin Dunn
Software Craftsman