# Eventos de cada componente

> Todos los eventos de todos los componentes de Pyzed: qué avisa cada uno, qué recibe el handler y cuántos eventos puede tener cada componente.

Source: https://albakore.github.io/pyzed/es/library/events/

Los widgets de Pyzed reaccionan a eventos en dos capas:

- **Sus eventos propios**: los parámetros `on_*` de cada componente, como `on_press` de un botón o
  `on_select` de un árbol. Avisan de lo que significa para el componente (se cerró una pestaña, se abrió
  una fila) y suelen pasar un valor (el texto, el elemento, el estado nuevo).
- **Los eventos comunes**: 18 eventos que tiene cualquier widget, sea cual sea, y que se conectan con
  `.on(...)`: clics, paso del puntero, arrastre, foco, teclas y tamaño. Un `pz.Component` además lanza
  `on_mount` y `on_unmount`.

Así que un componente puede tener sus eventos propios más los 18 comunes. Entre los 114
componentes de la biblioteca hay **160 eventos propios**; los que más tienen aparecen primero en la tabla
del final.

```python
ui.list_item("main.py", self.abrir, icon="file").on(  # on_press es su evento propio
    right_click=self.mostrar_menu,                     # los comunes: cualquier widget
    mouse_enter=lambda: setattr(self, "encima", "main.py"),
    drag=lambda e: self.mover(e.dx, e.dy),             # recibe el pz.Event
)
```

## Los eventos comunes

Los tiene todo widget. Un handler sin argumentos se llama sin nada; uno con un argumento recibe un `pz.Event`.

| Grupo | Evento | Cuándo |
| --- | --- | --- |
| Ratón | `click` | Se hizo clic en el widget (se pulsó y soltó el botón izquierdo). |
| Ratón | `double_click` | Dos clics seguidos. |
| Ratón | `right_click` | Se pulsó el botón derecho (úsalo para menús contextuales). |
| Ratón | `middle_click` | Se pulsó el botón central (la rueda). |
| Ratón | `mouse_down` | Se pulsó cualquier botón sobre el widget (`event.button`). |
| Ratón | `mouse_up` | Se soltó cualquier botón sobre el widget (`event.button`). |
| Ratón | `mouse_enter` | El puntero entró en el widget. |
| Ratón | `mouse_leave` | El puntero salió del widget. |
| Ratón | `mouse_move` | El puntero se movió sobre el widget (`event.x`, `event.y`). |
| Ratón | `scroll` | La rueda giró sobre el widget (`event.dx`, `event.dy` en líneas). |
| Arrastre | `drag_start` | Se pulsó el botón izquierdo y el puntero se movió unos píxeles. |
| Arrastre | `drag` | El puntero se movió mientras se arrastra (`event.dx`, `event.dy` desde el anterior). |
| Arrastre | `drag_end` | Se soltó el botón después de arrastrar. |
| Foco | `focus` | Se hizo clic en el widget y ahora recibe las teclas. |
| Foco | `blur` | Un clic en otro sitio le quitó el foco. |
| Teclado | `key_down` | Se pulsó una tecla con el foco (`event.key`, por ejemplo `"ctrl-s"`). |
| Teclado | `key_up` | Se soltó una tecla con el foco (`event.key`). |
| Tamaño | `resize` | El widget cambió de tamaño, también la primera vez (`event.width`, `event.height`). |

### Campos de `pz.Event`

| Propiedad | Descripción |
| --- | --- |
| `type` | El nombre del evento (`"click"`, o un evento propio de un componente). |
| `x`, `y` | Posición del puntero relativa al widget (`position` da las dos). |
| `window_x`, `window_y` | Posición del puntero en la ventana. |
| `screen_x`, `screen_y` | En la pantalla (`None` donde el sistema no lo dice, como Wayland). |
| `dx`, `dy` | Cantidad de desplazamiento, o movimiento del arrastre desde el `drag` anterior. |
| `width`, `height` | El tamaño del widget (`size` da los dos). |
| `button` | `"left"`, `"right"`, `"middle"`… |
| `key` | La combinación de teclas, como `"ctrl-s"`. |
| `shift`, `ctrl`, `alt`, `logo` | Modificadores pulsados. |
| `value`, `source` | En los eventos propios de un componente: el dato y el componente. |

## Qué reciben los handlers

Los controles que producen un valor llaman a tu función con él. Las formas más habituales:

| Handler | Descripción | Eventos |
| --- | --- | --- |
| `()` | Nada: el evento ya es la noticia (una pulsación, un cierre, Enter). | `ui.alert(on_close=)`, `pz.mouse_area(on_press=)`, `pz.mouse_area(on_release=)`, `pz.mouse_area(on_right_press=)`… |
| `(event)` | Un `pz.Event`: su `value` trae el dato y `source` el componente. | `ui.AuthPrompt(on_pick=)`, `ui.AuthPrompt(on_cancel=)`, `ui.AuthPrompt(on_open_url=)`, `ui.AuthPrompt(on_copy=)`… |
| `(text)` | El texto nuevo, en cada pulsación de tecla. | `ui.shortcuts(on_query=)`, `ui.picker(on_query=)`, `ui.search_input(on_input=)`, `ui.input(on_input=)`… |
| `(x, y)` | La posición del puntero, relativa al widget. | `pz.mouse_area(on_move=)`, `pz.canvas(on_press=)`, `pz.canvas(on_release=)`, `pz.canvas(on_right_press=)`… |
| `(value)` | El valor nuevo: un número, un color, una opción… | `ui.number_field(on_change=)`, `ui.slider(on_change=)`, `ui.toggle_group(on_select=)`, `ui.radio_group(on_select=)`… |
| `(info)` | Un dict (desplazamiento y tamaños) o un `ui.ErrorInfo`. | `pz.scrollable(on_scroll=)`, `ui.editor(on_scroll=)`, `ui.error_boundary(on_error=)`, `ui.error_boundary(on_details=)`… |
| `(id)` | El id de la fila o pestaña (en un árbol, su ruta). | `ui.tree(on_toggle=)`, `ui.tree(on_select=)`, `ui.tree(on_open=)`, `ui.tree(on_context=)` |
| `(tab_id)` | El id de la pestaña. | `ui.tab_bar(on_select=)`, `ui.tab_bar(on_close=)`, `ui.tab_bar(on_drag=)`, `ui.tab_bar(on_context=)` |
| `(row)` | La fila (el dict u objeto que pasaste en `rows`). | `ui.table(on_row_press=)`, `ui.table(on_row_double_press=)`, `ui.table(on_row_context=)` |
| `(dx, dy)` | Cuánto giró la rueda, en líneas. | `pz.mouse_area(on_scroll=)`, `pz.canvas(on_scroll=)` |
| `(checked)` | El estado nuevo, `True` o `False`. | `ui.checkbox(on_toggle=)`, `ui.switch(on_toggle=)` |
| `(line)` | La línea del registro (un `ui.LogEntry`). | `ui.console(on_context=)`, `ui.console(on_open=)` |
| `(name)` | Un nombre: del icono o de la acción del editor. | `ui.editor(on_action=)`, `ui.icon_picker_dialog(on_pick=)` |
| `(url)` | La URL del enlace. | `ui.markdown(on_link=)`, `ui.reference_browser(on_open_url=)` |
| `(size)` | El tamaño nuevo en píxeles, al terminar de arrastrar. | `ui.panel(on_resize=)`, `pz.resizable(on_resize=)` |
| `(item)` | La opción elegida. | `ui.segmented(on_select=)`, `ui.select(on_select=)` |

## Eventos de cada componente

**Propios** cuenta los eventos `on_*` del componente; **Total** suma los 18 comunes (y `mount` / `unmount` en las clases `pz.Component`).

| Componente | Propios | Total | Sus eventos |
| --- | --- | --- | --- |
| [Área de ratón](https://albakore.github.io/pyzed/es/library/mouse-area/#eventos) | 10 | 28 | `on_press`, `on_release`, `on_right_press`, `on_double_click`, `on_enter`, `on_exit`, `on_move`, `on_scroll`, `on_middle_press`, `on_middle_release` |
| [Consola](https://albakore.github.io/pyzed/es/library/console/#eventos) | 8 | 26 | `on_query`, `on_toggle_level`, `on_clear`, `on_copy`, `on_context`, `on_open`, `on_source`, `on_write` |
| [Barra de pestañas](https://albakore.github.io/pyzed/es/library/tab-bar/#eventos) | 7 | 25 | `on_select`, `on_close`, `on_drag`, `on_drop`, `on_drag_over`, `on_context`, `on_new` |
| [Editor](https://albakore.github.io/pyzed/es/library/editor/#eventos) | 6 | 24 | `on_change`, `on_cursor`, `on_scroll`, `on_zoom`, `on_action`, `on_hover` |
| [Barra de cambios](https://albakore.github.io/pyzed/es/library/edits-bar/#eventos) | 5 | 25 | `on_keep`, `on_reject`, `on_keep_file`, `on_reject_file`, `on_open` |
| [Lienzo](https://albakore.github.io/pyzed/es/library/canvas/#eventos) | 5 | 23 | `on_press`, `on_release`, `on_right_press`, `on_move`, `on_scroll` |
| [Marco de ventana](https://albakore.github.io/pyzed/es/library/window-frame/#eventos) | 5 | 23 | `on_drag`, `on_minimize`, `on_maximize`, `on_close`, `on_menu` |
| [Zona para soltar](https://albakore.github.io/pyzed/es/library/drop-zone/#eventos) | 5 | 25 | `on_drop`, `on_files`, `on_reject`, `on_enter`, `on_leave` |
| [Árbol](https://albakore.github.io/pyzed/es/library/tree/#eventos) | 4 | 22 | `on_toggle`, `on_select`, `on_open`, `on_context` |
| [Aviso de inicio de sesión](https://albakore.github.io/pyzed/es/library/auth-prompt/#eventos) | 4 | 24 | `on_pick`, `on_cancel`, `on_open_url`, `on_copy` |
| [Selector de fecha](https://albakore.github.io/pyzed/es/library/date-picker/#eventos) | 4 | 24 | `on_change`, `on_open`, `on_close`, `on_dismiss` |
| [Tabla](https://albakore.github.io/pyzed/es/library/table/#eventos) | 4 | 22 | `on_sort`, `on_row_press`, `on_row_double_press`, `on_row_context` |
| [Cambios sin guardar](https://albakore.github.io/pyzed/es/library/unsaved-changes/#eventos) | 3 | 21 | `on_save`, `on_discard`, `on_cancel` |
| [Campo de texto](https://albakore.github.io/pyzed/es/library/input/#eventos) | 3 | 21 | `on_input`, `on_submit`, `on_clear` |
| [Diálogo de error](https://albakore.github.io/pyzed/es/library/error-dialog/#eventos) | 3 | 21 | `on_close`, `on_go_to`, `on_logs` |
| [Fila de lista](https://albakore.github.io/pyzed/es/library/list-item/#eventos) | 3 | 21 | `on_press`, `on_right_press`, `on_double_press` |
| [Llamada a herramienta](https://albakore.github.io/pyzed/es/library/tool-call/#eventos) | 3 | 23 | `on_allow`, `on_allow_always`, `on_deny` |
| [Paleta de comandos](https://albakore.github.io/pyzed/es/library/command-palette/#eventos) | 3 | 21 | `on_query`, `on_submit`, `on_press` |
| [Pregunta](https://albakore.github.io/pyzed/es/library/prompt/#eventos) | 3 | 21 | `on_input`, `on_submit`, `on_cancel` |
| [Select](https://albakore.github.io/pyzed/es/library/select/#eventos) | 3 | 21 | `on_select`, `on_open`, `on_close` |
| [Selector de hora](https://albakore.github.io/pyzed/es/library/time-picker/#eventos) | 3 | 23 | `on_change`, `on_open`, `on_close` |
| [Selector de iconos](https://albakore.github.io/pyzed/es/library/icon-picker/#eventos) | 3 | 23 | `on_change`, `on_pick`, `on_close` |
| [Selector de rango de fechas](https://albakore.github.io/pyzed/es/library/date-range-picker/#eventos) | 3 | 23 | `on_change`, `on_open`, `on_close` |
| [Botón dividido](https://albakore.github.io/pyzed/es/library/split-button/#eventos) | 2 | 20 | `on_press`, `on_menu` |
| [Buscador](https://albakore.github.io/pyzed/es/library/picker/#eventos) | 2 | 20 | `on_query`, `on_submit` |
| [Calendario](https://albakore.github.io/pyzed/es/library/calendar/#eventos) | 2 | 22 | `on_change`, `on_month` |
| [Campo numérico](https://albakore.github.io/pyzed/es/library/number-field/#eventos) | 2 | 20 | `on_change`, `on_submit` |
| [Chip](https://albakore.github.io/pyzed/es/library/chip/#eventos) | 2 | 20 | `on_press`, `on_remove` |
| [Confirmación](https://albakore.github.io/pyzed/es/library/confirm/#eventos) | 2 | 20 | `on_confirm`, `on_cancel` |
| [Deslizador](https://albakore.github.io/pyzed/es/library/slider/#eventos) | 2 | 20 | `on_change`, `on_release` |
| [Fila de servicio](https://albakore.github.io/pyzed/es/library/service-row/#eventos) | 2 | 22 | `on_toggle`, `on_primary` |
| [Historial de hilos](https://albakore.github.io/pyzed/es/library/thread-history/#eventos) | 2 | 22 | `on_open`, `on_delete` |
| [Límite de errores](https://albakore.github.io/pyzed/es/library/error-boundary/#eventos) | 2 | 20 | `on_error`, `on_details` |
| [Migas de pan](https://albakore.github.io/pyzed/es/library/breadcrumbs/#eventos) | 2 | 20 | `on_press`, `on_more` |
| [Notificación](https://albakore.github.io/pyzed/es/library/toast/#eventos) | 2 | 20 | `on_dismiss`, `on_press` |
| [Selector de color](https://albakore.github.io/pyzed/es/library/color-picker/#eventos) | 2 | 22 | `on_change`, `on_press` |
| [Acordeón](https://albakore.github.io/pyzed/es/library/accordion/#eventos) | 1 | 19 | `on_toggle` |
| [Alerta](https://albakore.github.io/pyzed/es/library/alert/#eventos) | 1 | 19 | `on_close` |
| [Atajos](https://albakore.github.io/pyzed/es/library/shortcuts/#eventos) | 1 | 19 | `on_query` |
| [Aviso](https://albakore.github.io/pyzed/es/library/callout/#eventos) | 1 | 19 | `on_dismiss` |
| [Barra de estado](https://albakore.github.io/pyzed/es/library/status-bar/#eventos) | 1 | 19 | `on_press` |
| [Barra de título](https://albakore.github.io/pyzed/es/library/title-bar/#eventos) | 1 | 19 | `on_press` |
| [Botón](https://albakore.github.io/pyzed/es/library/button/#eventos) | 1 | 19 | `on_press` |
| [Botón de icono](https://albakore.github.io/pyzed/es/library/icon-button/#eventos) | 1 | 19 | `on_press` |
| [Campo de búsqueda](https://albakore.github.io/pyzed/es/library/search-input/#eventos) | 1 | 19 | `on_input` |
| [Capa](https://albakore.github.io/pyzed/es/library/layer/#eventos) | 1 | 19 | `on_dismiss` |
| [Capa de diálogo](https://albakore.github.io/pyzed/es/library/dialog-layer/#eventos) | 1 | 19 | `on_dismiss` |
| [Casilla](https://albakore.github.io/pyzed/es/library/checkbox/#eventos) | 1 | 19 | `on_toggle` |
| [Catálogo](https://albakore.github.io/pyzed/es/library/catalog/#eventos) | 1 | 21 | `on_install` |
| [Cifra](https://albakore.github.io/pyzed/es/library/stat/#eventos) | 1 | 19 | `on_press` |
| [Desplazable](https://albakore.github.io/pyzed/es/library/scrollable/#eventos) | 1 | 19 | `on_scroll` |
| [Desplegable](https://albakore.github.io/pyzed/es/library/disclosure/#eventos) | 1 | 19 | `on_toggle` |
| [División](https://albakore.github.io/pyzed/es/library/split/#eventos) | 1 | 19 | `on_resize` |
| [Elección](https://albakore.github.io/pyzed/es/library/choice/#eventos) | 1 | 19 | `on_cancel` |
| [Espacio de trabajo](https://albakore.github.io/pyzed/es/library/workspace/#eventos) | 1 | 19 | `on_resize` |
| [Grupo de alternancia](https://albakore.github.io/pyzed/es/library/toggle-group/#eventos) | 1 | 19 | `on_select` |
| [Grupo de radios](https://albakore.github.io/pyzed/es/library/radio-group/#eventos) | 1 | 19 | `on_select` |
| [Insignia](https://albakore.github.io/pyzed/es/library/badge/#eventos) | 1 | 19 | `on_press` |
| [Interruptor](https://albakore.github.io/pyzed/es/library/switch/#eventos) | 1 | 19 | `on_toggle` |
| [Lista virtual](https://albakore.github.io/pyzed/es/library/virtual-list/#eventos) | 1 | 19 | `on_scroll` |
| [Markdown](https://albakore.github.io/pyzed/es/library/markdown/#eventos) | 1 | 19 | `on_link` |
| [Menú](https://albakore.github.io/pyzed/es/library/menu/#eventos) | 1 | 19 | `on_press` |
| [Modal](https://albakore.github.io/pyzed/es/library/modal/#eventos) | 1 | 19 | `on_close` |
| [Panel](https://albakore.github.io/pyzed/es/library/panel/#eventos) | 1 | 19 | `on_resize` |
| [Popover](https://albakore.github.io/pyzed/es/library/popover/#eventos) | 1 | 19 | `on_dismiss` |
| [Redimensionable](https://albakore.github.io/pyzed/es/library/resizable/#eventos) | 1 | 19 | `on_resize` |
| [Segmentado](https://albakore.github.io/pyzed/es/library/segmented/#eventos) | 1 | 19 | `on_select` |
| [Selector de archivos](https://albakore.github.io/pyzed/es/library/file-input/#eventos) | 1 | 19 | `on_change` |
| [Tarjeta](https://albakore.github.io/pyzed/es/library/card/#eventos) | 1 | 19 | `on_press` |
| [Visor de referencia](https://albakore.github.io/pyzed/es/library/reference-browser/#eventos) | 1 | 19 | `on_open_url` |
| [Acerca de](https://albakore.github.io/pyzed/es/library/about/#eventos) | 0 | 18 | — |
| [Animación](https://albakore.github.io/pyzed/es/library/animation/#eventos) | 0 | 18 | — |
| [Avatar](https://albakore.github.io/pyzed/es/library/avatar/#eventos) | 0 | 18 | — |
| [Barra de herramientas](https://albakore.github.io/pyzed/es/library/toolbar/#eventos) | 0 | 18 | — |
| [Cabecera de lista](https://albakore.github.io/pyzed/es/library/list-header/#eventos) | 0 | 18 | — |
| [Cabecera de panel](https://albakore.github.io/pyzed/es/library/panel-header/#eventos) | 0 | 18 | — |
| [Campo de formulario](https://albakore.github.io/pyzed/es/library/field/#eventos) | 0 | 18 | — |
| [Código QR](https://albakore.github.io/pyzed/es/library/qr-code/#eventos) | 0 | 18 | — |
| [Columna](https://albakore.github.io/pyzed/es/library/column/#eventos) | 0 | 18 | — |
| [Contador](https://albakore.github.io/pyzed/es/library/count-badge/#eventos) | 0 | 18 | — |
| [Contenedor](https://albakore.github.io/pyzed/es/library/container/#eventos) | 0 | 18 | — |
| [Cuadrícula](https://albakore.github.io/pyzed/es/library/grid/#eventos) | 0 | 18 | — |
| [Disposición anclada](https://albakore.github.io/pyzed/es/library/anchor-layout/#eventos) | 0 | 18 | — |
| [Divisor](https://albakore.github.io/pyzed/es/library/divider/#eventos) | 0 | 18 | — |
| [Dona](https://albakore.github.io/pyzed/es/library/donut/#eventos) | 0 | 18 | — |
| [Efectos](https://albakore.github.io/pyzed/es/library/effects/#eventos) | 0 | 18 | — |
| [Encabezado](https://albakore.github.io/pyzed/es/library/heading/#eventos) | 0 | 18 | — |
| [Espacio](https://albakore.github.io/pyzed/es/library/spacing/#eventos) | 0 | 18 | — |
| [Estado vacío](https://albakore.github.io/pyzed/es/library/empty-state/#eventos) | 0 | 18 | — |
| [Etiqueta](https://albakore.github.io/pyzed/es/library/label/#eventos) | 0 | 18 | — |
| [Facepile](https://albakore.github.io/pyzed/es/library/facepile/#eventos) | 0 | 18 | — |
| [Fila](https://albakore.github.io/pyzed/es/library/row/#eventos) | 0 | 18 | — |
| [Flex](https://albakore.github.io/pyzed/es/library/flex/#eventos) | 0 | 18 | — |
| [Gráfico de barras](https://albakore.github.io/pyzed/es/library/bar-chart/#eventos) | 0 | 18 | — |
| [Grupo de ajustes](https://albakore.github.io/pyzed/es/library/settings-group/#eventos) | 0 | 18 | — |
| [Icono](https://albakore.github.io/pyzed/es/library/icon/#eventos) | 0 | 18 | — |
| [Imagen](https://albakore.github.io/pyzed/es/library/image/#eventos) | 0 | 18 | — |
| [Indicador](https://albakore.github.io/pyzed/es/library/indicator/#eventos) | 0 | 18 | — |
| [Kbd](https://albakore.github.io/pyzed/es/library/kbd/#eventos) | 0 | 18 | — |
| [Medidor de contexto](https://albakore.github.io/pyzed/es/library/context-meter/#eventos) | 0 | 18 | — |
| [Minigráfico](https://albakore.github.io/pyzed/es/library/sparkline/#eventos) | 0 | 18 | — |
| [Pila](https://albakore.github.io/pyzed/es/library/stack/#eventos) | 0 | 18 | — |
| [Pista de atajo](https://albakore.github.io/pyzed/es/library/keybinding-hint/#eventos) | 0 | 18 | — |
| [Plan](https://albakore.github.io/pyzed/es/library/plan/#eventos) | 0 | 20 | — |
| [Progreso](https://albakore.github.io/pyzed/es/library/progress/#eventos) | 0 | 18 | — |
| [Responsivo](https://albakore.github.io/pyzed/es/library/responsive/#eventos) | 0 | 18 | — |
| [Resumen de cambios](https://albakore.github.io/pyzed/es/library/diff-stat/#eventos) | 0 | 18 | — |
| [Shader](https://albakore.github.io/pyzed/es/library/shader/#eventos) | 0 | 18 | — |
| [Spinner](https://albakore.github.io/pyzed/es/library/spinner/#eventos) | 0 | 18 | — |
| [Terminal](https://albakore.github.io/pyzed/es/library/terminal/#eventos) | 0 | 18 | — |
| [Texto](https://albakore.github.io/pyzed/es/library/text/#eventos) | 0 | 18 | — |
| [Texto enriquecido](https://albakore.github.io/pyzed/es/library/rich-text/#eventos) | 0 | 18 | — |
| [Tooltip](https://albakore.github.io/pyzed/es/library/tooltip/#eventos) | 0 | 18 | — |
| [Vista de diferencias](https://albakore.github.io/pyzed/es/library/diff-view/#eventos) | 0 | 18 | — |

Sigue con [Apps, ventanas, formularios y componentes](https://albakore.github.io/pyzed/es/guides/classes/), que explica cómo crear tus propios eventos, e [Imperativo, declarativo y funcional](https://albakore.github.io/pyzed/es/guides/code-styles/), con las tres formas de manejarlos.
