Skip to content

Commit

Permalink
Merge pull request #3558 from isolver/hotfix-form-textbox2
Browse files Browse the repository at this point in the history
BF: Forms with editable TextBox2 and iohub mouse setPosition
  • Loading branch information
peircej committed Feb 15, 2021
2 parents 55e2811 + 1e39233 commit bec1846
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
2 changes: 1 addition & 1 deletion psychopy/iohub/devices/mouse/__init__.py
Expand Up @@ -161,7 +161,7 @@ def setPosition(self, pos, display_index=None):
print2err(' mouse.setPos did not update mouse pos')
else:
self._lastPosition = self._position
self._position = px, py
self._position = pos[0], pos[1]

self._last_display_index = self._display_index
self._display_index = mouse_display_index
Expand Down
27 changes: 24 additions & 3 deletions psychopy/iohub/devices/mouse/win32.py
Expand Up @@ -143,11 +143,32 @@ def _initialMousePos(self):
this method gets the current system cursor pos.
"""
if self._position is None:
self._position = 0.0, 0.0
self._lastPosition = 0.0, 0.0
p = 0.0, 0.0
mpos = ctypes.wintypes.POINT()
if self._user32.GetCursorPos(ctypes.byref(mpos)):
self._position = [mpos.x, mpos.y]
display_index = self.getDisplayIndexForMousePosition(
(mpos.x,mpos.y))

if display_index == -1 and self._last_display_index is not None:
display_index = self._last_display_index

if display_index != self._display_device.getIndex():
# sys mouse is currently not in psychopy window
# so keep pos to window center.
display_index = -1

if display_index == -1:
self._display_index = self._display_device.getIndex()
self._last_display_index = self._display_index
wm_pix = self._display_device._displayCoord2Pixel(p[0],
p[1],
self._display_index)
self._nativeSetMousePos(*wm_pix)
else:
p = self._display_device._pixel2DisplayCoord(
mpos.x, mpos.y, display_index)

self._position = p
self._lastPosition = self._position

def _nativeSetMousePos(self, px, py):
Expand Down
10 changes: 9 additions & 1 deletion psychopy/visual/form.py
Expand Up @@ -779,7 +779,15 @@ def _drawCtrls(self):
element._baseY - self._getScrollOffset())
if self._inRange(element):
element.draw()


def setAutoDraw(self, value, log=None):
"""Sets autoDraw for Form and any responseCtrl contained within
"""
for i in self.items:
if i['responseCtrl']:
i['responseCtrl'].setAutoDraw(value)
BaseVisualStim.setAutoDraw(self, value, log)

def draw(self):
"""Draw all form elements"""
# Check mouse wheel
Expand Down

0 comments on commit bec1846

Please sign in to comment.