Re: [PyQt] Re: problem with QAbstractItemModel

2009-11-07 Thread Linos

Vicent Mas escribió:

On 2009-11-06 Baz Walter  said:


...
your implementation of QAbstractItemModel.index is going to get called
*a lot* and in many unforseen ways. 


Yes, but it is a general fact, not something that happens to my particular 
implementation, right?




i think a more sane implementation
would be something like this:

 def index(self, row, column, parent):
 if self.hasIndex(row, column, parent):
 branch = self.nodeFromIndex(parent)
 return self.createIndex(row, column, branch.childAtRow(row))
 return QModelIndex()

this fixes your immediate bug, and will probably avoid many others.



I know that my implementation is very rough, but it is intended just for 
testing purposes. Of course your workaround and other similar (like the one 
sent by Linos) fixes the problem, but they leave the main question unanswered:  
why wrong row values are passed to the index method? Is it expected? If it is 
developers are forced to include good sanity code in their index method 
implementation (as you and Linos did), but I've not seen any reference to this 
in the Qt documentation. IMHO the Qt model implementation should not allow 
wrong row values to be passed to the index method. In fact, the example in the 
'Editable Tree Model Example' section of the Qt documentation doesn't check at 
all the validity of the row argument passed to the index method 
implementation.


On the other hand the fact that my script works fine with some Qt/PyQt versions 
but fails with recent versions seems to indicate that there is a bug either in 
the Qt implemention of models or in that PyQt versions.


Vicent

PS: Baz, thanks for your code snippet
::

Share what you know, learn what you don't


Hi,
	in the qt examples from qt 4.5 documentation you can see they use this in the 
model:

http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treemodel-cpp.html

QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent)
 const
 {
 if (!hasIndex(row, column, parent))
 return QModelIndex();

 TreeItem *parentItem;

 if (!parent.isValid())
 parentItem = rootItem;
 else
 parentItem = static_cast(parent.internalPointer());

 TreeItem *childItem = parentItem->child(row);
 if (childItem)
 return createIndex(row, column, childItem);
 else
 return QModelIndex();
 }


and this in the item class.
http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treeitem-cpp.html

TreeItem *TreeItem::child(int row)
 {
 return childItems.value(row);
 }

but they can do this because QList .value method dont get an error if it is out 
of bounds.

http://doc.trolltech.com/4.5/qlist.html#value

T QList::value ( int i ) const

Returns the value at index position i in the list.

If the index i is out of bounds, the function returns a default-constructed 
value. If you are certain that the index is going to be within bounds, you can 
use at() instead, which is slightly faster.



I am using this same strategy but like i am using python list i check before if 
i can return the children, you can use a "try except" too.


Regards,
Miguel Angel.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Re: problem with QAbstractItemModel

2009-11-07 Thread Vicent Mas
On 2009-11-07 Linos  said:

> ...
> Hi,
>   in the qt examples from qt 4.5 documentation you can see they use this 
> in
>  the model:
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treemodel-cpp.html
> 
> QModelIndex TreeModel::index(int row, int column, const QModelIndex
>  &parent) const
>   {
>   if (!hasIndex(row, column, parent))
>   return QModelIndex();
> 
>   TreeItem *parentItem;
> 
>   if (!parent.isValid())
>   parentItem = rootItem;
>   else
>   parentItem = static_cast(parent.internalPointer());
> 
>   TreeItem *childItem = parentItem->child(row);
>   if (childItem)
>   return createIndex(row, column, childItem);
>   else
>   return QModelIndex();
>   }
> 

Thanks for this info. I simply didn't check this page because I was interested 
in editable models not in read-only models. Its funny to see that index method 
implementation in the read-only example is more complex than in the editable 
one.

But still, it is nearly the same workaround provided by Baz and doesn't answer 
my question about validity of the passed row argument.

> and this in the item class.
> http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treeitem-cpp.html
> 
> TreeItem *TreeItem::child(int row)
>   {
>   return childItems.value(row);
>   }
> 
> but they can do this because QList .value method dont get an error if it is
>  out of bounds.

Yes but, as you can see in the in the index method provided in that example, 
this is called *after* the row argument has been validated so it has no impact 
in my question.

Vicent
::

Share what you know, learn what you don't



signature.asc
Description: This is a digitally signed message part.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Re: problem with QAbstractItemModel

2009-11-07 Thread Vicent Mas
On 2009-11-07 Vicent Mas  said:

> On 2009-11-07 Linos  said:
> > ...
> > Hi,
> > in the qt examples from qt 4.5 documentation you can see they use this
> > in the model:
> > http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treemodel-cpp.html
> >
> > QModelIndex TreeModel::index(int row, int column, const QModelIndex
> >  &parent) const
> >   {
> >   if (!hasIndex(row, column, parent))
> >   return QModelIndex();
> >
> >   TreeItem *parentItem;
> >
> >   if (!parent.isValid())
> >   parentItem = rootItem;
> >   else
> >   parentItem = static_cast(parent.internalPointer());
> >
> >   TreeItem *childItem = parentItem->child(row);
> >   if (childItem)
> >   return createIndex(row, column, childItem);
> >   else
> >   return QModelIndex();
> >   }
> 
> Thanks for this info. I simply didn't check this page because I was
>  interested in editable models not in read-only models. Its funny to see
>  that index method implementation in the read-only example is more complex
>  than in the editable one.
> 
> But still, it is nearly the same workaround provided by Baz and doesn't
>  answer my question about validity of the passed row argument.
> 
> > and this in the item class.
> > http://doc.trolltech.com/4.5/itemviews-simpletreemodel-treeitem-cpp.html
> >
> > TreeItem *TreeItem::child(int row)
> >   {
> >   return childItems.value(row);
> >   }
> >
> > but they can do this because QList .value method dont get an error if it
> > is out of bounds.
> 
> Yes but, as you can see in the in the index method provided in that
>  example, this is called *after* the row argument has been validated so it
>  has no impact in my question.
> 

OK, finally I got it. The validity of the parent model index passed to the 
QAbstractItemModel *must* be checked. It is said explicitely in the page 
referenced by Linos:

Models must implement an index() function to provide indexes for views and 
delegates to use when accessing data. Indexes are created for other components 
when they are referenced by their row and column numbers, and their parent 
model index. If an invalid model index is specified as the parent, it is up to 
the model to return an index that corresponds to a top-level item in the 
model.

Checking the parent validity in the way suggested by Balz will check 
implicitely the row and column validity.

As I said I did read the "Editable tree model example" which doesn't do that 
checking (I don't know why) but not the "Simple tree model example" (which 
does exactly that checking) so I was puzzled.

THANKS guys for your help.

Vicent
::

Share what you know, learn what you don't



signature.asc
Description: This is a digitally signed message part.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] Regressions on destruction of objects?

2009-11-07 Thread Pierre Raybaut
FYI, with PyQt4 v4.6.1, the matplotlib's Qt4 backend is no longer usable 
interactively because the 'destroyed()' signal is not emitted when 
matplotlib's figure (QMainWindow instance) is closed (and destroyed, 
thanks to the Qt.WA_DeleteOnClose attribute). In other words, one can 
only show one figure with matplotlib/PyQt4 v4.6.1.


Is there going to be a v4.6.2 release soon with this issue fixed?

Thanks,
Cheers,
Pierre
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Regressions on destruction of objects?

2009-11-07 Thread Phil Thompson
On Sat, 07 Nov 2009 15:52:48 +0100, Pierre Raybaut 
wrote:
> FYI, with PyQt4 v4.6.1, the matplotlib's Qt4 backend is no longer usable 
> interactively because the 'destroyed()' signal is not emitted when 
> matplotlib's figure (QMainWindow instance) is closed (and destroyed, 
> thanks to the Qt.WA_DeleteOnClose attribute). In other words, one can 
> only show one figure with matplotlib/PyQt4 v4.6.1.
> 
> Is there going to be a v4.6.2 release soon with this issue fixed?

I haven't yet decided if the next release is going to be v4.6.2 or v4.7.

Phil
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] newbie questions...

2009-11-07 Thread Darren Dale
On Thu, Aug 14, 2008 at 3:59 PM, Phil Thompson
 wrote:
> On Tue, 12 Aug 2008 20:31:37 +0100, Chris Withers 
> wrote:
>> Phil Thompson wrote:
 That seems weird to put it politely. I would have thought they both had
>>
 the same interfaces?
>>>
>>> It's not a technical limitation. It is to prevent people developing a
>>> commercial product with the GPL version and then switching to the
>>> commercial version at the last minute. The PyQt commercial license has
>> the
>>> same restriction. In reality we would be open to discussion (usually
>>> involving backdating the purchase of the commercial licenses).
>>
>> Heh, I'd *love* to see this one come to court ;-)
>> Seriously, I'm all for licensing that sees companies rewarded for their
>> hard work, but I'd be seriously interested in how this would be argued
>> in court...
>>
>> Thankfully all the stuff I'm developing is open source, so I don't have
>> that problem :-)
>>
 Anyway, some questions:

 - where do I get the Qt Designer from?
>>>
>>> It's part of Qt.
>>
>> Is this Qt for Java or Qt for C++? Which one do I install?
>
> Certainly Qt for C++, probably both.
>
 - how come PyQt4 isn't on PyPI? (Nowadays I'm used to just specifying
 packages as egg requirements in a buildout.cfg
 (http://buildout.zope.org/) but I guess I can't do that with PyQt4?)
>>>
>>> PyPI is a PIA to use when you are not using eggs.
>>
>> Okay, let me rephrase: how come PyQt4 isn't available as an egg?
>> (for the record, I hate eggs, but the python community has adopted them,
>> so I'm just attempting to put up and shut up. zc.buildout does offer
>> some analgesic for the agony)
>
> It's never seemed important.

I distribute a GPL package that depends on PyQt4 and PyMca, and the
latter depends on PyQwt. PyQwt has had a hard time keeping abreast of
recent changes in sip/PyQt4. This causes problems for my users when,
for example, ubuntu upgrades their version of sip/PyQt4 and breaks
pyqwt in their own package manager.

It might be useful if packages like sip/PyQt and PyQwt used the
standard python distribution utilities. For example, if distutils were
used to create source distributions and installers that were then
posted at PyPI, it would be possible to use pip/easy_install to
install the whole stack with a single command. The utilities in
Distribute/setuptools/PEP-390 could be used to specify version
requirements. I could specify that my package depends on
>=pyqwt-5.2.0, pyqwt-5.2.0 would specify its own dependencies, and so
on. My understanding is that multiversion support with eggs would help
prevent version incompatibilities, but I don't have practical
experience.

> I'm also not sure that distutils is up to the job of building PyQt.

Yes, that could undermine the whole approach.

Darren
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] QGraphicsView rubberband traces

2009-11-07 Thread Ahmet Emre Aladağ
Hi All,

I see leftover (rectangle) footprints/traces when I use rubberband as
dragmode to make a selection on GraphicsView. There are lots of rectangles
and they don't disappear as I enlarge my selection. Just like re-painting
doesn't work. When I move another item over those leftovers, they are
removed like the item is a eraser.

This happens only on Linux dists (Pardus+PyQT 4.5.2 and Kubuntu+PyQt 4.6.1).
There's no problem with Windows XP+PyQt 4.6.1. Also it's not special to my
laptop. My friends had the same issue on theirs.

The example program I'm using is: http://pastebin.com/m5ae3c97f and same
thing also happens on simpler apps.
Screenshot: http://img43.imageshack.us/img43/5260/rubberband.png

By the way, there's no problem when I write a program with rubberband in C++
and QT.

Any ideas about what the reason might be?


-- 
Ahmet Emre Aladağ
http://www.emrealadag.com
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

[PyQt] cleaning up after removing items from layout

2009-11-07 Thread Lee Harr

I have a fairly complex layout created with Qt Designer.

In one area, there is a QVBoxLayout which I fill up with
items at runtime. It works fine, resizes nicely, looks good.

The problem is that at some point I want to remove all of
those items and fill it up again with all new items.

The new items that get put in work fine also, and as long
as the window never gets resized it looks good. But as
soon as the window size changes, I can see that the old
items are still there somehow.


The code I'm using to clear out the layout looks something
like this:

while layout.count():
    item = layout.itemAt(0)
    layout.removeItem(item)


The items are actually QHBoxLayouts with several things
inside of them. I can't call item.destroy() because they
don't have a destroy method.

I tried manually creating a destroy method that goes
through and destroys everything in the item, but that
is not doing the trick either.


How can I make sure that the items get completely
destroyed, all the way down to everything that is
contained?

  
_
Windows Live: Keep your friends up to date with what you do online.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092010
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


RE: [PyQt] cleaning up after removing items from layout

2009-11-07 Thread Lee Harr

 
Content-Type: text/plain; charset="windows-1256"
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0


> Could you post the whole code in py file?

The actual code is here:

http://code.google.com/p/pybotwar/source/browse/qt4view.py


The item that is getting added is the class at line 362.

And the method that tries to remove the original items
is at line 172.




I also made a small example of the problem...

repop.ui is a QMainWindow made with Qt Designer that has
a VBoxLayout laid out with a horizontal spacer horizontally
then laid out with a vertical spacer vertically.

It does not show exactly the same behavior. When this is run,
you can see a blotch where all of the items get written over
one another the 2nd time through.





# repop.py

import os
import sys

from PyQt4 import QtCore, QtGui, uic, QtSvg
from PyQt4.Qt import QHBoxLayout

uidir = 'data/ui'


class RP(QtGui.QMainWindow):
    def __init__(self):
    QtGui.QMainWindow.__init__(self)
    uifile = 'repop.ui'
    uipath = os.path.join(uidir, uifile)
    RPClass, _ = uic.loadUiType(uipath)
    self.ui = RPClass()
    self.ui.setupUi(self)

    self.pop()
    self.repop()

    def pop(self):
    for n in range(10):
    ri = RI(str(n))
    self.ui.vl.addLayout(ri)

    def repop(self):
    vl = self.ui.vl
    while vl.count():
    item = vl.itemAt(0)
    vl.removeItem(item)

    self.pop()


class RI(QtGui.QHBoxLayout):
    def __init__(self, name, rend=None):
    QtGui.QHBoxLayout.__init__(self)

    vl = QtGui.QVBoxLayout()
    nm = QtGui.QLabel(name)
    vl.addWidget(nm)

    self.addLayout(vl)



if __name__ == '__main__':
    app = QtGui.QApplication(sys.argv)
    rp = RP()
    rp.show()
    app.exec_()

# end


Thanks for any suggestions.

  
_
Windows Live: Friends get your Flickr, Yelp, and Digg updates when they e-mail 
you.
http://www.microsoft.com/middleeast/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_3:092010
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt