First of all, thanks guys for the feedback.
On Wed, Jul 13, 2011 at 10:43 AM, Chris Morgan <[email protected]> wrote:
> You certainly can't insert new syntax structures in Python code. The "best"
> you can do in that way is doing it all as a string (with triple-quoted
> strings to help) and parse it out of that. But then you don't get any
> syntax highlighting in text editors or things like that.
I agree with you the point here is not create another language, but
use the power o python to create something simple as QML to describe
scenes.
In my opinion is not productive write programs in 3 different
languages (Python + QML + javasrcript). Would be nice have all the
code write in python.
>
> One way which could be done is with context managers (which would make
> Python 2.6 the minimum version, or 2.5 with "from __future__ import
> with_statement"), which could end up with code looking like this:
>
> with Rectangle() as Rectangle1: # I think this could work, but it could
> need to be "with Rectangle('Rectangle1'):"
> anchors = Anchor(center_in=parent) # I would welcome the opportunity to
> change "centerIn" to "center_in" or "centerin"
> width = 800
> height = 480
> color = 'red'
> with Rectangle() as Rectangle2:
> anchors = Anchor(fill=parent)
> color = 'white'
> with Rectangle() as Rectangle3:
> anchors = Anchor(center_in=parent)
> width = 200
> height = 200
> color = 'black'
> with Image() as Image1:
> anchors = Anchor(center_in=parent)
> source = 'logo.png'
> width = 64
> height = 64
> with MouseArea(): # "as MouseArea2" can be optional.
> Auto-assign an ID.
> anchors = Anchor(fill=parent)
> def onClick(self):
> print "show"
>
> I'm not very familiar with QML though, not having used it at all (only
> looked at it superficially). There could be some problems which couldn't be
> resolved in this way; I am not certain.
>
> Basically, the context manager would be used to create scope (not hard, just
> doing some munging of f_locals() of the outer frame in __enter__ and
> __exit__ to get the things defined inside correctly). If we're only dealing
> with a certain set of possible attribute names, this is quite reasonable,
> but if you can put in custom ones then it wouldn't work (if you set a value
> to the same thing inside the block as outside, it wouldn't be picked up
> unless it's been cleared out of the local "scope" by the context manager).
> And how about functions - is it only certain function names which are
> allowed?
About scope stuff, you need have access to another object scope, QML
use this to set the properties for other objects, something like that:
with Rectangle() as Rectangle3:
anchors = Anchor(center_in=parent)
width = Rectangle2.width /2
Then I think scope is very important on QML.
About functions names, some names are predefined (signals/slots), but
you can create new ones.
>
> Being comparatively magic stuff, this might not be the best way to do it
> (i.e. you'd do it this sort of a way in Ruby (if you ever used it in the
> first place!) without a second thought, but in Python you'd think twice
> before doing it). But hey, it'd be fun!
>
> Concerning using Python code in the QML, I don't like that notion. It feels
> icky (from __future__ import braces, for starters). And indentation and
> syntax highlighting of Python code would be messy; no text editors would
> support it already, whereas lots of text editors support Python code.
>
> Anyway, there's my mad way of doing it. You who know QML and can see what I
> mean, please find all the problems in it! It wouldn't surprise me if it is
> impractical (though I think it could be practical).
>
> I think the originally specified way of doing it with classes may be the
> best way of doing it, though probably with a metaclass added to do some
> things (though I don't know what, yet).
Using the class declaration style, you can use the class name as
object id, and use meta class to do the magical stuff.
Thanks
--
Renato Araujo Oliveira Filho
Instituto Nokia de Tecnologia - INdT
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside