[PyQt] observing attributes in dip

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Wed Jul 13 16:32:11 BST 2011


why this doesn't work?

--------- i_widget.py ---------

# dip imports
from dip.model import Str, Instance

# PyQt4 imports
from PyQt4 import QtGui

# imagis imports
from i_action_container import IActionContainer

class IWidget(IActionContainer):

    # the identifier of the widget
    id = Str()

    # the name of the widget
    name = Str()

    # The PyQt4.QtGui.QWidget instance that implements the widget.
    widget = Instance(QtGui.QWidget)

    # The parent of the internal widget.
    parent = Instance(QtGui.QWidget)

----- widget.py --------

# dip imports
from dip.model import Model, implements, observe

# imagis imports
from i_widget import IWidget
import PyQt4

@implements(IWidget)
class Widget(Model):
    """ Base class for all ui widgets that can manage an internal
    PyQt4.QtCore.QWidget.
    """

    @observe('IWidget.name')
    def name(self, c):
        print 'changing: ', c.new


    @IWidget.widget.default
    def widget(self):
        return QtGui.QWidget()

if __name__ == '__main__':
    from dip.model import Instance, Str
    from PyQt4 import QtGui

    class W(Widget):

        id = 'example.id'
        name = Str('text')

    app = QtGui.QApplication([])
    w = W()
    w.name = 'xxx'
    w.widget.show()
    app.exec_()

the observer is never called

-- 
Lic. José M. Rodriguez Bacallao
Centro de Biofisica Medica
-----------------------------------------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.

Recuerda: El arca de Noe fue construida por aficionados, el titanic
por profesionales
-----------------------------------------------------------------


More information about the PyQt mailing list