Hi once again... :-)

On 11/7/07, Johan Mårtenson <[EMAIL PROTECTED]> wrote:
>
> Hi again,
>
> On 11/7/07, Emmanuele Bassi <[EMAIL PROTECTED]> wrote:
> >
> > hi;
> >
> > On Wed, 2007-11-07 at 21:19 +0100, Johan Mårtenson wrote:
> >
> > > def key_event(stage, event):
> > >     timeline = clutter.Timeline(100, 26)
> > >     alpha = clutter.Alpha(timeline, clutter.sine_func )
> > >
> > >     path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100)))
> > >
> > >     # Up
> > >     if event.keyval == 65362:
> > >         menu = stage.get_nth_child(0)
> > >         path_forward.apply(menu)
> > >
> > >         timeline.start ()
> >
> > the timeline, alpha and path_forward objects go out of scope when
> > control reaches the end of the key_event signal handler; hence, you see
> > no behaviour running because python will simply garbage collect those
> > objects.
>
>
> I  forgot about that, thanks.
>
> you should either declare path_forward as a global variable or, going
> > down the object oriented path, as an instance member of your application
> > class.
>
>
> And indeed you're right. Just making the variables global fixes it.
>

Actually, I still don't get the behavior I'm expecting. In the attached
program, I want the HBox menu to slide to the middle and stay there but once
it gets there it instead slides back again. What am I getting wrong?

Also, is there a nicer way of comparing keys than using b.keyval == 65362
for arrow up and 113 for q?

ciao,
> > Emmanuele.
>
>
> Thanks,
>
>  Johan
>

Thanks,

Johan

--
> > Emmanuele Bassi, OpenedHand Ltd.
> > Unit R, Homesdale Business Centre
> > 216-218 Homesdale Rd., Bromley - BR12QZ
> > http://www.o-hand.com
> >
> > --
> > To unsubscribe send a mail to [EMAIL PROTECTED]
> >
> >
>
#! /usr/bin/python

import clutter

def key_event(stage, b):

    global timeline
    global alpha
    global path_forward
    
    timeline = clutter.Timeline(100, 26)
    alpha = clutter.Alpha(timeline, clutter.ramp_func)

    path_forward = clutter.BehaviourPath(alpha, ((0, 0), (100, 100)))

    # Up
    if b.keyval == 65362:
        menu = stage.get_nth_child(0)
        path_forward.apply(menu)
        timeline.start()

    # q
    if b.keyval == 113:
        clutter.main_quit()

    return True

def build_scene():
    label = clutter.Label()
    label.set_text('Some label')
    label.show()

    menu = clutter.HBox()

    menu.add(label)

    menu.set_position(0, 0)
    menu.show()

    stage = clutter.stage_get_default()
    stage.set_size(300, 300)
    stage.set_color(clutter.color_parse("#7F7F7F"))

    stage.add(menu)
    stage.show()

    return stage

def main():
    stage = build_scene()

    stage.connect("key-press-event", key_event)

    clutter.main()

if __name__ == '__main__':
    main()

Reply via email to