From 713ea1f6440e0547bef9606e36719df55f3292d2 Mon Sep 17 00:00:00 2001 From: Todd OST Date: Fri, 20 Sep 2024 10:26:21 +0100 Subject: [PATCH] BF: Fix error writing Polygon initial colors in JS --- .../experiment/components/polygon/__init__.py | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/psychopy/experiment/components/polygon/__init__.py b/psychopy/experiment/components/polygon/__init__.py index 2249f0a9d4..5f40d265d7 100644 --- a/psychopy/experiment/components/polygon/__init__.py +++ b/psychopy/experiment/components/polygon/__init__.py @@ -293,28 +293,27 @@ def writeInitCodeJS(self, buff): if self.params['interpolate'].val != 'linear': interpolate = 'false' - code += (" ori: {ori}, \n" - " pos: {pos}, \n" - " draggable: {draggable}, \n" - " anchor: {anchor},\n" - " lineWidth: {lineWidth}, \n" - " colorSpace: {colorSpace},\n") - - if inits['lineColor'] == 'undefined': - code += " lineColor: {lineColor},\n" - else: - code += " lineColor: new util.Color({lineColor}),\n" - - if inits['fillColor'] == 'undefined': - code += " fillColor: {fillColor},\n" - else: - code += " fillColor: new util.Color({fillColor}),\n" - - - code += ( " fillColor: {fillColor},\n" - " opacity: {opacity}, depth: {depth}, interpolate: {interpolate},\n" - "}});\n\n") - + # make a util.Color object for non-transparent + for key in ("fillColor", "lineColor"): + if inits[key].val != "undefined": + inits[key].val = "new util.Color(%s)" % inits[key] + inits[key].valType = "code" + # add other params + code += ( + " ori: {ori}, \n" + " pos: {pos}, \n" + " draggable: {draggable}, \n" + " anchor: {anchor}, \n" + " lineWidth: {lineWidth}, \n" + " lineColor: {lineColor}, \n" + " fillColor: {fillColor}, \n" + " colorSpace: {colorSpace}, \n" + " opacity: {opacity}, \n" + " depth: {depth}, \n" + " interpolate: {interpolate}, \n" + "}});\n" + "\n" + ) buff.writeIndentedLines(code.format(name=inits['name'], unitsStr=unitsStr, anchor=inits['anchor'],