On Tuesday 20 April 2010 04:25:01 pm Matti Airas wrote:
> On 20.04.2010 17:43, ext Mark Summerfield wrote:
> > Seems good to me. However, there needs to be a decision about whether to
> > provide the QVariant(type, object) factory function or static
> > QVariant.type() methods. I prefer the factory function.
>
> Oops, should've read more carefully. *blushes*
>
> > Also, I should have written them my Pythonically (rather than like
> >
> > C++!):
> > # static functions approach
> > QVariant.ushort(pythonObject) -> QVariant
> > QVariant.uint(pythonObject) -> QVariant
> >
> > # factory function approach (based on Richard Dale's ideas)
> > QVariant("ushort", pythonObject) -> QVariant
> > QVariant("uint", pythonObject) -> QVariant
>
> Applied this.
>
> I have to say I still prefer the former approach. It gives a fighting
> chance to syntactic checkers (as in IDEs) to detect typos and other
> errors. Also, since the underlying Qt QVariant only accepts a limited
> number of types and probably won't change too much (if at all), the
> increased versatility would be kinda wasted (if I have understood
> correctly).
>
> Furthermore, static functions is the method PyQt already uses, and if
> there are no significant advantages in either syntax, I think we ought
> to pick the more comformant one. I'd even go as far to change the
> function names as follows:
>
> QVariant.fromUInt(pythonObject) -> QVariant
>
> It's a bit uglier but that's the syntax PyQt already uses and the names
> would be identical to QVariant.Type constants.
>
> But then again, I'm hardly experienced enough on PyQt/PySide programming
> to have strong opinions about this one.
You can extend QVariants with the Qt metatype system to wrap previously
unknown types, and so if you wanted that to work, then maybe types as strings
would be easier to make extensible, instead of hard coded method names.
Although I suppose you can use meta programming to trap unknown method callls
on the QVariant class, and then assume they were type names.
I did start some of this discussion when I was talking about the problem with
QtDBus serialization that i'd had with QtRuby where we needed to force a
particular C++ type to be in a QVariant like a 'ushort'. I still can't
remember if there is anywhere else in the Qt api where you need to do it. If
there isn't, maybe it is best to design how to make QtDBus calls look most
Pythonic, as opposed to thinking about QVariants.
-- Richard
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside