I am running into an issue with engine_init and Qt. Here is my code:
from sgtk.platform.qt import QtGui
from tank import Hook
class EngineInit(Hook):
def execute(self, engine, **kwargs):
"""
Executed when a Toolkit engine has been fully initialized.
At this point, all apps and frameworks have been loaded,
and the engine is fully operational.
The default implementation does nothing.
:param engine: Engine that has been initialized.
:type engine: :class:`~sgtk.platform.Engine`
"""
self.engine = engine
# Store a handy reference to the Shotgun API
self.sg = self.parent.shotgun
if self.engine.context.project:
# QtGui.QMessageBox.information(self, "Greetings", "Hello!")
self.logger.info("*** Project Id: {}".format(self.engine.context.project.get("id")))
self.logger.info("*** User Id: {}".format(self.engine.context.user.get("id")))
If I run this ‘as-is’ everything works fine. I get the info lines logged with my project and user id numbers. But, if I uncomment the QtGui line, the code never gets to the logging and I get an error (see below) about the parent being passed in to QMessageBox. If I am running this from a Toolkit app I am able to use QtGui.QApplication.activeWindow()
as the parent. But, what should I be using for the parent when it is coming from engine_init as self
does not seem to work because that tries to use EngineInit as the parent to the message box. What should that be using as the parent?
In case it helps, here is the error I am getting:
2020-08-27 11:29:57,465 [ ERROR] [PROXY] Exception raised while executing hook '/Users/mharris/work/sandbox/Shotgun/toolkit/configs/tk-config-default2/core/hooks/engine_init.py'
Traceback (most recent call last):
File "/Users/mharris/Library/Caches/Shotgun/pipetd-dev/p122c1.basic.desktop/cfg/install/core/python/tank/pipelineconfig.py", line 1218, in execute_core_hook_internal
return_value = hook.execute_hook(hook_path, parent, **kwargs)
File "/Users/mharris/Library/Caches/Shotgun/pipetd-dev/p122c1.basic.desktop/cfg/install/core/python/tank/hook.py", line 577, in execute_hook
return execute_hook_method([hook_path], parent, None, **kwargs)
File "/Users/mharris/Library/Caches/Shotgun/pipetd-dev/p122c1.basic.desktop/cfg/install/core/python/tank/hook.py", line 631, in execute_hook_method
ret_val = hook_method(**kwargs)
File "/Users/mharris/work/sandbox/Shotgun/toolkit/configs/tk-config-default2/core/hooks/engine_init.py", line 37, in execute
QtGui.QMessageBox.information(self, "Greetings", "Hello!")
TypeError: 'PySide.QtGui.QMessageBox.information' called with wrong argument types:
PySide.QtGui.QMessageBox.information(EngineInit, str, str)
Supported signatures:
PySide.QtGui.QMessageBox.information(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QMessageBox.StandardButtons = QMessageBox.Ok, PySide.QtGui.QMessageBox.StandardButton = NoButton)
PySide.QtGui.QMessageBox.information(PySide.QtGui.QWidget, unicode, unicode, PySide.QtGui.QMessageBox.StandardButton, PySide.QtGui.QMessageBox.StandardButton = NoButton)