Python curses 模块,mousemask() 实例源码

我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用curses.mousemask()

项目:captiv8    作者:wraith-wireless    | 项目源码 | 文件源码
def setup():
    """
     sets environment up and creates main window
     :returns: the main window object
    """
    # setup the console
    mmask = curses.ALL_MOUSE_EVENTS # for now accept all mouse events
    main = curses.initscr()         # get a window object
    y,x = main.getmaxyx()           # get size
    if y < 24 or x < 80:            # verify minimum size rqmts
        raise RuntimeError("Terminal must be at least 80 x 24")
    curses.noecho()                 # turn off key echoing
    curses.cbreak()                 # turn off key buffering
    curses.mousemask(mmask)         # accept mouse events
    initcolors()                    # turn on and set color pallet
    main.keypad(1)                  # let curses handle multibyte special keys
    main.clear()                    # erase everything
    banner(main)                    # write the banner
    mainmenu(main)                  # then the min and menu
    main.attron(CPS[RED])           # make the border red
    main.border(0)                  # place the border
    main.attroff(CPS[RED])          # turn off the red
    curses.curs_set(0)              # hide the cursor
    main.refresh()                  # and show everything
    return main
项目:sciibo    作者:fdev    | 项目源码 | 文件源码
def create_screen(fn):
    """
    Initializes curses and passes a Screen to the main loop function `fn`.
    Based on curses.wrapper.
    """
    try:
        # Make escape key more responsive
        os.environ['ESCDELAY'] = '25'

        stdscr = curses.initscr()

        curses.noecho()
        curses.cbreak()
        stdscr.keypad(1)
        stdscr.nodelay(1)
        curses.curs_set(0)

        curses.mousemask(curses.BUTTON1_CLICKED)

        if curses.has_colors():
            curses.start_color()
            curses.use_default_colors()

        screen = Screen(stdscr)
        fn(screen)

    finally:
        # Set everything back to normal
        if 'stdscr' in locals():
            curses.use_default_colors()
            curses.curs_set(1)
            stdscr.keypad(0)
            curses.echo()
            curses.nocbreak()
            curses.endwin()
项目:Adwear    作者:Uberi    | 项目源码 | 文件源码
def set_mouse_tracking(self, enable=True):
        """
        Enable mouse tracking.

        After calling this function get_input will include mouse
        click events along with keystrokes.
        """
        enable = bool(enable)
        if enable == self._mouse_tracking_enabled:
            return

        if enable:
            curses.mousemask(0
                | curses.BUTTON1_PRESSED | curses.BUTTON1_RELEASED
                | curses.BUTTON2_PRESSED | curses.BUTTON2_RELEASED
                | curses.BUTTON3_PRESSED | curses.BUTTON3_RELEASED
                | curses.BUTTON4_PRESSED | curses.BUTTON4_RELEASED
                | curses.BUTTON1_DOUBLE_CLICKED | curses.BUTTON1_TRIPLE_CLICKED
                | curses.BUTTON2_DOUBLE_CLICKED | curses.BUTTON2_TRIPLE_CLICKED
                | curses.BUTTON3_DOUBLE_CLICKED | curses.BUTTON3_TRIPLE_CLICKED
                | curses.BUTTON4_DOUBLE_CLICKED | curses.BUTTON4_TRIPLE_CLICKED
                | curses.BUTTON_SHIFT | curses.BUTTON_ALT
                | curses.BUTTON_CTRL)
        else:
            raise NotImplementedError()

        self._mouse_tracking_enabled = enable
项目:ci_edit    作者:google    | 项目源码 | 文件源码
def __init__(self, cursesScreen):
    self.clicks = 0
    self.debugMouseEvent = (0, 0, 0, 0, 0)
    self.exiting = False
    self.modalUi = None
    self.modeStack = []
    self.priorClick = 0
    self.savedMouseButton1Down = False
    self.savedMouseWindow = None
    self.savedMouseX = -1
    self.savedMouseY = -1
    self.cursesScreen = cursesScreen
    self.ch = 0
    curses.mousemask(-1)
    curses.mouseinterval(0)
    # Enable mouse tracking in xterm.
    sys.stdout.write('\033[?1002;h\n')
    #sys.stdout.write('\033[?1005;h\n')
    curses.meta(1)
    # Access ^c before shell does.
    curses.raw()
    # Enable Bracketed Paste Mode.
    sys.stdout.write('\033[?2004;h\n')
    #curses.start_color()
    curses.use_default_colors()
    if 0:
      assert(curses.COLORS == 256)
      assert(curses.can_change_color() == 1)
      assert(curses.has_colors() == 1)
      app.log.detail("color_content:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
      for i in range(16, curses.COLORS):
        curses.init_color(i, 500, 500, i * 787 % 1000)
      app.log.detail("color_content, after:")
      for i in range(0, curses.COLORS):
        app.log.detail("color", i, ": ", curses.color_content(i))
    self.setUpPalette()
    if 1:
      #rows, cols = self.cursesScreen.getmaxyx()
      cursesWindow = self.cursesScreen
      cursesWindow.leaveok(1)  # Don't update cursor position.
      cursesWindow.scrollok(0)
      cursesWindow.timeout(10)
      cursesWindow.keypad(1)
      self.top, self.left = cursesWindow.getyx()
      self.rows, self.cols = cursesWindow.getmaxyx()
      app.window.mainCursesWindow = cursesWindow
    self.zOrder = []