On Tue, Jul 12, 2011 at 4:43 PM, Renato Araujo Oliveira Filho
<[email protected]> wrote:
> Hi guys,
>
> Last week I spent some time working on a idea I had some time ago,
> this is a way to describe QML scenes without QML :D. In other words is
> a new way to describe scenes only using Python.
> With that you remove the necessity of use QML code in your python programs.
>
> My idea is in early stage then I would like to discuss with you is,
> which is the best way to describe scenes in python?. I'm not a heavy
> python user, then I'm not familiar with all python features, because
> of that I want your opinions.
>
> My first try is something like that:
>
> class Rectangle1(Rectangle):
>    anchors = Anchor(centerIn = parent)
>    width = 800
>    height = 480
>    color = 'red'
>    class Rectangle2(Rectangle):
>        anchors = Anchor(fill = parent)
>        color = 'white'
>        class Rectangle3(Rectangle):
>            anchors = Anchor(centerIn = parent)
>            width = 200
>            height = 200
>            color = 'black'
>            class Image1(Image):
>                anchors = Anchor(centerIn = parent)
>                source = 'logo.png'
>                width = 64
>                height = 64
>                class MouseArea2(MouseArea):
>                    anchors = Anchor(fill = parent)
>                    def onClick(self):
>                        print "show"
>
>
>
> This describe a scene with 3 rectangle, 1 image and a mouse area, this
> is very similar to QML code I only translate the QML code to python,
> but I do not know if there is some a best pythonic way to do that.
>
> What do you think about this way to describe scenes?
>
> Do you have any suggestions to make this more pythonic?
>
>
> The initial code, it can be found on my github repostiry[1], this is
> very early to report bugs or even try use that, first I need to figure
> out the best way to describe the scenes and then I will work on new
> features and stability.
>
> I hope someone can give some feedback and help me to develop the idea.
>
> [1] https://github.com/renatofilho/pysideQML
>
> Thanks

This sort of direct conversion from QML to python I think makes a lot
of sense.   It makes it easier to transition between the two, makes it
easier to use existing documentation, and so on.

I don't think using class makes sense since the QML objects are used
in a radically different manner than python classes.  For one thing,
they refer to individual objects, rather than a type of object that is
re-used, so I think it is much more analogous to a python variable
than a class.  In order to clearly differentiate the QML objects from
python classes, I think that it would be better, if possible, to use
your own statement, like QML.  Or better yet make things everything
statements on their own, similar to how they are in QML with
javascript.

So in my vision your code would become something like this:

Rectangle Rectangle1:
    anchors Anchor(centerIn = parent)
    width 800
    height 480
    color 'red'
    Rectangle Rectangle2:
        anchors Anchor(fill = parent)
        color 'white'
        Rectangle Rectangle3:
            anchors Anchor(centerIn = parent)
            width 200
            height 200
            color 'black'
            Image Image1:
                anchors Anchor(centerIn = parent)
                source 'logo.png'
                width 64
                height 64
                MouseArea MouseArea2:
                    anchors Anchor(fill = parent)
                    onClick self:
                        print "show"

I am not sure if it is possible to do this within python, I am not
familiar with the coding of new statements within python (if that is
even possible).  But doing it this way I think would be much more
analagous to how it works in javascript, and would clearly separate it
from what I think are substantially different concepts in python like
classes.

However, being able to use python's object-oriented interfaces would
be very useful to let people modify QML objects programattically.  So
in the example, Rectangle would also be a class, and each of the
rectangles, Rectangle1, Rectangle2, and Rectangle3 would be instances
of that class.  All of the So you would be able to use standard QML
syntax, but you would also be able to access the properties of the
objects, like this:

Rectangle1.anchors=Anchor(centerIn = parent)
Rectangle1.width=800
Rectangle1.Rectangle2.Rectangle3.width=200 or Rectangle3.width=200
(depending on whether you want names to be global or local).

-Todd
_______________________________________________
PySide mailing list
[email protected]
http://lists.pyside.org/listinfo/pyside

Reply via email to