internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: psychopy/psychopy

Issue:
Inconsistent method signature (or missing hook?)
Windows XP, Psychopy 1.80.06

window.flip calls dispatch_events() for each _eventDispatchers (pyglet winType), but DirectInputDevice (hardware/joystick/pyglet_input/directinput.py) has a different signature for that method: _dispatch_event. Needs to be fixed somewhere.



Discussion:
Try adding these lines at the end of class DirectInputDevice (~line 164) in file hardware/joystick/pyglet_input/directinput.py:

```
def dispatch_events(self):
    # standardize the method signature
    self._dispatch_events()
```

sounds like that will work for now, but with the switch to pyglet 1.2 (which is where the joystick code was stolen from) I suspect this issue might 'go away'


Resolving patch:
diff --git a/psychopy/hardware/joystick/pyglet_input/directinput.py b/psychopy/hardware/joystick/pyglet_input/directinput.py
--- a/psychopy/hardware/joystick/pyglet_input/directinput.py
+++ b/psychopy/hardware/joystick/pyglet_input/directinput.py
@@ -162,6 +162,10 @@ def _dispatch_events(self):
             index = event.dwOfs // 4
             self.controls[index]._set_value(event.dwData)
 
+    def dispatch_events(self):
+        # standardize the method signature
+        self._dispatch_events()
+
 _i_dinput = None
 
 def _init_directinput():


Test patch:
Repository: psychopy/psychopy

Issue:
Wrong link for polygon help button
Dear all,

The help button for the polygon dialog redirects to the wrong Web page:
http://www.psychopy.org/builder/components/shape.html

I guess it should now be:
http://www.psychopy.org/builder/components/polygon.html

I just updated to v1.81.02, so I guess the report is still relevant. I didn't check all the other buttons; I don't know which labels have been changed recently.

To be sure, I still included the output of sysInfo.py below.

Best,

Axel

Willkommen auf PsychoPy2!
v1.81.02

##### Running: /Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/demos/coder/sysInfo.py

Paths to files on the system:
    userPrefsFile: /Users/akohler/.psychopy2/userPrefs.cfg
    appDataFile: /Users/akohler/.psychopy2/appData.cfg
    demos: /Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/demos
    appFile: /Applications/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/PsychoPy.py

System info:
Darwin-12.5.0-x86_64-i386-32bit
OS X 10.8.5 running on x86_64

Python info
/Applications/PsychoPy2.app/Contents/MacOS/python
2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)]
numpy 1.7.1
scipy 0.12.0
matplotlib 1.3.0
pyglet 1.1.4
pyo 0.6.6

PsychoPy 1.81.02
have shaders: True

OpenGL info:
vendor: Intel Inc.
rendering engine: Intel HD Graphics 3000 OpenGL Engine
OpenGL version: 2.1 INTEL-8.16.80
(Selected) Extensions:
    True GL_ARB_multitexture
    True GL_EXT_framebuffer_object
    True GL_ARB_fragment_program
    True GL_ARB_shader_objects
    True GL_ARB_vertex_shader
    True GL_ARB_texture_non_power_of_two
    True GL_ARB_texture_float
    False GL_STEREO
    max vertices in vertex array: 1048575
1.7780  WARNING     Movie2 stim could not be imported and won't be available
6.5262  WARNING     Monitor specification not found. Creating a temporary one...



Discussion:

Resolving patch:
diff --git a/psychopy/app/builder/components/polygon.py b/psychopy/app/builder/components/polygon.py
--- a/psychopy/app/builder/components/polygon.py
+++ b/psychopy/app/builder/components/polygon.py
@@ -36,7 +36,7 @@ def __init__(self, exp, parentName, name='polygon', interpolate='linear',
                     stopType=stopType, stopVal=stopVal,
                     startEstim=startEstim, durationEstim=durationEstim)
         self.type='Polygon'
-        self.url="http://www.psychopy.org/builder/components/shape.html"
+        self.url="http://www.psychopy.org/builder/components/polygon.html"
         self.exp.requirePsychopyLibs(['visual'])
         self.order=['nVertices']
         #params


Test patch:
Repository: psychopy/psychopy

Issue:
`_translate()` undefined in (at least) `MonitorCenter.py`
I noticed this while trying to run the Monitor Center in PsychoPy 1.81.02 (as released) from source.

Basically, strings are translated assuming that there is a `_translate()` function. But this function hasn't been defined anywhere! It appears that the problem was first introduced in e541dbe (although the `_()` functions was later renamed to `_translate()`).

What puzzles me is that quite a bit of work has been done on the Monitor Center after the offending commit, suggesting that you didn't experience this problem during development (assuming you don't code without testing). But to me it looks completely broken?!

I haven't checked other parts of the code to see if the problem occurs elsewhere as well.



Discussion:
Ah, I think the issue is that you launch Monitor Center directly, whereas most of us launch it through the PsychoPy app. `_translate()` is set up as a global in the application startup (or when prefs are imported?) so that needs to be done for the monitor center too. This issue is one we could create a test for in the test suite, so that you won't have the issue in the future.
@jeremygray and @hsogo will know best where to fix this I think

Confirmed, I launch it through OpenSesame's `psychopy_monitor_center` extension:
- https://github.com/smathot/OpenSesame/tree/master/extensions/psychopy_monitor_center

I get that error when I launch it from the command line: `pythonw MonitorCenter.py`. Yes, the `_translate()` function is defined globally, upon `from psychopy.app import localization`. Adding that line at the top of MonitorCenter.py meant that I could launch it from the command line, and do so with the language preference as automatically set in my psychopy settings. So I think that is the only fix needed. Commit forthcoming.


Resolving patch:
diff --git a/psychopy/monitors/MonitorCenter.py b/psychopy/monitors/MonitorCenter.py
--- a/psychopy/monitors/MonitorCenter.py
+++ b/psychopy/monitors/MonitorCenter.py
@@ -6,6 +6,7 @@
 
 import wx
 from wx import grid
+from psychopy.app import localization
 from psychopy import monitors, hardware, logging
 from psychopy.app import dialogs
 import time, os


Test patch:
Repository: psychopy/psychopy

Issue:
proposal: "duration (loops)" for sound and video files
A natural thing to want to do is play a sound or movie clip for the duration of the file. It might be worth the (small?) effort to add support for duration to be specified in terms of loops through the media file, with the default being 1.

This would allow auto-terminating a routine when a sound ends.



Discussion:

Resolving patch:
diff --git a/psychopy/sound.py b/psychopy/sound.py
--- a/psychopy/sound.py
+++ b/psychopy/sound.py
@@ -203,7 +203,6 @@ def __init__(self,value="C",secs=0.5,octave=4, sampleRate=44100, bits=16, name='
         """
         self.name=name#only needed for autoLogging
         self.autoLog=autoLog
-        self.loops = 0 #-1 for infinite, or a number of loops
         #check initialisation
         if not mixer.get_init():
             pygame.mixer.init(sampleRate, -16, 2, 3072)
@@ -216,6 +215,9 @@ def __init__(self,value="C",secs=0.5,octave=4, sampleRate=44100, bits=16, name='
 
         #try to create sound
         self._snd=None
+        #distinguish the loops requested from loops actual because of infinite tones
+        # (which have many loops but none requested)
+        self.requestedLoops = self.loops = int(loops) #-1 for infinite or a number of loops
         self.setSound(value=value, secs=secs, octave=octave)
 
     def play(self, fromStart=True, log=True, loops=None):
@@ -278,6 +280,7 @@ def setVolume(self,newVol, log=True):
     def _setSndFromFile(self, fileName):
         #load the file
         self.fileName = fileName
+        self.loops = self.requestedLoops #in case a tone with inf loops had been used before
         self._snd = mixer.Sound(self.fileName)
 
     def _setSndFromArray(self, thisArray):
@@ -369,7 +372,9 @@ def __init__(self, value="C", secs=0.5, octave=4, stereo=True, volume=1.0,
         #try to create sound; set volume and loop before setSound (else needsUpdate=True)
         self._snd=None
         self.volume = min(1.0, max(0.0, volume))
-        self.loops = int(loops) #-1 for infinite or a number of loops
+        #distinguish the loops requested from loops actual because of infinite tones
+        # (which have many loops but none requested)
+        self.requestedLoops = self.loops = int(loops) #-1 for infinite or a number of loops
 
         self.setSound(value=value, secs=secs, octave=octave, hamming=hamming)
         self.needsUpdate = False
@@ -460,6 +465,7 @@ def _setSndFromFile(self, fileName):
         # want mono sound file played to both speakers, not just left / 0
         self.fileName = fileName
         self._sndTable = pyo.SndTable(initchnls=self.channels)
+        self.loops = self.requestedLoops #in case a tone with inf loops had been used before
         # mono file loaded to all chnls:
         self._sndTable.setSound(self.fileName,
                                 start=self.startTime, stop=self.stopTime)


Test patch:
Repository: psychopy/psychopy

Issue:
RatingScale Marker turns grey if the scale times out. Does not refresh.
In psychopy 1.81.03 RatingScale Marker turns gray if the scale times out without submitting and does not refresh to specified color on subsequent trials. 
Any suggestions how to fix that? 



Discussion:

Resolving patch:
diff --git a/psychopy/visual/ratingscale.py b/psychopy/visual/ratingscale.py
--- a/psychopy/visual/ratingscale.py
+++ b/psychopy/visual/ratingscale.py
@@ -6,6 +6,7 @@
 # Copyright (C) 2015 Jonathan Peirce
 # Distributed under the terms of the GNU General Public License (GPL).
 
+import copy
 import sys
 import numpy
 
@@ -347,9 +348,6 @@ def _initFirst(self, showAccept, mouseOnly, noMouse, singleClick, acceptKeys,
                 self.mouseOnly = False
                 logging.warning("RatingScale %s: ignoring mouseOnly (because showAccept and singleClick are False)" % self.name)
 
-        self.scale = scale
-        self.showScale = (scale is not None)
-
         # 'choices' is a list of non-numeric (unordered) alternatives:
         if choices and len(list(choices)) < 2:
             logging.error("RatingScale %s: choices requires 2 or more items" % self.name)
@@ -391,6 +389,7 @@ def _initFirst(self, showAccept, mouseOnly, noMouse, singleClick, acceptKeys,
             else:
                 self.labelTexts = [unicode(self.low)] + [''] * (self.high-self.low - 1) + [unicode(self.high)]
 
+        self.scale = scale
         if tickMarks and not(labels is False):
             if labels is None:
                 self.labelTexts = tickMarks
@@ -401,6 +400,7 @@ def _initFirst(self, showAccept, mouseOnly, noMouse, singleClick, acceptKeys,
                 self.labelTexts = tickMarks
             if self.scale == "<default>":
                 self.scale = False
+        self.showScale = (self.scale not in [None, False])
 
         # Marker pre-positioned? [do after anchors]
         try:
@@ -738,6 +738,7 @@ def _initMarker(self, marker, markerColor, expansion):
             self.markerBaseSize = self.baseSize
         self.markerColor = markerColor
         self.markerYpos = self.offsetVert + self.markerOffsetVert
+        self.markerOrig = copy.copy(self.marker)  # save initial state, restore on reset
 
     def _initTextElements(self, win, scale, textColor,
                           textFont, textSize, showValue, tickMarks):
@@ -1127,6 +1128,7 @@ def reset(self, log=True):
         """
         # only resets things that are likely to have changed when the ratingScale instance is used by a subject
         self.noResponse = True
+        self.marker = copy.copy(self.markerOrig)  # restore in case it turned gray, etc
         self.markerPlaced = False  # placed by subject or markerStart: show on screen
         self.markerPlacedBySubject = False  # placed by subject is actionable: show value, singleClick
         self.markerPlacedAt = False


Test patch:
Repository: psychopy/psychopy

Issue:
Dropped final character in saved filename with mic.record
Hi,

filename = '../data/20150312094043_voice_ID1000_S001_T001_R001_pataka'
microphone.switchOn()
core.wait(3)
mic.microphone.AdvAudioCapture(name='mic', stereo = False)
mic.record(sec=20, block=False, filename = filename + '.wav')  
Using this line to specify file name results in 20150312094043_voice_ID1000_S001_T001_R001_patak.wav instead of 20150312094043_voice_ID1000_S001_T001_R001_pataka.wav 
 Note the dropped 'a' at the end of pataka

However, by adding an intermediate character in the concatenation, all characters are used.

 mic.record(sec=20, block=False, filename = filename + '123456' + '.wav')
20150312094043_voice_ID1000_S001_T001_R001_pataka123456.wav

This could be my misunderstanding of how python concatenate works somehow.

This error does not happen with a shorter filename e.g. filename = '../data/mySubject1234' writes out as mySubject1234.wav

Using Psychop v1.81.03 on mac 10.8.2

Thanks.



Discussion:
This is a bug, will fix. The issue is not the length of the filename, but the fact that it ends with an 'a'. The bug is that if a filename is given to .record(), any trailing '.wav' is supposed to be removed, but that is done incorrectly and removes any of the characters w, a, v, or .

Possible work arounds: 
1. end your filenames with another character, e.g., x:
    mic.record(sec=20, block=False, filename = filename + 'x.wav')
   It does not have to be 'x'. This will give you filenames like
    20150312094043_voice_ID1000_S001_T001_R001_patakax.wav
2. Set the filename prior to calling .record()
    mic.wavOutFilename = filename + '.wav'
    mic.record(sec=20, block=False)
   This will give you file names with extra stufff (a timestamp, in unix epoch time), like
     20150312094043_voice_ID1000_S001_T001_R001_pataka-1426173235.230.wav


Resolving patch:
diff --git a/psychopy/microphone.py b/psychopy/microphone.py
--- a/psychopy/microphone.py
+++ b/psychopy/microphone.py
@@ -185,7 +185,9 @@ def _record(self, sec, filename='', block=True, log=True):
             onsettime = '-%d' % self.fileOnset + ms[1:]
             self.savedFile = onsettime.join(os.path.splitext(self.wavOutFilename))
         else:
-            self.savedFile = os.path.abspath(filename).strip('.wav') + '.wav'
+            self.savedFile = os.path.abspath(filename)
+            if not self.savedFile.endswith('.wav'):
+                self.savedFile += '.wav'
 
         t0 = core.getTime()
         self.recorder.run(self.savedFile, self.duration, **self.options)


Test patch:
Repository: psychopy/psychopy

Issue:
.addData() with mutable objects needs to use a copy
See http://stackoverflow.com/questions/29362421/understanding-psychopys-data-logging/29366793

Could use copy() for everything, but only needed for mutables

```
try: hash(value)
except: value = copy.deepcopy(value)
```



Discussion:

Resolving patch:
diff --git a/psychopy/data.py b/psychopy/data.py
--- a/psychopy/data.py
+++ b/psychopy/data.py
@@ -222,6 +222,12 @@ def addData(self, name, value):
         """
         if name not in self.dataNames:
             self.dataNames.append(name)
+        # could just copy() every value, but not always needed, so check:
+        try:
+            hash(value)
+        except TypeError:
+            # unhashable type (list, dict, ...) == mutable, so need a copy()
+            value = copy.deepcopy(value)
         self.thisEntry[name]=value
 
     def nextEntry(self):
diff --git a/psychopy/sound.py b/psychopy/sound.py
--- a/psychopy/sound.py
+++ b/psychopy/sound.py
@@ -468,8 +468,13 @@ def _setSndFromFile(self, fileName):
         self._sndTable = pyo.SndTable(initchnls=self.channels)
         self.loops = self.requestedLoops #in case a tone with inf loops had been used before
         # mono file loaded to all chnls:
-        self._sndTable.setSound(self.fileName,
+        try:
+            self._sndTable.setSound(self.fileName,
                                 start=self.startTime, stop=self.stopTime)
+        except:
+            msg = 'Could not open sound file; not found or format not supported (%s)' % fileName
+            logging.error(msg)
+            raise TypeError(msg)
         self._updateSnd()
         self.duration = self._sndTable.getDur()
 


Test patch:
diff --git a/psychopy/tests/test_data/test_ExperimentHandler.py b/psychopy/tests/test_data/test_ExperimentHandler.py
--- a/psychopy/tests/test_data/test_ExperimentHandler.py
+++ b/psychopy/tests/test_data/test_ExperimentHandler.py
@@ -76,6 +76,28 @@ def test_default(self):
         #    print e
         #print 'done'
 
+    def test_addData_with_mutable_values(self):
+        # add mutable objects to data, check that the value *at that time* is saved
+        exp = data.ExperimentHandler(
+            name='testExp',
+            savePickle=False,
+            saveWideText=True,
+            dataFileName=self.tmpDir + 'mutables'
+            )
+
+        mutant = [1]
+        exp.addData('mutable', mutant)
+        exp.nextEntry()
+        mutant[0] = 9999
+        exp.addData('mutable', mutant)
+        exp.nextEntry()
+
+        exp.saveAsWideText(exp.dataFileName+'.csv', delim=',')
+
+        #get data file contents:
+        contents = open(exp.dataFileName+'.csv', 'rU').read()
+        assert contents == "mutable,\n[1],\n[9999],\n"
+
     def test_unicode_conditions(self):
         fileName = self.tmpDir + 'unicode_conds'
Repository: psychopy/psychopy

Issue:
Polygon setEdges does not update the ShapeStim vertices
If I make a polygon object:

``` python
poly = visual.Polygon(win, edges=3, lineWidth=3, radius=3)
poly.draw()
win.flip()
```

and then want to change the shape on the fly in code, I would have though I would do:

``` python
poly.setEdges(5)
poly.draw()
win.flip()
```

This doesn't actually change the shape that gets shown though, but the following code does:

``` python
poly.setEdges(5)
poly.setVertices(poly.vertices)
poly.draw()
win.flip()
```

I think this is because `poly.setEdges` calls `poly._calcVertices` which sets the `poly.vertices` attribute, but `poly.setEdges` doesn't pass the new array to the `poly.setVertices` method, which I gather is inherited from `ShapeStim`.



Discussion:

Resolving patch:
diff --git a/psychopy/visual/polygon.py b/psychopy/visual/polygon.py
--- a/psychopy/visual/polygon.py
+++ b/psychopy/visual/polygon.py
@@ -47,13 +47,14 @@ def _calcVertices(self):
             ) * self.radius
             for e in xrange(int(round(self.edges)))
         ])
-    
+
     @attributeSetter
     def edges(self, edges):
         """Int or float. Number of edges of the polygon. Floats are rounded to int.
         :ref:`Operations <attrib-operations>` supported."""
         self.__dict__['edges'] = edges
         self._calcVertices()
+        self.setVertices(self.vertices, log=False)
     def setEdges(self, edges, operation='', log=None):
         """Usually you can use 'stim.attribute = value' syntax instead,
         but use this method if you need to suppress the log message"""
@@ -66,7 +67,7 @@ def radius(self, radius):
         May be a -2tuple or list to stretch the polygon asymmetrically.
 
         :ref:`Operations <attrib-operations>` supported.
-        
+
         Usually there's a setAttribute(value, log=False) method for each attribute. Use this if you want to disable logging."""
         self.__dict__['radius'] = numpy.array(radius)
         self._calcVertices()
@@ -74,4 +75,4 @@ def radius(self, radius):
     def setRadius(self, radius, operation='', log=None):
         """Usually you can use 'stim.attribute = value' syntax instead,
         but use this method if you need to suppress the log message"""
-        setAttribute(self, 'radius', radius, log, operation)
\ No newline at end of file
+        setAttribute(self, 'radius', radius, log, operation)


Test patch:
Repository: psychopy/psychopy

Issue:
bug: _relpath() in wrong place now
I introduced this when refactoring Builder. The proper fix is to delete _relpath completely, and replace with python 2.7's native handling of relative paths. Will fix when the style dust settles in a few days.



Discussion:

Resolving patch:
diff --git a/psychopy/app/builder/builder.py b/psychopy/app/builder/builder.py
--- a/psychopy/app/builder/builder.py
+++ b/psychopy/app/builder/builder.py
@@ -2126,21 +2126,3 @@ def appDataToFrames(prefs):
 def framesToAppData(prefs):
     pass
 
-
-def _relpath(path, start='.'):
-    """This code is based on os.path.relpath in the Python 2.6 distribution,
-    included here for compatibility with Python 2.5"""
-
-    if not path:
-        raise ValueError("no path specified")
-
-    start_list = os.path.abspath(start).split(os.path.sep)
-    path_list = os.path.abspath(path).split(os.path.sep)
-
-    # Work out how much of the filepath is shared by start and path.
-    i = len(os.path.commonprefix([start_list, path_list]))
-
-    rel_list = ['..'] * (len(start_list) - i) + path_list[i:]
-    if not rel_list:
-        return path
-    return os.path.join(*rel_list)
diff --git a/psychopy/app/builder/dialogs/__init__.py b/psychopy/app/builder/dialogs/__init__.py
--- a/psychopy/app/builder/dialogs/__init__.py
+++ b/psychopy/app/builder/dialogs/__init__.py
@@ -1644,3 +1644,22 @@ def show(self):
         else:
             self.OK = False
         return wx.ID_OK
+
+
+def _relpath(path, start='.'):
+    """This code is based on os.path.relpath in the Python 2.6 distribution,
+    included here for compatibility with Python 2.5"""
+
+    if not path:
+        raise ValueError("no path specified")
+
+    start_list = os.path.abspath(start).split(os.path.sep)
+    path_list = os.path.abspath(path).split(os.path.sep)
+
+    # Work out how much of the filepath is shared by start and path.
+    i = len(os.path.commonprefix([start_list, path_list]))
+
+    rel_list = ['..'] * (len(start_list) - i) + path_list[i:]
+    if not rel_list:
+        return path
+    return os.path.join(*rel_list)
\ No newline at end of file


Test patch:
Repository: psychopy/psychopy

Issue:
numpy future warning
```
##### Running: /Users/jgray/code/psychopy/psychopy/demos/coder/stimuli/colors.py #####
/Users/jgray/code/psychopy/psychopy/visual/helpers.py:246: 
FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if numpy.all(win.dkl_rgb == numpy.ones([3, 3])):
```



Discussion:
`if win.dkl_rgb is None or numpy.all(win.dkl_rgb == numpy.ones([3, 3])):`

is that the same?

There's no FutureWarning if I add that into visual.helpers.py 

probably need the same fix at visual/helpers.py:253: `if numpy.all(win.lms_rgb == numpy.ones([3, 3])):`


Resolving patch:
diff --git a/psychopy/visual/helpers.py b/psychopy/visual/helpers.py
--- a/psychopy/visual/helpers.py
+++ b/psychopy/visual/helpers.py
@@ -243,14 +243,16 @@ def setColor(obj, color, colorSpace=None, operation='',
     if colorSpace in ['rgb', 'rgb255']:
         setattr(obj, rgbAttrib, newColor)
     elif colorSpace == 'dkl':
-        if numpy.all(win.dkl_rgb == numpy.ones([3, 3])):
+        if (win.dkl_rgb is None or
+                numpy.all(win.dkl_rgb == numpy.ones([3, 3]))):
             dkl_rgb = None
         else:
             dkl_rgb = win.dkl_rgb
         setattr(obj, rgbAttrib, colors.dkl2rgb(
             numpy.asarray(newColor).transpose(), dkl_rgb))
     elif colorSpace == 'lms':
-        if numpy.all(win.lms_rgb == numpy.ones([3, 3])):
+        if (win.lms_rgb is None or
+                numpy.all(win.lms_rgb == numpy.ones([3, 3]))):
             lms_rgb = None
         elif win.monitor.getPsychopyVersion() < '1.76.00':
             logging.error("The LMS calibration for this monitor was carried"


Test patch: