我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用curses.KEY_MOUSE。
def test_select_line(self): self.runWithTestFile([ self.displayCheck(0, 0, [ " ci . ", " ", " 1 "]), self.cursorCheck(2, 7), 't', 'e', 's', 't', CTRL_J, 'a', 'p', 'p', 'l', 'e', CTRL_J, 'o', 'r', 'a', 'n', 'g', 'e', self.cursorCheck(4, 13), self.selectionCheck(2, 6, 0, 0, 0), CTRL_L, self.selectionCheck(2, 6, 2, 0, 4), KEY_UP, self.selectionCheck(1, 5, 2, 6, 0), CTRL_L, self.selectionCheck(2, 0, 1, 0, 4), CTRL_L, self.selectionCheck(2, 6, 1, 0, 4), self.addMouseInfo(0, 2, 10, curses.BUTTON1_PRESSED), curses.KEY_MOUSE, self.selectionCheck(2, 6, 0, 3, 2), CTRL_Q, 'n']);
def executeCommandList(self, cmdList): for cmd, eventInfo in cmdList: if cmd == curses.KEY_RESIZE: self.handleScreenResize(self.focusedWindow) continue self.focusedWindow.controller.doCommand(cmd, eventInfo) if cmd == curses.KEY_MOUSE: self.handleMouse(eventInfo) self.focusedWindow.controller.onChange()
def test_select_line_via_line_numbers(self): self.runWithTestFile([ self.displayCheck(0, 0, [ " ci . ", " ", " 1 "]), self.cursorCheck(2, 7), 'a', 'b', 'c', CTRL_J, 'd', 'e', CTRL_J, 'f', 'g', 'h', 'i', self.cursorCheck(4, 11), self.addMouseInfo(0, 3, 2, curses.BUTTON1_PRESSED), curses.KEY_MOUSE, CTRL_L, CTRL_Q, 'n']);
def input(self, engine): '''This method is called by `engine.play_game`. It receives a character from the user and interprets it. Invokes `self.travel` for the steering of the cursor. It doesn't do any output except for printing the field initialization message, and forcing the entire screen to be redrawn on unrecognised input (to de-fuck-up the screen). ''' if self.gametype == 'hex': direction_keys = self.direction_keys['hex'] else: direction_keys = self.direction_keys['square'] look_for = ['reveal', 'flag', 'toggle-attention'] + direction_keys # Receive input from player. ch = self.window.getch() # Interpret. command = None if ch == curses.KEY_MOUSE: _, x, y, _, buttons = curses.getmouse() valid = True if self.gametype == 'hex': valid = self.mouse_travel_hex(x, y, engine.field) else: valid = self.mouse_travel_square(x, y, engine.field) if valid: for tmp_command in ('flag', 'reveal'): for mask in self.cfg['curses-mouse-input'][tmp_command]: if buttons & mask: command = tmp_command else: continue break else: # Keyboard input: for key in look_for: if ch in self.cfg['curses-input'][key]: command = key # Act. if command == 'flag': engine.flag(self.cursor) elif command == 'reveal': pre_game = engine.game_status == 'pre-game' if pre_game: self.message('Initializing field... This may take a while.') curses.reset_shell_mode() # BUG: see comments above __init__ engine.reveal(self.cursor) if pre_game: curses.reset_prog_mode() # BUG: see comments above __init__ # Clear junk that gets on the screen from impatient players. self.window.redrawwin() elif command in direction_keys: self.travel(engine.field, command) elif command == 'toggle-attention': self.attention_mode = not self.attention_mode elif ch != curses.KEY_MOUSE: # Don't do this all the time, that'd be a little wasteful. self.window.redrawwin()
def mainloop(screen): from sciibo.core.state import State # Get username from environment try: env_user = getpass.getuser() except KeyError: env_user = '' # Create a new state state = State() state.set_name(env_user) state.set_scene('Main') try: while state.running: # Handle key and mouse input ch = screen.get_key() while ch: if ch == curses.KEY_MOUSE: result = screen.get_mouse(state.scene) if result: state.scene.on_mouse(*result) else: state.scene.on_key(ch) # Handle all key presses in queue ch = screen.get_key() # Register frame tick state.scene.on_tick() # Update the screen screen.update(state.scene) time.sleep(1.0 / 24) except KeyboardInterrupt: state.quit() except Exception: # Make sure threads are stopped when an exception is encountered state.quit() # Re-raise exception so screen can be terminated # before displaying exception in console raise
def _get_input(self, wait_tenths): # this works around a strange curses bug with window resizing # not being reported correctly with repeated calls to this # function without a doupdate call in between curses.doupdate() key = self._getch(wait_tenths) resize = False raw = [] keys = [] while key >= 0: raw.append(key) if key==KEY_RESIZE: resize = True elif key==KEY_MOUSE: keys += self._encode_mouse_event() else: keys.append(key) key = self._getch_nodelay() processed = [] try: while keys: run, keys = escape.process_keyqueue(keys, True) processed += run except escape.MoreInputRequired: key = self._getch(self.complete_tenths) while key >= 0: raw.append(key) if key==KEY_RESIZE: resize = True elif key==KEY_MOUSE: keys += self._encode_mouse_event() else: keys.append(key) key = self._getch_nodelay() while keys: run, keys = escape.process_keyqueue(keys, False) processed += run if resize: processed.append('window resize') return processed, raw