[PyQt] observing attributes in dip
Phil Thompson
phil at riverbankcomputing.com
Wed Jul 13 19:27:25 BST 2011
On Wed, 13 Jul 2011 11:32:11 -0400, Lic. José M. Rodriguez Bacallao
<jmrbcu at gmail.com> wrote:
> 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
Either use...
@observe('IWidget.name')
def some_other_name(self, c):
...or (my preference)...
@IWidget.name.observer
def name(self, c):
Phil
More information about the PyQt
mailing list