Python termios.tcflush() Examples

The following are 26 code examples of termios.tcflush(). 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 termios , or try the search function .
Example #1
Source File: __init__.py    From enlighten with Mozilla Public License 2.0 5 votes vote down vote up
def clear(self):
        termios.tcflush(self.stdread, termios.TCIFLUSH) 
Example #2
Source File: serialposix.py    From android_universal with MIT License 5 votes vote down vote up
def reset_output_buffer(self):
        """\
        Clear output buffer, aborting the current output and discarding all
        that is in the buffer.
        """
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCOFLUSH) 
Example #3
Source File: serialposix.py    From android_universal with MIT License 5 votes vote down vote up
def reset_input_buffer(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCIFLUSH) 
Example #4
Source File: keypress.py    From term2048 with MIT License 5 votes vote down vote up
def __getKey():
        """Return a key pressed by the user"""
        try:
            tty.setcbreak(sys.stdin.fileno())
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            ch = sys.stdin.read(1)
            return ord(ch) if ch else None
        finally:
            termios.tcsetattr(__fd, termios.TCSADRAIN, __old) 
Example #5
Source File: keypress.py    From term2048-AI with MIT License 5 votes vote down vote up
def __getKey():
        """Return a key pressed by the user"""
        try:
            tty.setcbreak(sys.stdin.fileno())
            termios.tcflush(sys.stdin, termios.TCIOFLUSH)
            ch = sys.stdin.read(1)
            return ord(ch) if ch else None
        finally:
            termios.tcsetattr(__fd, termios.TCSADRAIN, __old) 
Example #6
Source File: main_daemon.py    From Pythonic with GNU General Public License v3.0 5 votes vote down vote up
def run(self):

        if self.b_init:
            self.b_init = False
            self.fd = sys.stdin.fileno() 
            if os.isatty(sys.stdin.fileno()):
                self.old_settings = termios.tcgetattr(self.fd) 
                tty.setraw(sys.stdin.fileno()) 

        while not self.b_exit:

            rd_fs, wrt_fs, err_fs =  select.select([sys.stdin], [], [], self.interval)

            if rd_fs and os.isatty(sys.stdin.fileno()):
                cmd = rd_fs[0].read(1)

                if cmd == ('q' or 'Q'): # quit
                    termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                    termios.tcflush(self.fd, termios.TCIOFLUSH)
                    self.b_exit = True
                    self.quit_app.emit()

                elif cmd == ('p' or 'P'): # show proccesses
                    self.b_procs = True
                    termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                    self.print_procs.emit()
                    tty.setraw(sys.stdin.fileno()) 

                elif cmd == ('l' or 'L'): # show log
                    if self.b_log:
                        termios.tcsetattr(self.fd, termios.TCSADRAIN, self.old_settings)
                        reset_screen() # reset the screen to hide the log list
                        tty.setraw(sys.stdin.fileno()) 
                    self.b_log = not self.b_log
                    
                else:
                    sys.stdout.write('\b')

            else:
                if os.isatty(sys.stdin.fileno()):
                    self.callback() 
Example #7
Source File: randpool.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def getch(self):
                termios.tcflush(0, termios.TCIFLUSH) # XXX Leave this in?
                return os.read(self._fd, 1) 
Example #8
Source File: randpool.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def close(self, delay = 0):
                if delay:
                    time.sleep(delay)
                    termios.tcflush(self._fd, termios.TCIFLUSH)
                termios.tcsetattr(self._fd, termios.TCSAFLUSH, self._old) 
Example #9
Source File: randpool.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def getch(self):
                termios.tcflush(0, termios.TCIFLUSH) # XXX Leave this in?
                return os.read(self._fd, 1) 
Example #10
Source File: randpool.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def close(self, delay = 0):
                if delay:
                    time.sleep(delay)
                    termios.tcflush(self._fd, termios.TCIFLUSH)
                termios.tcsetattr(self._fd, termios.TCSAFLUSH, self._old) 
Example #11
Source File: randpool.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def getch(self):
                termios.tcflush(0, termios.TCIFLUSH) # XXX Leave this in?
                return os.read(self._fd, 1) 
Example #12
Source File: serialposix.py    From ddt4all with GNU General Public License v3.0 5 votes vote down vote up
def reset_input_buffer(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCIFLUSH) 
Example #13
Source File: pikspect.py    From pikaur with GNU General Public License v3.0 5 votes vote down vote up
def _restore(cls, what: Optional[TcAttrsType] = None) -> None:
        if sys.stdout.isatty():
            # termios.tcdrain(sys.stdout.fileno())
            # if sys.stderr.isatty():
            #     termios.tcdrain(sys.stderr.fileno())
            # if sys.stdin.isatty():
            #     termios.tcflush(sys.stdin.fileno(), termios.TCIOFLUSH)
            if what:
                termios.tcsetattr(sys.stdin.fileno(), termios.TCSANOW, what) 
Example #14
Source File: serialposix.py    From android3dblendermouse with Apache License 2.0 5 votes vote down vote up
def reset_output_buffer(self):
        """\
        Clear output buffer, aborting the current output and discarding all
        that is in the buffer.
        """
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCOFLUSH) 
Example #15
Source File: serialposix.py    From android3dblendermouse with Apache License 2.0 5 votes vote down vote up
def reset_input_buffer(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCIFLUSH) 
Example #16
Source File: serialposix.py    From AstroBox with GNU Affero General Public License v3.0 5 votes vote down vote up
def flushOutput(self):
        """Clear output buffer, aborting the current output and
        discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCOFLUSH) 
Example #17
Source File: serialposix.py    From AstroBox with GNU Affero General Public License v3.0 5 votes vote down vote up
def flushInput(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCIFLUSH) 
Example #18
Source File: ipc.py    From hupper with MIT License 5 votes vote down vote up
def restore_termios(stream, state):
        if state and is_stream_interactive(stream):
            fd = stream.fileno()
            termios.tcflush(fd, termios.TCIOFLUSH)
            termios.tcsetattr(fd, termios.TCSANOW, state) 
Example #19
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def flushInput(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCIFLUSH) 
Example #20
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def flushOutput(self):
        """Clear output buffer, aborting the current output and
        discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCOFLUSH) 
Example #21
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def flushInput(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCIFLUSH) 
Example #22
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def flushOutput(self):
        """Clear output buffer, aborting the current output and
        discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCOFLUSH) 
Example #23
Source File: serialposix.py    From Jandroid with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def flushInput(self):
        """Clear input buffer, discarding all that is in the buffer."""
        if not self._isOpen: raise portNotOpenError
        termios.tcflush(self.fd, TERMIOS.TCIFLUSH) 
Example #24
Source File: serialposix.py    From ddt4all with GNU General Public License v3.0 5 votes vote down vote up
def reset_output_buffer(self):
        """\
        Clear output buffer, aborting the current output and discarding all
        that is in the buffer.
        """
        if not self.is_open:
            raise portNotOpenError
        termios.tcflush(self.fd, termios.TCOFLUSH) 
Example #25
Source File: runner.py    From Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision with MIT License 4 votes vote down vote up
def run():
    """execute the TraCI control loop"""
    step = 0
    
    traci.trafficlight.setPhase("0", 0)
    while traci.simulation.getMinExpectedNumber() > 0:
        
        traci.simulationStep()
        # timeout = 0.2
        # print("Time right now - ",step)
        # rlist, wlist, xlist = select([sys.stdin],[],[],timeout)

        # if rlist:
        #     print("Key pressed - ")
        #     print(rlist)
        #     traci.vehicle.addFull(vehID='left_'+str(step),routeID='r0',typeID='car',depart='triggered',departLane='random',departPos='random')
        #     termios.tcflush(sys.stdin,termios.TCIFLUSH)

        key = stdscr.getch()
        stdscr.addch(20,25,key)
        stdscr.refresh()

        if key == curses.KEY_RIGHT: 
            stdscr.addstr(2, 20, "Up")
            traci.vehicle.addFull(vehID='right_'+str(step),routeID='r0',typeID='car',depart='triggered',departLane='random',departPos='random')

        elif key == curses.KEY_DOWN: 
            stdscr.addstr(3, 20, "Down")
            traci.vehicle.addFull(vehID='down_'+str(step),routeID='r3',typeID='car',depart='triggered',departLane='random',departPos='random')

        elif key == curses.KEY_LEFT: 
            stdscr.addstr(4, 20, "Left")
            traci.vehicle.addFull(vehID='left_'+str(step),routeID='r6',typeID='car',depart='triggered',departLane='random',departPos='random')

        elif key == curses.KEY_UP: 
            stdscr.addstr(5, 20, "Up")
            traci.vehicle.addFull(vehID='up_'+str(step),routeID='r9',typeID='car',depart='triggered',departLane='random',departPos='random')

        step += 1
    curses.endwin()
    traci.close()
    sys.stdout.flush() 
Example #26
Source File: runner.py    From Smart-Traffic-Signals-in-India-using-Deep-Reinforcement-Learning-and-Advanced-Computer-Vision with MIT License 4 votes vote down vote up
def run(self):
        import traci
        """execute the TraCI control loop"""
        step = 0
        phase = 0
        states = [0,1,2,3,4,5,6,7]
        traci.trafficlight.setPhase("0", 0)
        while traci.simulation.getMinExpectedNumber() > 0:
            
            traci.simulationStep()
            
            action = random.choice(states)
            traci.trafficlight.setPhase("0", action)
            phase = traci.trafficlight.getPhase("0")
            #print(phase)
            # timeout = 0.2
            # print("Time right now - ",step)
            # rlist, wlist, xlist = select([sys.stdin],[],[],timeout)

            # if rlist:
            #     print("Key pressed - ")
            #     print(rlist)
            #     traci.vehicle.addFull(vehID='left_'+str(step),routeID='r0',typeID='car',depart='triggered',departLane='random',departPos='random')
            #     termios.tcflush(sys.stdin,termios.TCIFLUSH)
            '''
            key = fstdscr.getch()
            stdscr.addch(20,25,key)
            stdscr.refresh()

            if key == curses.KEY_RIGHT: 
                stdscr.addstr(2, 20, "Up")
                traci.vehicle.addFull(vehID='right_'+str(step),routeID='r0',typeID='car',depart='triggered',departLane='random',departPos='random')

            elif key == curses.KEY_DOWN: 
                stdscr.addstr(3, 20, "Down")
                traci.vehicle.addFull(vehID='down_'+str(step),routeID='r3',typeID='car',depart='triggered',departLane='random',departPos='random')

            elif key == curses.KEY_LEFT: 
                stdscr.addstr(4, 20, "Left")
                traci.vehicle.addFull(vehID='left_'+str(step),routeID='r6',typeID='car',depart='triggered',departLane='random',departPos='random')

            elif key == curses.KEY_UP: 
                stdscr.addstr(5, 20, "Up")
                traci.vehicle.addFull(vehID='up_'+str(step),routeID='r9',typeID='car',depart='triggered',departLane='random',departPos='random')
               ''' 

            step += 1
        #.curses.endwin()
        traci.close()
        sys.stdout.flush()