def close(self, evt): if self.toplevel: self.toplevel = None try: self.game.unwatchGame(self.cookie) except CORBA.SystemException, ex: print "System exception trying to unwatch game:" print " ", CORBA.id(ex), ex id = poa.servant_to_id(self) poa.deactivate_object(id)
def main(args): orb = CORBA.ORB_init(args) poa = orb.resolve_initial_references("RootPOA") orb.register_value_factory(CORBA.id(ValueTest.Three), Three_i) ti = Test_i() to = ti._this() print orb.object_to_string(to) poa._get_the_POAManager().activate() orb.run()
def killGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] try: info.obj.kill() msg = "killed" except CORBA.SystemException, ex: print "System exception trying to kill game:" print " ", CORBA.id(ex), ex msg = "error contacting object"
def getGameList(self): """Get the list of games from the GameFactory, and populate the Listbox in the GUI""" # To make life interesting, we get the game information # structures one at a time from the server. It would be far # more sensible to get them many at a time. self.gameList = [] self.listbox.delete(0, END) try: seq, iterator = self.gameFactory.listGames(0) except CORBA.SystemException, ex: print "System exception contacting GameFactory:" print " ", CORBA.id(ex), ex return
def getGameList(self): """Get the list of games from the GameFactory, and populate the Listbox in the GUI""" # To make life interesting, we get the game information # structures one at a time from the server. It would be far # more sensible to get them many at a time. self.gameList = [] self.listbox.delete(0,END) try: seq, iterator = self.gameFactory.listGames(0) except CORBA.SystemException, ex: print "System exception contacting GameFactory:" print " ", CORBA.id(ex), ex return
def click(self, evt): x = evt.x / 100 y = evt.y / 100 try: self.statusMessage("Waiting for other player...") state = self.controller.play(x, y) self.drawState(state) except TicTacToe.GameController.SquareOccupied: self.statusMessage("Square already occupied") except TicTacToe.GameController.NotYourGo: self.statusMessage("Not your go") except TicTacToe.GameController.InvalidCoordinates: self.statusMessage("Eek! Invalid coordinates") except CORBA.SystemException: print "System exception trying to contact GameController:" print " ", CORBA.id(ex), ex self.statusMessage("System exception contacting GameController!")
def newGameEntered(self, evt): name = evt.widget.get() self.newGameDialogue.destroy() self.newGameDialogue = None if name == "": self.statusMessage("You must give a non-empty name") return try: game = self.gameFactory.newGame(name) except TicTacToe.GameFactory.NameInUse: self.statusMessage("Game name in use") return except CORBA.SystemException, ex: print "System exception trying to create new game:" print " ", CORBA.id(ex), ex self.statusMessage("System exception trying to create new game") return
def selectGame(self, evt): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] try: players = info.obj._get_players() if players == 0: msg = "no players yet" elif players == 1: msg = "one player waiting" else: msg = "game in progress" except CORBA.SystemException, ex: print "System exception contacting Game:" print " ", CORBA.id(ex), ex msg = "error contacting Game object"
def watchGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] si = Spectator_i(self.master, info.name) id = poa.activate_object(si) so = poa.id_to_reference(id) try: cookie, state = info.obj.watchGame(so) si.go(info.obj, cookie, state) self.statusMessage("Watching %s" % info.name) except CORBA.SystemException, ex: poa.deactivate_object(id) print "System exception trying to watch game:" print " ", CORBA.id(ex), ex self.statusMessage("%s: system exception contacting game" % \ info.name) self.getGameList()
def main(args): orb = CORBA.ORB_init(args) poa = orb.resolve_initial_references("RootPOA") poa._get_the_POAManager().activate() orb.register_value_factory(CORBA.id(ValueTest.Three), Three_i) obj = orb.string_to_object(args[1]) obj = obj._narrow(ValueTest.Test) v1 = ValueTest.One("hello", 123) v2 = ValueTest.One("test", 42) v3 = ValueTest.Two(None, None) v4 = ValueTest.Two(v1, None) v5 = ValueTest.Two(v1, v2) v6 = ValueTest.Two(v1, v1) v7 = Derived.Five("abc", 456, "more") obj.show("Simple values") r1 = obj.op1(v1) r2 = obj.op1(v2) r3 = obj.op1(None) obj.show("Two different values") obj.op2(v1, v2) obj.show("Nil, value") obj.op2(None, v1) obj.show("Value, nil") obj.op2(v1, None) obj.show("Two nils") obj.op2(None, None) obj.show("Two references to the same value") obj.op2(v1, v1) obj.show("Value containing two nils") r4 = obj.op3(v3) obj.show("Value containing value, nil") r5 = obj.op3(v4) obj.show("Value containing val1, val2") r6 = obj.op3(v5) obj.show("Value containing two references to same value") r7 = obj.op3(v6) obj.show("Derived value (should be truncated)") r8 = obj.op1(v7) obj.show("Same derived value twice") obj.op2(v7, v7) obj.show("Base value, derived value") obj.op2(v1, v7) obj.show("Derived value, base value") obj.op2(v7, v1) obj.show("String in valuebox") r9 = obj.op4("Hello") obj.show("Empty value box") r10 = obj.op4(None) obj.show("Nil abstract interface") obj.op5(None) fi = Four_i() fo = fi._this() obj.show("Abstract interface set to object reference") obj.op5(fo) t = Three_i("experiment") obj.show("Abstract interface set to value") obj.op5(t) # Any tests a1 = CORBA.Any(ValueTest._tc_One, v1) a2 = CORBA.Any(Derived._tc_Five, v7) v8 = Derived.Six(1.234, "test") a3 = CORBA.Any(Derived._tc_Six, v8) a4 = CORBA.Any(ValueTest._tc_One, None) a5 = CORBA.Any(ValueTest._tc_One, v2) a6 = CORBA.Any(ValueTest._tc_One, v2) obj.show("Value in Any") obj.op6(a1) obj.show("Derived value in Any") obj.op6(a2) obj.show("Completely unknown value in any") obj.op6(a3) obj.show("Nil value in any") obj.op6(a4) obj.show("Two anys") obj.op7(a1, a5) obj.show("Same any twice") obj.op7(a1, a1) obj.show("Different anys containing same value") obj.op7(a5, a6) obj.show("Same derived value twice") obj.op7(a2, a2) obj.show("Any and value") obj.op8(a1, v2) obj.show("Any and same value") obj.op8(a1, v1) obj.show("Any and derived") obj.op8(a1, v7) obj.show("Same derived value in any and value") obj.op8(a2, v7) obj.show("Value and any") obj.op9(v2, a1) obj.show("Value and same value in any") obj.op9(v1, a1) obj.show("Derived value and any") obj.op9(v7, a1) obj.show("Same derived value as value and in any") obj.op9(v7, a2) obj.show("Empty value") e1 = ValueTest.Empty() e2 = ValueTest.Empty() obj.op10(e1) obj.show("Different empty values") obj.op11(e1, e2) obj.show("Same empty values") obj.op11(e1, e1) obj.show("Empty value, None") obj.op11(e1, None) obj.show("None, empty value") obj.op11(None, e1) obj.show("None, None") obj.op11(None, None) obj.show("Container of empty values") c1 = ValueTest.Container(e1, e2) obj.op12(c1) orb.destroy()
class GameBrowser: """This class implements a top-level user interface to the game player. It lists the games currently running in the GameFactory. The user can choose to create new games, and join, watch or kill existing games.""" def __init__(self, orb, poa, gameFactory): self.orb = orb self.poa = poa self.gameFactory = gameFactory self.initGui() self.getGameList() print "GameBrowser initialised" def initGui(self): """Initialise the Tk objects for the GUI""" self.master = Tk() self.master.title("Game Client") self.master.resizable(0, 0) frame = Frame(self.master) # List box and scrollbar listframe = Frame(frame) scrollbar = Scrollbar(listframe, orient=VERTICAL) self.listbox = Listbox(listframe, exportselection=0, width=30, height=20, yscrollcommand=scrollbar.set) scrollbar.config(command=self.listbox.yview) self.listbox.pack(side=LEFT, fill=BOTH, expand=1) scrollbar.pack(side=RIGHT, fill=Y) self.listbox.bind("<ButtonRelease-1>", self.selectGame) listframe.grid(row=0, column=0, rowspan=6) # Padding Frame(frame, width=20).grid(row=0, column=1, rowspan=6) # Buttons newbutton = Button(frame, text="New game", command=self.newGame) joinbutton = Button(frame, text="Join game", command=self.joinGame) watchbutton = Button(frame, text="Watch game", command=self.watchGame) killbutton = Button(frame, text="Kill game", command=self.killGame) updatebutton = Button(frame, text="Update list", command=self.update) quitbutton = Button(frame, text="Quit", command=frame.quit) newbutton.config(width=15) joinbutton.config(width=15) watchbutton.config(width=15) killbutton.config(width=15) updatebutton.config(width=15) quitbutton.config(width=15) self.newbutton = newbutton newbutton.bind("<ButtonRelease-1>", self.setNewButtonPosition) newbutton.grid(row=0, column=2) joinbutton.grid(row=1, column=2) watchbutton.grid(row=2, column=2) killbutton.grid(row=3, column=2) updatebutton.grid(row=4, column=2) quitbutton.grid(row=5, column=2) self.newGameDialogue = None # Padding at bottom Frame(frame, height=10).grid(row=6, columnspan=3) # Status bar self.statusbar = Label(self.master, text="", bd=1, relief=SUNKEN, anchor=W) self.statusbar.pack(side=BOTTOM, fill=X) frame.pack(side=TOP) def getGameList(self): """Get the list of games from the GameFactory, and populate the Listbox in the GUI""" # To make life interesting, we get the game information # structures one at a time from the server. It would be far # more sensible to get them many at a time. self.gameList = [] self.listbox.delete(0, END) try: seq, iterator = self.gameFactory.listGames(0) except CORBA.SystemException, ex: print "System exception contacting GameFactory:" print " ", CORBA.id(ex), ex return if len(seq) > 0: print "listGames() did not return an empty sequence as it should" if iterator is None: print "No games in the GameFactory" return try: more = 1 while more: seq, more = iterator.next_n(1) for info in seq: # seq should only ever have one element, but loop # to be safe self.gameList.append(info) self.listbox.insert(END, info.name) iterator.destroy() except CORBA.SystemException, ex: print "System exception contacting GameIterator:" print " ", CORBA.id(ex), ex
stype = "noughts" else: stype = "crosses" pi.go(info.obj, controller, stype) self.statusMessage("%s: joined game as %s" % (info.name, stype)) except TicTacToe.Game.CannotJoin, ex: poa.deactivate_object(id) self.statusMessage("%s: cannot join game" % info.name) except CORBA.SystemException, ex: poa.deactivate_object(id) print "System exception trying to join game:" print " ", CORBA.id(ex), ex self.statusMessage("%s: system exception contacting game" % \ info.name) self.getGameList() def watchGame(self): selection = self.listbox.curselection() if selection == (): return index = int(selection[0]) info = self.gameList[index] si = Spectator_i(self.master, info.name) id = poa.activate_object(si) so = poa.id_to_reference(id) try: