def init_qt_app(self): self.logger.debug("%s: Initializing QtApp for Unreal", self) from sgtk.platform.qt5 import QtWidgets if not QtWidgets.QApplication.instance(): self._qt_app = QtWidgets.QApplication(sys.argv) self._qt_app.setQuitOnLastWindowClosed(False) unreal.log("Created QApplication instance: {0}".format( self._qt_app)) def _app_tick(dt): QtWidgets.QApplication.processEvents() tick_handle = unreal.register_slate_post_tick_callback(_app_tick) def _app_quit(): unreal.unregister_slate_post_tick_callback(tick_handle) QtWidgets.QApplication.instance().aboutToQuit.connect(_app_quit) else: self._qt_app = QtWidgets.QApplication.instance() # Make the QApplication use the dark theme. Must be called after the QApplication is instantiated self._initialize_dark_look_and_feel()
def init_qt_app(self): self.logger.debug("%s: Initializing QtApp for Unreal", self) from sgtk.platform.qt5 import QtWidgets if not QtWidgets.QApplication.instance(): self._qt_app = QtWidgets.QApplication(sys.argv) self._qt_app.setQuitOnLastWindowClosed(False) else: self._qt_app = QtWidgets.QApplication.instance() # On other platforms than Windows, we need to process the Qt events otherwise # UIs are "frozen". We use a slate tick callback to do that on a regular basis. # It is not clear why this is not needed on Windows, possibly because a # dedicated Windows event dispatcher is used instead of a regular # QAbstractEventDispatcher if sys.platform != "win32": unreal.register_slate_post_tick_callback( self._process_qt_events_cb) # Make the QApplication use the dark theme. Must be called after the QApplication is instantiated self._initialize_dark_look_and_feel()
window.eventTick(delta_seconds) # This function will be called when the application is closing. def __QtAppQuit__(): unreal.unregister_slate_post_tick_callback(tick_handle) # This function is called by the windows when they are closing. (Only if the connection is properly made.) def __QtWindowClosed__(window=None): if window in opened_windows: opened_windows.remove(window) # This part is for the initial setup. Need to run once to spawn the application. unreal_app = QtWidgets.QApplication.instance() if not unreal_app: unreal_app = QtWidgets.QApplication(sys.argv) tick_handle = unreal.register_slate_post_tick_callback(__QtAppTick__) unreal_app.aboutToQuit.connect(__QtAppQuit__) existing_windows = {} opened_windows = [] # desired_window_class: class QtGui.QWidget : The window class you want to spawn # return: The new or existing window def spawnQtWindow(desired_window_class=None): window = existing_windows.get(desired_window_class, None) if not window: window = desired_window_class() existing_windows[desired_window_class] = window window.aboutToClose = __QtWindowClosed__ if window not in opened_windows: opened_windows.append(window) window.show()
#################### """) assetregistry_pretickhandle = None def assetregistry_postload_handle(deltaTime): """ Run callback method after registry run to prevent crashed when create new asset at startupS """ unreal.log_warning("..Checking Asset Registy Status...") if AssetRegistry.is_loading_assets(): unreal.log_warning("..Asset registy still loading...") else: unreal.log_warning("Asset registy ready!") unreal.unregister_slate_post_tick_callback(assetregistry_pretickhandle) AssetRegistryPostLoad.run_callbacks() assetregistry_pretickhandle = unreal.register_slate_post_tick_callback(assetregistry_postload_handle) import BlueprintLibrary import UserInterfaces def reload(): import importlib importlib.reload(BlueprintLibrary) importlib.reload(UserInterfaces) unreal_uiutils.refresh()
return wrapper if __name__ == "__main__": # NOTE This part is for the initial setup. Need to run once to spawn the application. unreal_app = QtWidgets.QApplication.instance() if not unreal_app: unreal_app = QtWidgets.QApplication([]) def __QtAppTick__(delta_seconds): QtWidgets.QApplication.sendPostedEvents() tick_handle = unreal.register_slate_post_tick_callback(__QtAppTick__) __QtAppQuit__ = partial(unreal.unregister_slate_post_tick_callback, tick_handle) unreal_app.aboutToQuit.connect(__QtAppQuit__) # NOTE override show method QtWidgets.QWidget.show = slate_deco(QtWidgets.QWidget.show) with open(os.path.join(CONFIG, "main.css"), "r") as f: unreal_app.setStyleSheet(f.read()) fail_menus = create_menu() if fail_menus: global __tick_menu_elapsed__ __tick_menu_elapsed__ = 0
def __init__(self): self.schedule = deque() self._delegate_handle = unreal.register_slate_post_tick_callback( self._callback)
Listen server bound to the unreal slate tick used to recieve commands from external python instances """ import unreal import socket import select import sys import tools_library.ue4 import tools_library.framework.types.listen_server listen_port = tools_library.ue4.listen_port() listen_server = tools_library.framework.types.listen_server.ListenServer( listen_port) def slate_tick(delta_seconds): """Function bound to unreal's slate tick""" listen_server.tick() def engine_shutdown(): """Called when unreal shuts down""" unreal.unregister_slate_post_tick_callback(slate_tick_handle) unreal.unregister_python_shutdown_callback(engine_shutdown_handle) slate_tick_handle = unreal.register_slate_post_tick_callback(slate_tick) engine_shutdown_handle = unreal.register_python_shutdown_callback( engine_shutdown)