sketchingpy.control_struct
Data structures to support inputs and controls.
License:
BSD
1"""Data structures to support inputs and controls. 2 3License: 4 BSD 5""" 6 7import typing 8 9 10class Button: 11 """Description of a key or button.""" 12 13 def __init__(self, name: str): 14 """Create a new button record. 15 16 Args: 17 name: The name of the button. 18 """ 19 self._name = name 20 21 def get_name(self) -> str: 22 """Get the name of this button. 23 24 Returns: 25 The name of the button. 26 """ 27 return self._name 28 29 30Buttons = typing.Iterable[Button] 31KeyboardCallback = typing.Callable[[Button, 'Keyboard'], None] 32MouseCallback = typing.Callable[[Button, 'Mouse'], None] 33 34 35class Mouse: 36 """Data structure describing a mouse.""" 37 38 def get_pointer_x(self): 39 """Get the x coordinate of the mouse pointer. 40 41 Get the current horizontal coordinate of the mouse pointer or, in the case of a touchscreen, 42 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 43 44 Returns: 45 The horizontal coordinate of the mouse pointer. 46 """ 47 raise NotImplementedError('Use implementor.') 48 49 def get_pointer_y(self): 50 """Get the y coordinate of the mouse pointer. 51 52 Get the current vertical coordinate of the mouse pointer or, in the case of a touchscreen, 53 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 54 55 Returns: 56 The vertical coordinate of the mouse pointer. 57 """ 58 raise NotImplementedError('Use implementor.') 59 60 def get_buttons_pressed(self) -> Buttons: 61 """Information about the mouse buttons currently pressed. 62 63 Get information about mouse buttons currently pressed. 64 65 Returns: 66 Collection of buttons currently pressed. 67 """ 68 raise NotImplementedError('Use implementor.') 69 70 def on_button_press(self, callback: MouseCallback): 71 """Callback for when a mouse button is pressed. 72 73 Register a callback for when a button is pressed, calling a function with the button and 74 mouse. Will pass two arguments to that callback function: first a Button followed by a 75 Mouse. Will unregister prior callbacks for on_button_press. 76 77 Args: 78 callback: The function to invoke when a mouse button or equivalent is pressed. 79 """ 80 raise NotImplementedError('Use implementor.') 81 82 def on_button_release(self, callback: MouseCallback): 83 """Callback for when a mouse button is released. 84 85 Register a callback for when a button is unpressed, calling a function with the button and 86 mouse. Will pass two arguments to that callback function: first a Button followed by a 87 Mouse. Will unregister prior callbacks for on_button_press. 88 89 Args: 90 callback: The function to invoke when a mouse button or equivalent is unpressed. 91 """ 92 raise NotImplementedError('Use implementor.') 93 94 95class Keyboard: 96 """Data structure describing a keyboard.""" 97 98 def get_keys_pressed(self) -> Buttons: 99 """Get a list of keys currently pressed. 100 101 Get a list of keys as Buttons. 102 103 Returns: 104 Get list of buttons pressed. 105 """ 106 raise NotImplementedError('Use implementor.') 107 108 def on_key_press(self, callback: KeyboardCallback): 109 """Callback for when a key is pressed. 110 111 Register a callback for when a key is pressed, calling a function with the key and keyboard. 112 Will pass two arguments to that callback function: first a Button followed by a Keyboard. 113 Will unregister prior callbacks for on_key_press. 114 115 Args: 116 callback: The function to invoke when a key is pressed. 117 """ 118 raise NotImplementedError('Use implementor.') 119 120 def on_key_release(self, callback: KeyboardCallback): 121 """Callback for when a key is released. 122 123 Register a callback for when a key is unpressed, calling a function with the key and 124 keyboard. Will pass two arguments to that callback function: first a Button followed by a 125 Keyboard. Will unregister prior callbacks for on_key_release. 126 127 Args: 128 callback: The function to invoke when a key is released. 129 """ 130 raise NotImplementedError('Use implementor.')
11class Button: 12 """Description of a key or button.""" 13 14 def __init__(self, name: str): 15 """Create a new button record. 16 17 Args: 18 name: The name of the button. 19 """ 20 self._name = name 21 22 def get_name(self) -> str: 23 """Get the name of this button. 24 25 Returns: 26 The name of the button. 27 """ 28 return self._name
Description of a key or button.
36class Mouse: 37 """Data structure describing a mouse.""" 38 39 def get_pointer_x(self): 40 """Get the x coordinate of the mouse pointer. 41 42 Get the current horizontal coordinate of the mouse pointer or, in the case of a touchscreen, 43 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 44 45 Returns: 46 The horizontal coordinate of the mouse pointer. 47 """ 48 raise NotImplementedError('Use implementor.') 49 50 def get_pointer_y(self): 51 """Get the y coordinate of the mouse pointer. 52 53 Get the current vertical coordinate of the mouse pointer or, in the case of a touchscreen, 54 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 55 56 Returns: 57 The vertical coordinate of the mouse pointer. 58 """ 59 raise NotImplementedError('Use implementor.') 60 61 def get_buttons_pressed(self) -> Buttons: 62 """Information about the mouse buttons currently pressed. 63 64 Get information about mouse buttons currently pressed. 65 66 Returns: 67 Collection of buttons currently pressed. 68 """ 69 raise NotImplementedError('Use implementor.') 70 71 def on_button_press(self, callback: MouseCallback): 72 """Callback for when a mouse button is pressed. 73 74 Register a callback for when a button is pressed, calling a function with the button and 75 mouse. Will pass two arguments to that callback function: first a Button followed by a 76 Mouse. Will unregister prior callbacks for on_button_press. 77 78 Args: 79 callback: The function to invoke when a mouse button or equivalent is pressed. 80 """ 81 raise NotImplementedError('Use implementor.') 82 83 def on_button_release(self, callback: MouseCallback): 84 """Callback for when a mouse button is released. 85 86 Register a callback for when a button is unpressed, calling a function with the button and 87 mouse. Will pass two arguments to that callback function: first a Button followed by a 88 Mouse. Will unregister prior callbacks for on_button_press. 89 90 Args: 91 callback: The function to invoke when a mouse button or equivalent is unpressed. 92 """ 93 raise NotImplementedError('Use implementor.')
Data structure describing a mouse.
39 def get_pointer_x(self): 40 """Get the x coordinate of the mouse pointer. 41 42 Get the current horizontal coordinate of the mouse pointer or, in the case of a touchscreen, 43 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 44 45 Returns: 46 The horizontal coordinate of the mouse pointer. 47 """ 48 raise NotImplementedError('Use implementor.')
Get the x coordinate of the mouse pointer.
Get the current horizontal coordinate of the mouse pointer or, in the case of a touchscreen, the point of last touch input if available. Defaults to 0 if no mouse events have been seen.
Returns:
The horizontal coordinate of the mouse pointer.
50 def get_pointer_y(self): 51 """Get the y coordinate of the mouse pointer. 52 53 Get the current vertical coordinate of the mouse pointer or, in the case of a touchscreen, 54 the point of last touch input if available. Defaults to 0 if no mouse events have been seen. 55 56 Returns: 57 The vertical coordinate of the mouse pointer. 58 """ 59 raise NotImplementedError('Use implementor.')
Get the y coordinate of the mouse pointer.
Get the current vertical coordinate of the mouse pointer or, in the case of a touchscreen, the point of last touch input if available. Defaults to 0 if no mouse events have been seen.
Returns:
The vertical coordinate of the mouse pointer.
96class Keyboard: 97 """Data structure describing a keyboard.""" 98 99 def get_keys_pressed(self) -> Buttons: 100 """Get a list of keys currently pressed. 101 102 Get a list of keys as Buttons. 103 104 Returns: 105 Get list of buttons pressed. 106 """ 107 raise NotImplementedError('Use implementor.') 108 109 def on_key_press(self, callback: KeyboardCallback): 110 """Callback for when a key is pressed. 111 112 Register a callback for when a key is pressed, calling a function with the key and keyboard. 113 Will pass two arguments to that callback function: first a Button followed by a Keyboard. 114 Will unregister prior callbacks for on_key_press. 115 116 Args: 117 callback: The function to invoke when a key is pressed. 118 """ 119 raise NotImplementedError('Use implementor.') 120 121 def on_key_release(self, callback: KeyboardCallback): 122 """Callback for when a key is released. 123 124 Register a callback for when a key is unpressed, calling a function with the key and 125 keyboard. Will pass two arguments to that callback function: first a Button followed by a 126 Keyboard. Will unregister prior callbacks for on_key_release. 127 128 Args: 129 callback: The function to invoke when a key is released. 130 """ 131 raise NotImplementedError('Use implementor.')
Data structure describing a keyboard.
99 def get_keys_pressed(self) -> Buttons: 100 """Get a list of keys currently pressed. 101 102 Get a list of keys as Buttons. 103 104 Returns: 105 Get list of buttons pressed. 106 """ 107 raise NotImplementedError('Use implementor.')
Get a list of keys currently pressed.
Get a list of keys as Buttons.
Returns:
Get list of buttons pressed.
109 def on_key_press(self, callback: KeyboardCallback): 110 """Callback for when a key is pressed. 111 112 Register a callback for when a key is pressed, calling a function with the key and keyboard. 113 Will pass two arguments to that callback function: first a Button followed by a Keyboard. 114 Will unregister prior callbacks for on_key_press. 115 116 Args: 117 callback: The function to invoke when a key is pressed. 118 """ 119 raise NotImplementedError('Use implementor.')
Callback for when a key is pressed.
Register a callback for when a key is pressed, calling a function with the key and keyboard. Will pass two arguments to that callback function: first a Button followed by a Keyboard. Will unregister prior callbacks for on_key_press.
Arguments:
- callback: The function to invoke when a key is pressed.
121 def on_key_release(self, callback: KeyboardCallback): 122 """Callback for when a key is released. 123 124 Register a callback for when a key is unpressed, calling a function with the key and 125 keyboard. Will pass two arguments to that callback function: first a Button followed by a 126 Keyboard. Will unregister prior callbacks for on_key_release. 127 128 Args: 129 callback: The function to invoke when a key is released. 130 """ 131 raise NotImplementedError('Use implementor.')
Callback for when a key is released.
Register a callback for when a key is unpressed, calling a function with the key and keyboard. Will pass two arguments to that callback function: first a Button followed by a Keyboard. Will unregister prior callbacks for on_key_release.
Arguments:
- callback: The function to invoke when a key is released.