async2v.util module¶
Summary¶
Functions:
length_normalizer |
Scale lengths according to screen resolution |
parse_resolution |
Parse a resolution string of the format WIDTHxHEIGHT to a tuple (width, height). |
Reference¶
-
parse_resolution
(value)¶ Parse a resolution string of the format WIDTHxHEIGHT to a tuple (width, height).
Parameters: value ( str
) – Input string of the format WIDTHxHEIGHT. Only integral values are supported.Return type: Tuple
[int
,int
]
-
length_normalizer
(size, reference=600)¶ Scale lengths according to screen resolution
Returns a function that scales lengths according to the given screen size based on a reference value. This allows to easily define lengths in a readable way independent from the actual screen resolution.
- Example usage:
>>> s = length_normalizer(surface.get_size()) >>> render_hud_text(surface, 'Hello!', size=s(60)) >>> render_hud_text(surface, 'World!', size=s(40), position=(1, 0))
Parameters: Return type: Returns: Function that returns scaled size as
int
-
coroutine
run_in_executor
(func, *args)¶ Run a function in a thread pool executor.
This is a convenience wrapper for
asyncio.get_event_loop().run_in_executor(...)
.Use this within your components to allow the main loop to continue during expensive operations, for example:
async def process(self): result = await run_in_executor(self._expensive_operation, self.input.value.image) self.output.push(result)
See
asyncio.loop.run_in_executor
for more information.Parameters: - func (
Callable
) – Expensive function or method that shall run outside the main loop - args – Arguments to pass to
func
Return type: Future
Returns: Future that will contain the to the return value of
func
as a result- func (