-
Notifications
You must be signed in to change notification settings - Fork 0
general
Version: v1.1.2
A module for general utilities for the package.
A custom dictionary providing bijective mapping between a main type and a
hashable secondary type. It works like a two-way dictionary as in you can each
key-value pair is a value-key pair as well. The keys() method returns all
keys, or optionally just the primary ones, while the values() method returns
all values or optionally just the secondary ones (classic keys and values).
def __init__(self, primary_type: type) -> NoneInitializer for the class.
Parameters:
- primary_type: The type of the main keys for keys() and values().
def __getitem__(self, item: Any) -> AnyReturns a value from the internal dictionary accessed with '[]' (either of the main or the secondary type).
Parameters:
- item: The key whose associated value is to be returned.
Returns: The (primary/secondary type) value associated with the key.
def __setitem__(self, key: Any, value: Any) -> NoneSets/updates a key-value pair in a bijective way.
Parameters:
- key: Usually the object of primary type.
- value: Usually the object of secondary type.
def __delitem__(self, item: Any) -> NoneDeletes a key-value pair in a bijective way.
Parameters:
- item: Usually the object of primary type.
def __len__(self) -> intReturns the adjusted size of the internal dictionary.
def __repr__(self) -> strReturns the repr of the internal dictionary.
keys(self, primary_only: bool = True) -> list | tuple[list, list]Returns the keys of the internal dictionary.
Parameters:
- primary_only: A flag to only return the keys of the primary type (default behaviour).
Returns: Either a list of keys of the primary type or additionally a list of keys of the secondary type.
def values(self, secondary_only: bool = True) -> list | tuple[list, list]Returns the values of the internal dictionary.
Parameters:
- secondary_only: A flag to only return the keys of the secondary type (default behaviour).
Returns: Either a list of values of the secondary type or additionally (as the first item of the return tuple) a list of values of the primary type.
Read-only descriptor for use with protected storage attributes.
def __set_name__(self, owner: type, name: str) -> NoneSets the name of the storage attribute.
Parameters:
- owner: The managed class.
- name: The managed attribute's name.
def __get__(self, instance: Any, instance_type: type = None) -> AnyReturns the value of the protected storage attribute.
Parameters:
- instance: An instance of the managed class (managed instance).
- instance_type: Reference to the managed class, unused here.
Returns: Either the descriptor object itself or the value in the storage attribute.
def __set__(self, instance: Any, value: Any) -> NeverSets the value of the protected storage attribute (would, but read-only).
Parameters:
- instance: An instance of the managed class (managed instance).
- value: The value to set for the storage attribute.
Raises: AttributeError: Notifies the user about the attribute being read-only.
Temporarily blocks the signals of the handled QObject.
def __init__(self, obj: _T) -> NoneInitializer for the class.
Parameters:
- obj: An object whose signals should be blocked temporarily.
def __enter__(self) -> _TBlocks the signals of the handled QObject.
Returns: The handled object.
def __exit__(self, exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None) -> NoneUnblocks the signals of the handled QObject.
Example usage:
with SignalBlocker(self._cmbTestCombobox) as obj:
obj.setCurrentIndex(3) # The `currentIndexChanged` signal is not emittedNote that since it uses a generic type, type checkers will see the actual type of the blocked object (obj).
A metaclass making instance classes singletons.
def __call__(cls, *args, **kwargs) -> AnyReturns the existing instance or creates a new one.
def qt_connect(signal: Callable, slot: Callable, unique: bool = False) -> NoneConnects a Qt signal to a slot method. It uses the new-style connection creation, while having a simple signature and removing the need to sprinkle 'type: ignore' around connections.
Parameters:
- signal: The signal of a Qt-object.
- slot: A method of a class serving as a slot for the signal.
- unique: Whether the connection should be set to unique. The default is False.
def resource_path(relative_path: str) -> strGet absolute path to resource (for apps built with PyInstaller).
Parameters:
- relative_path: A string representing a relative path to the requested resource.
Returns: The absolute path to the requested resource (as a simple string).
def _stub_repr_function_like(f: cached_property | FunctionType | MethodType, class_bound: bool) -> strCreates a stub representation for a function-like object.
Parameters:
- f: The function-like object whose stub representation is to be made.
- class_bound: A flag to add 'self' to the representation.
Returns: The stub representation of the input function-like object.
stub_repr(obj: object, signals: list[str] | None = None, extra_cvs: str | None = None, add_getattr: bool = False) -> strCreates a specifically formatted stub representation of an object. Static methods must be changed to class methods for them to be compatible with the function (which cannot yet handle static methods). Dunder methods are usually not included (apart from __init__ or when requested a special __getattr__.)
Parameters:
- obj: The object whose stub representation is to be made.
- signals: A list of strings representing the (Qt) signals of the object, as
[sigName(carriedType1, ...)]. The default is None. - extra_cvs: A string of extra class variables that are not defined as CVs in the source code. The default is None.
- add_getattr: A flag for adding a special
__getattr__method to the repr. For public Qt-based classes, it needs so that the static type checker does not warn about variables declared outside__init__. The default is False.
These stub creator functions are for internal use mainly but you can see examples for their usage at the bottom of modules in the _init_module() functions.