[prev in list] [next in list] [prev in thread] [next in thread]
List: pykde
Subject: Re: [PyKDE] Speed of derived objects
From: Jim Bublitz <jbublitz () nwinternet ! com>
Date: 2002-11-26 1:47:22
[Download RAW message or body]
On 25-Nov-02 Vincent Wagelaar wrote:
> On Monday 25 November 2002 22:44, Hans-Peter Jansen wrote:
>
> [snip]
> Hopefully this example is nice enough? I think this is problably
> one of the few cases where you need to make an C++ implementation
> because of speed. It would be nice if calling (overloaded)
> methods in the next version of Python would be speedier!! On my
> computer it's about ten times slower than directly calling
> QListViewItem in both populating the listview and sorting.
Phil might disagree, but I don't think there are major speed
improvements available for the bindings.
You're doing a lot of essentially invariant stuff in the paintCell
and key methods however. Try something like:
from qt import QListViewItem, QColorGroup, QColor
Green = QColor (0, 155, 0)
Red = QColor (200, 0, 0)
Orange = QColor (255, 100, 0)
class ColorListItem(QListViewItem):
def __init__(self, *args):
QListViewItem.__init__(self, *args)
# this gives you a QColorGroup with everything
# set to black, so you probably need to expand
# this a little - could get tricky if you plan
# to allow user changes in colors. I didn't see
# any way to extract the color group info from
# QListViewItem, but I didn't look very hard
# either.
self.colorGroup = QColorGroup ()
# might not need to do these - I think
# they're correct, but might not be much
# faster
self.ptCell = QListViewItem.paintCell
self.keyCall = QListViewItem.key
try:
self.pstr = float (str (self.text (0)))
except:
self.pstr = 0
self.keyVal = "%015d" % (self.pstr*100+100000)
if self.pstr == 0:
color = Orange
elif self.pstr > 0:
color = Green
else:
color = Red
self.colorGroup.setColor (QColorGroup.Text, color)
def paintCell (self, painter, qg, column, width, align):
if column == 0:
self.ptCell (self, painter, self.colorGroup,\
column, width, align)
else:
self.ptCell (self, painter, qg, column,\
width, align)
def key (self, column, asc):
if column == 0:
return self.kevVal
else:
return self.keyCall(self, column, asc)
I haven't tested this, but the basic idea should give you some
speed improvement - hard to say how much. If the values for the
QListViewItems can be changed, you'll need to break the stuff in
__init__ into a separate method and "re-calculate" when the value
changes (overload setText?). You also probably need a more involved
setup for self.colorGroup (different ctor?), but you should only do
that once. You could also do self.colorGroup as 3 different globals
- one for each condition - but that'll make it harder to customize
colors.
Jim
_______________________________________________
PyKDE mailing list PyKDE@mats.gmd.de
http://mats.gmd.de/mailman/listinfo/pykde
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic