Howdy, Stranger!

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

Supported by

[solved] Forms

edited January 2013 in OpenSesame

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

  • edited 3:33AM

    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:

    image

    Hope this clears things up, and happy holidays!

    Cheers,
    Sebastiaan

  • edited 3:33AM

    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?

    from libopensesame import widgets
    form = widgets.form(self.experiment,)
    text = widgets.label(form, center=True, text="Hello  world")
    text.draw_text(text, html=True)
    text.draw_frame(rect=[10, 10, 100, 10], style='normal')
    form.canvas.show()
    

    Best regards,

    Jákup

  • edited December 2012

    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!

  • edited 3:33AM

    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

  • edited 3:33AM

    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.

    __text1__
    This text
     is right
      aligned
    __end__
    
    __text2__
    This text
    is left  
    aligned  
    __end__
    
    widget 0 0 1 1 label text=[text1] center=no
    widget 1 0 1 1 label text=[text2] center=no
    widget 0 1 2 1 button

    Hope this helps!

  • edited 3:33AM

    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

  • edited December 2012

    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?

    canvas.text(text1)
    canvas.set_font(style='mono')
    canvas.text(text2)
    canvas.set_font(style='serif')
    canvas.text(text3)
    canvas.show()
    

    Best regards,

    Jákup

  • edited 3:33AM

    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:

    __text2__
    <span style='mono'>This text
    is left
    aligned</span>
    __end__
    __text1__
    
    <span style='mono'>This text
     is right
      aligned</span>
    __end__
    
    widget 0 0 1 1 label center="no" text="[text1]"
    widget 1 0 1 1 label center="no" text="[text2]"
    widget 0 1 2 1 button

    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!

  • edited 3:33AM

    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

  • edited 3:33AM

    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!

  • edited 3:33AM

    Yes that did the trick! Thank you very much for that :)

    Best regards,

    Jákup

Sign In or Register to comment.

agen judi bola , sportbook, casino, togel, number game, singapore, tangkas, basket, slot, poker, dominoqq, agen bola. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 50.000 ,- bonus cashback hingga 10% , diskon togel hingga 66% bisa bermain di android dan IOS kapanpun dan dimana pun. poker , bandarq , aduq, domino qq , dominobet. Semua permainan bisa dimainkan hanya dengan 1 ID. minimal deposit 10.000 ,- bonus turnover 0.5% dan bonus referral 20%. Bonus - bonus yang dihadirkan bisa terbilang cukup tinggi dan memuaskan, anda hanya perlu memasang pada situs yang memberikan bursa pasaran terbaik yaitu http://45.77.173.118/ Bola168. Situs penyedia segala jenis permainan poker online kini semakin banyak ditemukan di Internet, salah satunya TahunQQ merupakan situs Agen Judi Domino66 Dan BandarQ Terpercaya yang mampu memberikan banyak provit bagi bettornya. Permainan Yang Di Sediakan Dewi365 Juga sangat banyak Dan menarik dan Peluang untuk memenangkan Taruhan Judi online ini juga sangat mudah . Mainkan Segera Taruhan Sportbook anda bersama Agen Judi Bola Bersama Dewi365 Kemenangan Anda Berapa pun akan Terbayarkan. Tersedia 9 macam permainan seru yang bisa kamu mainkan hanya di dalam 1 ID saja. Permainan seru yang tersedia seperti Poker, Domino QQ Dan juga BandarQ Online. Semuanya tersedia lengkap hanya di ABGQQ. Situs ABGQQ sangat mudah dimenangkan, kamu juga akan mendapatkan mega bonus dan setiap pemain berhak mendapatkan cashback mingguan. ABGQQ juga telah diakui sebagai Bandar Domino Online yang menjamin sistem FAIR PLAY disetiap permainan yang bisa dimainkan dengan deposit minimal hanya Rp.25.000. DEWI365 adalah Bandar Judi Bola Terpercaya & resmi dan terpercaya di indonesia. Situs judi bola ini menyediakan fasilitas bagi anda untuk dapat bermain memainkan permainan judi bola. Didalam situs ini memiliki berbagai permainan taruhan bola terlengkap seperti Sbobet, yang membuat DEWI365 menjadi situs judi bola terbaik dan terpercaya di Indonesia. Tentunya sebagai situs yang bertugas sebagai Bandar Poker Online pastinya akan berusaha untuk menjaga semua informasi dan keamanan yang terdapat di POKERQQ13. Kotakqq adalah situs Judi Poker Online Terpercayayang menyediakan 9 jenis permainan sakong online, dominoqq, domino99, bandarq, bandar ceme, aduq, poker online, bandar poker, balak66, perang baccarat, dan capsa susun. Dengan minimal deposit withdraw 15.000 Anda sudah bisa memainkan semua permaina pkv games di situs kami. Jackpot besar,Win rate tinggi, Fair play, PKV Games