Beispiel #1
0
 def _inject_mouse(screen, x, y, button):
     """
     Inject a mouse event into the input buffers.
     """
     if sys.platform == "win32":
         event = win32console.PyINPUT_RECORDType(win32console.MOUSE_EVENT)
         event.MousePosition.X = x
         event.MousePosition.Y = y
         if button & MouseEvent.LEFT_CLICK != 0:
             event.ButtonState |= win32con.FROM_LEFT_1ST_BUTTON_PRESSED
         if button & MouseEvent.RIGHT_CLICK != 0:
             event.ButtonState |= win32con.RIGHTMOST_BUTTON_PRESSED
         if button & MouseEvent.DOUBLE_CLICK != 0:
             event.EventFlags |= win32con.DOUBLE_CLICK
         screen._stdin.WriteConsoleInput([event])
     else:
         # Curses doesn't like no value in some cases - use a dummy button
         # click which we don't use instead.
         bstate = curses.BUTTON4_CLICKED
         if button & MouseEvent.LEFT_CLICK != 0:
             bstate |= curses.BUTTON1_CLICKED
         if button & MouseEvent.RIGHT_CLICK != 0:
             bstate |= curses.BUTTON3_CLICKED
         if button & MouseEvent.DOUBLE_CLICK != 0:
             bstate |= curses.BUTTON1_DOUBLE_CLICKED
         curses.ungetmouse(0, x, y, 0, bstate)
Beispiel #2
0
 def _inject_mouse(screen, x, y, button):
     """
     Inject a mouse event into the input buffers.
     """
     if sys.platform == "win32":
         event = win32console.PyINPUT_RECORDType(win32console.MOUSE_EVENT)
         event.MousePosition.X = x
         event.MousePosition.Y = y
         if button & MouseEvent.LEFT_CLICK != 0:
             event.ButtonState |= win32con.FROM_LEFT_1ST_BUTTON_PRESSED
         if button & MouseEvent.RIGHT_CLICK != 0:
             event.ButtonState |= win32con.RIGHTMOST_BUTTON_PRESSED
         if button & MouseEvent.DOUBLE_CLICK != 0:
             event.EventFlags |= win32con.DOUBLE_CLICK
         screen._stdin.WriteConsoleInput([event])
     else:
         # Curses doesn't like no value in some cases - use a dummy button
         # click which we don't use instead.
         bstate = curses.BUTTON4_CLICKED
         if button & MouseEvent.LEFT_CLICK != 0:
             bstate |= curses.BUTTON1_CLICKED
         if button & MouseEvent.RIGHT_CLICK != 0:
             bstate |= curses.BUTTON3_CLICKED
         if button & MouseEvent.DOUBLE_CLICK != 0:
             bstate |= curses.BUTTON1_DOUBLE_CLICKED
         curses.ungetmouse(0, x, y, 0, bstate)
Beispiel #3
0
 def h_exit_mouse(self, _input):
     mouse_event = self.parent.safe_get_mouse_event()
     if mouse_event and self.intersted_in_mouse_event(mouse_event):
         self.handle_mouse_event(mouse_event)
     else:
         if mouse_event and self._test_safe_to_exit():
             curses.ungetmouse(*mouse_event)
             ch = self.parent.curses_pad.getch()
             assert ch == curses.KEY_MOUSE
         self.editing = False
         self.how_exited = EXITED_MOUSE
Beispiel #4
0
 def h_exit_mouse(self, _input):
     mouse_event = self.parent.safe_get_mouse_event()
     if mouse_event and self.intersted_in_mouse_event(mouse_event):
         self.handle_mouse_event(mouse_event)
     else:
         if mouse_event:
             curses.ungetmouse(*mouse_event)
             ch = self.parent.curses_pad.getch()
             assert ch == curses.KEY_MOUSE
         self.editing = False
         self.how_exited = EXITED_MOUSE
Beispiel #5
0
 def h_exit_mouse(self, inpt=None):
     mouse_event = self.parent.safe_get_mouse_event()
     if mouse_event and self.interested_in_mouse_event(mouse_event):
         self.handle_mouse_event(mouse_event)
     else:
         if mouse_event:
             curses.ungetmouse(*mouse_event)
             ch = self.parent.curses_pad.getch()
             assert ch == curses.KEY_MOUSE
         self.editing = False
         self.how_exited = 'mouse'
Beispiel #6
0
def _setup_mouse(signal):
    if signal['value']:
        curses.mousemask(MOUSEMASK)
        curses.mouseinterval(0)

        ## this line solves this problem:
        ## If a mouse click triggers an action that disables curses and
        ## starts curses again, (e.g. running a ## file by clicking on its
        ## preview) and the next key is another mouse click, the bstate of this
        ## mouse event will be invalid.  (atm, invalid bstates are recognized
        ## as scroll-down, so this avoids an errorneous scroll-down action)
        curses.ungetmouse(0, 0, 0, 0, 0)
    else:
        curses.mousemask(0)
Beispiel #7
0
def _setup_mouse(signal):
    if signal['value']:
        curses.mousemask(MOUSEMASK)
        curses.mouseinterval(0)

        ## this line solves this problem:
        ## If an action, following a mouse click, includes the
        ## suspension and re-initializion of the ui (e.g. running a
        ## file by clicking on its preview) and the next key is another
        ## mouse click, the bstate of this mouse event will be invalid.
        ## (atm, invalid bstates are recognized as scroll-down)
        curses.ungetmouse(0,0,0,0,0)
    else:
        curses.mousemask(0)
Beispiel #8
0
def _setup_mouse(signal):
    if signal['value']:
        curses.mousemask(MOUSEMASK)
        curses.mouseinterval(0)

        # This line solves this problem:
        # If a mouse click triggers an action that disables curses and
        # starts curses again, (e.g. running a ## file by clicking on its
        # preview) and the next key is another mouse click, the bstate of this
        # mouse event will be invalid.  (atm, invalid bstates are recognized
        # as scroll-down, so this avoids an errorneous scroll-down action)
        curses.ungetmouse(0, 0, 0, 0, 0)
    else:
        curses.mousemask(0)
Beispiel #9
0
    def __process_mouse_event(self):
        i, x, y, z, event = curses.getmouse()

        if event == curses.BUTTON2_PRESSED:
            curses.ungetmouse(0, 0, 0, 0, 0)
            self.entry_i += self.hl
        elif event == curses.BUTTON4_PRESSED:
            curses.ungetmouse(0, 0, 0, 0, 0)
            self.entry_i -= self.hl
        elif event in [curses.BUTTON1_PRESSED, curses.BUTTON3_PRESSED]:
            if self.y <= y <= self.y + self.h:
                fi, nf, ht = self.entry_i, len(self.entries), self.hl
                if fi < (nf - ht):
                    self.entry_i = int(fi / ht) * ht + max(y - self.y - 1, 0)
                else:  # lastpage
                    self.entry_i = nf - (ht - max(y - self.y - 1, 0))

                # process double click
                click_tm = self.app.click_tm
                if time.time() - click_tm < 0.3:
                    return dec_str(self.entries[self.entry_i])
                self.app.click_tm = time.time()
Beispiel #10
0
    def __process_mouse_event(self):
        i,x,y,z,event = curses.getmouse()

        if event == curses.BUTTON2_PRESSED:
            curses.ungetmouse(0,0,0,0,0)
            self.entry_i += self.hl
        elif event == curses.BUTTON4_PRESSED:
            curses.ungetmouse(0,0,0,0,0)
            self.entry_i -= self.hl
        elif event in [curses.BUTTON1_PRESSED, curses.BUTTON3_PRESSED]:
            if  self. y <= y <= self.y + self.h:
                fi, nf, ht =  self.entry_i, len(self.entries), self.hl
                if fi < (nf - ht):
                    self.entry_i =  int(fi/ht)*ht + max (y - self.y - 1, 0)
                else: # lastpage
                    self.entry_i = nf - (ht - max (y - self.y - 1, 0))

                # process double click
                click_tm =  self.app.click_tm
                if time.time() - click_tm < 0.3:
                    return dec_str(self.entries[self.entry_i])
                self.app.click_tm = time.time()
Beispiel #11
0
def module_funcs(stdscr):
    "Test module-level functions"

    for func in [curses.baudrate, curses.beep, curses.can_change_color,
                 curses.cbreak, curses.def_prog_mode, curses.doupdate,
                 curses.filter, curses.flash, curses.flushinp,
                 curses.has_colors, curses.has_ic, curses.has_il,
                 curses.isendwin, curses.killchar, curses.longname,
                 curses.nocbreak, curses.noecho, curses.nonl,
                 curses.noqiflush, curses.noraw,
                 curses.reset_prog_mode, curses.termattrs,
                 curses.termname, curses.erasechar, curses.getsyx]:
        func()

    # Functions that actually need arguments
    if curses.tigetstr("cnorm"):
        curses.curs_set(1)
    curses.delay_output(1)
    curses.echo() ; curses.echo(1)

    f = tempfile.TemporaryFile()
    stdscr.putwin(f)
    f.seek(0)
    curses.getwin(f)
    f.close()

    curses.halfdelay(1)
    curses.intrflush(1)
    curses.meta(1)
    curses.napms(100)
    curses.newpad(50,50)
    win = curses.newwin(5,5)
    win = curses.newwin(5,5, 1,1)
    curses.nl() ; curses.nl(1)
    curses.putp('abc')
    curses.qiflush()
    curses.raw() ; curses.raw(1)
    curses.setsyx(5,5)
    curses.tigetflag('hc')
    curses.tigetnum('co')
    curses.tigetstr('cr')
    curses.tparm('cr')
    curses.typeahead(sys.__stdin__.fileno())
    curses.unctrl('a')
    curses.ungetch('a')
    curses.use_env(1)

    # Functions only available on a few platforms
    if curses.has_colors():
        curses.start_color()
        curses.init_pair(2, 1,1)
        curses.color_content(1)
        curses.color_pair(2)
        curses.pair_content(curses.COLOR_PAIRS - 1)
        curses.pair_number(0)

        if hasattr(curses, 'use_default_colors'):
            curses.use_default_colors()

    if hasattr(curses, 'keyname'):
        curses.keyname(13)

    if hasattr(curses, 'has_key'):
        curses.has_key(13)

    if hasattr(curses, 'getmouse'):
        (availmask, oldmask) = curses.mousemask(curses.BUTTON1_PRESSED)
        # availmask indicates that mouse stuff not available.
        if availmask != 0:
            curses.mouseinterval(10)
            # just verify these don't cause errors
            m = curses.getmouse()
            curses.ungetmouse(*m)
Beispiel #12
0
 def unget(self):
     curses.ungetmouse(self.mouseid, self.x, self.y, self.z, self.bstate)
Beispiel #13
0
 def unget(self):
     curses.ungetmouse(self.mouseid, self.x, self.y, self.z, self.bstate)
Beispiel #14
0
def mouse_event(tab):
    i, x, y, z, event = curses.getmouse()
    app = tab.pane.app
    h, w = app.win.getmaxyx()
    click_tm = app.click_tm
    app.click_tm = time.time()
    if event == curses.BUTTON2_PRESSED:
        curses.ungetmouse(0, 0, 0, 0, 0)
        return page_next(tab)
    elif event == curses.BUTTON4_PRESSED:
        curses.ungetmouse(0, 0, 0, 0, 0)
        return page_previous(tab)
    elif event in [curses.BUTTON1_PRESSED, curses.BUTTON3_PRESSED]:

        #command line if click is at  bottom line
        if y == h - 1:
            return command_line(tab)

        #pane click (select pane and file)
        if not app.act_pane.mode in [PANE_MODE_HIDDEN, PANE_MODE_FULL]:
            #x1,x2 = 0.,w
            #else:
            if x > int(w / 2):
                if app.lpane.mode in [PANE_MODE_LEFT, PANE_MODE_TREE_LEFT]:
                    app.act_pane, app.noact_pane = app.rpane, app.lpane
                else:
                    app.act_pane, app.noact_pane = app.lpane, app.rpane
                    #x1,x2 = w/2,w
            else:
                if app.lpane.mode in [PANE_MODE_LEFT, PANE_MODE_TREE_LEFT]:
                    app.act_pane, app.noact_pane = app.lpane, app.rpane
                else:
                    app.act_pane, app.noact_pane = app.rpane, app.lpane
                    #x1,x2 = 0.,w/2

        #open/close new tab if click is at top line
        if y == 0:
            for i, t in enumerate(tab.pane.tabs):
                if t.win.check_focus(x, 0):
                    if event == curses.BUTTON1_PRESSED:
                        tab.pane.act_tab = tab.pane.tabs[i]
                    elif event == curses.BUTTON3_PRESSED:
                        if len(tab.pane.tabs) > 1:
                            close_tab(tab.pane.act_tab)
                        return 10
                    break
            else:
                if event == curses.BUTTON1_PRESSED:
                    #newtab doubleclick at empty space
                    if time.time() - click_tm < 0.3:
                        new_tab(tab.pane.act_tab)
                return 10

        #file click (select  file)
        if app.act_pane.mode not in [
                PANE_MODE_TREE_RIGHT, PANE_MODE_TREE_LEFT
        ]:
            tab = app.act_pane.act_tab
            tab.file_i = tab.file_a + y - 3
            if tab.file_i > tab.file_z:
                tab.file_i = tab.file_z
                return 10
        #double click processing
        if event == curses.BUTTON1_PRESSED and y not in [0, 1, 2, h - 1]:
            #double click delay 300ms
            tm = time.time()
            if tm - click_tm < 0.3:  # and app.last_event == 1:
                curses.mousemask(0)
                enter(tab)
                curses.mousemask(curses.ALL_MOUSE_EVENTS)
                curses.ungetmouse(0, 0, 0, 0, 0)
        #files selection
        if event in [curses.BUTTON3_PRESSED] and y not in [1]:
            filename = tab.sorted[tab.file_i]
            if tab.selections.count(filename):
                tab.selections.remove(filename)
            else:
                tab.selections.append(filename)
    return 10
Beispiel #15
0
def mouse_event(tab):
    i,x,y,z,event = curses.getmouse()
    app = tab.pane.app
    h, w = app.win.getmaxyx()
    click_tm =  app.click_tm
    app.click_tm = time.time()
    if event == curses.BUTTON2_PRESSED:
        curses.ungetmouse(0,0,0,0,0)
        return page_next(tab)
    elif event == curses.BUTTON4_PRESSED:
        curses.ungetmouse(0,0,0,0,0)
        return page_previous(tab)
    elif event in [curses.BUTTON1_PRESSED, curses.BUTTON3_PRESSED]:

        #command line if click is at  bottom line
        if y == h-1:
            return command_line(tab)

        #pane click (select pane and file)
        if not app.act_pane.mode in [PANE_MODE_HIDDEN, PANE_MODE_FULL]:
                #x1,x2 = 0.,w
        #else:
            if x > int(w/2):
                if app.lpane.mode in [PANE_MODE_LEFT, PANE_MODE_TREE_LEFT]:
                    app.act_pane, app.noact_pane = app.rpane, app.lpane
                else:
                    app.act_pane, app.noact_pane = app.lpane, app.rpane
                    #x1,x2 = w/2,w
            else:
                if app.lpane.mode in [PANE_MODE_LEFT, PANE_MODE_TREE_LEFT]:
                    app.act_pane, app.noact_pane  = app.lpane, app.rpane
                else:
                    app.act_pane, app.noact_pane = app.rpane, app.lpane
                    #x1,x2 = 0.,w/2

        #open/close new tab if click is at top line
        if y== 0:
            for i, t in enumerate(tab.pane.tabs):
                if t.win.check_focus(x,0):
                    if event == curses.BUTTON1_PRESSED:
                        tab.pane.act_tab = tab.pane.tabs[i]
                    elif event == curses.BUTTON3_PRESSED:
                        if len(tab.pane.tabs)>1:
                            close_tab(tab.pane.act_tab)
                        return 10
                    break
            else:
                if event == curses.BUTTON1_PRESSED:
                    #newtab doubleclick at empty space
                    if time.time() - click_tm < 0.3:
                        new_tab(tab.pane.act_tab)
                return 10

        #file click (select  file)
        if app.act_pane.mode not in [PANE_MODE_TREE_RIGHT, PANE_MODE_TREE_LEFT]:
            tab = app.act_pane.act_tab
            tab.file_i = tab.file_a + y - 3
            if tab.file_i > tab.file_z:
                tab.file_i = tab.file_z
                return 10
        #double click processing
        if event == curses.BUTTON1_PRESSED and y not in [0,1,2,h-1]:
            #double click delay 300ms
            tm =time.time()
            if tm - click_tm < 0.3:# and app.last_event == 1:
                curses.mousemask(0)
                enter(tab)
                curses.mousemask(curses.ALL_MOUSE_EVENTS)
                curses.ungetmouse(0,0,0,0,0)
        #files selection
        if event in [curses.BUTTON3_PRESSED] and y not in [1]:
            filename = tab.sorted[tab.file_i]
            if tab.selections.count(filename):
                tab.selections.remove(filename)
            else:
                tab.selections.append(filename)
    return 10