campy.gui.events.mouse module¶
Interact with the graphics libraries via mouse events.
- MOUSE_CLICKED
- MOUSE_PRESSED
- MOUSE_RELEASED
- MOUSE_MOVED
- MOUSE_DRAGGED
-
class
campy.gui.events.mouse.
GMouseEvent
(event_type, gwindow, x, y)[source]¶ Bases:
object
An event generated by some mouse interaction.
Each mouse event records its event type, its parent window, and the mouse coordinate of the event.
# Each mouse event # This event subclass represents a mouse event. Each mouse event # records the event type (MOUSE_PRESSED, # MOUSE_RELEASED, MOUSE_CLICKED, # MOUSE_MOVED, MOUSE_DRAGGED) along # with the coordinates of the event. Clicking the mouse generates # three events in the following order: MOUSE_PRESSED, # MOUSE_RELEASED, MOUSE_CLICKED.
# As an example, the following program uses mouse events to let # the user draw rectangles on the graphics window. The only # complexity in this code is the use of the library functions # min and abs to ensure that the # dimensions of the rectangle are positive:
# gw = _gwindow.GWindow # print("This program lets the user draw rectangles.") # while(True): # e = gevents.waitForEvent(); # if (e.getEventType() == MOUSE_PRESSED): # startX = e.getX(); # startY = e.getY(); # rect = gobjects.GRect(startX, startY, 0, 0); # rect.setFilled(True); # gw.add(rect); # elif(e.getEventType() == MOUSE_DRAGGED): # x = min(e.getX(), startX); # y = min(e.getY(), startY); # width = abs(e.getX() - startX); # height = abs(e.getY() - startY); # rect.setBounds(x, y, width, height);
# Attributes: # gwindow [GWindow]: GWindow in which MouseEvent occurred. # x [float]: The x-coordinate at which the event occurred. # y [float]: The y-coordinate at which the event occurred.
# Notes: # The x- and y-coordinates are given relative to the window origin at # the upper left corner of the window.
-
window
¶
-
x
¶
-
y
¶
-
-
class
campy.gui.events.mouse.
MouseEventType
[source]¶ Bases:
enum.Enum
-
MOUSE_CLICKED
= 1¶
-
MOUSE_DRAGGED
= 4¶
-
MOUSE_MOVED
= 3¶
-
MOUSE_RELEASED
= 2¶
-
-
campy.gui.events.mouse.
onmouseclicked
(function)[source]¶ Usage:
%gui tk from campy.gui.events.mouse import * from campy.graphics.gobjects import * from campy.graphics.gwindow import * window = GWindow() @onmouseclicked def add_circle(event): event.window.add(GOval(100, 100, x=event.x - 50, y=event.y - 50))
-
campy.gui.events.mouse.
onmousedragged
(function)[source]¶ Usage:
%gui tk from campy.gui.events.mouse import * from campy.graphics.gobjects import * from campy.graphics.gwindow import * window = GWindow() @onmousedragged def add_circle(event): event.window.add(GOval(100, 100, x=event.x - 50, y=event.y - 50))
-
campy.gui.events.mouse.
onmousemoved
(function)[source]¶ Usage:
%gui tk from campy.gui.events.mouse import * from campy.graphics.gobjects import * from campy.graphics.gwindow import * window = GWindow() @onmousemoved def add_circle(event): event.window.add(GOval(100, 100, x=event.x - 50, y=event.y - 50))
-
campy.gui.events.mouse.
onmousereleased
(function)[source]¶ Usage:
%gui tk from campy.gui.events.mouse import * from campy.graphics.gobjects import * from campy.graphics.gwindow import * window = GWindow() @onmousereleased def add_rect(event): event.window.add(GRect(100, 100, x=event.x - 50, y=event.y - 50))