|
24 | 24 | fromnumpy.typingimportArrayLike,NDArray
|
25 | 25 |
|
26 | 26 | __all__= (
|
| 27 | +"Capitalization", |
27 | 28 | "FlashOperation",
|
| 29 | +"TextInputType", |
28 | 30 | "Window",
|
29 | 31 | "WindowFlags",
|
30 | 32 | "get_grabbed_window",
|
@@ -89,6 +91,56 @@ class FlashOperation(enum.IntEnum):
|
89 | 91 | """Flash until focus is gained."""
|
90 | 92 |
|
91 | 93 |
|
| 94 | +classTextInputType(enum.IntEnum): |
| 95 | +"""SDL input types for text input. |
| 96 | +
|
| 97 | + .. seealso:: |
| 98 | + :any:`Window.start_text_input` |
| 99 | + https://wiki.libsdl.org/SDL3/SDL_TextInputType |
| 100 | +
|
| 101 | + .. versionadded:: Unreleased |
| 102 | + """ |
| 103 | + |
| 104 | +TEXT=lib.SDL_TEXTINPUT_TYPE_TEXT |
| 105 | +"""The input is text.""" |
| 106 | +TEXT_NAME=lib.SDL_TEXTINPUT_TYPE_TEXT_NAME |
| 107 | +"""The input is a person's name.""" |
| 108 | +TEXT_EMAIL=lib.SDL_TEXTINPUT_TYPE_TEXT_EMAIL |
| 109 | +"""The input is an e-mail address.""" |
| 110 | +TEXT_USERNAME=lib.SDL_TEXTINPUT_TYPE_TEXT_USERNAME |
| 111 | +"""The input is a username.""" |
| 112 | +TEXT_PASSWORD_HIDDEN=lib.SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_HIDDEN |
| 113 | +"""The input is a secure password that is hidden.""" |
| 114 | +TEXT_PASSWORD_VISIBLE=lib.SDL_TEXTINPUT_TYPE_TEXT_PASSWORD_VISIBLE |
| 115 | +"""The input is a secure password that is visible.""" |
| 116 | +NUMBER=lib.SDL_TEXTINPUT_TYPE_NUMBER |
| 117 | +"""The input is a number.""" |
| 118 | +NUMBER_PASSWORD_HIDDEN=lib.SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_HIDDEN |
| 119 | +"""The input is a secure PIN that is hidden.""" |
| 120 | +NUMBER_PASSWORD_VISIBLE=lib.SDL_TEXTINPUT_TYPE_NUMBER_PASSWORD_VISIBLE |
| 121 | +"""The input is a secure PIN that is visible.""" |
| 122 | + |
| 123 | + |
| 124 | +classCapitalization(enum.IntEnum): |
| 125 | +"""Text capitalization for text input. |
| 126 | +
|
| 127 | + .. seealso:: |
| 128 | + :any:`Window.start_text_input` |
| 129 | + https://wiki.libsdl.org/SDL3/SDL_Capitalization |
| 130 | +
|
| 131 | + .. versionadded:: Unreleased |
| 132 | + """ |
| 133 | + |
| 134 | +NONE=lib.SDL_CAPITALIZE_NONE |
| 135 | +"""No auto-capitalization will be done.""" |
| 136 | +SENTENCES=lib.SDL_CAPITALIZE_SENTENCES |
| 137 | +"""The first letter of sentences will be capitalized.""" |
| 138 | +WORDS=lib.SDL_CAPITALIZE_WORDS |
| 139 | +"""The first letter of words will be capitalized.""" |
| 140 | +LETTERS=lib.SDL_CAPITALIZE_LETTERS |
| 141 | +"""All letters will be capitalized.""" |
| 142 | + |
| 143 | + |
92 | 144 | class_TempSurface:
|
93 | 145 | """Holds a temporary surface derived from a NumPy array."""
|
94 | 146 |
|
@@ -133,6 +185,9 @@ def __eq__(self, other: object) -> bool:
|
133 | 185 | returnNotImplemented
|
134 | 186 | returnbool(self.p==other.p)
|
135 | 187 |
|
| 188 | +def__hash__(self)->int: |
| 189 | +returnhash(self.p) |
| 190 | + |
136 | 191 | def_as_property_pointer(self)->Any:# noqa: ANN401
|
137 | 192 | returnself.p
|
138 | 193 |
|
@@ -369,6 +424,69 @@ def relative_mouse_mode(self) -> bool:
|
369 | 424 | defrelative_mouse_mode(self,enable:bool,/)->None:
|
370 | 425 | _check(lib.SDL_SetWindowRelativeMouseMode(self.p,enable))
|
371 | 426 |
|
| 427 | +defstart_text_input( |
| 428 | +self, |
| 429 | +*, |
| 430 | +type:TextInputType=TextInputType.TEXT,# noqa: A002 |
| 431 | +capitalization:Capitalization|None=None, |
| 432 | +autocorrect:bool=True, |
| 433 | +multiline:bool|None=None, |
| 434 | +android_type:int|None=None, |
| 435 | + )->None: |
| 436 | +"""Start receiving text input events supporting Unicode. This may open an on-screen keyboard. |
| 437 | +
|
| 438 | + This method is meant to be paired with :any:`set_text_input_area`. |
| 439 | +
|
| 440 | + Args: |
| 441 | + type: Type of text being inputted, see :any:`TextInputType` |
| 442 | + capitalization: Capitalization hint, default is based on `type` given, see :any:`Capitalization`. |
| 443 | + autocorrect: Enable auto completion and auto correction. |
| 444 | + multiline: Allow multiple lines of text. |
| 445 | + android_type: Input type for Android, see SDL docs. |
| 446 | +
|
| 447 | + .. seealso:: |
| 448 | + :any:`stop_text_input` |
| 449 | + :any:`set_text_input_area` |
| 450 | + https://wiki.libsdl.org/SDL3/SDL_StartTextInputWithProperties |
| 451 | +
|
| 452 | + .. versionadded:: Unreleased |
| 453 | + """ |
| 454 | +props=Properties() |
| 455 | +props[("SDL_PROP_TEXTINPUT_TYPE_NUMBER",int)]=int(type) |
| 456 | +ifcapitalizationisnotNone: |
| 457 | +props[("SDL_PROP_TEXTINPUT_CAPITALIZATION_NUMBER",int)]=int(capitalization) |
| 458 | +props[("SDL_PROP_TEXTINPUT_AUTOCORRECT_BOOLEAN",bool)]=autocorrect |
| 459 | +ifmultilineisnotNone: |
| 460 | +props[("SDL_PROP_TEXTINPUT_MULTILINE_BOOLEAN",bool)]=multiline |
| 461 | +ifandroid_typeisnotNone: |
| 462 | +props[("SDL_PROP_TEXTINPUT_ANDROID_INPUTTYPE_NUMBER",int)]=int(android_type) |
| 463 | +_check(lib.SDL_StartTextInputWithProperties(self.p,props.p)) |
| 464 | + |
| 465 | +defset_text_input_area(self,rect:tuple[int,int,int,int],cursor:int)->None: |
| 466 | +"""Assign the area used for entering Unicode text input. |
| 467 | +
|
| 468 | + Args: |
| 469 | + rect: `(x, y, width, height)` rectangle used for text input |
| 470 | + cursor: Cursor X position, relative to `rect[0]` |
| 471 | +
|
| 472 | + .. seealso:: |
| 473 | + :any:`start_text_input` |
| 474 | + https://wiki.libsdl.org/SDL3/SDL_SetTextInputArea |
| 475 | +
|
| 476 | + .. versionadded:: Unreleased |
| 477 | + """ |
| 478 | +_check(lib.SDL_SetTextInputArea(self.p, (rect,),cursor)) |
| 479 | + |
| 480 | +defstop_text_input(self)->None: |
| 481 | +"""Stop receiving text events for this window and close relevant on-screen keyboards. |
| 482 | +
|
| 483 | + .. seealso:: |
| 484 | + :any:`start_text_input` |
| 485 | +
|
| 486 | + .. versionadded:: Unreleased |
| 487 | + """ |
| 488 | +_check(lib.SDL_StopTextInput(self.p)) |
| 489 | + |
372 | 490 |
|
373 | 491 | defnew_window(# noqa: PLR0913
|
374 | 492 | width:int,
|
|