Howdy, Stranger!

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

Supported by

[solved] mouseover to highlight image buttons

edited September 2014 in OpenSesame

Hello All,

I am working on an experiment that involves users choosing between a large number of image buttons. To help the user orienting, it would be useful to highlight the image button at mouseover. I was wondering, does anyone have experience implementing this? Any pointers would be greatly appreciated!

Comments

  • edited 12:45PM

    Hi Jan-Maarten,

    Welcome (finally!) to the forum. The short answer is that forms do not provide mouse-over functionality. However, if you really want this functionality, you could implement your own form programmatically. This may be more trouble than it's worth though, but here's a quick script to get you started.

    Cheers!
    Sebastiaan

    from openexp.canvas import canvas
    from openexp.mouse import mouse
    
    # A list of button texts
    buttons = [
        'Click me!',
        'No click me!',
        'Leave me alone',
        'Avoid me'
        ]
    
    # Specify the geometry
    cols = 2
    button_width = 300
    button_height = 100
    margin = 50
    
    # Create a canvas and a mouse object. We set the timeout to 0 so that we can
    # poll the mouse continuously
    my_canvas = canvas(exp)
    my_mouse = mouse(exp, timeout=0, visible=True)
    
    # Loop until a mouse button was clicked.
    button_clicked = None
    while button_clicked == None:
        # Get a mouse click
        mouse_button = my_mouse.get_click()[0]
        # Get cursor position
        cx, cy = my_mouse.get_pos()[0]
        my_canvas.clear()
        # Loop through all the buttons. `enumerate()` is a built-in Python function
        # that also returns indices for the list that you walk through.
        for i, button in enumerate(buttons):
            # Determine the column and row of a button, based om the buttons index.
            col = i % cols
            row = i / cols
            # From there, determine the x and y coordinates of the button's top
            # left corner.
            x = margin + col * (margin+button_width)
            y = margin + row * (margin+button_height)
            # If the cursor was over this button, choose a color to highlight the
            # button.
            if cx > x and cx < x+button_width and cy > y and cy < y+button_height:
                color = 'blue'
                # ... and if this button was clicked, take note of this
                if mouse_button != None:
                    button_clicked = button 
            # Otherwise stick to white.
            else:
                color = 'white'
            # Draw the button!
            my_canvas.rect(x, y, button_width, button_height, color=color)
            my_canvas.text(button, x=x+button_width/2, y=y+button_height/2)
        my_canvas.show()
    # Set button_clicked as an experimental variable, so that you can log it etc.
    exp.set('button_clicked', button_clicked)
    
  • edited 12:45PM

    Thank you! I'll have to see whether I can do this within the time frame for our current study, but it will be great for future reference!

    Cheers, Jan-Maarten

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