[PyQt] Odd sorting behaviour in QSortProxyModel

2012-01-10 Thread David Townshend
Hi

I've found something rather odd that happens when sorting in a
QSortFilterProxyModel with datetime.date datatypes.  If I call sort()
on a column containing datetime.date values, it doesn't appear to do
anything.  If I then call sort on another column, then on the first
column again, it works.  I am using python 3.2 and PyQt 4.8.3 on
Windows XP. I haven't tried this on any other platform.  Does anyone
else get this behaviour?

The following code shows illustrates the problem:

from datetime import date
from PyQt4.QtCore import QAbstractTableModel, Qt, QDate
from PyQt4.QtGui import QSortFilterProxyModel

class Model(QAbstractTableModel):

    def rowCount(self, parent=None):
        return 4

    def columnCount(self, parent=None):
        return 2

    def data(self, index, role):
        if role != Qt.DisplayRole:
            return super().data(index, role)
        values = [(11, date(2011, 1, 1)),
                  (10, date(2010, 1, 1)),
                  (14, date(2014, 1, 1)),
                  (5, date(2005, 1, 1))]
        return values[index.row()][index.column()]

model = Model()
sortModel = QSortFilterProxyModel()
sortModel.setSourceModel(model)

col = 1

print("These should be sorted, but aren't")
sortModel.sort(col)
for row in range(4):
    print(sortModel.data(sortModel.index(row, col), Qt.DisplayRole))

print("Now they are sorted")
sortModel.sort(0)
sortModel.sort(col)
for row in range(4):
    print(sortModel.data(sortModel.index(row, col), Qt.DisplayRole))
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Override QStyledItemDelegate.initStyleOption not working?

2012-01-10 Thread Andreas Pakulat
On 10.01.12 21:19:18, Andreas Pakulat wrote:
> On 10.01.12 10:19:13, Phil Thompson wrote:
> > On Tue, 10 Jan 2012 00:11:49 +0100, Andreas Pakulat  wrote:
> > > Hi,
> > > 
> > > I'd like to customize the display of a model via a styleditemdelegate,
> > > in particular I want to add a decorating icon depending on some custom
> > > role from the model.
> > > 
> > > As far as I can see the easiest way to do this would be overriding
> > > initStyleOption since then I can set the icon and icon-size directly on
> > > the option and leave the rest to the standard paint etc. methods.
> > > 
> > > Unfortunately it seems this does not work in PyQt, the code is executed
> > > properly but the icon does not show up in the itemview. Since the
> > > function in C++ takes a pointer to the option-parameter I wonder wether
> > > this is simply not possible with PyQt or wether I need to go hunting for
> > > the bug elsewhere?
> > > 
> > > Using Qt 4.7.4, sip 4.13  and PyQt 4.8.6
> > 
> > Are you keeping a reference to the option - if not see if this makes a
> > difference.
> 
> Unfortunately no, I've written up a small example for what I'm trying to
> do and attached it.
> 
> I've also tried overriding paint(), calling initStyleOption there, then
> calling the parent paint() function and the icon is set on the option
> parameter in between, but the icon is not painted in the gui...

On that note, overriding the sizeHint() function of QStyledItemDelegate
also does not seem to work. Its never called.

Andreas

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


Re: [PyQt] Gesture programming in PyQt

2012-01-10 Thread Phil Thompson
On Tue, 10 Jan 2012 19:28:09 +0100, Detlev Offenbach
 wrote:
> Am Montag, 9. Januar 2012, 22:17:45 schrieb Phil Thompson:
>> On Mon, 09 Jan 2012 19:11:18 +0100, Detlev Offenbach
>> 
>>  wrote:
>> > Am Montag, 9. Januar 2012, 09:58:39 schrieb Phil Thompson:
>> >> On Sun, 08 Jan 2012 18:05:52 +0100, Detlev Offenbach
>> >> 
>> >>  wrote:
>> >> > Am Samstag, 7. Januar 2012, 18:31:16 schrieb Phil Thompson:
>> >> >> On Sat, 7 Jan 2012 15:33:08 +0100, Detlev Offenbach
>> >> >> 
>> >> >>  wrote:
>> >> >> > Hi Phil,
>> >> >> > 
>> >> >> > can you test my little test script on your side? I tried it
>> >> >> > over
>> >> >> > here
>> >> >> 
>> >> >> with
>> >> >> 
>> >> >> > Python 3.2.2, Qt 4.7.4 and latest released sip/PyQt.
>> >> >> 
>> >> >> What is it supposed to do?
>> >> >> 
>> >> >> Phil
>> >> > 
>> >> > I used it to get some know how in gesture programming. The custom
>> >> 
>> >> gesture
>> >> 
>> >> > should register swipes using the touchpad of e.g. a MacBook. I
>> 
>> couldn't
>> 
>> >> > get it
>> >> > working because it crashed when the custome gesture recognizer is
>> >> > registered.
>> >> > The script itself doesn't do anything useful except printing some
>> 
>> info
>> 
>> >> > about
>> >> > the gesture being handled.
>> >> 
>> >> So what do I have to do to test it?
>> > 
>> > Just start it and perform some swipes on the touchpad. As I said, for
>> > me
>> > it
>> > even failed starting up.
>> 
>> What touchpad?
> 
> E.g. the touchpad of a MacBook.

I know ;), but if you could see my development environment you would
notice a complete absence of touchpads.

>> For me it starts up and displays the "Testing Gestures" text. I quit it
>> with the close button.
> 
> That means, I have to check my installation. What versions did you test
it 
> with (Qt, PyQt4)?

Current snapshots (including the fix to QGestureRecognizer.create()) and
Qt v4.8.

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


Re: [PyQt] Gesture programming in PyQt

2012-01-10 Thread Detlev Offenbach
Am Montag, 9. Januar 2012, 22:17:45 schrieb Phil Thompson:
> On Mon, 09 Jan 2012 19:11:18 +0100, Detlev Offenbach
> 
>  wrote:
> > Am Montag, 9. Januar 2012, 09:58:39 schrieb Phil Thompson:
> >> On Sun, 08 Jan 2012 18:05:52 +0100, Detlev Offenbach
> >> 
> >>  wrote:
> >> > Am Samstag, 7. Januar 2012, 18:31:16 schrieb Phil Thompson:
> >> >> On Sat, 7 Jan 2012 15:33:08 +0100, Detlev Offenbach
> >> >> 
> >> >>  wrote:
> >> >> > Hi Phil,
> >> >> > 
> >> >> > can you test my little test script on your side? I tried it
> >> >> > over
> >> >> > here
> >> >> 
> >> >> with
> >> >> 
> >> >> > Python 3.2.2, Qt 4.7.4 and latest released sip/PyQt.
> >> >> 
> >> >> What is it supposed to do?
> >> >> 
> >> >> Phil
> >> > 
> >> > I used it to get some know how in gesture programming. The custom
> >> 
> >> gesture
> >> 
> >> > should register swipes using the touchpad of e.g. a MacBook. I
> 
> couldn't
> 
> >> > get it
> >> > working because it crashed when the custome gesture recognizer is
> >> > registered.
> >> > The script itself doesn't do anything useful except printing some
> 
> info
> 
> >> > about
> >> > the gesture being handled.
> >> 
> >> So what do I have to do to test it?
> > 
> > Just start it and perform some swipes on the touchpad. As I said, for me
> > it
> > even failed starting up.
> 
> What touchpad?

E.g. the touchpad of a MacBook.

> 
> For me it starts up and displays the "Testing Gestures" text. I quit it
> with the close button.

That means, I have to check my installation. What versions did you test it 
with (Qt, PyQt4)?

Regards,
Detlev
-- 
Detlev Offenbach
det...@die-offenbachs.de
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


Re: [PyQt] Override QStyledItemDelegate.initStyleOption not working?

2012-01-10 Thread Phil Thompson
On Tue, 10 Jan 2012 00:11:49 +0100, Andreas Pakulat  wrote:
> Hi,
> 
> I'd like to customize the display of a model via a styleditemdelegate,
> in particular I want to add a decorating icon depending on some custom
> role from the model.
> 
> As far as I can see the easiest way to do this would be overriding
> initStyleOption since then I can set the icon and icon-size directly on
> the option and leave the rest to the standard paint etc. methods.
> 
> Unfortunately it seems this does not work in PyQt, the code is executed
> properly but the icon does not show up in the itemview. Since the
> function in C++ takes a pointer to the option-parameter I wonder wether
> this is simply not possible with PyQt or wether I need to go hunting for
> the bug elsewhere?
> 
> Using Qt 4.7.4, sip 4.13  and PyQt 4.8.6

Are you keeping a reference to the option - if not see if this makes a
difference.

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


Re: [PyQt] QWebkit / QWebFrame

2012-01-10 Thread Andreas Pakulat
On 09.01.12 16:30:43, James Polk wrote:
> Howdy,
> 
> I believe Guru Hans-Peter ;-) posted a collection of PyQt examples that
> he converted into Python from the Qt C++ examples..
> 
> In one titled "fancybrowser.py"
> 
> 
> There's a few lines that read...
> 
> 
>         @QtCore.pyqtSlot()
>         def submit(self):
>             frame = self.ui.webView.page().mainFrame()
> 
> then
> 
> 
>             firstName    = frame.findFirstElement("#firstname")
> 
> 
> It appears that the function "findFirstElement()" appeared in a version of Qt
> that came along after the one I'm on (4.5.3)
> 
> 1) Can anyone suggest a code workaround that would accomplish same 
> 
>     that will work in 4.5.3 rather than 4.7 or 4.8 (whenever that appeared)

The function was added in 4.6 along with the rest of the API to access
the webpage elements. There's no way to access the DOM tree with older
Qt versions, except loading the website into QDom (provided its
complying with the XML standard) or loading it into another Webkit-based
browser that does allow to access the DOM Api in whatever version you
have available.

> 2) Secondly,...as an alternative, one that I hesitate to try,...is it 
> possible for two
>     versions of Qt (and I guess two versions of PyQt and Sip) to exist 
> simultaneously?
>     Using one version for *this* and another version for *that* ?

Not in the same application. You'll probably need something like
virtualenv to properly separate both PyQt/sip installations and it
probably also won't work with a system-installed PyQt/sip on Linux (i.e.
distribution packages).

Andreas

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