widgets.pyi 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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 Circle, 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. canvas: FigureCanvasBase | None
  32. def __init__(self, ax: Axes) -> None: ...
  33. def connect_event(self, event: Event, callback: Callable) -> None: ...
  34. def disconnect_events(self) -> None: ...
  35. class Button(AxesWidget):
  36. label: Text
  37. color: ColorType
  38. hovercolor: ColorType
  39. def __init__(
  40. self,
  41. ax: Axes,
  42. label: str,
  43. image: ArrayLike | PIL.Image.Image | None = ...,
  44. color: ColorType = ...,
  45. hovercolor: ColorType = ...,
  46. *,
  47. useblit: bool = ...
  48. ) -> None: ...
  49. def on_clicked(self, func: Callable[[Event], Any]) -> int: ...
  50. def disconnect(self, cid: int) -> None: ...
  51. class SliderBase(AxesWidget):
  52. orientation: Literal["horizontal", "vertical"]
  53. closedmin: bool
  54. closedmax: bool
  55. valmin: float
  56. valmax: float
  57. valstep: float | ArrayLike | None
  58. drag_active: bool
  59. valfmt: str
  60. def __init__(
  61. self,
  62. ax: Axes,
  63. orientation: Literal["horizontal", "vertical"],
  64. closedmin: bool,
  65. closedmax: bool,
  66. valmin: float,
  67. valmax: float,
  68. valfmt: str,
  69. dragging: Slider | None,
  70. valstep: float | ArrayLike | None,
  71. ) -> None: ...
  72. def disconnect(self, cid: int) -> None: ...
  73. def reset(self) -> None: ...
  74. class Slider(SliderBase):
  75. slidermin: Slider | None
  76. slidermax: Slider | None
  77. val: float
  78. valinit: float
  79. track: Rectangle
  80. poly: Polygon
  81. hline: Line2D
  82. vline: Line2D
  83. label: Text
  84. valtext: Text
  85. def __init__(
  86. self,
  87. ax: Axes,
  88. label: str,
  89. valmin: float,
  90. valmax: float,
  91. *,
  92. valinit: float = ...,
  93. valfmt: str | None = ...,
  94. closedmin: bool = ...,
  95. closedmax: bool = ...,
  96. slidermin: Slider | None = ...,
  97. slidermax: Slider | None = ...,
  98. dragging: bool = ...,
  99. valstep: float | ArrayLike | None = ...,
  100. orientation: Literal["horizontal", "vertical"] = ...,
  101. initcolor: ColorType = ...,
  102. track_color: ColorType = ...,
  103. handle_style: dict[str, Any] | None = ...,
  104. **kwargs
  105. ) -> None: ...
  106. def set_val(self, val: float) -> None: ...
  107. def on_changed(self, func: Callable[[float], Any]) -> int: ...
  108. class RangeSlider(SliderBase):
  109. val: tuple[float, float]
  110. valinit: tuple[float, float]
  111. track: Rectangle
  112. poly: Polygon
  113. label: Text
  114. valtext: Text
  115. def __init__(
  116. self,
  117. ax: Axes,
  118. label: str,
  119. valmin: float,
  120. valmax: float,
  121. *,
  122. valinit: tuple[float, float] | None = ...,
  123. valfmt: str | None = ...,
  124. closedmin: bool = ...,
  125. closedmax: bool = ...,
  126. dragging: bool = ...,
  127. valstep: float | ArrayLike | None = ...,
  128. orientation: Literal["horizontal", "vertical"] = ...,
  129. track_color: ColorType = ...,
  130. handle_style: dict[str, Any] | None = ...,
  131. **kwargs
  132. ) -> None: ...
  133. def set_min(self, min: float) -> None: ...
  134. def set_max(self, max: float) -> None: ...
  135. def set_val(self, val: ArrayLike) -> None: ...
  136. def on_changed(self, func: Callable[[tuple[float, float]], Any]) -> int: ...
  137. class CheckButtons(AxesWidget):
  138. labels: list[Text]
  139. def __init__(
  140. self,
  141. ax: Axes,
  142. labels: Sequence[str],
  143. actives: Iterable[bool] | None = ...,
  144. *,
  145. useblit: bool = ...,
  146. label_props: dict[str, Any] | None = ...,
  147. frame_props: dict[str, Any] | None = ...,
  148. check_props: dict[str, Any] | None = ...,
  149. ) -> None: ...
  150. def set_label_props(self, props: dict[str, Any]) -> None: ...
  151. def set_frame_props(self, props: dict[str, Any]) -> None: ...
  152. def set_check_props(self, props: dict[str, Any]) -> None: ...
  153. def set_active(self, index: int) -> None: ...
  154. def get_status(self) -> list[bool]: ...
  155. def on_clicked(self, func: Callable[[str], Any]) -> int: ...
  156. def disconnect(self, cid: int) -> None: ...
  157. @property
  158. def lines(self) -> list[tuple[Line2D, Line2D]]: ...
  159. @property
  160. def rectangles(self) -> list[Rectangle]: ...
  161. class TextBox(AxesWidget):
  162. label: Text
  163. text_disp: Text
  164. cursor_index: int
  165. cursor: LineCollection
  166. color: ColorType
  167. hovercolor: ColorType
  168. capturekeystrokes: bool
  169. def __init__(
  170. self,
  171. ax: Axes,
  172. label: str,
  173. initial: str = ...,
  174. *,
  175. color: ColorType = ...,
  176. hovercolor: ColorType = ...,
  177. label_pad: float = ...,
  178. textalignment: Literal["left", "center", "right"] = ...,
  179. ) -> None: ...
  180. @property
  181. def text(self) -> str: ...
  182. def set_val(self, val: str) -> None: ...
  183. def begin_typing(self, x = ...) -> None: ...
  184. def stop_typing(self) -> None: ...
  185. def on_text_change(self, func: Callable[[str], Any]) -> int: ...
  186. def on_submit(self, func: Callable[[str], Any]) -> int: ...
  187. def disconnect(self, cid: int) -> None: ...
  188. class RadioButtons(AxesWidget):
  189. activecolor: ColorType
  190. value_selected: str
  191. labels: list[Text]
  192. def __init__(
  193. self,
  194. ax: Axes,
  195. labels: Iterable[str],
  196. active: int = ...,
  197. activecolor: ColorType | None = ...,
  198. *,
  199. useblit: bool = ...,
  200. label_props: dict[str, Any] | Sequence[dict[str, Any]] | None = ...,
  201. radio_props: dict[str, Any] | None = ...,
  202. ) -> None: ...
  203. def set_label_props(self, props: dict[str, Any]) -> None: ...
  204. def set_radio_props(self, props: dict[str, Any]) -> None: ...
  205. def set_active(self, index: int) -> None: ...
  206. def on_clicked(self, func: Callable[[str], Any]) -> int: ...
  207. def disconnect(self, cid: int) -> None: ...
  208. @property
  209. def circles(self) -> list[Circle]: ...
  210. class SubplotTool(Widget):
  211. figure: Figure
  212. targetfig: Figure
  213. buttonreset: Button
  214. def __init__(self, targetfig: Figure, toolfig: Figure) -> None: ...
  215. class Cursor(AxesWidget):
  216. visible: bool
  217. horizOn: bool
  218. vertOn: bool
  219. useblit: bool
  220. lineh: Line2D
  221. linev: Line2D
  222. background: Any
  223. needclear: bool
  224. def __init__(
  225. self,
  226. ax: Axes,
  227. *,
  228. horizOn: bool = ...,
  229. vertOn: bool = ...,
  230. useblit: bool = ...,
  231. **lineprops
  232. ) -> None: ...
  233. def clear(self, event: Event) -> None: ...
  234. def onmove(self, event: Event) -> None: ...
  235. class MultiCursor(Widget):
  236. axes: Sequence[Axes]
  237. horizOn: bool
  238. vertOn: bool
  239. visible: bool
  240. useblit: bool
  241. needclear: bool
  242. vlines: list[Line2D]
  243. hlines: list[Line2D]
  244. def __init__(
  245. self,
  246. canvas: Any,
  247. axes: Sequence[Axes],
  248. *,
  249. useblit: bool = ...,
  250. horizOn: bool = ...,
  251. vertOn: bool = ...,
  252. **lineprops
  253. ) -> None: ...
  254. def connect(self) -> None: ...
  255. def disconnect(self) -> None: ...
  256. def clear(self, event: Event) -> None: ...
  257. def onmove(self, event: Event) -> None: ...
  258. class _SelectorWidget(AxesWidget):
  259. onselect: Callable[[float, float], Any]
  260. useblit: bool
  261. background: Any
  262. validButtons: list[MouseButton]
  263. def __init__(
  264. self,
  265. ax: Axes,
  266. onselect: Callable[[float, float], Any],
  267. useblit: bool = ...,
  268. button: MouseButton | Collection[MouseButton] | None = ...,
  269. state_modifier_keys: dict[str, str] | None = ...,
  270. use_data_coordinates: bool = ...,
  271. ) -> None: ...
  272. def update_background(self, event: Event) -> None: ...
  273. def connect_default_events(self) -> None: ...
  274. def ignore(self, event: Event) -> bool: ...
  275. def update(self) -> None: ...
  276. def press(self, event: Event) -> bool: ...
  277. def release(self, event: Event) -> bool: ...
  278. def onmove(self, event: Event) -> bool: ...
  279. def on_scroll(self, event: Event) -> None: ...
  280. def on_key_press(self, event: Event) -> None: ...
  281. def on_key_release(self, event: Event) -> None: ...
  282. def set_visible(self, visible: bool) -> None: ...
  283. def get_visible(self) -> bool: ...
  284. @property
  285. def visible(self) -> bool: ...
  286. def clear(self) -> None: ...
  287. @property
  288. def artists(self) -> tuple[Artist]: ...
  289. def set_props(self, **props) -> None: ...
  290. def set_handle_props(self, **handle_props) -> None: ...
  291. def add_state(self, state: str) -> None: ...
  292. def remove_state(self, state: str) -> None: ...
  293. class SpanSelector(_SelectorWidget):
  294. snap_values: ArrayLike | None
  295. onmove_callback: Callable[[float, float], Any]
  296. minspan: float
  297. grab_range: float
  298. drag_from_anywhere: bool
  299. ignore_event_outside: bool
  300. canvas: FigureCanvasBase | None
  301. def __init__(
  302. self,
  303. ax: Axes,
  304. onselect: Callable[[float, float], Any],
  305. direction: Literal["horizontal", "vertical"],
  306. *,
  307. minspan: float = ...,
  308. useblit: bool = ...,
  309. props: dict[str, Any] | None = ...,
  310. onmove_callback: Callable[[float, float], Any] | None = ...,
  311. interactive: bool = ...,
  312. button: MouseButton | Collection[MouseButton] | None = ...,
  313. handle_props: dict[str, Any] | None = ...,
  314. grab_range: float = ...,
  315. state_modifier_keys: dict[str, str] | None = ...,
  316. drag_from_anywhere: bool = ...,
  317. ignore_event_outside: bool = ...,
  318. snap_values: ArrayLike | None = ...,
  319. ) -> None: ...
  320. def new_axes(self, ax: Axes, *, _props: dict[str, Any] | None = ...) -> 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],
  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],
  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],
  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. ) -> None: ...
  462. def onrelease(self, event: Event) -> None: ...
  463. def onmove(self, event: Event) -> None: ...