def setup_master(): missionControlPort = int(sys.argv[1]) webServerPort = int(sys.argv[2]) # do a cleanup, and also register kill_slaves to be called on exit. kill_slaves(nodeNames) import atexit atexit.register(kill_slaves, nodeNames) # Launch the monitor slaves for node in nodeNames: cmd = "ssh -n {0} cd {1}; {2} -c system/headless.cfg monitor.py --mc @{3}:{4} -N {5} -L off --interactive-off".format( node, os.getcwd(), ogetexecpath(), serverName, missionControlPort, node) olaunch(cmd) sleep(0.1) # Launch the web server global ps porthole.initialize(webServerPort, './index.html') ps = porthole.getService()
# Basic porthole example import porthole # Setup porthole porthole.initialize(4080, './input.html') ps = porthole.getService() # print input events def onEvent(): e = getEvent() if(e.getServiceType() == ServiceType.Keyboard): if(e.getType() == EventType.Down): print("Key down: " + chr(e.getSourceId())) if(e.getServiceType() == ServiceType.Pointer): if(e.getType() == EventType.Down): print("Pointer button down") elif(e.getType() == EventType.Up): print("Pointer button up") elif(e.getType() == EventType.Move): print("Pointer move:" + str(e.getPosition())) setEventFunction(onEvent)
# This example shows how to do basic camera streaming to # a web interface using porthole. # opena browser to http://127.0.0.1:4080 import porthole # Setup porthole porthole.initialize('porthole/default.xml') porthole.getService().setServerStartedCommand("print('porthole web server ready! connect to http://localhost:4080')") porthole.getService().setCameraCreatedCommand("onCameraCreated(%id%)") def onCameraCreated(camId): global clientCamera camera = getCameraById(camId); #camera.setOverlayEnabled(False) camera.setHeadOffset(getDefaultCamera().getHeadOffset()) print("camera created " + camera.getName()) getDefaultCamera().addChild(camera)
img.setData(v.getPixels()) img.setAutosize(False) # Inserting these resulted in it not working img.setSize(uim.getUi().getSize()) img.setStereo(True) v.play() # stores the id of the last web client connected. This is # the client in charge of controlling the running application. appControllerClient = "" mc = getMissionControlClient() # Setup web server if(isMaster()): porthole.initialize(4080, 'index.html') ps = porthole.getService() ps.setConnectedCommand('onClientConnected("%id%")') ps.setDisconnectedCommand('onClientDisconnected("%id%")') # This quick command is used to easily forward js commands to clients from # launched apps addQuickCommand('calljs', "ps.sendjs(\"%1%({0})\".format(%2%), appControllerClient)", 2, 'call js on porthole clients') def startApplication(clientId, appName): global appControllerClient, numApps, AppDict, currApp print "Preparing to Launch " + appName appControllerClient = clientId # 'app' is the application identifier, we can use it to send mission controlling # messages to the app using it.
import porthole # Setup web server porthole.initialize() ps = porthole.getService() ps.setDisconnectedCommand('onClientDisconnected()') def onClientDisconnected(): ps.clearCache()
# Basic porthole example import porthole # Setup porthole porthole.initialize(4080, './input.html') ps = porthole.getService() # print input events def onEvent(): e = getEvent() if (e.getServiceType() == ServiceType.Keyboard): if (e.getType() == EventType.Down): print("Key down: " + chr(e.getSourceId())) if (e.getServiceType() == ServiceType.Pointer): if (e.getType() == EventType.Down): print("Pointer button down") elif (e.getType() == EventType.Up): print("Pointer button up") elif (e.getType() == EventType.Move): print("Pointer move:" + str(e.getPosition())) setEventFunction(onEvent)
'M1Pt', 'M1Eta', 'M1Charge', 'M2Pt', 'M2Eta', 'M2Charge', 'MDr', 'Njets', 'Met', 'McType'] for f in fields: queueCommand("{0} = ds.addField('{0}', FieldType.Float, '{0}')".format(f)) ds.open("/Users/febret/omegalib/apps/simdata.csv", CsvLoader()) f = Filter() plots = [] selectionFilters = [] #------------------------------------------------------------------------------- # Web API import porthole porthole.initialize(8080, 'signac/viewer/index.html') ps = porthole.getService() # client requests lists of available fields def requestFieldList(client_id): data = [] for f in fields: data.append({'label': f}) ps.sendjs("receiveFieldList({0})" .format(data), client_id) # client requests creation of a new plot def requestNewPlot(client_id): plot = Plot() plot.setSize(400,400) plot.getBrush(0).setFilter(f)
# Basic porthole example import porthole # The box position. Will be updated by clients and read by new clients when they # connect. savedX = 0 savedY = 0 # Setup porthole porthole.initialize(4080, './dragSync.html') ps = porthole.getService() ps.setConnectedCommand("sendBoxPosition('%id%')") def sendBoxPosition(clientId): ps.sendjs( "$('#box').offset({left:" + str(savedX) + ", top:" + str(savedY) + "})", clientId)
# This example shows how to do use the porthole pointer interface to send mouse # and keyboard events to a remote application # open a browser to http://127.0.0.1:4080 import porthole # Setup porthole porthole.initialize('porthole/portholePointer.xml') porthole.getService().setServerStartedCommand("print('porthole web server ready! connect to http://localhost:4080')") #------------------------------------------------------------------------------ def onEvent(): e = getEvent() if(e.getServiceType() == ServiceType.Pointer): x = e.getPosition().x y = e.getPosition().y print("Pointer position: {0},{1}".format(x, y)) elif(e.getServiceType() == ServiceType.Keyboard and e.getType() == EventType.Down): print("Key Pressed: {0} = {1}".format(e.getSourceId(), chr(e.getSourceId()))) setEventFunction(onEvent)
from omium import * import porthole from overlay import * o = Omium.getInstance() ui = UiModule.createAndInitialize().getUi() porthole.initialize(4080, './hello.html') ps = porthole.getService() ps.setServerStartedCommand('loadUi()') def loadUi(): global img global p img = Overlay() img.setAutosize(True) guifx = OverlayEffect() guifx.setShaders('overlay/overlay.vert', 'overlay/overlay-flipy.frag') img.setEffect(guifx) p = o.getPixels() img.setTexture(p) o.open('http://localhost:4080') onResize() getDisplayConfig().canvasChangedCommand = 'onResize()' def onResize(): r = getDisplayConfig().getCanvasRect() o.resize(r[2], r[3]) porthole.broadcastjs("Hello()")
# Basic example showing use of the porthole streaming HTML5 interface from omega import * from cyclops import * import porthole porthole.initialize() porthole.getService().setConnectedCommand("print('client connected: %id%')") porthole.getService().setDisconnectedCommand( "print('client disconnected: %id%')") porthole.getService().setCameraCreatedCommand("onPortholeCameraCreated(%id%)") porthole.getService().setCameraDestroyedCommand( "onPortholeCameraDestroyed(%id%)") def onPortholeCameraCreated(id): print('Porthole camera created: ' + str(id)) cam = getCameraById(id) # Diable overlay (2D) stuff for the porthole camera. Just draw the 3D scene. cam.setOverlayEnabled(False) # Attach the porthole camera to the default one, to follow it. getDefaultCamera().addChild(cam) def onPortholeCameraDestroyed(id): cam = getCameraById(id) getDefaultCamera().removeChild(cam) box = BoxShape.create(0.8, 0.8, 0.8) box.setPosition(Vector3(0, 2, -3))
# create a box that will be oriented through sliders box = BoxShape.create(1,1,1) box.setEffect('colored -d red') box.setPosition(0, 2, -4) l = Light.create() l.setPosition(0, 4, 0) l.setColor(Color('white')) l.setAmbient(Color(0.2, 0.2, 0.2, 1)) def createUi(): global bw # create a webView to show the porthole interface. width = 440 height = 200 ui = UiModule.createAndInitialize() uiroot = ui.getUi() bw = BrowserWindow('Box Orientation', uiroot, width, height) bw.loadUrl("http://127.0.0.1:4080") bw.setDraggable(True) # Setup porthole porthole.initialize('syncSlider.xml') porthole.getService().setServerStartedCommand("createUi()") # Web interface callbacks def onOrientationChanged(pitch, yaw, roll, clientId): box.setOrientation(quaternionFromEulerDeg(pitch, yaw, roll)) # Update slider state on all connected clients. porthole.getService().broadcastjs('updateSliders({0}, {1}, {2})'.format(pitch,yaw,roll), clientId)
# Basic porthole example import porthole # Setup porthole porthole.initialize(4080, './chat.html') ps = porthole.getService() # Client call this function when posting a message. def postMessage(message, sender): print("{0}: {1}".format(sender, message)) ps.broadcastjs("messageReceived('{0}: {1}')".format(sender, message), '')
#------------------------------------------------------------------------------- # setup mission control and porthole from omega import * import porthole import sys missionControlPort = getMissionControlServer().getPort() webServerPort = 5005 # Launch the web server porthole.initialize(webServerPort, './index.html') webServer = porthole.getService() #------------------------------------------------------------------------------- # choose what services to launch here #import monitor import launcher
# This example shows how to do basic camera streaming to # a web interface using porthole. # opena browser to http://127.0.0.1:4080 import porthole # create a spinning box box = BoxShape.create(1,1,1) box.setEffect('colored -d red') box.setPosition(0, 2, -4) l = Light.create() l.setPosition(0, 4, 0) l.setColor(Color('white')) l.setAmbient(Color(0.2, 0.2, 0.2, 1)) # Setup porthole porthole.initialize('porthole/examples/basicPorthole.xml') porthole.getService().setServerStartedCommand("print('porthole web server ready! connect to http://localhost:4080')") porthole.getService().setCameraCreatedCommand("onCameraCreated(%id%)") # this dictionary will store the camera associated to each connected client clientCamera = {} def onCameraCreated(camId): global clientCamera camera = getCameraById(camId); camera.setOverlayEnabled(False) print("camera created " + camera.getName()) # porthole camera names are in the format [clientId]-[cameraId] # where clientId is a string, and cameraId is the numeric # camera identifier. args = camera.getName().split('-')
# Basic porthole example import porthole # Setup porthole porthole.initialize(4080, './chat.html') ps = porthole.getService() # Client call this function when posting a message. def postMessage(message, sender): print("{0}: {1}".format(sender, message) ) ps.broadcastjs("messageReceived('{0}: {1}')".format(sender, message), '')
global btn box.pitch(dt) box.yaw(dt / 3) setUpdateFunction(onUpdate) bw = None def createWebUi(): global bw # create a webView to show the porthole interface. width = 240 height = 240 ui = UiModule.createAndInitialize() uiroot = ui.getUi() bw = BrowserWindow('browser', uiroot, width, height) bw.loadUrl("http://127.0.0.1:4080") bw.setDraggable(True) # Setup porthole porthole.initialize('colorPicker.xml') porthole.getService().setConnectedCommand("print('client connected: %id%')") porthole.getService().setDisconnectedCommand( "print('client disconnected: %id%')") porthole.getService().setServerStartedCommand("createWebUi()")
box.getMaterial().setColor(Color(colorString), Color('black')) # Spin the box! def onUpdate(frame, t, dt): global btn box.pitch(dt) box.yaw(dt / 3) setUpdateFunction(onUpdate) bw = None def createWebUi(): global bw # create a webView to show the porthole interface. width = 240 height = 240 ui = UiModule.createAndInitialize() uiroot = ui.getUi() bw = BrowserWindow('browser', uiroot, width, height) bw.loadUrl("http://127.0.0.1:4080") bw.setDraggable(True) # Setup porthole porthole.initialize('colorPicker.xml') porthole.getService().setConnectedCommand("print('client connected: %id%')") porthole.getService().setDisconnectedCommand("print('client disconnected: %id%')") porthole.getService().setServerStartedCommand("createWebUi()")
# a web interface using porthole. # open a browser to http://127.0.0.1:4080 from cyclops import * import porthole # create a spinning box box = BoxShape.create(1,1,1) box.setEffect('colored -d red') box.setPosition(0, 2, -4) l = Light.create() l.setPosition(0, 4, 0) l.setColor(Color('white')) l.setAmbient(Color(0.2, 0.2, 0.2, 1)) # Setup porthole ps = porthole.initialize(4080, './stream.html') camera = None def createCamera(clientId): global camera camera = getOrCreateCamera('cam'); camera.setOverlayEnabled(False) print("camera created " + camera.getName()) pc = porthole.PortholeCamera() pc.initialize(camera, 'camera-stream', 400, 400) ps.findClient(clientId).addCamera(pc) #------------------------------------------------------------------------------ # MAIN UPDATE FUNCTION # Spin the box, and update the porthole cameras def onUpdate(frame, t, dt):