@@ -249,13 +249,11 @@ Let's take a look at how we can define events to link ``Graphics`` and their pro
249
249
Events
250
250
------
251
251
252
- Events can be a multitude of things: traditional events such as mouse or keyboard events, but they can also be
253
- You can use renderer events, such as mouse or keyboard events, or events related to ``Graphic `` properties.
254
-
252
+ Events can be a multitude of things: traditional events such as mouse or keyboard events, or events related to ``Graphic `` properties.
255
253
256
254
There are two ways to add events in ``fastplotlib ``.
257
255
258
- 1) Use the method ::
256
+ 1) Use the method ` add_event_handler() ` ::
259
257
260
258
def event_handler(ev):
261
259
pass
@@ -275,29 +273,16 @@ There are two ways to add events in ``fastplotlib``.
275
273
276
274
277
275
The ``event_handler `` is a user-defined function that accepts an event instance as the first and only positional argument.
278
- Information about the structure of event instances are described below. The `"event_type" `
276
+ Information about the structure of event instances are described below. The `` "event_type" ` `
279
277
is a string that identifies the type of event; this can be either a ``pygfx.Event `` or a ``Graphic `` property event.
280
- See the above graphic-specific properties that can be used for events and below for the available ``pygfx `` events.
281
-
282
- Rendering engine (``pygfx ``) events:
283
- - "key_down"
284
- - "key_up"
285
- - "pointer_down"
286
- - "pointer_move"
287
- - "pointer_up"
288
- - "pointer_enter"
289
- - "pointer_leave"
290
- - "click"
291
- - "double_click"
292
- - "wheel"
293
- - "close"
294
- - "resize"
295
-
296
- When an event occurs, the user-defined event handler will receive and event object. Depending on the type of event, the
278
+
279
+ ``graphic.supported_events `` will return a tuple of all ``event_type `` strings that this graphic supports.
280
+
281
+ When an event occurs, the user-defined event handler will receive an event object. Depending on the type of event, the
297
282
event object will have relevant information that can be used in the callback. See below for event tables.
298
283
299
- Event Attributes
300
- ^^^^^^^^^^^^^^^^
284
+ Graphic property events
285
+ ^^^^^^^^^^^^^^^^^^^^^^^
301
286
302
287
All ``Graphic `` events have the following attributes:
303
288
@@ -427,13 +412,107 @@ event_type: "selection"
427
412
| value | np.ndarray | new [min, max] of selection |
428
413
+----------+------------+-----------------------------+
429
414
430
- Renderer Events
431
- ^^^^^^^^^^^^^^^
415
+ Rendering engine events from a Graphic
416
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
417
+
418
+ Rendering engine event handlers can be added to a graphic or to a Figure (see next section).
419
+ Here is a description of all rendering engine events and their attributes.
420
+
421
+ * **pointer_down **: emitted when the user interacts with mouse,
422
+ touch or other pointer devices, by pressing it down.
423
+
424
+ * *x *: horizontal position of the pointer within the widget.
425
+ * *y *: vertical position of the pointer within the widget.
426
+ * *button *: the button to which this event applies. See "Mouse buttons" section below for details.
427
+ * *buttons *: a tuple of buttons being pressed down.
428
+ * *modifiers *: a tuple of modifier keys being pressed down. See section below for details.
429
+ * *ntouches *: the number of simultaneous pointers being down.
430
+ * *touches *: a dict with int keys (pointer id's), and values that are dicts
431
+ that contain "x", "y", and "pressure".
432
+ * *time_stamp *: a timestamp in seconds.
433
+
434
+ * **pointer_up **: emitted when the user releases a pointer.
435
+ This event has the same keys as the pointer down event.
436
+
437
+ * **pointer_move **: emitted when the user moves a pointer.
438
+ This event has the same keys as the pointer down event.
439
+ This event is throttled.
440
+
441
+ * **double_click **: emitted on a double-click.
442
+ This event looks like a pointer event, but without the touches.
443
+
444
+ * **wheel **: emitted when the mouse-wheel is used (scrolling),
445
+ or when scrolling/pinching on the touchpad/touchscreen.
446
+
447
+ Similar to the JS wheel event, the values of the deltas depend on the
448
+ platform and whether the mouse-wheel, trackpad or a touch-gesture is
449
+ used. Also, scrolling can be linear or have inertia. As a rule of
450
+ thumb, one "wheel action" results in a cumulative ``dy `` of around
451
+ 100. Positive values of ``dy `` are associated with scrolling down and
452
+ zooming out. Positive values of ``dx `` are associated with scrolling
453
+ to the right. (A note for Qt users: the sign of the deltas is (usually)
454
+ reversed compared to the QWheelEvent.)
455
+
456
+ On MacOS, using the mouse-wheel while holding shift results in horizontal
457
+ scrolling. In applications where the scroll dimension does not matter,
458
+ it is therefore recommended to use `delta = event['dy'] or event['dx'] `.
459
+
460
+ * *dx *: the horizontal scroll delta (positive means scroll right).
461
+ * *dy *: the vertical scroll delta (positive means scroll down or zoom out).
462
+ * *x *: the mouse horizontal position during the scroll.
463
+ * *y *: the mouse vertical position during the scroll.
464
+ * *buttons *: a tuple of buttons being pressed down.
465
+ * *modifiers *: a tuple of modifier keys being pressed down.
466
+ * *time_stamp *: a timestamp in seconds.
467
+
468
+ * **key_down **: emitted when a key is pressed down.
469
+
470
+ * *key *: the key being pressed as a string. See section below for details.
471
+ * *modifiers *: a tuple of modifier keys being pressed down.
472
+ * *time_stamp *: a timestamp in seconds.
432
473
433
- You can also add events to a `` Figure `` object's renderer. This is useful for defining click events where
434
- you want to map your click position to the nearest graphic object for example .
474
+ * ** key_up **: emitted when a key is released.
475
+ This event has the same keys as the key down event .
435
476
436
- Renderer events can be added using either method mentioned above (i.e. using the method or via a decorator).
477
+
478
+ Time stamps
479
+ ~~~~~~~~~~~
480
+
481
+ Since the time origin of ``time_stamp `` values is undefined,
482
+ time stamp values only make sense in relation to other time stamps.
483
+
484
+
485
+ Mouse buttons
486
+ ~~~~~~~~~~~~~
487
+
488
+ * 0: No button.
489
+ * 1: Left button.
490
+ * 2: Right button.
491
+ * 3: Middle button
492
+ * 4-9: etc.
493
+
494
+
495
+ Keys
496
+ ~~~~
497
+
498
+ The key names follow the `browser spec <https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent >`_.
499
+
500
+ * Keys that represent a character are simply denoted as such. For these the case matters:
501
+ "a", "A", "z", "Z" "3", "7", "&", " " (space), etc.
502
+ * The modifier keys are:
503
+ "Shift", "Control", "Alt", "Meta".
504
+ * Some example keys that do not represent a character:
505
+ "ArrowDown", "ArrowUp", "ArrowLeft", "ArrowRight", "F1", "Backspace", etc.
506
+
507
+
508
+ Add renderer event handlers to a Figure
509
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
510
+
511
+ You can add event handlers to a ``Figure `` object's renderer. For example, this is useful for defining click events
512
+ where you want to map click positions to the nearest graphic object. See the previous section for a description
513
+ of all the renderer events.
514
+
515
+ Renderer event handlers can be added using a method or a decorator.
437
516
438
517
For example: ::
439
518
@@ -484,7 +563,9 @@ ImageWidget
484
563
485
564
Often times, developing UIs for interacting with multi-dimension image data can be tedious and repetitive.
486
565
In order to aid with common image and video visualization requirements the ``ImageWidget `` automatically generates sliders
487
- to easily navigate through different dimensions of your data. Let's look at an example: ::
566
+ to easily navigate through different dimensions of your data. The image widget supports 2D, 3D and 4D arrays.
567
+
568
+ Let's look at an example: ::
488
569
489
570
import fastplotlib as fpl
490
571
import imageio.v3 as iio
0 commit comments