[PySide] complicated dictionaries
Aaron Richiger
a.richi at bluewin.ch
Thu Apr 25 01:40:37 CEST 2013
Am 25.04.2013 01:17, schrieb John Ehresman:
> On 4/24/13 6:59 PM, Matthew Ngaha wrote:
>> Can anybody please explain this tutorial to me:
>>
>> http://qt-project.org/wiki/Auto-generating-QObject-from-template-in-PySide
>>
>> Im about to give up. im not great at python and trying to figure out
>> the python syntax vs what pyside is meant to be doing is really
>> confusing me. There are some fancy builtin objects being used that are
>> behaving like dictionaries kwarggs, __dict__, and some confusing inner
>> functions. As it is a pyside tutorial why didnt it just focus mainly
>> on pyside and just use a normal dictionary and basic function process
>> for the python code?
> Agreed. I just looked at the page for the first time and can't figure
> out what it's trying to accomplish (and I know a fair bit about python
> and pyside). I'd suggest just skipping it out or are you trying to do
> something similar?
>
> Cheers,
>
> John
Partially agreed:) The tutorial is an interesting puzzle, but
definitively not a beginners tutorial. It's fairly advanced python and I
had to study the code for a moment to understand it even if I'm using
Python almost every day... I would also suggest to skip it, because it's
at most 10% PySide related, 90% or more is Python related. I would study
other tutorials if you want to get used to PySide.
For people still interested in this tutorial: It goes towards meta
programming. It allows you defining many different classes with very
little code (but only as long as the classes exactly fit into the
limitations of this template). E.g. if you need classes for Persons,
Buildings and Cars, the following will set them up for you:
Car = AutoQObject(
('model', str),
('inStock', bool),
name='Car'
)
Person = AutoQObject(
('age', int),
('car', Car),
name='Person'
)
Building = AutoQObject(
('id_', int),
name='Building'
)
The text in the tutorial description describes best, what the template
(which is AutoQObject) does:
"Attributes, getters, setters and notification methods are automatically
generated."
I can hardly think of a realistic example, where one would need this,
because the classes generated from the template are quite limited, most
often, you need more flexibility (e.g. don't need all notification
methods, but need other methods). Please also note, that the code is not
even PEP8 conform, which makes it even harder to understand and in my
opinion, the author is mixing up classes with objects in the text, but
this is just a detail:)
Hope this helps!
Aaron
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
More information about the PySide
mailing list