[solved] Forms
Greetings.
Since the release of 0.27, I've been converting many of the items in my experiment to forms using Python scripting. But how do you use the extra functions, such as "label.draw_text(text, html=True)", etc.?
Best regards,
Jákup
Comments
Hi Jákup,
These functions are mostly for internal use, so it's debatable whether they should be included in the documentation. But you could, in principle, use them in an inline_script.
Essentially, most of these functions, such as draw_text() render a specific part of the form to a canvas. For example, let's say that you have a label widget myLabel with the text "My text", which is part of a form called myForm. If you then call
myForm._exec()to execute the complete form, this will (among other things) call
myForm.render()to render the form onto a canvas that is a property of the form (myForm.canvas). This will in turn (among other things) call
myLabel.render()to draw the label, which will (among other things) call
myLabel.draw_text("My text")to draw the actual text. Does that make sense?
I don't immediately see any situations where calling functions such as draw_text() would be useful. But it is possible to do so, for example to render only some parts of the form. In the snippet below, you can see how a form (from this example) is constructed and then rendered partially by calling specific functions on the widgets (rather than form._exec() or form.render()):
[pastebin:yXMtG0Be]
The result will be an incompletely rendered form, like this:
Hope this clears things up, and happy holidays!
Cheers,
Sebastiaan
Check out SigmundAI.eu for our OpenSesame AI assistant!
Dear Sebastiaan.
Thank you very much for your lucid reply. This makes things much more clear for me. The reason I wanted to know, is the "html=True" parameter in the draw_text() function. If this would allow for using html code to format your text displays using forms, than that would indeed be a very powerful thing. I have also been trying to use the draw_frame() function, so I could draw a frame around different cells of the form. But alas, also unsuccessful.
How would you do these things in the simple hello world example below?
Best regards,
Jákup
Ah, I see. To use HTML you don't need to do anything special: You can type your HTML tags (just a small subset actually) directly into your sketchpad, form, inline_script, etc.
Edit: Only the Xpyriment back-end currently supports all the tags shown in the documentation
For more info, see
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Hello again.
And thank you for your fast reply!
I have played around with some of the canvas HTML codes, but I haven't gotten alignment tags to work. The thing is, I would like to do a custom form, with two text columns, where the one on the left is right justified, and the one on the right is left justified.
Oh, and happy holidays to you too btw!
Best regards,
Jákup
Alignment tags are not supported, unfortunately. The only tags that have been implemented are the ones shown in the example. You can pass the center keyword to a label widget, but this just toggles between left and center alignment, without a possibility for right alignment.
As a crude workaround, though, you could pad you text with spaces to make it seem right aligned. For example, this script will show a left and right aligned column side by side. Note that this will only work properly if you select a monospace font, and if you set center to no.
Hope this helps!
Check out SigmundAI.eu for our OpenSesame AI assistant!
It certainly did
I will use this work-around, although I will have to change the font after this item. I know this is possible using canvas functions, but is it possible with forms as well? Or, to put it another way: is it possible to map a canvas text to a form cell?
And thanks for the heads-up about the backend! I've been working with legacy. With xpyriment my formatting tags are working nicely.
Best regards,
Jákup
Hmm... I may have spoken too fast. I cannot get it too work, using canvas functions, to display different fonts on the same canvas. I assume it must be possible, seeing as you can do this with the sketchpad. So what am I missing, for example in the code below?
Best regards,
Jákup
If I understand correctly, your goal is to temporarily use the monospace font (i.e. for the purpose of alignment), but without changing the default font to monospace. Is that correct? If so, the easiest way is probably to define the font style using span tags in a form, like so:
This way you don't have to change the default font to 'monospace'.
However, presenting text with different fonts on the same canvas is possible as well. The following script (the full version of your example, essentially) should work:
[pastebin:gSehHL15]
In what sense doesn't this work for you? Do you get an error message? (As an aside, for clarity I would avoid using the name canvas for a canvas, because it causes confusion with the class, which is also called canvas.)
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Greetings.
I just tested your code, and re-tested mine, with all three backends. And the set_font canvas function only seems to work with xpyriment. Is this right?
Best regards,
Jákup
Yes, that's a known issue: https://github.com/smathot/OpenSesame/issues/120
For the Psycho back-end there's currently no real way around this: On some systems the back-end simply ignores the font altogether and falls back to some 'sans serif' default. I think this has to do with the different font naming schemes on different systems, but I have to look into it (it definitely needs to be fixed).
For the legacy back-end, the problem is that the canvas refuses to forget a previous font, and you can workaround it like this:
[pastebin:uAYH1iuf]
Cheers!
Check out SigmundAI.eu for our OpenSesame AI assistant!
Yes that did the trick! Thank you very much for that
Best regards,
Jákup