[PyQt] help with dip and PyQt4 widgets

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Fri Jul 8 18:19:22 BST 2011


but the view will need to be pure pyqt, not dip?

On Fri, Jul 8, 2011 at 1:13 PM, Darren Dale <dsdale24 at gmail.com> wrote:
> Have you considered trying to decouple your model and view, as
> described throughout the documentation?
>
> On Fri, Jul 8, 2011 at 1:04 PM, Lic. José M. Rodriguez Bacallao
> <jmrbcu at gmail.com> wrote:
>> yes, I know, I read that in the docs, but, how to do something similar
>> to what I want to achieve?
>>
>> On Fri, Jul 8, 2011 at 12:20 PM, Lic. José M. Rodriguez Bacallao
>> <jmrbcu at gmail.com> wrote:
>>> I tried that before and still getting the same error. I thinks is
>>> something like the C++ part of the widget is not created at the time
>>> when the properties methods are called to set my initial values as
>>> this  happen before __init__ is called.
>>>
>>> On Fri, Jul 8, 2011 at 12:05 PM, Demetrius Cassidy <dcassidy36 at gmail.com> wrote:
>>>> You need to call QToolButton's __init__() method.
>>>>
>>>> class Indicator(QtGui.QToolButton, Model):
>>>>     def __init__(self)
>>>>        super(Indicator, self).__init__()
>>>> On Fri, Jul 8, 2011 at 1:49 PM, Lic. José M. Rodriguez Bacallao
>>>> <jmrbcu at gmail.com> wrote:
>>>>>
>>>>> hi folks, I am creating a composite widget with PyQt4 and Dip, the
>>>>> problem I have is that when I use dip properties for setting PyQt4
>>>>> properties in the constructor I am getting an error saying that the
>>>>> underlying C++ object has been delete, I think this is due to the way
>>>>> dip works because it call properties methods before the actual Qt4
>>>>> widget as been created when I pass an initial value in the
>>>>> constructor. When I construct the object with properties initial
>>>>> values and the use the properties accesors to set the value, this
>>>>> doens't happen. So, my question is, which is the right way to
>>>>> construct a custom composite widget with dip?
>>>>>
>>>>> # dip imports
>>>>> from dip.model import Model, Instance, Str
>>>>>
>>>>> # PyQt4 imports
>>>>> from PyQt4 import QtCore, QtGui
>>>>>
>>>>> class Indicator(QtGui.QToolButton, Model):
>>>>>
>>>>>    # the indicator identifier, it must be unique for all indicators
>>>>>    id = Str()
>>>>>
>>>>>    # the indicator text, this text will be shown
>>>>>    # beside the icon if one is defined
>>>>>    text = Str()
>>>>>
>>>>>    # the indicator tooltip
>>>>>    tooltip = Str()
>>>>>
>>>>>    # the indicator icon
>>>>>    icon = Instance(QtGui.QIcon)
>>>>>
>>>>>    @id.getter
>>>>>    def id(self):
>>>>>        print 'getting value'
>>>>>        return self.objectName()
>>>>>
>>>>>    @id.setter
>>>>>    def id(self, id):
>>>>>        print 'setting value'
>>>>>        self.setObjectName(id)
>>>>>
>>>>>    @text.getter
>>>>>    def text(self):
>>>>>        return self.text()
>>>>>
>>>>>    @text.setter
>>>>>    def text(self, text):
>>>>>        self.setText(text)
>>>>>
>>>>>    @tooltip.getter
>>>>>    def tooltip(self):
>>>>>        return self.toolTip()
>>>>>
>>>>>    @tooltip.setter
>>>>>    def tooltip(self, tooltip):
>>>>>        self.setToolTip(tooltip)
>>>>>
>>>>>    @icon.getter
>>>>>    def icon(self):
>>>>>        return self.icon()
>>>>>
>>>>>    @icon.setter
>>>>>    def icon(self, icon):
>>>>>        self.icon = icon
>>>>>
>>>>>    def perform(self):
>>>>>        raise NotImplementedError
>>>>>
>>>>> if __name__ == '__main__':
>>>>>    app = QtGui.QApplication([])
>>>>>
>>>>>    i = Indicator(text='xxx')
>>>>>    i.show()
>>>>>
>>>>>    app.exec_()
>>>>>
>>>>> --
>>>>> 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
>>>>> -----------------------------------------------------------------
>>>>> _______________________________________________
>>>>> PyQt mailing list    PyQt at riverbankcomputing.com
>>>>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>>>
>>>
>>>
>>>
>>> --
>>> 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
>>> -----------------------------------------------------------------
>>>
>>
>>
>>
>> --
>> 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
>> -----------------------------------------------------------------
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>



-- 
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