def send(message='ping 1234', port=PORT): ''' Sends a raw message Trick here is that PyQt5 does not do automatic str<->byte encoding, but pya does. Also something weird with the addresses ''' payload = message + '\r\n' psock = QTcpSocket() if not isGSI(): payload = payload.encode() psock.connectToHost(localhost, port) if psock.waitForConnected(): psock.write(payload) if psock.waitForReadyRead(3000): ret = psock.readLine() if not isGSI(): ret = bytes(ret).decode('utf-8') handle_query(ret) else: raise Exception('Not acknowledged') else: print('Connection Fail! (tried {}:{})'.format(localhost, port))
''' The simplest interpreter you can imagine. Currently there are 4 commands and 0 queries Other ideas to implement: - query for value of variable as a string - execute arbitrary line of code, return its return value as a string - execute a macro ''' from __future__ import print_function from lyipc import quickmsg, isGSI import lyipc.server import os import traceback if not isGSI(): raise RuntimeError('Non-klayout serving does not make sense') import pya def quiet_load_layout(filename, mode=0): ''' Swallow the error if the file is not completely written yet, or if the last file was not completely rendered. This doesn't seem to fatally affect the program. Modes are - 0 (default): replacing the current layout view - 1: making a new view - 2: adding the layout to the current view (mode 2) ''' main = pya.Application.instance().main_window() try: view = main.load_layout(filename, mode)