widgets.pyi 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. from .artist import Artist
  2. from .axes import Axes
  3. from .backend_bases import FigureCanvasBase, Event, MouseEvent, MouseButton
  4. from .collections import LineCollection
  5. from .figure import Figure
  6. from .lines import Line2D
  7. from .patches import Polygon, Rectangle
  8. from .text import Text
  9. import PIL.Image
  10. from collections.abc import Callable, Collection, Iterable, Sequence
  11. from typing import Any, Literal
  12. from numpy.typing import ArrayLike
  13. from .typing import ColorType
  14. import numpy as np
  15. class LockDraw:
  16. def __init__(self) -> None: ...
  17. def __call__(self, o: Any) -> None: ...
  18. def release(self, o: Any) -> None: ...
  19. def available(self, o: Any) -> bool: ...
  20. def isowner(self, o: Any) -> bool: ...
  21. def locked(self) -> bool: ...
  22. class Widget:
  23. drawon: bool
  24. eventson: bool
  25. active: bool
  26. def set_active(self, active: bool) -> None: ...
  27. def get_active(self) -> None: ...
  28. def ignore(self, event) -> bool: ...
  29. class AxesWidget(Widget):
  30. ax: Axes
  31. def __init__(self, ax: Axes) -> None: ...
  32. @property
  33. def canvas(self) -> FigureCanvasBase | None: ...
  34. def connect_event(self, event: Event, callback: Callable) -> None: ...
  35. def disconnect_events(self) -> None: ...
  36. class Button(AxesWidget):
  37. label: Text
  38. color: ColorType
  39. hovercolor: ColorType
  40. def __init__(
  41. self,
  42. ax: Axes,
  43. label: str,
  44. image: ArrayLike | PIL.Image.Image | None = ...,
  45. color: ColorType = ...,
  46. hovercolor: ColorType = ...,
  47. *,
  48. useblit: bool = ...
  49. ) -> None: ...
  50. def on_clicked(self, func: Callable[[Event], Any]) -> int: ...
  51. def disconnect(self, cid: int) -> None: ...
  52. class SliderBase(AxesWidget):
  53. orientation: Literal["horizontal", "vertical"]
  54. closedmin: bool
  55. closedmax: bool
  56. valmin: float
  57. valmax: float
  58. valstep: float | ArrayLike | None
  59. drag_active: bool
  60. valfmt: str
  61. def __init__(
  62. self,
  63. ax: Axes,
  64. orientation: Literal["horizontal", "vertical"],
  65. closedmin: bool,
  66. closedmax: bool,
  67. valmin: float,
  68. valmax: float,
  69. valfmt: str,
  70. dragging: Slider | None,
  71. valstep: float | ArrayLike | None,
  72. ) -> None: ...
  73. def disconnect(self, cid: int) -> None: ...
  74. def reset(self) -> None: ...
  75. class Slider(SliderBase):
  76. slidermin: Slider | None
  77. slidermax: Slider | None
  78. val: float
  79. valinit: float
  80. track: Rectangle
  81. poly: Polygon
  82. hline: Line2D
  83. vline: Line2D
  84. label: Text
  85. valtext: Text
  86. def __init__(
  87. self,
  88. ax: Axes,
  89. label: str,
  90. valmin: float,
  91. valmax: float,
  92. *,
  93. valinit: float = ...,
  94. valfmt: str | None = ...,
  95. closedmin: bool = ...,
  96. closedmax: bool = ...,
  97. slidermin: Slider | None = ...,
  98. slidermax: Slider | None = ...,
  99. dragging: bool = ...,
  100. valstep: float | ArrayLike | None = ...,
  101. orientation: Literal["horizontal", "vertical"] = ...,
  102. initcolor: ColorType = ...,
  103. track_color: ColorType = ...,
  104. handle_style: dict[str, Any] | None = ...,
  105. **kwargs
  106. ) -> None: ...
  107. def set_val(self, val: float) -> None: ...
  108. def on_changed(self, func: Callable[[float], Any]) -> int: ...
  109. class RangeSlider(SliderBase):
  110. val: tuple[float, float]
  111. valinit: tuple[float, float]
  112. track: Rectangle
  113. poly: Polygon
  114. label: Text
  115. valtext: Text
  116. def __init__(
  117. self,
  118. ax: Axes,
  119. label: str,
  120. valmin: float,
  121. valmax: float,
  122. *,
  123. valinit: tuple[float, float] | None = ...,
  124. valfmt: str | None = ...,
  125. closedmin: bool = ...,
  126. closedmax: bool = ...,
  127. dragging: bool = ...,
  128. valstep: float | ArrayLike | None = ...,
  129. orientation: Literal["horizontal", "vertical"] = ...,
  130. track_color: ColorType = ...,
  131. handle_style: dict[str, Any] | None = ...,
  132. **kwargs
  133. ) -> None: ...
  134. def set_min(self, min: float) -> None: ...
  135. def set_max(self, max: float) -> None: ...
  136. def set_val(self, val: ArrayLike) -> None: ...
  137. def on_changed(self, func: Callable[[tuple[float, float]], Any]) -> int: ...
  138. class CheckButtons(AxesWidget):
  139. labels: list[Text]
  140. def __init__(
  141. self,
  142. ax: Axes,
  143. labels: Sequence[str],
  144. actives: Iterable[bool] | None = ...,
  145. *,
  146. useblit: bool = ...,
  147. label_props: dict[str, Sequence[Any]] | None = ...,
  148. frame_props: dict[str, Any] | None = ...,
  149. check_props: dict[str, Any] | None = ...,
  150. ) -> None: ...
  151. def set_label_props(self, props: dict[str, Sequence[Any]]) -> None: ...
  152. def set_frame_props(self, props: dict[str, Any]) -> None: ...
  153. def set_check_props(self, props: dict[str, Any]) -> None: ...
  154. def set_active(self, index: int, state: bool | None = ...) -> None: ... # type: ignore[override]
  155. def clear(self) -> None: ...
  156. def get_status(self) -> list[bool]: ...
  157. def get_checked_labels(self) -> list[str]: ...
  158. def on_clicked(self, func: Callable[[str | None], Any]) -> int: ...
  159. def disconnect(self, cid: int) -> None: ...
  160. class TextBox(AxesWidget):
  161. label: Text
  162. text_disp: Text
  163. cursor_index: int
  164. cursor: LineCollection
  165. color: ColorType
  166. hovercolor: ColorType
  167. capturekeystrokes: bool
  168. def __init__(
  169. self,
  170. ax: Axes,
  171. label: str,
  172. initial: str = ...,
  173. *,
  174. color: ColorType = ...,
  175. hovercolor: ColorType = ...,
  176. label_pad: float = ...,
  177. textalignment: Literal["left", "center", "right"] = ...,
  178. ) -> None: ...
  179. @property
  180. def text(self) -> str: ...
  181. def set_val(self, val: str) -> None: ...
  182. def begin_typing(self) -> None: ...
  183. def stop_typing(self) -> None: ...
  184. def on_text_change(self, func: Callable[[str], Any]) -> int: ...
  185. def on_submit(self, func: Callable[[str], Any]) -> int: ...
  186. def disconnect(self, cid: int) -> None: ...
  187. class RadioButtons(AxesWidget):
  188. activecolor: ColorType
  189. value_selected: str
  190. labels: list[Text]
  191. def __init__(
  192. self,
  193. ax: Axes,
  194. labels: Iterable[str],
  195. active: int = ...,
  196. activecolor: ColorType | None = ...,
  197. *,
  198. useblit: bool = ...,
  199. label_props: dict[str, Sequence[Any]] | None = ...,
  200. radio_props: dict[str, Any] | None = ...,
  201. ) -> None: ...
  202. def set_label_props(self, props: dict[str, Sequence[Any]]) -> None: ...
  203. def set_radio_props(self, props: dict[str, Any]) -> None: ...
  204. def set_active(self, index: int) -> None: ...
  205. def clear(self) -> None: ...
  206. def on_clicked(self, func: Callable[[str | None], Any]) -> int: ...
  207. def disconnect(self, cid: int) -> None: ...
  208. class SubplotTool(Widget):
  209. figure: Figure
  210. targetfig: Figure
  211. buttonreset: Button
  212. def __init__(self, targetfig: Figure, toolfig: Figure) -> None: ...
  213. class Cursor(AxesWidget):
  214. visible: bool
  215. horizOn: bool
  216. vertOn: bool
  217. useblit: bool
  218. lineh: Line2D
  219. linev: Line2D
  220. background: Any
  221. needclear: bool
  222. def __init__(
  223. self,
  224. ax: Axes,
  225. *,
  226. horizOn: bool = ...,
  227. vertOn: bool = ...,
  228. useblit: bool = ...,
  229. **lineprops
  230. ) -> None: ...
  231. def clear(self, event: Event) -> None: ...
  232. def onmove(self, event: Event) -> None: ...
  233. class MultiCursor(Widget):
  234. axes: Sequence[Axes]
  235. horizOn: bool
  236. vertOn: bool
  237. visible: bool
  238. useblit: bool
  239. vlines: list[Line2D]
  240. hlines: list[Line2D]
  241. def __init__(
  242. self,
  243. canvas: Any,
  244. axes: Sequence[Axes],
  245. *,
  246. useblit: bool = ...,
  247. horizOn: bool = ...,
  248. vertOn: bool = ...,
  249. **lineprops
  250. ) -> None: ...
  251. def connect(self) -> None: ...
  252. def disconnect(self) -> None: ...
  253. def clear(self, event: Event) -> None: ...
  254. def onmove(self, event: Event) -> None: ...
  255. class _SelectorWidget(AxesWidget):
  256. onselect: Callable[[float, float], Any]
  257. useblit: bool
  258. background: Any
  259. validButtons: list[MouseButton]
  260. def __init__(
  261. self,
  262. ax: Axes,
  263. onselect: Callable[[float, float], Any] | None = ...,
  264. useblit: bool = ...,
  265. button: MouseButton | Collection[MouseButton] | None = ...,
  266. state_modifier_keys: dict[str, str] | None = ...,
  267. use_data_coordinates: bool = ...,
  268. ) -> None: ...
  269. def update_background(self, event: Event) -> None: ...
  270. def connect_default_events(self) -> None: ...
  271. def ignore(self, event: Event) -> bool: ...
  272. def update(self) -> None: ...
  273. def press(self, event: Event) -> bool: ...
  274. def release(self, event: Event) -> bool: ...
  275. def onmove(self, event: Event) -> bool: ...
  276. def on_scroll(self, event: Event) -> None: ...
  277. def on_key_press(self, event: Event) -> None: ...
  278. def on_key_release(self, event: Event) -> None: ...
  279. def set_visible(self, visible: bool) -> None: ...
  280. def get_visible(self) -> bool: ...
  281. def clear(self) -> None: ...
  282. @property
  283. def artists(self) -> tuple[Artist]: ...
  284. def set_props(self, **props) -> None: ...
  285. def set_handle_props(self, **handle_props) -> None: ...
  286. def add_state(self, state: str) -> None: ...
  287. def remove_state(self, state: str) -> None: ...
  288. class SpanSelector(_SelectorWidget):
  289. snap_values: ArrayLike | None
  290. onmove_callback: Callable[[float, float], Any]
  291. minspan: float
  292. grab_range: float
  293. drag_from_anywhere: bool
  294. ignore_event_outside: bool
  295. def __init__(
  296. self,
  297. ax: Axes,
  298. onselect: Callable[[float, float], Any],
  299. direction: Literal["horizontal", "vertical"],
  300. *,
  301. minspan: float = ...,
  302. useblit: bool = ...,
  303. props: dict[str, Any] | None = ...,
  304. onmove_callback: Callable[[float, float], Any] | None = ...,
  305. interactive: bool = ...,
  306. button: MouseButton | Collection[MouseButton] | None = ...,
  307. handle_props: dict[str, Any] | None = ...,
  308. grab_range: float = ...,
  309. state_modifier_keys: dict[str, str] | None = ...,
  310. drag_from_anywhere: bool = ...,
  311. ignore_event_outside: bool = ...,
  312. snap_values: ArrayLike | None = ...,
  313. ) -> None: ...
  314. def new_axes(
  315. self,
  316. ax: Axes,
  317. *,
  318. _props: dict[str, Any] | None = ...,
  319. _init: bool = ...,
  320. ) -> None: ...
  321. def connect_default_events(self) -> None: ...
  322. @property
  323. def direction(self) -> Literal["horizontal", "vertical"]: ...
  324. @direction.setter
  325. def direction(self, direction: Literal["horizontal", "vertical"]) -> None: ...
  326. @property
  327. def extents(self) -> tuple[float, float]: ...
  328. @extents.setter
  329. def extents(self, extents: tuple[float, float]) -> None: ...
  330. class ToolLineHandles:
  331. ax: Axes
  332. def __init__(
  333. self,
  334. ax: Axes,
  335. positions: ArrayLike,
  336. direction: Literal["horizontal", "vertical"],
  337. *,
  338. line_props: dict[str, Any] | None = ...,
  339. useblit: bool = ...,
  340. ) -> None: ...
  341. @property
  342. def artists(self) -> tuple[Line2D]: ...
  343. @property
  344. def positions(self) -> list[float]: ...
  345. @property
  346. def direction(self) -> Literal["horizontal", "vertical"]: ...
  347. def set_data(self, positions: ArrayLike) -> None: ...
  348. def set_visible(self, value: bool) -> None: ...
  349. def set_animated(self, value: bool) -> None: ...
  350. def remove(self) -> None: ...
  351. def closest(self, x: float, y: float) -> tuple[int, float]: ...
  352. class ToolHandles:
  353. ax: Axes
  354. def __init__(
  355. self,
  356. ax: Axes,
  357. x: ArrayLike,
  358. y: ArrayLike,
  359. *,
  360. marker: str = ...,
  361. marker_props: dict[str, Any] | None = ...,
  362. useblit: bool = ...,
  363. ) -> None: ...
  364. @property
  365. def x(self) -> ArrayLike: ...
  366. @property
  367. def y(self) -> ArrayLike: ...
  368. @property
  369. def artists(self) -> tuple[Line2D]: ...
  370. def set_data(self, pts: ArrayLike, y: ArrayLike | None = ...) -> None: ...
  371. def set_visible(self, val: bool) -> None: ...
  372. def set_animated(self, val: bool) -> None: ...
  373. def closest(self, x: float, y: float) -> tuple[int, float]: ...
  374. class RectangleSelector(_SelectorWidget):
  375. drag_from_anywhere: bool
  376. ignore_event_outside: bool
  377. minspanx: float
  378. minspany: float
  379. spancoords: Literal["data", "pixels"]
  380. grab_range: float
  381. def __init__(
  382. self,
  383. ax: Axes,
  384. onselect: Callable[[MouseEvent, MouseEvent], Any] | None = ...,
  385. *,
  386. minspanx: float = ...,
  387. minspany: float = ...,
  388. useblit: bool = ...,
  389. props: dict[str, Any] | None = ...,
  390. spancoords: Literal["data", "pixels"] = ...,
  391. button: MouseButton | Collection[MouseButton] | None = ...,
  392. grab_range: float = ...,
  393. handle_props: dict[str, Any] | None = ...,
  394. interactive: bool = ...,
  395. state_modifier_keys: dict[str, str] | None = ...,
  396. drag_from_anywhere: bool = ...,
  397. ignore_event_outside: bool = ...,
  398. use_data_coordinates: bool = ...,
  399. ) -> None: ...
  400. @property
  401. def corners(self) -> tuple[np.ndarray, np.ndarray]: ...
  402. @property
  403. def edge_centers(self) -> tuple[np.ndarray, np.ndarray]: ...
  404. @property
  405. def center(self) -> tuple[float, float]: ...
  406. @property
  407. def extents(self) -> tuple[float, float, float, float]: ...
  408. @extents.setter
  409. def extents(self, extents: tuple[float, float, float, float]) -> None: ...
  410. @property
  411. def rotation(self) -> float: ...
  412. @rotation.setter
  413. def rotation(self, value: float) -> None: ...
  414. @property
  415. def geometry(self) -> np.ndarray: ...
  416. class EllipseSelector(RectangleSelector): ...
  417. class LassoSelector(_SelectorWidget):
  418. verts: None | list[tuple[float, float]]
  419. def __init__(
  420. self,
  421. ax: Axes,
  422. onselect: Callable[[list[tuple[float, float]]], Any] | None = ...,
  423. *,
  424. useblit: bool = ...,
  425. props: dict[str, Any] | None = ...,
  426. button: MouseButton | Collection[MouseButton] | None = ...,
  427. ) -> None: ...
  428. class PolygonSelector(_SelectorWidget):
  429. grab_range: float
  430. def __init__(
  431. self,
  432. ax: Axes,
  433. onselect: Callable[[ArrayLike, ArrayLike], Any] | None = ...,
  434. *,
  435. useblit: bool = ...,
  436. props: dict[str, Any] | None = ...,
  437. handle_props: dict[str, Any] | None = ...,
  438. grab_range: float = ...,
  439. draw_bounding_box: bool = ...,
  440. box_handle_props: dict[str, Any] | None = ...,
  441. box_props: dict[str, Any] | None = ...
  442. ) -> None: ...
  443. def onmove(self, event: Event) -> bool: ...
  444. @property
  445. def verts(self) -> list[tuple[float, float]]: ...
  446. @verts.setter
  447. def verts(self, xys: Sequence[tuple[float, float]]) -> None: ...
  448. class Lasso(AxesWidget):
  449. useblit: bool
  450. background: Any
  451. verts: list[tuple[float, float]] | None
  452. line: Line2D
  453. callback: Callable[[list[tuple[float, float]]], Any]
  454. def __init__(
  455. self,
  456. ax: Axes,
  457. xy: tuple[float, float],
  458. callback: Callable[[list[tuple[float, float]]], Any],
  459. *,
  460. useblit: bool = ...,
  461. props: dict[str, Any] | None = ...,
  462. ) -> None: ...
  463. def onrelease(self, event: Event) -> None: ...
  464. def onmove(self, event: Event) -> None: ...