Skip to content

Commit

Permalink
BF: Keep track of context for colorpicker and prepend a $ if it's goi…
Browse files Browse the repository at this point in the history
…ng to Builder - otherwise it compiles as a string and breaks
  • Loading branch information
Todd authored and Todd committed Mar 3, 2021
1 parent 0419007 commit 054dab7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion psychopy/app/builder/dialogs/paramCtrls.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def __init__(self, parent, valType,
self.validate()

def colorPicker(self, evt):
dlg = PsychoColorPicker(self.GetTopLevelParent().frame)
dlg = PsychoColorPicker(self.GetTopLevelParent().frame, context='builder')
dlg.ShowModal()
dlg.Destroy()

Expand Down
12 changes: 10 additions & 2 deletions psychopy/app/colorpicker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PsychoColorPicker(wx.Dialog):
Reference to a :class:`~wx.Frame` which owns this dialog.
"""
def __init__(self, parent):
def __init__(self, parent, context=None):
wx.Dialog.__init__(
self,
parent,
Expand All @@ -40,6 +40,9 @@ def __init__(self, parent):
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.SetMinSize(wx.Size(600, 480))

# Store context
self.context = context

# current output color, should be displayed in the preview
global LAST_COLOR
self._color = LAST_COLOR.copy()
Expand Down Expand Up @@ -339,6 +342,8 @@ def onCopyObject(self, event):
outputSpace = self.cboOutputSpace.GetSelection()
toReturn = "colors.Color({}, space='{}')".format(
self.getOutputValue(), self._spaces[outputSpace])
if self.context == 'builder':
toReturn = "$" + toReturn
self._copyToClipboard(toReturn)
self.Close()
event.Skip()
Expand All @@ -347,7 +352,10 @@ def onCopyValue(self, event):
"""Event to copy the color to the clipboard as a value.
"""
self._copyToClipboard(self.getOutputValue()) # copy out to clipboard
toReturn = self.getOutputValue()
if self.context == 'builder':
toReturn = "$" + toReturn
self._copyToClipboard(toReturn) # copy out to clipboard
self.Close()
event.Skip()

Expand Down

0 comments on commit 054dab7

Please sign in to comment.