Skip to content

MetaObject

⋔ Inheritance diagram

graph TD
  1473299784768["core.MetaObject"]
  140713234304496["builtins.object"]
  140713234304496 --> 1473299784768

🛈 DocStrings

Contains meta-information about Qt objects.

Source code in prettyqt\core\metaobject.py
class MetaObject:
    """Contains meta-information about Qt objects."""

    def __init__(self, metaobject: core.QMetaObject):
        self.item = metaobject

    def __getattr__(self, val):
        return getattr(self.item, val)

    def get_super_class(self) -> MetaObject | None:
        """Get SuperClass MetaObject."""
        return MetaObject(klass) if (klass := self.superClass()) is not None else None

    def get_all_super_classes(self) -> list[MetaObject]:
        """Get SuperClass MetaObject."""
        klasses = []
        while klass := self.superClass():
            klasses.append(MetaObject(klass))
        return klasses

    def get_name(self) -> str:
        """Get MetaObject class name."""
        return self.className()

    def get_class_info(self, include_super: bool = True) -> dict[str, str]:
        """Get MetaObject class info.

        Arguments:
            include_super: Whether to include class info from parent classes.
        """
        start = 0 if include_super else self.item.classInfoOffset()
        count = self.item.classInfoCount()
        classinfos = [self.item.classInfo(i) for i in range(start, count)]
        return {i.name(): i.value() for i in classinfos}

    def get_method(self, index: int | str) -> core.MetaMethod:
        """Get MetaMethod based on index or name.

        Arguments:
            index: index or method name
        """
        if isinstance(index, int):
            method = core.MetaMethod(self.item.method(index))
            if not method.isValid():
                raise KeyError(index)
            return method
        for method in self.get_methods():
            if method.get_name() in [index, helpers.to_lower_camel(index)]:
                return method
        raise KeyError(index)

    def get_enum(self, index: int | str) -> core.MetaEnum:
        """Get MetaEnum based on index or name.

        Arguments:
            index: index or Enum name
        """
        if isinstance(index, int):
            enum = core.MetaEnum(self.item.enumerator(index))
            if not enum.isValid():
                raise KeyError(index)
            return enum
        for enumerator in self.get_enums():
            if enumerator.get_name() in [index, helpers.to_lower_camel(index)]:
                return enumerator
        raise KeyError(index)

    def has_property(self, name: str):
        """Check if a property with given name exists.

        Only checks for non-dynamic properties.

        Arguments:
            name: property name
        """
        try:
            self.get_property(name)
            return True
        except KeyError:
            return False

    def get_property(self, index: int | str) -> core.MetaProperty:
        """Get MetaProperty based on index or name.

        Only returns non-dynamic properties.

        Arguments:
            index: index or property name
        """
        if isinstance(index, int):
            prop = core.MetaProperty(self.item.property(index))
            if not prop.isValid():
                raise KeyError(index)
            return prop
        for prop in self.get_properties():
            if prop.get_name() in [index, helpers.to_lower_camel(index)]:
                return prop
        raise KeyError(index)

    def get_constructor(self, index: int | str) -> core.MetaMethod:
        """Get ctor MetaMethod based on index or name.

        Arguments:
            index: index or constructor name
        """
        if isinstance(index, int):
            method = core.MetaMethod(self.item.constructor(index))
            if not method.isValid():
                raise KeyError(index)
            return method
        for method in self.get_constructors():
            if method.get_name() in [index, helpers.to_lower_camel(index)]:
                return method
        raise KeyError(index)

    def get_methods(
        self,
        include_super: bool = True,
        type_filter: core.metamethod.MethodTypeStr | None = None,
        filter_internal: bool = True,
    ) -> list[core.MetaMethod]:
        """Get all MetaMethods based on given criteria.

        Arguments:
            include_super: Whether to include Methods from parent classes
            type_filter: Method type to filter for.
            filter_internal: Filter Qt-internal methods
        """
        start = 0 if include_super else self.item.methodOffset()
        methods = [
            method
            for i in range(start, self.item.methodCount())
            if not (method := self.get_method(i)).get_name().startswith("_q_")
            or not filter_internal
        ]
        if type_filter is None:
            return methods
        else:
            return [i for i in methods if i.get_method_type() == type_filter]

    def get_enums(self, include_super: bool = True) -> list[core.MetaEnum]:
        """Get all MetaEnums based on given criteria.

        Arguments:
            include_super: Whether to include Enums from parent classes.
        """
        start = 0 if include_super else self.item.enumeratorOffset()
        return [self.get_enum(i) for i in range(start, self.item.enumeratorCount())]

    def get_constructors(self) -> list[core.MetaMethod]:
        """Get all ctor MetaMethods."""
        count = self.item.constructorCount()
        return [core.MetaMethod(self.item.constructor(i)) for i in range(count)]

    def get_properties(
        self,
        include_super: bool = True,
        only_writable: bool = False,
        only_stored: bool = False,
        only_bindable: bool = False,
        only_designable: bool = False,
        only_final: bool = False,
        only_required: bool = False,
        only_enum_type: bool = False,
        only_flag_type: bool = False,
        only_with_notifiers: bool = False,
        only_with_type_name: str = "",
    ) -> list[core.MetaProperty]:
        """Get all MetaProperties based on given criteria.

        Arguments:
            include_super: Whether to include properties from parent classes,
            only_writable: Whether to filter for writable properties.
            only_stored: Whether to filter for stored properties.
            only_bindable: Whether to filter for bindable properties.
            only_designable: Whether to filter for designable properties.
            only_final: Whether to filter for final properties.
            only_required: Whether to filter for required properties.
            only_enum_type: Whether to filter for Enum type properties.
            only_flag_type: Whether to filter for Flag_type properties.
            only_with_notifiers: Whether to filter for properties with notifier.
            only_with_type_name: Only include properties with given give name as type.
        """
        start = 0 if include_super else self.item.propertyOffset()
        count = self.item.propertyCount()
        prop_list = []
        for i in range(start, count):
            prop = self.item.property(i)
            if (
                (only_writable and not prop.isWritable())
                or (only_stored and not prop.isStored())
                or (only_bindable and not prop.isBindable())
                or (only_designable and not prop.isDesignable())
                or (only_final and not prop.isFinal())
                or (only_required and not prop.isRequired())
                or (only_enum_type and not prop.isEnumType())
                or (only_flag_type and not prop.isFlagType())
                or (only_with_notifiers and not prop.hasNotifier())
                or (only_with_type_name and prop.typeName() != only_with_type_name)
            ):
                continue
            prop_list.append(core.MetaProperty(prop))
        return prop_list

    def get_property_values(
        self, qobject: core.QObject, cast_types: bool = False
    ) -> dict[str, Any]:
        """Get a dictionary containing all MetaProperties values from given qobject.

        Arguments:
            qobject: QObject to get properties from
            cast_types: Whether to cast types to PrettyQt classes.
        """
        vals = {prop.get_name(): prop.read(qobject) for prop in self.get_properties()}
        if cast_types:
            return {k: datatypes.make_serializable(v) for k, v in vals.items()}
        else:
            return vals

    def get_signals(
        self, include_super: bool = True, only_notifiers: bool = False
    ) -> list[core.MetaMethod]:
        """Get all signal MetaMethods based on given criteria.

        Arguments:
            include_super: Whether to include Signals from parent classes
            only_notifiers: Whether to filter for property notifier signals
        """
        if only_notifiers:
            return [  # type: ignore
                prop.get_notify_signal()
                for prop in self.get_properties(include_super)
                if prop.hasNotifySignal()
            ]
        else:
            return self.get_methods(include_super=include_super, type_filter="signal")

    def get_slots(self, include_super: bool = True) -> list[core.MetaMethod]:
        """Get all slot MetaMethods based on given criteria.

        Arguments:
            include_super: Whether to include Slots from parent classes
        """
        return self.get_methods(include_super=include_super, type_filter="slot")

    def get_plain_methods(self, include_super: bool = True) -> list[core.MetaMethod]:
        """Get all plain MetaMethods based on given criteria.

        Arguments:
            include_super: Whether to include plain methods from parent classes
        """
        return self.get_methods(include_super=include_super, type_filter="method")

    def get_meta_type(self) -> core.MetaType:
        """Get Meta type of this MetaObject."""
        return core.MetaType(self.metaType().id())

    def get_user_property(self) -> core.MetaProperty | None:
        """Get MetaProperty marked as userprop."""
        return core.MetaProperty(p) if (p := self.userProperty()).isValid() else None

    # just experimenting
    @classmethod
    def invoke_method(
        cls,
        obj: core.QObject,
        method: str,
        *args,
        connection_type: constants.ConnectionTypeStr = "auto",
    ):
        conn = constants.CONNECTION_TYPE[connection_type]
        args = tuple(core.Q_ARG(type(arg), arg) for arg in args)
        return cls.invokeMethod(obj, method, conn, *args)

    def get_new_instance(self, *args, **kwargs):
        args = tuple(core.Q_ARG(type(i), i) for i in args)
        kwargs = {k: core.Q_ARG(type(v), v) for k, v in kwargs.items()}
        # requires core.QGenericArgumentHolder for PySide6
        self.newInstance(*args, **kwargs)

    def connect_signals(
        self,
        source_qobject: core.QObject,
        fn_or_qobject: Callable | core.QObject,
        only_notifiers: bool = False,
    ) -> list[core.QMetaObject.Connection]:
        """Connect all signals of a given qobject.

        Either connect all signals to a function or connect each signal
        to the corresponding signal of the receiver.
        """
        handles = []
        for signal in self.get_signals(only_notifiers=only_notifiers):
            signal_name = signal.get_name()
            if not hasattr(source_qobject, signal_name):
                # PyQt6 reports applicationNameChanged for QCoreApplication,
                # but it doesnt exist...
                logger.warning(f"Signal {signal_name} does not exist.")
                continue
            signal_instance = source_qobject.__getattribute__(signal_name)
            slot = (
                fn_or_qobject.__getattribute__(signal_name)
                if isinstance(fn_or_qobject, core.QObject)
                else fn_or_qobject
            )
            handle = signal_instance.connect(slot)
            handles.append(handle)
        logger.debug(f"connected {len(handles)} signals to {fn_or_qobject}.")
        return handles

    def copy(self, qobject: T, forward_signals: bool = True) -> T:
        """Create a copy of given QObject.

        Arguments:
            qobject: QObject to create a copied instance for.
            forward_signals: Whether to connect all signals from qobject to the new
                             instance.
        """
        try:
            new = type(qobject)()
        except TypeError:
            # this should should cover most cases.
            new = type(qobject)(qobject.orientation())
        for prop in self.get_properties(only_writable=True):
            val = prop.read(qobject)
            prop.write(new, val)
        if forward_signals:
            self.connect_signals(new, qobject)
        logger.debug(f"copied {qobject!r}")
        return new

    @classmethod
    def copy_properties_to(cls, source: core.QObject, target: core.QObject):
        """Sets all properties of target to value of source.

        Only sets properties which exist for both QObjects.

        Arguments:
            source: Source QObject
            target: Target QObject
        """
        source_metaobj = cls(source.metaObject())
        target_metaobj = cls(target.metaObject())
        for prop in target_metaobj.get_properties(only_writable=True):
            if source_metaobj.has_property(prop_name := prop.get_name()):
                target.setProperty(prop_name, source.property(prop_name))

    def get_property_class_affiliations(self) -> dict[str, list[core.MetaProperty]]:
        """Get a mapping of class -> property affiliations."""
        mapper = {}
        metaclass = self
        while metaclass is not None:
            mapper[metaclass.get_name()] = [
                metaclass.get_property(i)
                for i in range(metaclass.propertyOffset(), metaclass.propertyCount())
            ]
            metaclass = metaclass.get_super_class()
        return mapper

connect_signals(source_qobject: core.QObject, fn_or_qobject: Callable | core.QObject, only_notifiers: bool = False) -> list[core.QMetaObject.Connection]

Connect all signals of a given qobject.

Either connect all signals to a function or connect each signal to the corresponding signal of the receiver.

Source code in prettyqt\core\metaobject.py
def connect_signals(
    self,
    source_qobject: core.QObject,
    fn_or_qobject: Callable | core.QObject,
    only_notifiers: bool = False,
) -> list[core.QMetaObject.Connection]:
    """Connect all signals of a given qobject.

    Either connect all signals to a function or connect each signal
    to the corresponding signal of the receiver.
    """
    handles = []
    for signal in self.get_signals(only_notifiers=only_notifiers):
        signal_name = signal.get_name()
        if not hasattr(source_qobject, signal_name):
            # PyQt6 reports applicationNameChanged for QCoreApplication,
            # but it doesnt exist...
            logger.warning(f"Signal {signal_name} does not exist.")
            continue
        signal_instance = source_qobject.__getattribute__(signal_name)
        slot = (
            fn_or_qobject.__getattribute__(signal_name)
            if isinstance(fn_or_qobject, core.QObject)
            else fn_or_qobject
        )
        handle = signal_instance.connect(slot)
        handles.append(handle)
    logger.debug(f"connected {len(handles)} signals to {fn_or_qobject}.")
    return handles

copy(qobject: T, forward_signals: bool = True) -> T

Create a copy of given QObject.

Parameters:

Name Type Description Default
qobject T

QObject to create a copied instance for.

required
forward_signals bool

Whether to connect all signals from qobject to the new instance.

True
Source code in prettyqt\core\metaobject.py
def copy(self, qobject: T, forward_signals: bool = True) -> T:
    """Create a copy of given QObject.

    Arguments:
        qobject: QObject to create a copied instance for.
        forward_signals: Whether to connect all signals from qobject to the new
                         instance.
    """
    try:
        new = type(qobject)()
    except TypeError:
        # this should should cover most cases.
        new = type(qobject)(qobject.orientation())
    for prop in self.get_properties(only_writable=True):
        val = prop.read(qobject)
        prop.write(new, val)
    if forward_signals:
        self.connect_signals(new, qobject)
    logger.debug(f"copied {qobject!r}")
    return new

copy_properties_to(source: core.QObject, target: core.QObject) classmethod

Sets all properties of target to value of source.

Only sets properties which exist for both QObjects.

Parameters:

Name Type Description Default
source QObject

Source QObject

required
target QObject

Target QObject

required
Source code in prettyqt\core\metaobject.py
@classmethod
def copy_properties_to(cls, source: core.QObject, target: core.QObject):
    """Sets all properties of target to value of source.

    Only sets properties which exist for both QObjects.

    Arguments:
        source: Source QObject
        target: Target QObject
    """
    source_metaobj = cls(source.metaObject())
    target_metaobj = cls(target.metaObject())
    for prop in target_metaobj.get_properties(only_writable=True):
        if source_metaobj.has_property(prop_name := prop.get_name()):
            target.setProperty(prop_name, source.property(prop_name))

get_all_super_classes() -> list[MetaObject]

Get SuperClass MetaObject.

Source code in prettyqt\core\metaobject.py
def get_all_super_classes(self) -> list[MetaObject]:
    """Get SuperClass MetaObject."""
    klasses = []
    while klass := self.superClass():
        klasses.append(MetaObject(klass))
    return klasses

get_class_info(include_super: bool = True) -> dict[str, str]

Get MetaObject class info.

Parameters:

Name Type Description Default
include_super bool

Whether to include class info from parent classes.

True
Source code in prettyqt\core\metaobject.py
def get_class_info(self, include_super: bool = True) -> dict[str, str]:
    """Get MetaObject class info.

    Arguments:
        include_super: Whether to include class info from parent classes.
    """
    start = 0 if include_super else self.item.classInfoOffset()
    count = self.item.classInfoCount()
    classinfos = [self.item.classInfo(i) for i in range(start, count)]
    return {i.name(): i.value() for i in classinfos}

get_constructor(index: int | str) -> core.MetaMethod

Get ctor MetaMethod based on index or name.

Parameters:

Name Type Description Default
index int | str

index or constructor name

required
Source code in prettyqt\core\metaobject.py
def get_constructor(self, index: int | str) -> core.MetaMethod:
    """Get ctor MetaMethod based on index or name.

    Arguments:
        index: index or constructor name
    """
    if isinstance(index, int):
        method = core.MetaMethod(self.item.constructor(index))
        if not method.isValid():
            raise KeyError(index)
        return method
    for method in self.get_constructors():
        if method.get_name() in [index, helpers.to_lower_camel(index)]:
            return method
    raise KeyError(index)

get_constructors() -> list[core.MetaMethod]

Get all ctor MetaMethods.

Source code in prettyqt\core\metaobject.py
def get_constructors(self) -> list[core.MetaMethod]:
    """Get all ctor MetaMethods."""
    count = self.item.constructorCount()
    return [core.MetaMethod(self.item.constructor(i)) for i in range(count)]

get_enum(index: int | str) -> core.MetaEnum

Get MetaEnum based on index or name.

Parameters:

Name Type Description Default
index int | str

index or Enum name

required
Source code in prettyqt\core\metaobject.py
def get_enum(self, index: int | str) -> core.MetaEnum:
    """Get MetaEnum based on index or name.

    Arguments:
        index: index or Enum name
    """
    if isinstance(index, int):
        enum = core.MetaEnum(self.item.enumerator(index))
        if not enum.isValid():
            raise KeyError(index)
        return enum
    for enumerator in self.get_enums():
        if enumerator.get_name() in [index, helpers.to_lower_camel(index)]:
            return enumerator
    raise KeyError(index)

get_enums(include_super: bool = True) -> list[core.MetaEnum]

Get all MetaEnums based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include Enums from parent classes.

True
Source code in prettyqt\core\metaobject.py
def get_enums(self, include_super: bool = True) -> list[core.MetaEnum]:
    """Get all MetaEnums based on given criteria.

    Arguments:
        include_super: Whether to include Enums from parent classes.
    """
    start = 0 if include_super else self.item.enumeratorOffset()
    return [self.get_enum(i) for i in range(start, self.item.enumeratorCount())]

get_meta_type() -> core.MetaType

Get Meta type of this MetaObject.

Source code in prettyqt\core\metaobject.py
def get_meta_type(self) -> core.MetaType:
    """Get Meta type of this MetaObject."""
    return core.MetaType(self.metaType().id())

get_method(index: int | str) -> core.MetaMethod

Get MetaMethod based on index or name.

Parameters:

Name Type Description Default
index int | str

index or method name

required
Source code in prettyqt\core\metaobject.py
def get_method(self, index: int | str) -> core.MetaMethod:
    """Get MetaMethod based on index or name.

    Arguments:
        index: index or method name
    """
    if isinstance(index, int):
        method = core.MetaMethod(self.item.method(index))
        if not method.isValid():
            raise KeyError(index)
        return method
    for method in self.get_methods():
        if method.get_name() in [index, helpers.to_lower_camel(index)]:
            return method
    raise KeyError(index)

get_methods(include_super: bool = True, type_filter: core.metamethod.MethodTypeStr | None = None, filter_internal: bool = True) -> list[core.MetaMethod]

Get all MetaMethods based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include Methods from parent classes

True
type_filter MethodTypeStr | None

Method type to filter for.

None
filter_internal bool

Filter Qt-internal methods

True
Source code in prettyqt\core\metaobject.py
def get_methods(
    self,
    include_super: bool = True,
    type_filter: core.metamethod.MethodTypeStr | None = None,
    filter_internal: bool = True,
) -> list[core.MetaMethod]:
    """Get all MetaMethods based on given criteria.

    Arguments:
        include_super: Whether to include Methods from parent classes
        type_filter: Method type to filter for.
        filter_internal: Filter Qt-internal methods
    """
    start = 0 if include_super else self.item.methodOffset()
    methods = [
        method
        for i in range(start, self.item.methodCount())
        if not (method := self.get_method(i)).get_name().startswith("_q_")
        or not filter_internal
    ]
    if type_filter is None:
        return methods
    else:
        return [i for i in methods if i.get_method_type() == type_filter]

get_name() -> str

Get MetaObject class name.

Source code in prettyqt\core\metaobject.py
def get_name(self) -> str:
    """Get MetaObject class name."""
    return self.className()

get_plain_methods(include_super: bool = True) -> list[core.MetaMethod]

Get all plain MetaMethods based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include plain methods from parent classes

True
Source code in prettyqt\core\metaobject.py
def get_plain_methods(self, include_super: bool = True) -> list[core.MetaMethod]:
    """Get all plain MetaMethods based on given criteria.

    Arguments:
        include_super: Whether to include plain methods from parent classes
    """
    return self.get_methods(include_super=include_super, type_filter="method")

get_properties(include_super: bool = True, only_writable: bool = False, only_stored: bool = False, only_bindable: bool = False, only_designable: bool = False, only_final: bool = False, only_required: bool = False, only_enum_type: bool = False, only_flag_type: bool = False, only_with_notifiers: bool = False, only_with_type_name: str = '') -> list[core.MetaProperty]

Get all MetaProperties based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include properties from parent classes,

True
only_writable bool

Whether to filter for writable properties.

False
only_stored bool

Whether to filter for stored properties.

False
only_bindable bool

Whether to filter for bindable properties.

False
only_designable bool

Whether to filter for designable properties.

False
only_final bool

Whether to filter for final properties.

False
only_required bool

Whether to filter for required properties.

False
only_enum_type bool

Whether to filter for Enum type properties.

False
only_flag_type bool

Whether to filter for Flag_type properties.

False
only_with_notifiers bool

Whether to filter for properties with notifier.

False
only_with_type_name str

Only include properties with given give name as type.

''
Source code in prettyqt\core\metaobject.py
def get_properties(
    self,
    include_super: bool = True,
    only_writable: bool = False,
    only_stored: bool = False,
    only_bindable: bool = False,
    only_designable: bool = False,
    only_final: bool = False,
    only_required: bool = False,
    only_enum_type: bool = False,
    only_flag_type: bool = False,
    only_with_notifiers: bool = False,
    only_with_type_name: str = "",
) -> list[core.MetaProperty]:
    """Get all MetaProperties based on given criteria.

    Arguments:
        include_super: Whether to include properties from parent classes,
        only_writable: Whether to filter for writable properties.
        only_stored: Whether to filter for stored properties.
        only_bindable: Whether to filter for bindable properties.
        only_designable: Whether to filter for designable properties.
        only_final: Whether to filter for final properties.
        only_required: Whether to filter for required properties.
        only_enum_type: Whether to filter for Enum type properties.
        only_flag_type: Whether to filter for Flag_type properties.
        only_with_notifiers: Whether to filter for properties with notifier.
        only_with_type_name: Only include properties with given give name as type.
    """
    start = 0 if include_super else self.item.propertyOffset()
    count = self.item.propertyCount()
    prop_list = []
    for i in range(start, count):
        prop = self.item.property(i)
        if (
            (only_writable and not prop.isWritable())
            or (only_stored and not prop.isStored())
            or (only_bindable and not prop.isBindable())
            or (only_designable and not prop.isDesignable())
            or (only_final and not prop.isFinal())
            or (only_required and not prop.isRequired())
            or (only_enum_type and not prop.isEnumType())
            or (only_flag_type and not prop.isFlagType())
            or (only_with_notifiers and not prop.hasNotifier())
            or (only_with_type_name and prop.typeName() != only_with_type_name)
        ):
            continue
        prop_list.append(core.MetaProperty(prop))
    return prop_list

get_property(index: int | str) -> core.MetaProperty

Get MetaProperty based on index or name.

Only returns non-dynamic properties.

Parameters:

Name Type Description Default
index int | str

index or property name

required
Source code in prettyqt\core\metaobject.py
def get_property(self, index: int | str) -> core.MetaProperty:
    """Get MetaProperty based on index or name.

    Only returns non-dynamic properties.

    Arguments:
        index: index or property name
    """
    if isinstance(index, int):
        prop = core.MetaProperty(self.item.property(index))
        if not prop.isValid():
            raise KeyError(index)
        return prop
    for prop in self.get_properties():
        if prop.get_name() in [index, helpers.to_lower_camel(index)]:
            return prop
    raise KeyError(index)

get_property_class_affiliations() -> dict[str, list[core.MetaProperty]]

Get a mapping of class -> property affiliations.

Source code in prettyqt\core\metaobject.py
def get_property_class_affiliations(self) -> dict[str, list[core.MetaProperty]]:
    """Get a mapping of class -> property affiliations."""
    mapper = {}
    metaclass = self
    while metaclass is not None:
        mapper[metaclass.get_name()] = [
            metaclass.get_property(i)
            for i in range(metaclass.propertyOffset(), metaclass.propertyCount())
        ]
        metaclass = metaclass.get_super_class()
    return mapper

get_property_values(qobject: core.QObject, cast_types: bool = False) -> dict[str, Any]

Get a dictionary containing all MetaProperties values from given qobject.

Parameters:

Name Type Description Default
qobject QObject

QObject to get properties from

required
cast_types bool

Whether to cast types to PrettyQt classes.

False
Source code in prettyqt\core\metaobject.py
def get_property_values(
    self, qobject: core.QObject, cast_types: bool = False
) -> dict[str, Any]:
    """Get a dictionary containing all MetaProperties values from given qobject.

    Arguments:
        qobject: QObject to get properties from
        cast_types: Whether to cast types to PrettyQt classes.
    """
    vals = {prop.get_name(): prop.read(qobject) for prop in self.get_properties()}
    if cast_types:
        return {k: datatypes.make_serializable(v) for k, v in vals.items()}
    else:
        return vals

get_signals(include_super: bool = True, only_notifiers: bool = False) -> list[core.MetaMethod]

Get all signal MetaMethods based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include Signals from parent classes

True
only_notifiers bool

Whether to filter for property notifier signals

False
Source code in prettyqt\core\metaobject.py
def get_signals(
    self, include_super: bool = True, only_notifiers: bool = False
) -> list[core.MetaMethod]:
    """Get all signal MetaMethods based on given criteria.

    Arguments:
        include_super: Whether to include Signals from parent classes
        only_notifiers: Whether to filter for property notifier signals
    """
    if only_notifiers:
        return [  # type: ignore
            prop.get_notify_signal()
            for prop in self.get_properties(include_super)
            if prop.hasNotifySignal()
        ]
    else:
        return self.get_methods(include_super=include_super, type_filter="signal")

get_slots(include_super: bool = True) -> list[core.MetaMethod]

Get all slot MetaMethods based on given criteria.

Parameters:

Name Type Description Default
include_super bool

Whether to include Slots from parent classes

True
Source code in prettyqt\core\metaobject.py
def get_slots(self, include_super: bool = True) -> list[core.MetaMethod]:
    """Get all slot MetaMethods based on given criteria.

    Arguments:
        include_super: Whether to include Slots from parent classes
    """
    return self.get_methods(include_super=include_super, type_filter="slot")

get_super_class() -> MetaObject | None

Get SuperClass MetaObject.

Source code in prettyqt\core\metaobject.py
def get_super_class(self) -> MetaObject | None:
    """Get SuperClass MetaObject."""
    return MetaObject(klass) if (klass := self.superClass()) is not None else None

get_user_property() -> core.MetaProperty | None

Get MetaProperty marked as userprop.

Source code in prettyqt\core\metaobject.py
def get_user_property(self) -> core.MetaProperty | None:
    """Get MetaProperty marked as userprop."""
    return core.MetaProperty(p) if (p := self.userProperty()).isValid() else None

has_property(name: str)

Check if a property with given name exists.

Only checks for non-dynamic properties.

Parameters:

Name Type Description Default
name str

property name

required
Source code in prettyqt\core\metaobject.py
def has_property(self, name: str):
    """Check if a property with given name exists.

    Only checks for non-dynamic properties.

    Arguments:
        name: property name
    """
    try:
        self.get_property(name)
        return True
    except KeyError:
        return False