Howdy, Stranger!

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

Supported by

Text width in pixels on Mac OSX

edited October 2016 in Expyriment

Hello,
I got a problem with some strings I'd like to be presented in a specific way.
Each string is on a specific canvas, which are presented the right way. But now I'd like to change the x-coordinate of the presented canvasses respectively to the text-width (in pixels) of the canvas presented before.
I could only find solutions for Windows (like this: http://stackoverflow.com/questions/32555015/how-to-get-the-visual-length-of-a-text-string-in-python). Since I am bound to Mac OSX atm, I'd like to ask you if you know about an equivalent for Mac?
I am using MacOS Sierra 10.12 and OpenSesame 3.1.3.

Comments

  • Dear Kiri,

    you can use the surface_size attribute of the stimulus to get an estimation of the width of your text stimulus, based on the underlying Pygame surface on which the text is presented on. This will work independently from the OS. However, keep in mind that, while this estimate seems not too bad for the width (as opposed to the height), as can be seen in the attached example, it is not guaranteed to be accurate. So, depending on what you need the text width for, if you need more precision (e.g. for calculating visual angles), you will not get around actually measuring the stimulus size on screen.

    Example:

    import expyriment as xpy
    
    exp = xpy.control.initialize()
    s = xpy.stimuli.TextLine("WWW", text_colour=xpy.misc.constants.C_GREEN,
                             background_colour=xpy.misc.constants.C_RED)
    s.present()
    print s.surface_size
    

    I hope this helps. Let me know if you have any further questions.

    Best,
    Florian

  • Hi Florian,

    thank you very much. I got very near to a solution.
    So far, I defined the following function in my code:

    def GetSize(text): 
        exp = xpy.control.initialize()
        s = xpy.stimuli.TextLine(text)
        s.present()
        return s.surface_size
    

    Since I want to "write a sentence" by printing a word behind another word (which should not be presented anymore) I use this function within an inline-script in a for-loop:

    for i, word in enumerate(sentence):
            z = GetSize(word)
            x = x + int(z[i])
    

    I hope you see where I want to go from there. Unfortunately, I get the error message IndexError: tuple index out of range even if the sentence is not finished. Everything else seems to work. Since I am not that used to programming with python, I'd like to ask for another tipp at this stage.

    Thank you very much (also in advance).

    Kiri

  • Hi Kiri,

    I am afraid I don't entirely understand what you are trying to do. In general, there is only need to initialize Expyriment once, at the beginning of your script (see also: http://docs.expyriment.org/Tutorial.html). I also don't understand what you mean with "inline". Could you maybe send me your whole Expyriment script? Then I can have a look.

    Best,
    Florian

  • Hi fladd,

    sorry, that I needed so much time. I've conducted my experiment now by showing the words in the center of the screen (which is standard for OS canvasses).

    Unfortunately, it's impossible to send the whole script.

    With "inline" I meant the whole script itself with both, prepare-phase and start-phase.

    What I originally tried to do was to alternate the coordinates of the words shown on the canvasses, respectively to the length of the words shown before. Length should not have been measured by letters, but by the width of the whole word in pixels. With Windows, there's a possibility as shown in the first link. But MacOS does not have such a library for fonts and their pixel-width (afaik).

    I now used the standard-method with centered text-presentation. But maybe someone might need a solution for a similar or even the same problem I had.

    So thank you for your support and have a nice Christmas.

    Best,
    Kiri

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