鼠标事件
wx.MouseEvent
This event class contains information about the events generated by the mouse: they include mouse buttons press and release events and mouse move events.
All mouse events involving the buttons use MOUSE_BTN_LEFT for the left mouse button, MOUSE_BTN_MIDDLE for the middle one and MOUSE_BTN_RIGHT for the right one. And if the system supports more buttons, theMOUSE_BTN_AUX1 and MOUSE_BTN_AUX2 events can also be generated. Note that not all mice have even a middle button so a portable application should avoid relying on the events from it (but the right button click can be emulated using the left mouse button with the control key under Mac platforms with a single button mouse).
For the wxEVT_ENTER_WINDOW and wxEVT_LEAVE_WINDOW events purposes, the mouse is considered to be inside the window if it is in the window client area and not inside one of its children. In other words, the parent window receives wxEVT_LEAVE_WINDOW event not only when the mouse leaves the window entirely but also when it enters one of its children.
The position associated with a mouse event is expressed in the window coordinates of the window which generated the event, you can use wx.Window.ClientToScreen to convert it to screen coordinates and possibly callwx.Window.ScreenToClient next to convert it to window coordinates of another window.
Events Emitted by this Class
Handlers bound for the following event types will receive a wx.MouseEvent parameter.
- EVT_LEFT_DOWN: Process a
wxEVT_LEFT_DOWNevent. The handler of this event should normally call event.Skip() to allow the default processing to take place as otherwise the window under mouse wouldn’t get the focus. - EVT_LEFT_UP: Process a
wxEVT_LEFT_UPevent. - EVT_LEFT_DCLICK: Process a
wxEVT_LEFT_DCLICKevent. - EVT_MIDDLE_DOWN: Process a
wxEVT_MIDDLE_DOWNevent. - EVT_MIDDLE_UP: Process a
wxEVT_MIDDLE_UPevent. - EVT_MIDDLE_DCLICK: Process a
wxEVT_MIDDLE_DCLICKevent. - EVT_RIGHT_DOWN: Process a
wxEVT_RIGHT_DOWNevent. - EVT_RIGHT_UP: Process a
wxEVT_RIGHT_UPevent. - EVT_RIGHT_DCLICK: Process a
wxEVT_RIGHT_DCLICKevent. - EVT_MOUSE_AUX1_DOWN: Process a
wxEVT_AUX1_DOWNevent. - EVT_MOUSE_AUX1_UP: Process a
wxEVT_AUX1_UPevent. - EVT_MOUSE_AUX1_DCLICK: Process a
wxEVT_AUX1_DCLICKevent. - EVT_MOUSE_AUX2_DOWN: Process a
wxEVT_AUX2_DOWNevent. - EVT_MOUSE_AUX2_UP: Process a
wxEVT_AUX2_UPevent. - EVT_MOUSE_AUX2_DCLICK: Process a
wxEVT_AUX2_DCLICKevent. - EVT_MOTION: Process a
wxEVT_MOTIONevent. - EVT_ENTER_WINDOW: Process a
wxEVT_ENTER_WINDOWevent. - EVT_LEAVE_WINDOW: Process a
wxEVT_LEAVE_WINDOWevent. - EVT_MOUSEWHEEL: Process a
wxEVT_MOUSEWHEELevent. - EVT_MOUSE_EVENTS: Process all mouse events.
Note
Note that under Windows CE mouse enter and leave events are not natively supported by the system but are generated by wxWidgets itself. This has several drawbacks: the LEAVE_WINDOW event might be received some time after the mouse left the window and the state variables for it may have changed during this time.
Note
Note the difference between methods like wx.MouseEvent.LeftDown and the inherited wx.MouseState.LeftIsDown : the former returns True when the event corresponds to the left mouse button click while the latter returns True if the left mouse button is currently being pressed. For example, when the user is dragging the mouse you can use wx.MouseEvent.LeftIsDown to test whether the left mouse button is (still) depressed. Also, by convention, if wx.MouseEvent.LeftDown returns True, wx.MouseEvent.LeftIsDown will also return True in wxWidgets whatever the underlying GUI behaviour is (which is platform-dependent). The same applies, of course, to other mouse buttons as well.
See also
Methods Summary
__init__ |
Constructor. |
Aux1DClick |
Returns True if the event was a first extra button double click. |
Aux1Down |
Returns True if the first extra button mouse button changed to down. |
Aux1Up |
Returns True if the first extra button mouse button changed to up. |
Aux2DClick |
Returns True if the event was a second extra button double click. |
Aux2Down |
Returns True if the second extra button mouse button changed to down. |
Aux2Up |
Returns True if the second extra button mouse button changed to up. |
Button |
Returns True if the event was generated by the specified button. |
ButtonDClick |
If the argument is omitted, this returns True if the event was a mouse double click event. |
ButtonDown |
If the argument is omitted, this returns True if the event was a mouse button down event. |
ButtonUp |
If the argument is omitted, this returns True if the event was a mouse button up event. |
Dragging |
Returns True if this was a dragging event (motion while a button is depressed). |
Entering |
Returns True if the mouse was entering the window. |
GetButton |
Returns the mouse button which generated this event or MOUSE_BTN_NONE if no button is involved (for mouse move, enter or leave event, for example). |
GetClickCount |
Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on. |
GetColumnsPerAction |
Returns the configured number of columns (or whatever) to be scrolled per wheel action. |
GetLinesPerAction |
Returns the configured number of lines (or whatever) to be scrolled per wheel action. |
GetLogicalPosition |
Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled). |
GetWheelAxis |
Gets the axis the wheel operation concerns. |
GetWheelDelta |
Get wheel delta, normally 120. |
GetWheelRotation |
Get wheel rotation, positive or negative indicates direction of rotation. |
IsButton |
Returns True if the event was a mouse button event (not necessarily a button down event - that may be tested using ButtonDown ). |
IsPageScroll |
Returns True if the system has been setup to do page scrolling with the mouse wheel instead of line scrolling. |
Leaving |
Returns True if the mouse was leaving the window. |
LeftDClick |
Returns True if the event was a left double click. |
LeftDown |
Returns True if the left mouse button changed to down. |
LeftUp |
Returns True if the left mouse button changed to up. |
MetaDown |
Returns True if the Meta key was down at the time of the event. |
MiddleDClick |
Returns True if the event was a middle double click. |
MiddleDown |
Returns True if the middle mouse button changed to down. |
MiddleUp |
Returns True if the middle mouse button changed to up. |
Moving |
Returns True if this was a motion event and no mouse buttons were pressed. |
RightDClick |
Returns True if the event was a right double click. |
RightDown |
Returns True if the right mouse button changed to down. |
RightUp |
Returns True if the right mouse button changed to up. |
Properties Summary
LinesPerAction |
See GetLinesPerAction |
LogicalPosition |
See GetLogicalPosition |
WheelDelta |
See GetWheelDelta |
WheelRotation |
See GetWheelRotation |
Class API
- class
wx.MouseEvent(Event, MouseState) -
Possible constructors:
MouseEvent(mouseEventType=wxEVT_NULL)This event class contains information about the events generated by the mouse: they include mouse buttons press and release events and mouse move events.
Methods
__init__(self, mouseEventType=wxEVT_NULL)-
Constructor.
Valid event types are:
wxEVT_ENTER_WINDOWwxEVT_LEAVE_WINDOWwxEVT_LEFT_DOWNwxEVT_LEFT_UPwxEVT_LEFT_DCLICKwxEVT_MIDDLE_DOWNwxEVT_MIDDLE_UPwxEVT_MIDDLE_DCLICKwxEVT_RIGHT_DOWNwxEVT_RIGHT_UPwxEVT_RIGHT_DCLICKwxEVT_AUX1_DOWNwxEVT_AUX1_UPwxEVT_AUX1_DCLICKwxEVT_AUX2_DOWNwxEVT_AUX2_UPwxEVT_AUX2_DCLICKwxEVT_MOTIONwxEVT_MOUSEWHEEL
Parameters: mouseEventType (wx.EventType) –
Aux1DClick(self)-
Returns
Trueif the event was a first extra button double click.Return type: bool
Aux1Down(self)-
Returns
Trueif the first extra button mouse button changed to down.Return type: bool
Aux1Up(self)-
Returns
Trueif the first extra button mouse button changed to up.Return type: bool
Aux2DClick(self)-
Returns
Trueif the event was a second extra button double click.Return type: bool
Aux2Down(self)-
Returns
Trueif the second extra button mouse button changed to down.Return type: bool
Aux2Up(self)-
Returns
Trueif the second extra button mouse button changed to up.Return type: bool
Button(self, but)-
Returns
Trueif the event was generated by the specified button.Parameters: but (MouseButton) – Return type: bool See also
MouseState.ButtoinIsDown()
ButtonDClick(self, but=MOUSE_BTN_ANY)-
If the argument is omitted, this returns
Trueif the event was a mouse double click event.Otherwise the argument specifies which double click event was generated (see wx.Button for the possible values).
Parameters: but (MouseButton) – Return type: bool
ButtonDown(self, but=MOUSE_BTN_ANY)-
If the argument is omitted, this returns
Trueif the event was a mouse button down event.Otherwise the argument specifies which button-down event was generated (see wx.Button for the possible values).
Parameters: but (MouseButton) – Return type: bool
ButtonUp(self, but=MOUSE_BTN_ANY)-
If the argument is omitted, this returns
Trueif the event was a mouse button up event.Otherwise the argument specifies which button-up event was generated (see wx.Button for the possible values).
Parameters: but (MouseButton) – Return type: bool
Dragging(self)-
Returns
Trueif this was a dragging event (motion while a button is depressed).Return type: bool See also
Entering(self)-
Returns
Trueif the mouse was entering the window.Return type: bool See also
GetButton(self)-
Returns the mouse button which generated this event or
MOUSE_BTN_NONEif no button is involved (for mouse move, enter or leave event, for example).Otherwise
MOUSE_BTN_LEFTis returned for the left button down, up and double click events,MOUSE_BTN_MIDDLEandMOUSE_BTN_RIGHTfor the same events for the middle and the right buttons respectively.Return type: int
GetClickCount(self)-
Returns the number of mouse clicks for this event: 1 for a simple click, 2 for a double-click, 3 for a triple-click and so on.
Currently this function is implemented only in Mac and returns -1 for the other platforms (you can still distinguish simple clicks from double-clicks as they generate different kinds of events however).
Return type: int New in version 2.9.0.
GetColumnsPerAction(self)-
Returns the configured number of columns (or whatever) to be scrolled per wheel action.
Default value under most platforms is three.
Return type: int New in version 2.9.5.
See also
GetLinesPerAction(self)-
Returns the configured number of lines (or whatever) to be scrolled per wheel action.
Default value under most platforms is three.
Return type: int See also
GetLogicalPosition(self, dc)-
Returns the logical mouse position in pixels (i.e. translated according to the translation set for the DC, which usually indicates that the window has been scrolled).
Parameters: dc (wx.DC) – Return type: wx.Point
GetWheelAxis(self)-
Gets the axis the wheel operation concerns.
Usually the mouse wheel is used to scroll vertically so
MOUSE_WHEEL_VERTICALis returned but some mice (and most trackpads) also allow to use the wheel to scroll horizontally in which caseMOUSE_WHEEL_HORIZONTALis returned.Notice that before wxWidgets 2.9.4 this method returned
int.Return type: wx.MouseWheelAxis
GetWheelDelta(self)-
Get wheel delta, normally 120.
This is the threshold for action to be taken, and one such action (for example, scrolling one increment) should occur for each delta.
Return type: int
GetWheelRotation(self)-
Get wheel rotation, positive or negative indicates direction of rotation.
Current devices all send an event when rotation is at least +/-WheelDelta, but finer resolution devices can be created in the future.
Because of this you shouldn’t assume that one event is equal to 1 line, but you should be able to either do partial line scrolling or wait until several events accumulate before scrolling.
Return type: int
IsButton(self)-
Returns
Trueif the event was a mouse button event (not necessarily a button down event - that may be tested usingButtonDown).Return type: bool
IsPageScroll(self)-
Returns
Trueif the system has been setup to do page scrolling with the mouse wheel instead of line scrolling.Return type: bool
Leaving(self)-
Returns
Trueif the mouse was leaving the window.Return type: bool See also
Entering.
LeftDClick(self)-
Returns
Trueif the event was a left double click.Return type: bool
LeftDown(self)-
Returns
Trueif the left mouse button changed to down.Return type: bool
LeftUp(self)-
Returns
Trueif the left mouse button changed to up.Return type: bool
MetaDown(self)-
Returns
Trueif the Meta key was down at the time of the event.Return type: bool
MiddleDClick(self)-
Returns
Trueif the event was a middle double click.Return type: bool
MiddleDown(self)-
Returns
Trueif the middle mouse button changed to down.Return type: bool
MiddleUp(self)-
Returns
Trueif the middle mouse button changed to up.Return type: bool
Moving(self)-
Returns
Trueif this was a motion event and no mouse buttons were pressed.If any mouse button is held pressed, then this method returns
FalseandDraggingreturnsTrue.Return type: bool
RightDClick(self)-
Returns
Trueif the event was a right double click.Return type: bool
RightDown(self)-
Returns
Trueif the right mouse button changed to down.Return type: bool
RightUp(self)-
Returns
Trueif the right mouse button changed to up.Return type: bool
Properties
LinesPerAction
LogicalPosition
WheelDelta-
See
GetWheelDelta
WheelRotation-
See
GetWheelRotation






Inheritance diagram for class MouseEvent:


浙公网安备 33010602011771号