def launch(*subprocess_args): """Starts the websocket server that will be hosted in the Photoshop extension. """ from avalon import api, photoshop api.install(photoshop) sys.excepthook = safe_excepthook # Launch Photoshop and the websocket server. process = subprocess.Popen(subprocess_args, stdout=subprocess.PIPE) websocket_server = WebServerTool() # Add Websocket route websocket_server.add_route("*", "/ws/", WebSocketAsync) # Add after effects route to websocket handler route_name = 'Photoshop' print("Adding {} route".format(route_name)) WebSocketAsync.add_route( route_name, PhotoshopRoute # keep same name as in extension ) websocket_server.start_server() while True: if process.poll() is not None: print("Photoshop process is not alive. Exiting") websocket_server.stop() sys.exit(1) try: _stub = photoshop.stub() if _stub: break except Exception: time.sleep(0.5) # Wait for application launch to show Workfiles. if os.environ.get("AVALON_PHOTOSHOP_WORKFILES_ON_LAUNCH", True): if os.getenv("WORKFILES_SAVE_AS"): workfiles.show(save=False) else: workfiles.show() # Photoshop could be closed immediately, withou workfile selection try: if photoshop.stub(): api.emit("application.launched") self.callback_queue = queue.Queue() while True: main_thread_listen(process, websocket_server) except ConnectionNotEstablishedYet: pass finally: # Wait on Photoshop to close before closing the websocket server process.wait() websocket_server.stop()
def launch(*subprocess_args): """Starts the websocket server that will be hosted in the Photoshop extension. """ from avalon import api, photoshop api.install(photoshop) sys.excepthook = safe_excepthook # Launch Photoshop and the websocket server. ConsoleTrayApp.process = subprocess.Popen( subprocess_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL ) websocket_server = WebServerTool() route_name = 'Photoshop' if websocket_server.port_occupied(websocket_server.host_name, websocket_server.port): log.info("Server already running, sending actual context and exit") asyncio.run(websocket_server.send_context_change(route_name)) sys.exit(1) # Add Websocket route websocket_server.add_route("*", "/ws/", WebSocketAsync) # Add after effects route to websocket handler print("Adding {} route".format(route_name)) WebSocketAsync.add_route( route_name, PhotoshopRoute # keep same name as in extension ) websocket_server.start_server() ConsoleTrayApp.websocket_server = websocket_server if os.environ.get("AVALON_PHOTOSHOP_WORKFILES_ON_LAUNCH", True): save = False if os.getenv("WORKFILES_SAVE_AS"): save = True ConsoleTrayApp.execute_in_main_thread(lambda: workfiles.show(save))
def launch_workfiles_app(*_args, **_kwargs): workfiles.show(os.path.join( cmds.workspace(query=True, rootDirectory=True), cmds.workspace(fileRuleEntry="scene")), parent=pipeline._parent)