Howdy, Stranger!

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

Supported by

[solved] Implementing Forms with Canvas Objects

edited April 2014 in OpenSesame

Hi all,

Apologies if this issue has already arisen. I've had a look and didn't see this anything that answered this question so am starting a new thread. I'm very new to Opensesame so I suspect the answer to this question will be fairly straightforward.

My experiment requires participants to view a series of objects (e.g. rectangles, circles, text) and respond to these stimuli by pressing a button (from a series of 11) on the screen. I'm managed to use the canvas objects to create my stimuli via the inline script facility. And have also managed to use form objects to create the button series. My problem is that I cannot seem to get the canvas objects to be presented on the same screen as the form objects. For example, when I present the canvas objects via the .show command, these objects will disappear as soon as I execute the form via the form._exec() command. How do I get the canvas objects and the form objects to present simultaneously?

Cheers.
Tim

Comments

  • edited 12:08AM

    Hi Tim,

    You cannot draw on forms in the same way that you can with canvas objects, so what you want to do (combining form widgets with custom drawing operations) is difficult. Since you're already familiar with inline_scripts, you could consider the following alternative.

    Step 1: Draw your images using PIL (Python imaging library) and save them as temporary images to the file pool. The following script (to be pasted in the prepare phase of an inline_script item) shows the general idea, but PIL is very well documented and easy to use.

    import os
    from PIL import Image, ImageDraw
    # Create a 100x100 image with PIL and draw a diagonal red line in it. See also:
    # - http://effbot.org/imagingbook/pil-index.htm
    im = Image.new('RGB', (100, 100))
    dr = ImageDraw.Draw(im)
    dr.line((0, 0, 100, 100), fill='red')
    # Save it as `diagonal_line.png` to the file pool
    im.save(os.path.join(exp.pool_folder, 'diagonal_line.png'))
    

    Step 2: Include the just-generated images in a form using the image or image_button widgets. For example (this is OpenSesame script, not Python):

    widget 0 0 1 1 image_button path="diagonal_line.png"
    

    Does that help at all?

    Cheers,
    Sebastiaan

  • edited 12:08AM

    Hi Sebastiaan,

    Sorry for the delayed reply. I was waiting to see if any more issues arose, and nothing has yet! So far so good. Thanks for your help.

    Regards,
    Tim

  • edited 12:08AM

    Ok, it seems I spoke too soon. I'm trying to use the 'ImageFont.truetype' command to specify font type and size. However, when I use this command, I get the following error:

    "ImportError: The _imagingft C module is not installed"

    The script runs fine when I don't use that command. However, I'd like to be able to specify font type and size.

    Any ideas?

    Cheers,
    Tim

  • edited 12:08AM

    Hi Tim,

    Right, that's because the standard distribution of PIL is not compiled with support for TrueType fonts. What you could try is replace the PIL module (which is a subfolder of OpenSesame) by a PIL version that is compiled with TrueType support. That will require a bit of Googling though—I assume it's possible, but I don't know right away how to do it.

    Another option would be to use the pygame drawing routines, which support TrueType out of the box. The script below does the same as the script above, but using PyGame instead of PIL. There's no real advantage to using one over the other (except TrueType support, obviously).

    import pygame
    import os
    # Create a 100x100 image with PyGame and draw a diagonal red line in it.
    # See also:
    # - http://www.pygame.org
    im = pygame.Surface( (100, 100) )
    pygame.draw.line(im, pygame.Color('red'), (0, 0), (100, 100))
    # Save it as `diagonal_line.png` to the file pool
    pygame.image.save(im, os.path.join(exp.pool_folder, 'diagonal_line.png'))
    

    Cheers,
    Sebastiaan

  • edited 12:08AM

    Pygame worked incredibly well. Thanks a lot Sebaastiaan! For anyone else using Pygame, I found this website very useful.

    http://www.pygame.org/docs/ref/surface.html

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