Removed query for color, added refresh of inventory after action

This commit is contained in:
wijnand 2018-05-03 14:33:09 +02:00
parent 481ffb6e13
commit 74efe81d6e

View file

@ -5,31 +5,36 @@ import avalon.fusion
class FusionSelectLoaderColor(api.InventoryAction):
"""Update the color of the selected tools"""
label = "Select Loader Color"
icon = "plus"
color = "#d8d8d8"
def process(self, containers):
"""Color all selected tools the selected colors"""
comp = avalon.fusion.get_current_comp()
# Get color of selected container
_tool = containers[0]["_tool"]
table = _tool.TileColor
if table:
color = QtGui.QColor.fromRgbF(table["R"], table["G"], table["B"])
else:
color = QtGui.QColor.fromRgbF(0.0, 0.0, 0.0)
# Launch pick color
color = QtGui.QColor(1.0, 1.0, 1.0)
picked_color = QtWidgets.QColorDialog().getColor(color)
with avalon.fusion.comp_lock_and_undo_chunk(comp):
for container in containers:
# Convert color to 0-1 floats
# Convert color to RGB 0-1 floats
rgb_f = picked_color.getRgbF()
rgb_f_table = {"R": rgb_f[0], "G": rgb_f[1], "B": rgb_f[2]}
# Update tool
tool = container["_tool"]
tool.TileColor = rgb_f_table
self.refresh()
def refresh(self):
"""Refresh Scene Inventory window"""
app = QtWidgets.QApplication.instance()
widgets = dict((w.objectName(), w) for w in app.allWidgets())
widget = widgets.get("SceneInventory")
widget.refresh()