Skip to content

Blender: Make color-picker dialog non-modal #3805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions src/windows/views/blender_listview.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,41 @@ def color_button_clicked(self, widget, param, index):
# Get translation object
_ = get_app()._tr

# Show color dialog
color_value = self.params[param["name"]]
currentColor = QColor("#FFFFFF")
if len(color_value) >= 3:
currentColor.setRgbF(color_value[0], color_value[1], color_value[2])
newColor = QColorDialog.getColor(currentColor, self, _("Select a Color"),
QColorDialog.DontUseNativeDialog)
if newColor.isValid():
widget.setStyleSheet("background-color: {}".format(newColor.name()))
self.params[param["name"]] = [newColor.redF(), newColor.greenF(), newColor.blueF()]
if "diffuse_color" in param.get("name"):
self.params[param["name"]].append(newColor.alphaF())

log.info('Animation param %s set to %s' % (param["name"], newColor.name()))
# Store our arguments for the callback to pick up again
self._color_scratchpad = (widget, param)

# Set up non-modal color dialog (to avoid blocking the eyedropper)
self.newColorDialog = QColorDialog(currentColor, self.win)
self.newColorDialog.setWindowTitle(_("Select a Color"))
self.newColorDialog.setWindowFlags(Qt.Tool)
self.newColorDialog.setOptions(QColorDialog.DontUseNativeDialog)
# Avoid signal loops
self.newColorDialog.blockSignals(True)
self.newColorDialog.colorSelected.connect(self.color_selected)
self.newColorDialog.finished.connect(self.newColorDialog.deleteLater)
self.newColorDialog.blockSignals(False)
self.newColorDialog.open()

@pyqtSlot(QColor)
def color_selected(self, newColor):
"""QColorDialog callback when the user chooses a color"""
if not self._color_scratchpad:
log.warning("QColorDialog callback called without parameter to set")
return
(widget, param) = self._color_scratchpad
if not newColor or not newColor.isValid():
return
widget.setStyleSheet("background-color: {}".format(newColor.name()))
self.params[param["name"]] = [
newColor.redF(), newColor.greenF(), newColor.blueF()
]
if "diffuse_color" in param.get("name"):
self.params[param["name"]].append(newColor.alphaF())
log.info('Animation param %s set to %s', param["name"], newColor.name())

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

self.selected = None
self.deselected = None
self._color_scratchpad = None
self.newColorDialog = None
self.selected_template = ""
self.final_render = False

Expand Down