Howdy, Stranger!

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

Supported by

draw with and track mouse at the same time

Hi everyone,
sorry, another question by me. This time I would like to draw something with the mouse and of course this has to be tracked for the later analysis.
In the forum I found a script which does the drawing well.
Here it is:
from openexp.canvas import canvas from openexp.mouse import mouse my_mouse = mouse(exp, buttonlist = ([1]), visible = True) my_canvas = canvas(exp) dot = exp.pool[u'dot3.png'] my_canvas.show() start = clock.time() my_mouse.set_pos(pos=(0, 0)) while clock.time() - start <= 3000: button, position, timestamp = my_mouse.get_click(timeout=10) x,y = position if button is not None else (None,None) if button is not None: (x0, y0) = (None,None) while my_mouse.get_pressed()==(1,0,0): (x, y), timestamp = my_mouse.get_pos() if (x0,y0) != (None, None): my_canvas.image(dot, x=x0, y=y0) my_canvas.line(x0,y0,x,y, penwidth=8) my_canvas.image(dot, x=x, y=y) else: my_canvas.image(dot, x=x, y=y) (x0,y0) = (x,y) my_canvas.show()
But this script does not log the position of the mouse as far as I can see. (Or am I wrong?)
Therefore I included after this script a mousetrap-response item. This does the logging, but it only starts after the drawing is done. But I want to log what is drawn.
It doesn't help if I reverse the order (first the mousetrp-response item and then the script for the drawing) because then it just logs the mouse-movements before the drawing which is neither what I want.
I want the movements of the drawing (the drawing itself) be logged.
(At the end I have a logger-item of course.)

Any ideas how I can achieve this?

Thanks a lot!
Pia

Comments

  • Hi Pia,

    You could append the latest coordinates to a list variable each iteration through the loop. So right after the my_mouse.get_pos() command, you place a line with coordinates_list.append((x,y)). Be sure to create the list variable prior to appending stuff to it.

    Alternatively you could just make a print-screen when the drawing is done. There's surely a python command for this.

    Cheers

    Josh

  • Thanks! Hm, unfortunately this gives an error-message, which I unfortunately don't understand:
    File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 102, in run self.experiment.python_workspace._exec(self.crun) File "C:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\python_workspace.py", line 161, in _exec exec(bytecode, self._globals) File "<string>", line 23, in <module> TypeError: 'instancemethod' object is not iterable

    Here is what I did:
    from openexp.canvas import canvas from openexp.mouse import mouse my_mouse = mouse(exp, buttonlist = ([1]), visible = True) my_canvas = canvas(exp) coordinates_list = list() dot = exp.pool[u'dot3.png'] my_canvas.show() start = clock.time() my_mouse.set_pos(pos=(0, 0)) while clock.time() - start <= 3000: button, position, timestamp = my_mouse.get_click(timeout=10) x,y = position if button is not None else (None,None) if button is not None: (x0, y0) = (None,None) while my_mouse.get_pressed()==(1,0,0): (x, y), timestamp = my_mouse.get_pos coordinates_list.append((x,y)) if (x0,y0) != (None, None): my_canvas.image(dot, x=x0, y=y0) my_canvas.line(x0,y0,x,y, penwidth=8) my_canvas.image(dot, x=x, y=y) else: my_canvas.image(dot, x=x, y=y) (x0,y0) = (x,y) my_canvas.show()
    So I included coordinates_list = list() in the beginning and placed coordinates_list.append((x,y)) after (x, y), timestamp = my_mouse.get_pos. Did I place it at the right place? What is my mistake?

    Thank you!!

  • Hi Pia,

    One mistake is this line:

    my_mouse.get_pos

    Can you change it to my_mouse.get_pos() and see whether it is enough to make the script work?

    Eduard

    Buy Me A Coffee

  • PiaPia
    edited May 2017

    Hi eduard,
    thanks, the error message disappears, but unfortunately I can't find my variable (coordinates_list) in the logfile. I placed an logger after the inline-script. And because the variable didn't show up automatically (with "log all variables") I added it manually, but it is still not in the logfile?
    So, how can I save the contents of this variable in the logfile?
    Thanks!
    Pia

    edit: I used print(coordinates_list) to print the coordinates_list in the debug window and it works. But how do I get it into the logfile?

  • Hi Pia,
    Only variables are logged that have the prefix var.. So if you changed the variable coordinates_list into var.coordinate_list, it will appear in the logfile.

    Eduard

    Buy Me A Coffee

  • Hi Pia, changing coordinates_list into exp.coordinates_list might work. The logger automatically stores all variables that are made available to the whole experiment (without .exp the variable can only be called within inline_scripts, but not, for instance, by the logger item).

    Your list may turn out huge though. Are you sure that a print-screen will not suffice?

    Cheers

    Josh

  • Greetings Ed

  • Thank you both!

    The experiment runs when I change the variable to var.coordinates_list and also when I change it to exp.coordinates_list but the list doesn't appear in the logfile, somehow. I also tried to add the variable to the logger, but it complains that this is (both) not a valid variable name...

    I have to log the coordinates because they are important for the later analysis. The participants have to draw a circle where a dot appeared before.

    Any idea what I can do to get the coordinates into the logfile?

  • Can you quickly upload your experiment? There must a be a little thing wrong somewhere....

    Buy Me A Coffee

  • Yes, I uploaded it!

  • Okay, so either change the variable exp.coordinate_list to var.coordinate_list, or add the custom variable coordinate_list (without exp or var) to the logger. Both solutions work for me.

    Eduard

    Buy Me A Coffee

  • Thanks a lot! It works!

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