Skip to content

Commit 4d41fd2

Browse files
authored
Merge pull request #3805 from ferdnyc/non-modal-color
Blender: Make color-picker dialog non-modal
2 parents f23c282 + 791e7a1 commit 4d41fd2

File tree

1 file changed

+33
-10
lines changed

1 file changed

+33
-10
lines changed

src/windows/views/blender_listview.py

+33-10
Original file line numberDiff line numberDiff line change
@@ -222,20 +222,41 @@ def color_button_clicked(self, widget, param, index):
222222
# Get translation object
223223
_ = get_app()._tr
224224

225-
# Show color dialog
226225
color_value = self.params[param["name"]]
227226
currentColor = QColor("#FFFFFF")
228227
if len(color_value) >= 3:
229228
currentColor.setRgbF(color_value[0], color_value[1], color_value[2])
230-
newColor = QColorDialog.getColor(currentColor, self, _("Select a Color"),
231-
QColorDialog.DontUseNativeDialog)
232-
if newColor.isValid():
233-
widget.setStyleSheet("background-color: {}".format(newColor.name()))
234-
self.params[param["name"]] = [newColor.redF(), newColor.greenF(), newColor.blueF()]
235-
if "diffuse_color" in param.get("name"):
236-
self.params[param["name"]].append(newColor.alphaF())
237-
238-
log.info('Animation param %s set to %s' % (param["name"], newColor.name()))
229+
# Store our arguments for the callback to pick up again
230+
self._color_scratchpad = (widget, param)
231+
232+
# Set up non-modal color dialog (to avoid blocking the eyedropper)
233+
self.newColorDialog = QColorDialog(currentColor, self.win)
234+
self.newColorDialog.setWindowTitle(_("Select a Color"))
235+
self.newColorDialog.setWindowFlags(Qt.Tool)
236+
self.newColorDialog.setOptions(QColorDialog.DontUseNativeDialog)
237+
# Avoid signal loops
238+
self.newColorDialog.blockSignals(True)
239+
self.newColorDialog.colorSelected.connect(self.color_selected)
240+
self.newColorDialog.finished.connect(self.newColorDialog.deleteLater)
241+
self.newColorDialog.blockSignals(False)
242+
self.newColorDialog.open()
243+
244+
@pyqtSlot(QColor)
245+
def color_selected(self, newColor):
246+
"""QColorDialog callback when the user chooses a color"""
247+
if not self._color_scratchpad:
248+
log.warning("QColorDialog callback called without parameter to set")
249+
return
250+
(widget, param) = self._color_scratchpad
251+
if not newColor or not newColor.isValid():
252+
return
253+
widget.setStyleSheet("background-color: {}".format(newColor.name()))
254+
self.params[param["name"]] = [
255+
newColor.redF(), newColor.greenF(), newColor.blueF()
256+
]
257+
if "diffuse_color" in param.get("name"):
258+
self.params[param["name"]].append(newColor.alphaF())
259+
log.info('Animation param %s set to %s', param["name"], newColor.name())
239260

240261
def generateUniqueFolder(self):
241262
""" Generate a new, unique folder name to contain Blender frames """
@@ -651,6 +672,8 @@ def __init__(self, parent, *args):
651672

652673
self.selected = None
653674
self.deselected = None
675+
self._color_scratchpad = None
676+
self.newColorDialog = None
654677
self.selected_template = ""
655678
self.final_render = False
656679

0 commit comments

Comments
 (0)