#!/usr/bin/env python import sys from omniORB import CORBA, PortableServer import CosNaming, calculator, calculator__POA class Scientific (calculator__POA.Scientific): def initializePlugin(self, guimanager): self.guiManager = guimanager file = open('gui.xml','r') self.guiManager.initializeUserInterface(file) def close(self): self.guiManager = null def square(self): self.guiManager.getText("display") print "test" # Initialise the ORB and find the root POA # orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID) print sys.argv """-ORBInitialHost localhost -ORBInitialPort 900""" orb = CORBA.ORB_init(["-ORBInitialHost", "localhost", "-ORBInitialPort", "1050"]) """orb = CORBA.ORB_init(["-ORBInitRef", "NameService=corbaname::localhost:1050"])""" poa = orb.resolve_initial_references("RootPOA") # Create an instance ei = Scientific() eo = ei._this() # Obtain a reference to the root naming context obj = orb.resolve_initial_references("NameService") rootContext = obj._narrow(CosNaming.NamingContext) if rootContext is None: print "Failed to narrow the root naming context" sys.exit(1) # Bind a context to the root context name = [CosNaming.NameComponent("CalcPlugScientific", "CalculatorPlugin")] try: testContext = rootContext.bind_new_context(name) print "New context bound" except CosNaming.NamingContext.AlreadyBound, ex: print "context already exists" obj = rootContext.resolve(name) testContext = obj._narrow(CosNaming.NamingContext) if testContext is None: print "context exists but is not a NamingContext" sys.exit(1) # Bind the object to the context name = [CosNaming.NameComponent("calculatorScientific", "Object")] try: testContext.bind(name, eo) print "New object bound" except CosNaming.NamingContext.AlreadyBound: testContext.rebind(name, eo) print "binding already existed -- rebound" name = [CosNaming.NameComponent("CalcPlugScientific", "CalculatorPlugin"), CosNaming.NameComponent("calculatorScientific", "Object")] try: obj = rootContext.resolve(name) print obj eo = obj._narrow(calculator.Plugin) print eo #eo.initializeUserInterface() except CosNaming.NamingContext.NotFound, ex: print "Name not found" sys.exit(1) # Activate the POA poaManager = poa._get_the_POAManager() poaManager.activate() # Block for ever (or until the ORB is shut down) orb.run()