def __init__(self, application): self.app = application self.address_val = AddressValidator()
class SolipsisUiFactory(protocol.ServerFactory): protocol = SolipsisUiProtocol def __init__(self, application): self.app = application self.address_val = AddressValidator() # UI events def do_check(self, arg): return str(self.app._CheckNodeProxy()) def do_mem(self, arg): return self.app._MemDebug() # UI events in menu def do_about(self, arg): return self.app._About(arg) def do_create(self, arg): return self.app._CreateNode(arg) def do_connect(self, arg): stream = StringIO() args = self.address_val._Validate(arg) if not args: args = self.address_val._Validate(COMMANDS['connect'][1]) print >> stream, "no valid address. Default used..." host, port = args.groups() self.app.config_data.host = host self.app.config_data.port = int(port) print >> stream, self.app._OpenConnect(arg) return stream.getvalue() def do_disconnect(self, arg): return self.app._Disconnect(arg) def do_kill(self, arg): print "calling _Kill" self.app._Kill(arg) def do_jump(self, arg): if not self.address_val._Validate(arg): arg = COMMANDS['jump'][1] return self.app._JumpNear(arg) def do_pref(self, arg): return self.app._Preferences(arg) def do_quit(self, arg): print "calling _Quit" self.app._Quit(arg) def do_display(self, arg): return self.app._DisplayNodeAddress(arg) # UI events in viewport def do_go(self, arg): # arg must be like 'x,y' try: position = [float(coord)*2**128 for coord in arg.split(',')] if len(position) == 2: return self.app._LeftClickViewport(position) else: return "enter position as 'x,y'" except ValueError: return "enter position as 'x,y'" def do_menu(self, arg): return self.app._RightClickViewport(arg) def do_hover(self, arg): # arg must be like 'x,y' try: position = [float(coord)*2**128 for coord in arg.split(',')] if len(position) == 2: return self.app._HoverViewport(position) else: return "enter position as 'x,y'" except ValueError: return "enter position as 'x,y'" def do_help(self, arg): str_stream = StringIO() if arg in ["", "all"]: pprint(COMMANDS, str_stream) elif arg in COMMANDS: print >> str_stream, COMMANDS[arg][0] else: print >> str_stream, "available commands are:" pprint(COMMANDS, str_stream) return str_stream.getvalue()