Here’s my working solution. Maybe there’s a more elegant way to do this?
from PySide2.QtWidgets import QApplication
def refresh_shotgunpanel():
for widget in QApplication.allWidgets():
if widget.objectName() != "panel_tk_multi_shotgunpanel_main":
continue
for child in widget.children():
if "ActionManager" not in type(child).__name__:
continue
break
else:
print("ActionManager not found")
break
child.refresh_request.emit()
print("Panel refreshed")
return
else:
print("Panel not found")
refresh_shotgunpanel()
I have a suggestion that might be easier. I tested it and it appears to work.
You need to get hold of the app object and call the navigate() method.
import sgtk
# get the current engine instance
engine = sgtk.platform.current_engine()
panel_app = engine.apps["tk-multi-shotgunpanel"]
# use the app's navigate method to trigger a refresh.
panel_app.navigate("Project", engine.context.project["id"], panel_app.PANEL)
In the example above, I’m in a project context, so I’m just refreshing the project. But if you are in a task context then you would pass "Task", engine.context.task["id"], ..., so that it navigates to the exact same context, but triggers a refresh.
Hope that helps?
You can use python to inspect the loader and it’s exposed functions, something like this:
from pprint import pprint
import sgtk
# get the current engine instance
engine = sgtk.platform.current_engine()
app = engine.apps["tk-multi-loader2"]
pprint(dir(app))
This will print all the apps functions and properties