[PyKDE] Python list handling for QRect, QPoint, and QSize
Hans-Peter Jansen
hpj at urpla.net
Mon Nov 4 20:39:00 GMT 2002
On Monday 04 November 2002 19:57, Phil Thompson wrote:
> On Monday 04 November 2002 6:36 pm, Hans-Peter Jansen wrote:
> > Hi Phil,
> >
> > since I catched the flu this weekend, I think of contributing something
> > useful to PyQt. Namely the IMHO missing handling of python lists, where
> > QRect, QPoint, and QSize objects are expected. (QColor?)
>
> I'm not sure I understand. Are you saying that you want to pass a list of
> (say) x and y coordinates wherever a QPoint was expected? (Wouldn't a tuple
> be better?)
Exactly. Why not support both.
Imagine a typical situation: restore position and size of an app:
(tuple or list doesn't matter much here)
wh = self.cfg.mainScreenSize
if wh:
self.resize(wh[0], wh[1])
xy = self.cfg.mainScreenLocation
if xy:
self.move(xy[0], xy[1])
would then read:
if self.cfg.mainScreenSize:
self.resize(self.cfg.mainScreenSize)
if self.cfg.mainScreenLocation:
self.move(self.cfg.mainScreenLocation)
Do you like this idea?
> Or are you saying that you want to make QPoint behave a bit like a list?
Not really. Sorry for being too vague.
> > On my first cursory look, there seem to be to ways, but I don't know
> > their implications:
> >
> > 1) implement __len__(), __getitem__() like in qstringlist.sip
> > 2) %MappedType Qxyz<QInt>, like in qvaluelist.sip
> >
> > Q1) Why is __setitem__ missing from 1
>
> Because I'm lazy and nobody has complained.
Fair enough.
> > Q2) Does method 2 provide transparent conversion from and to the correct
> > types, whereever they're used? (e.g. QObject)
>
> Yes.
>
> Phil
Hans-Peter
More information about the PyQt
mailing list