Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[open] Formatting Forms with Python Inline Scripts

edited March 2013 in OpenSesame

Hello,

I am in the process of making a form for judging images in a pilot study. So far, I've found programming with the form and widget library very simple, but I haven't been able to find support documentation for one problem.

Problem: I cannot figure out how to customize the colors of the form.

It seems like it should be fairly straightforward.

Thanks for any help in advance!

-Alex

Comments

  • edited 12:31AM

    Hi Alex,

    Forms inherit the colors and font specified in the general tab of the experiment. If you want to have different colors for each form, you need to modify the experiment background and foreground during the experiment, before the form is constructed. You can do this by inserting an inline_script item before your form, with the following code in the prepare phase:

    exp.set('foreground', 'yellow')
    exp.set('background', 'blue')
    

    Of course, you can use any color you like here. Note that the new colors will apply to all items that are constructed from this point onward!

    Btw, if you simply want to add some formatting to your text, you could also use the HTML subset:

    Cheers!
    Sebastiaan

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 12:31AM

    Hello Sebastiaan,

    I knew it would be a simple fix, many thanks!

    One more question, if you don't mind:

    How are the prepare and run code sections of an inline_script item related? It seems like most of the code one writes for items like stimulus displays should be placed in the body of Prepare; what examples of code are best placed in the body of Run?

    Thanks!
    Alex

    P.S. - I am very impressed with the flexibility and power of OpenSesame. I tried to learn PsychoPy, and had a rough go of it, but OpenSesame, and libopensesame are so intuitive, it took me about an hour to get a pretty complex program running. Bravo!

  • edited 12:31AM

    P.S. - I am very impressed with the flexibility and power of OpenSesame.

    Thanks!

    How are the prepare and run code sections of an inline_script item related?

    When a sequence item is executed, every item in it is called twice: First the prepare() function is called for every item (the prepare phase), and then the run() function is called for every item (the run phase). The idea is that items do as much as possible during the prepare phase, so that the run phase is as efficient as possible. For example, a sketchpad item constructs its canvas during the prepare phase, which is time consuming, and only calls the canvas.show() function during the run phase. Sometimes it's not possible to prepare things in advance, because they depend on what happens during the sequence (for example the participant's response). In that case, more work is shifted to the run phase, generally at the cost of introducing extra lag.

    So this is the general logic behind the two phases. In an inline_script you can in principle do whatever you want, but it's good practice to keep the above distinction in mind.

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 12:31AM

    Thank you for explaining.

    So then, in principle, you should place all your code in the prepare() phase, and OpenSesame decides which portions to execute at runtime and which to execute prior to runtime; but if you know beforehand that one portion of code will be dependent on another event in the sequence, then you should just go ahead and place that code in the run() phase?

    I just want to be clear on this so that I know when I might encounter undesirable latency in stimulus presentations.

  • edited 12:31AM

    So then, in principle, you should place all your code in the prepare() phase

    As much preparatory code as possible, yes, but not the code that directly controls stimulus presentation etc. For example, you would load a sound file in the prepare phase, but play it in the run phase. Similarly, you would construct a canvas in the prepare phase, and then show() it in the run phase.

    OpenSesame decides which portions to execute at runtime and which to execute prior to runtime;

    OpenSesame does not auto-detect which code to run when, if that's what you mean? You control this explicitly by putting your code into the prepare or run phase.

    but if you know beforehand that one portion of code will be dependent on another event in the sequence, then you should just go ahead and place that code in the run() phase?

    Yes!

    There's much bigger issues in the world, I know. But I first have to take care of the world I know.
    cogsci.nl/smathot

  • edited 12:31AM

    Ok, great! Thank you for explaining :)

Sign In or Register to comment.