def __init__(self, stdscr, configs): # Curses initialization. stdscr.clear() acurses.echo(False) acurses.cbreak() acurses.cursor(False) stdscr.refresh() self.stdscr = stdscr # Server communication initialization. self.client = Client() self.notif_client = NotificationClient() self.notif_client.set_listener(NotificationClient.PLAYLISTS_CHANGED, self.on_playlists_changed) self.notif_client.set_listener(NotificationClient.PLAYLIST_CHANGED, self.on_playlist_changed) # TODO: Handle connection loose in a right way. try: self.client.connect(configs.host, configs.port) self.notif_client.connect(configs.host, configs.nport) except ConnectionError as e: print('Connection failed. ' + str(e)) sys.exit(1) # Build the UI. height, width = self.stdscr.getmaxyx() # Creation of status (bottom screen) windows. win = status.Window(0, height - 2, width, 1) self.status_controller = status.Controller(win) win = prompt.Window(0, height - 1, width, 1) self.prompt_controller = prompt.Controller(win) # Creation of main windows. win = browser.Window(0, 0, width, height - 4) self.browser_controller = browser.Controller(self, win) self.browser_controller.set_path('/') win = playlist.Window(0, 0, width, height - 4) self.playlist_controller = playlist.Controller(self, win) self.playlist_controller.set_prompt_provider(self.prompt_controller.prompt) # Set active controller. self.controller = self.browser_controller self.controller.activate() # Start listening server's update notifications. self.notif_lock = Lock() self.notif_thread = NotificationThread(self.notif_client) self.notif_thread.start() self.command_handlers = {command.SWITCH_WINDOW: self.cmd_switch_window, command.QUIT: self.cmd_quit}
def set_input_mode(self, on): acurses.cursor(on)