Python curses.KEY_DOWN Examples
The following are 30
code examples of curses.KEY_DOWN().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
curses
, or try the search function
.
Example #1
Source File: hello_world.py From pycolab with Apache License 2.0 | 7 votes |
def main(argv=()): del argv # Unused. # Build a Hello World game. game = make_game() # Log a message in its Plot object. game.the_plot.log('Hello, world!') # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, 'q': 4, 'Q': 4, -1: 5}, delay=50, colour_fg=HELLO_COLOURS) # Let the game begin! ui.play(game)
Example #2
Source File: curses_ui_test.py From keras-lambda with MIT License | 6 votes |
def testCommandHistoryNavBackwardThenForward(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("help\n"), string_to_codes("babble\n"), [curses.KEY_UP], [curses.KEY_UP], [curses.KEY_DOWN], # Hit Up twice and Down once. string_to_codes("\n"), self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() self.assertEqual(3, len(ui.unwrapped_outputs)) # The 1st output is for command "help". self.assertEqual(["babble", " Aliases: b", "", " babble some"], ui.unwrapped_outputs[0].lines[:4]) # The 2nd and 3rd outputs are for command "babble". for i in [1, 2]: self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[i].lines)
Example #3
Source File: cued_catch.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv): del argv # Unused. # Build a cued_catch game. game = make_game(FLAGS.initial_cue_duration, FLAGS.cue_duration, FLAGS.num_trials, FLAGS.always_show_ball_symbol, FLAGS.reward_sigma, FLAGS.reward_free_trials) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 1, curses.KEY_DOWN: 2, -1: 3, 'q': 4, 'Q': 4}, delay=200, colour_fg=COLOURS) # Let the game begin! ui.play(game)
Example #4
Source File: t_maze.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv): del argv # Unused. # Build a t_maze game. game = make_game(FLAGS.difficulty, FLAGS.cue_after_teleport, FLAGS.timeout_frames, FLAGS.teleport_delay, FLAGS.limbo_time) # Build an ObservationCharacterRepainter that will make the teleporter and all # the goals look identical. repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 1, curses.KEY_DOWN: 2, curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4, -1: 5, 'q': 6, 'Q': 6}, repainter=repainter, delay=100, colour_fg=COLOURS) # Let the game begin! ui.play(game)
Example #5
Source File: wgwidget.py From apple_bleee with GNU General Public License v3.0 | 6 votes |
def set_up_handlers(self): """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition, but in most cases the add_handers or add_complex_handlers methods are what you want.""" #called in __init__ self.handlers = { curses.ascii.NL: self.h_exit_down, curses.ascii.CR: self.h_exit_down, curses.ascii.TAB: self.h_exit_down, curses.KEY_BTAB: self.h_exit_up, curses.KEY_DOWN: self.h_exit_down, curses.KEY_UP: self.h_exit_up, curses.KEY_LEFT: self.h_exit_left, curses.KEY_RIGHT: self.h_exit_right, # "^P": self.h_exit_up, # "^N": self.h_exit_down, curses.ascii.ESC: self.h_exit_escape, curses.KEY_MOUSE: self.h_exit_mouse, } self.complex_handlers = []
Example #6
Source File: main.py From dm-snake with MIT License | 6 votes |
def __init__(self, x, y, window): self.body_list = [] self.hit_score = 0 self.timeout = TIMEOUT # buat body snake for i in range(SNAKE_LENGTH, 0, -1): self.body_list.append(Body(x - i, y)) # buat kepala snake self.body_list.append(Body(x, y, '@')) self.window = window self.direction = KEY_RIGHT self.last_head_coor = (x, y) self.direction_map = { KEY_UP: self.move_up, KEY_DOWN: self.move_down, KEY_LEFT: self.move_left, KEY_RIGHT: self.move_right }
Example #7
Source File: curses_ui_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testCommandHistoryNavBackwardThenForward(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("help\n"), string_to_codes("babble\n"), [curses.KEY_UP], [curses.KEY_UP], [curses.KEY_DOWN], # Hit Up twice and Down once. string_to_codes("\n"), self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() self.assertEqual(3, len(ui.unwrapped_outputs)) # The 1st output is for command "help". self.assertEqual(["babble", " Aliases: b", "", " babble some"], ui.unwrapped_outputs[0].lines[:4]) # The 2nd and 3rd outputs are for command "babble". for i in [1, 2]: self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[i].lines)
Example #8
Source File: sequence_recall.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv): del argv # Unused. # Build a sequence_recall game. game = make_game(FLAGS.sequence_length, FLAGS.demo_light_on_frames, FLAGS.demo_light_off_frames, FLAGS.pause_frames, FLAGS.timeout_frames) # Build an ObservationCharacterRepainter that will turn the light numbers into # actual colours. repainter = rendering.ObservationCharacterRepainter(REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 1, curses.KEY_DOWN: 2, curses.KEY_LEFT: 3, curses.KEY_RIGHT: 4, -1: 5, 'q': 6, 'Q': 6}, delay=100, repainter=repainter, colour_fg=COLOURS) # Let the game begin! ui.play(game)
Example #9
Source File: aperture.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv=()): game = make_game(int(argv[1]) if len(argv) > 1 else 0) ui = human_ui.CursesUi( keys_to_actions={ # Basic movement. curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, # Do nothing. # Shoot aperture gun. 'w': 5, 'a': 6, 's': 7, 'd': 8, # Quit game. 'q': 9, 'Q': 9, }, delay=50, colour_fg=FG_COLOURS, colour_bg=BG_COLOURS) ui.play(game)
Example #10
Source File: better_scrolly_maze.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv=()): level = int(argv[1]) if len(argv) > 1 else 0 # Build a Better Scrolly Maze game. game = make_game(level) # Build the croppers we'll use to scroll around in it, etc. croppers = make_croppers(level) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5}, delay=100, colour_fg=COLOUR_FG, colour_bg=COLOUR_BG, croppers=croppers) # Let the game begin! ui.play(game)
Example #11
Source File: warehouse_manager.py From pycolab with Apache License 2.0 | 6 votes |
def main(argv=()): # Build a Warehouse Manager game. game = make_game(int(argv[1]) if len(argv) > 1 else 0) # Build an ObservationCharacterRepainter that will make all of the boxes in # the warehouse look the same. repainter = rendering.ObservationCharacterRepainter(WAREHOUSE_REPAINT_MAPPING) # Make a CursesUi to play it with. ui = human_ui.CursesUi( keys_to_actions={curses.KEY_UP: 0, curses.KEY_DOWN: 1, curses.KEY_LEFT: 2, curses.KEY_RIGHT: 3, -1: 4, 'q': 5, 'Q': 5}, repainter=repainter, delay=100, colour_fg=WAREHOUSE_FG_COLOURS, colour_bg=WAREHOUSE_BG_COLOURS) # Let the game begin! ui.play(game)
Example #12
Source File: curses_menu.py From curses-menu with MIT License | 6 votes |
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() go_to_max = ord("9") if len(self.items) >= 9 else ord(str(len(self.items))) if ord('1') <= user_input <= go_to_max: self.go_to(user_input - ord('0') - 1) elif user_input == curses.KEY_DOWN: self.go_down() elif user_input == curses.KEY_UP: self.go_up() elif user_input == ord("\n"): self.select() return user_input
Example #13
Source File: tui.py From python-curses-scroll-example with MIT License | 6 votes |
def input_stream(self): """Waiting an input and run a proper method according to type of input""" while True: self.display() ch = self.window.getch() if ch == curses.KEY_UP: self.scroll(self.UP) elif ch == curses.KEY_DOWN: self.scroll(self.DOWN) elif ch == curses.KEY_LEFT: self.paging(self.UP) elif ch == curses.KEY_RIGHT: self.paging(self.DOWN) elif ch == curses.ascii.ESC: break
Example #14
Source File: curses_ui_test.py From deep_image_model with Apache License 2.0 | 6 votes |
def testCommandHistoryNavBackwardThenForward(self): ui = MockCursesUI( 40, 80, command_sequence=[string_to_codes("help\n"), string_to_codes("babble\n"), [curses.KEY_UP], [curses.KEY_UP], [curses.KEY_DOWN], # Hit Up twice and Down once. string_to_codes("\n"), self._EXIT]) ui.register_command_handler( "babble", self._babble, "babble some", prefix_aliases=["b"]) ui.run_ui() self.assertEqual(3, len(ui.unwrapped_outputs)) # The 1st output is for command "help". self.assertEqual(["babble", " Aliases: b", "", " babble some"], ui.unwrapped_outputs[0].lines[:4]) # The 2nd and 3rd outputs are for command "babble". for i in [1, 2]: self.assertEqual(["bar"] * 60, ui.unwrapped_outputs[i].lines)
Example #15
Source File: tui.py From awesome-finder with MIT License | 6 votes |
def input_stream(self): """Waiting an input and run a proper method according to type of input""" while True: self.search(self.query) self.display() ch = self.search_window.getch() if curses.ascii.isprint(ch): self.write(ch) self.reset_top() elif ch in (curses.ascii.BS, curses.ascii.DEL, curses.KEY_BACKSPACE): self.delete() self.reset_top() elif ch == curses.KEY_UP: self.scroll(self.UP) elif ch == curses.KEY_DOWN: self.scroll(self.DOWN) elif ch == curses.KEY_LEFT: self.paging(self.UP) elif ch == curses.KEY_RIGHT: self.paging(self.DOWN) elif ch in (curses.ascii.LF, curses.ascii.NL): self.open_link() elif ch == curses.ascii.ESC: break
Example #16
Source File: CLI.py From email_hack with MIT License | 6 votes |
def input_stream(self): """Waiting an input and run a proper method according to type of input""" while any([client.running for client in CLIENTS]): ch = self.window.getch() if ch == curses.KEY_UP: self.scroll(self.UP) elif ch == curses.KEY_DOWN: self.scroll(self.DOWN) elif ch == curses.KEY_LEFT: self.scroll(self.LEFT, horizontal=True) elif ch == curses.KEY_RIGHT: self.scroll(self.RIGHT, horizontal=True) elif ch == ord("q"): self.EXIT_FLAG = 1
Example #17
Source File: pytrader.py From pytrader with MIT License | 6 votes |
def modal(self): """run the modal getch-loop for this dialog""" if self.win: done = False while not done: key_pressed = self.win.getch() if key_pressed in [27, ord("q"), curses.KEY_F10]: done = True if key_pressed == curses.KEY_DOWN: self.down(1) if key_pressed == curses.KEY_UP: self.down(-1) if key_pressed in [curses.KEY_IC, ord("=")]: self.toggle_select() self.down(1) for key, func in self.dlg_keys: if key == key_pressed: func() done = True # help the garbage collector clean up circular references # to make sure __del__() will be called to close the dialog del self.dlg_keys
Example #18
Source File: pytrader.py From pytrader with MIT License | 6 votes |
def validator(self, char): """here we tweak the behavior slightly, especially we want to end modal editing mode immediately on arrow up/down and on enter and we also want to catch ESC and F10, to abort the entire dialog""" if curses.ascii.isprint(char): return char if char == curses.ascii.TAB: char = curses.KEY_DOWN if char in [curses.KEY_DOWN, curses.KEY_UP]: self.result = char return curses.ascii.BEL if char in [10, 13, curses.KEY_ENTER, curses.ascii.BEL]: self.result = 10 return curses.ascii.BEL if char == 127: char = curses.KEY_BACKSPACE if char in [27, curses.KEY_F10]: self.result = -1 return curses.ascii.BEL return char
Example #19
Source File: test_curses.py From memory-analyzer with MIT License | 6 votes |
def setUp(self): self.mock_curses = mock.patch( "memory_analyzer.frontend.memanz_curses.curses" ).start() self.addCleanup(self.mock_curses.stop) self.mock_curses.LINES = 2 self.mock_curses.COLS = 100 self.mock_curses.KEY_DOWN = curses.KEY_DOWN self.mock_curses.KEY_UP = curses.KEY_UP self.mock_curses.KEY_PPAGE = curses.KEY_PPAGE self.mock_curses.KEY_NPAGE = curses.KEY_NPAGE self.mock_curses.KEY_RIGHT = curses.KEY_RIGHT self.mock_curses.KEY_LEFT = curses.KEY_LEFT self.statusbarstr = " | Navigate with arrows or wasd | Press 'q' to exit" self.pages = [["Page1", 10, 1024], ["Page2", 90, 100]] self.titles = ["Analysis of 1234", "Snapshot Differences"] self.win = memanz_curses.Window(self.mock_curses, self.pages, self.titles)
Example #20
Source File: wgwidget.py From HomePWN with GNU General Public License v3.0 | 6 votes |
def set_up_handlers(self): """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition, but in most cases the add_handers or add_complex_handlers methods are what you want.""" #called in __init__ self.handlers = { curses.ascii.NL: self.h_exit_down, curses.ascii.CR: self.h_exit_down, curses.ascii.TAB: self.h_exit_down, curses.KEY_BTAB: self.h_exit_up, curses.KEY_DOWN: self.h_exit_down, curses.KEY_UP: self.h_exit_up, curses.KEY_LEFT: self.h_exit_left, curses.KEY_RIGHT: self.h_exit_right, # "^P": self.h_exit_up, # "^N": self.h_exit_down, curses.ascii.ESC: self.h_exit_escape, curses.KEY_MOUSE: self.h_exit_mouse, } self.complex_handlers = []
Example #21
Source File: snake-game-OOP.py From Learning-Python-by-building-games with MIT License | 6 votes |
def __init__(self, x, y, window): self.body_list = [] self.hit_score = 0 self.timeout = TIMEOUT for i in range(SNAKE_LENGTH, 0, -1): self.body_list.append(Body(x - i, y)) self.body_list.append(Body(x, y, '#')) self.window = window self.direction = KEY_RIGHT self.last_head_coor = (x, y) self.direction_map = { KEY_UP: self.move_up, KEY_DOWN: self.move_down, KEY_LEFT: self.move_left, KEY_RIGHT: self.move_right }
Example #22
Source File: safety_ui.py From ai-safety-gridworlds with Apache License 2.0 | 6 votes |
def make_human_curses_ui(game_bg_colours, game_fg_colours, delay=100): """Instantiate a Python Curses UI for the terminal game. Args: game_bg_colours: dict of game element background colours. game_fg_colours: dict of game element foreground colours. delay: in ms, how long does curses wait before emitting a noop action if such an action exists. If it doesn't it just waits, so this delay has no effect. Our situation is the latter case, as we don't have a noop. Returns: A curses UI game object. """ return SafetyCursesUi( keys_to_actions={curses.KEY_UP: Actions.UP, curses.KEY_DOWN: Actions.DOWN, curses.KEY_LEFT: Actions.LEFT, curses.KEY_RIGHT: Actions.RIGHT, 'q': Actions.QUIT, 'Q': Actions.QUIT}, delay=delay, repainter=None, colour_fg=game_fg_colours, colour_bg=game_bg_colours)
Example #23
Source File: wgwidget.py From EDCOP with Apache License 2.0 | 6 votes |
def set_up_handlers(self): """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition, but in most cases the add_handers or add_complex_handlers methods are what you want.""" #called in __init__ self.handlers = { curses.ascii.NL: self.h_exit_down, curses.ascii.CR: self.h_exit_down, curses.ascii.TAB: self.h_exit_down, curses.KEY_BTAB: self.h_exit_up, curses.KEY_DOWN: self.h_exit_down, curses.KEY_UP: self.h_exit_up, curses.KEY_LEFT: self.h_exit_left, curses.KEY_RIGHT: self.h_exit_right, "^P": self.h_exit_up, "^N": self.h_exit_down, curses.ascii.ESC: self.h_exit_escape, curses.KEY_MOUSE: self.h_exit_mouse, } self.complex_handlers = []
Example #24
Source File: inspect.py From flowcraft with GNU General Public License v3.0 | 6 votes |
def _curses_keybindings(self): c = self.screen.getch() # Provide scroll up/down with keys or mouse wheel if c == curses.KEY_UP: self._updown("up") elif c == curses.KEY_DOWN: self._updown("down") elif c == curses.KEY_LEFT: self._rightleft("left") elif c == curses.KEY_RIGHT: self._rightleft("right") # Trigger screen size update on resize elif c == curses.KEY_RESIZE: self.screen_lines = self.screen.getmaxyx()[0] # Exit interface when pressing q elif c == ord('q'): raise Exception
Example #25
Source File: wgwidget.py From TelegramTUI with MIT License | 6 votes |
def set_up_handlers(self): """This function should be called somewhere during object initialisation (which all library-defined widgets do). You might like to override this in your own definition, but in most cases the add_handers or add_complex_handlers methods are what you want.""" #called in __init__ self.handlers = { curses.ascii.NL: self.h_exit_down, curses.ascii.CR: self.h_exit_down, curses.ascii.TAB: self.h_exit_down, curses.KEY_BTAB: self.h_exit_up, curses.KEY_DOWN: self.h_exit_down, curses.KEY_UP: self.h_exit_up, curses.KEY_LEFT: self.h_exit_left, curses.KEY_RIGHT: self.h_exit_right, # "^P": self.h_exit_up, # "^N": self.h_exit_down, curses.ascii.ESC: self.h_exit_escape, curses.KEY_MOUSE: self.h_exit_mouse, } self.complex_handlers = []
Example #26
Source File: multi_selection_menu.py From GPIOnext with MIT License | 6 votes |
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() go_to_max = ord("9") if len(self.items) >= 9 else ord(str(len(self.items))) if ord('1') <= user_input <= go_to_max: self.go_to(user_input - ord('0') - 1) elif user_input == curses.KEY_DOWN: self.go_down() elif user_input == curses.KEY_UP: self.go_up() elif user_input == ord(" "): if self.items[ self.current_option] .defaultText != '← Return to Main Menu': item = self.items[self.current_option] item.checked = not item.checked item.text = ('[X] ' if item.checked else '[ ] ') + item.defaultText self.items[self.current_option] = item self.draw() elif user_input in {curses.KEY_ENTER, 10, 13}: self.select_many() return user_input
Example #27
Source File: curses_menu.py From GPIOnext with MIT License | 6 votes |
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() go_to_max = ord("9") if len(self.items) >= 9 else ord(str(len(self.items))) if ord('1') <= user_input <= go_to_max: self.go_to(user_input - ord('0') - 1) elif user_input == curses.KEY_DOWN: self.go_down() elif user_input == curses.KEY_UP: self.go_up() elif user_input in {curses.KEY_ENTER, 10, 13}: self.select() return user_input
Example #28
Source File: extendedMenu.py From GPIOnext with MIT License | 6 votes |
def process_user_input(self): """ Gets the next single character and decides what to do with it """ user_input = self.get_input() go_to_max = ord("9") if len(self.items) >= 9 else ord(str(len(self.items))) if ord('1') <= user_input <= go_to_max: self.go_to(user_input - ord('0') - 1) elif user_input == curses.KEY_DOWN: self.go_down() elif user_input == curses.KEY_UP: self.go_up() elif user_input == ord(" "): if self.items[ self.current_option] .defaultText != '← Return to Main Menu': item = self.items[self.current_option] item.checked = not item.checked item.text = ('[X] ' if item.checked else '[ ] ') + item.defaultText self.items[self.current_option] = item self.draw() elif user_input in {curses.KEY_ENTER, 10, 13}: self.select_many() return user_input
Example #29
Source File: ui.py From scorer.py with GNU General Public License v2.0 | 6 votes |
def main(stdscr, matches): curses.curs_set(False) selected = 0 curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK) while True: printGames(stdscr, matches, selected) event = stdscr.getch() if event == ord("\n"): logging.info("Enter key pressed") return selected elif event == curses.KEY_UP: logging.info("Up key pressed") if selected != 0: selected -= 1 printGames(stdscr, matches, selected) elif event == curses.KEY_DOWN: logging.info("Down key pressed") if selected != len(matches) - 1: selected += 1 printGames(stdscr, matches, selected)
Example #30
Source File: wgmultiline.py From EDCOP with Apache License 2.0 | 5 votes |
def set_up_handlers(self): super(Pager, self).set_up_handlers() self.handlers = { curses.KEY_UP: self.h_scroll_line_up, curses.KEY_LEFT: self.h_scroll_line_up, curses.KEY_DOWN: self.h_scroll_line_down, curses.KEY_RIGHT: self.h_scroll_line_down, curses.KEY_NPAGE: self.h_scroll_page_down, curses.KEY_PPAGE: self.h_scroll_page_up, curses.KEY_HOME: self.h_show_beginning, curses.KEY_END: self.h_show_end, curses.ascii.NL: self.h_exit, curses.ascii.CR: self.h_exit, curses.ascii.SP: self.h_scroll_page_down, curses.ascii.TAB: self.h_exit, ord('j'): self.h_scroll_line_down, ord('k'): self.h_scroll_line_up, ord('x'): self.h_exit, ord('q'): self.h_exit, ord('g'): self.h_show_beginning, ord('G'): self.h_show_end, curses.ascii.ESC: self.h_exit_escape, } self.complex_handlers = [ ]