qt_binder.binder

class qt_binder.binder.Binder(*args, **traits)[source]

Bases: traits.has_traits.HasStrictTraits

Traited proxy for a QObject class.

The default proxy traits will be automatically assigned by inspecting the Qt class specified in the qclass class attribute. Since this inspection process can be time consuming, compared to normal class construction, this will only be done the first time the Binder class is instantiated.

For those traits that proxy a Qt Signal (or property that has a Signal), the Qt signal connection will only be made once a Traits listener is attached to the proxy trait.

The qobj can only be assigned once in the Binder's lifetime.

qclass

The QObject class that is going to be wrapped by this class.

qobj = Instance(QtCore.QObject)

The Qt object instance that is wrapped by the Binder instance.

loopback_guard = Instance(LoopbackGuard, args=())

The loopback guard.

id = Str()

An ID string, if any. It should be a valid Python identifier.

construct(*args, **kwds)[source]

Default constructor that will automatically instantiate qclass.

configure()[source]

Do any configuration of the qobj that is needed.

dispose()[source]

Remove any connections and otherwise clean up for disposal.

This does not mark any Qt objects for deletion.


class qt_binder.binder.Composite(*args, **traits)[source]

Bases: qt_binder.binder.Binder

Base class for Binders that hold other Binders as children.

Their QObjects may or may not have a similar parent-child relationship. The Composite is responsible for constructing its children, configuring them, and disposing of them.

child_binders = Property(List(Instance(Binder)))

The child Binder instances. This will typically be a Property returning a list of Binders that are attributes.

configure()[source]

Do any configuration of the qobj that is needed.

dispose()[source]

Remove any connections and otherwise clean up for disposal.

This does not mark any Qt objects for deletion.


class qt_binder.binder.NChildren(*args, **traits)[source]

Bases: qt_binder.binder.Composite

Base class for Composite Binders that have arbitrary unnamed children.

child_binders = List(Instance(Binder))

Any children. It will be filtered for Binders.


class qt_binder.binder.QtTrait(*args, **metadata)[source]

Bases: traits.trait_handlers.TraitType

Base class for Qt proxy traits on Binder classes.

Each subclass should override get() and set(). All QtTrait subclasses are property-like traits.

If there is a Qt Signal that should be connected to to propagate notifications, assign it to the signal attribute. The Qt Signal will only be connected to when a Traits listener is attached to this trait.

get(object, name)[source]

Get the value of this trait.

set(object, name, value)[source]

Set the value of this trait and notify listeners.

connect_signal(object, name)[source]

Connect to the Qt signal, if any.

disconnect_signal(object, name)[source]

Disconnect from the Qt signal, if any.


class qt_binder.binder.QtProperty(meta_prop, **metadata)[source]

Bases: qt_binder.binder.QtTrait

Proxy trait for a Qt static property.

Pass in a QMetaProperty from the QMetaObject.

get(object, name)[source]

Get the value of this trait.

set(object, name, value)[source]

Set the value of this trait and notify listeners.

If there is a Qt Signal for this property, it will notify the listeners. If there is not one for this property, this method will explicitly send a notification.


class qt_binder.binder.QtDynamicProperty(default_value=None, **metadata)[source]

Bases: qt_binder.binder.QtTrait

A Qt dynamic property added to the QObject.

The dynamic property will be created on the QObject when it is added to the Binder. The default value given to this trait will be the initial value. It should be an object that can be passed to QVariant.

Because most dynamic properties will be added this way to support Qt stylesheets, by default when the property is assigned a new value, the QObject associated with the Binder (which should be a QWidget) will be made to redraw itself in order to reevaluate the stylesheet rules with the new value. Turn this off by passing styled=False to the constructor.

get(object, name)[source]

Get the value of this trait.

set(object, name, value)[source]

Set the value of this trait and notify listeners.


class qt_binder.binder.QtGetterSetter(getter_name, setter_name=None, **metadata)[source]

Bases: qt_binder.binder.QtTrait

Proxy for a getter/setter pair of methods.

This is used for value()/setValue() pairs of methods that are frequently found in Qt, but which are not bona fide Qt properties.

If the names follow this convention, you only need to pass the name of the getter method. Otherwise, pass both.

get(object, name)[source]

Get the value of this trait.

set(object, name, value)[source]

Set the value of this trait and notify listeners.


class qt_binder.binder.QtSlot(meta_method, **metadata)[source]

Bases: qt_binder.binder.QtTrait

Proxy for a Qt slot method.

In general use, this trait will only be assigned to. If the slot takes no arguments, the value assigned is ignored. If the slot takes one argument, the value assigned is passed to the slot. If the slot takes more than one argument, the value assigned should be a tuple of the right size.

As a convenience, getting the value of this trait will return the slot method object itself to allow you to connect to it using the normal Qt mechanism.

The constructor should be passed the QMetaMethod for this slot.

get(object, name)[source]

Get the underlying method object.

set(object, name, value)[source]

Set the value of this trait.

See QtSlot for details on how the value is processed.


class qt_binder.binder.QtSignal(meta_method, **metadata)[source]

Bases: qt_binder.binder.QtSlot

Proxy for a Qt signal method.

In general use, this trait will only be listened to for events that are emitted internally from Qt. However, it can be assigned values, with the same argument semantics as QtSlot. Like QtSlot, getting the value of this trait will return the signal method object itself for you to connect to it using the normal Qt mechanism.

The constructor should be passed the QMetaMethod for this signal.

set(object, name, value)[source]

Emit the signal with the given value.

See QtSlot for details on how the value is processed.


class qt_binder.binder.Default(value)[source]

Bases: object

Specify a default value for an automatic QtTrait.


class qt_binder.binder.Rename(qt_name, default=<undefined>)[source]

Bases: object

Specify that an automatic QtTrait be renamed.

Use at the class level of a Binder to rename the trait to something else.

For QtSlot traits with multiple signatures, only the primary part of the name (without the mangled type signature) needs to be given.

Since one cannot use both a Default and Rename at the same time, one can also specify the default value here.

Previous topic

API Reference

Next topic

qt_binder.binding

This Page