Exemple #1
0
class TextProgress:
    """
    @authors: Brigitte Bigi
    @contact: brigitte.bigi((AATT))lpl-aix.fr
    @license: GPL
    @summary: A 3-lines progress self.bar.

    It looks like::

                            Header
    20% [===========----------------------------------]
                       progress message

    The progress self.bar is colored, if the terminal supports color
    output; and adjusts to the width of the terminal.

    """


    def __init__(self):
        """
        Constructor.
        """
        try:
            self.term = TerminalController()
        except:
            self.term = None

        if not (self.term.CLEAR_EOL and self.term.UP and self.term.BOL):
            self.term = None

        self.bar = BAR
        if self.term:
            self.bar = self.term.render(BAR)
        self.cleared = 1 #: true if we haven't drawn the self.bar yet.
        self.percent = 0
        self.text    = ""

    # End __init__
    # ------------------------------------------------------------------


    def update(self, percent, message):
        """
        Update the progress.

        @param text:     progress self.bar text  (default: None)
        @param fraction: progress self.bar value (default: 0)

        """
        n = int((WIDTH-10)*percent)

        if self.term:
            sys.stdout.write(
                self.term.BOL + self.term.UP + self.term.CLEAR_EOL +
                (self.bar % (100*percent, '='*n, '-'*(WIDTH-10-n))) +
                self.term.CLEAR_EOL + message.center(WIDTH))
        else:
            sys.stdout.write( '  => ' + message + " \n")

        self.percent = percent
        self.text    = message

    # End update
    # ------------------------------------------------------------------


    def clear(self):
        """
        Clear.
        """
        if not self.cleared:
            if self.term:
                sys.stdout.write(self.term.BOL + self.term.CLEAR_EOL +
                                 self.term.UP + self.term.CLEAR_EOL +
                                 self.term.UP + self.term.CLEAR_EOL)
            else:
                sys.stdout.write('\n'*50)
            self.cleared = 1

    # End clear
    # ------------------------------------------------------------------


    def set_fraction(self, percent):
        """
        Set a new progress value.

        @param fraction: new progress value

        """
        self.update(percent,self.text)

    # End set_fraction
    # ------------------------------------------------------------------


    def set_text(self,text):
        """
        Set a new progress text.

        @param text: new progress text

        """
        self.update(self.percent,text)

    # End set_text
    # ------------------------------------------------------------------


    def set_header(self,header):
        """
        Set a new progress label.

        @param label: new progress label

        """
        if self.term:
            self.header = self.term.render(HEADER % header.center(WIDTH))
        else:
            self.header = "          " + header

        sys.stdout.write(self.header)

    # End set_header
    # ------------------------------------------------------------------


    def set_new(self):
        """
        Initialize a new progress line.

        """
        sys.stdout.write('\n')
        self.clear()
        self.text = ""
        self.percent = 0
Exemple #2
0
        rob.relative_pos = (robot.relative_pos.x, robot.relative_pos.y)
        rob.third_led_found = robot.third_led_found
        rob.ratio = robot.ratio
        rob.dist_blue_white = robot.dist_blue_white
        rob.dist_red_white = robot.dist_red_white
        rob.absolut_pos_cm = (robot.absolut_pos_cm.x, robot.absolut_pos_cm.y)
        tmp_robots.append(rob)
    robots = tmp_robots
    if debug:
        print_robots(robots)
    newdata = True


if __name__ == "__main__":

    print(term.render("${BLUE}Starting Laustracker XBee Node${NORMAL}"))

    port = "/dev/ttyUSB0"

    parser = OptionParser()
    parser.add_option("-d", "--debug",
                      action="store_true", dest="debug",
                      help="Print status messages to stdout")
    parser.add_option("-r", "--robot", dest="robot", default=None,
                      help="Specify a robot to track")
    parser.add_option("-p", "--port", dest="port", default=port,
                      help="Serial port to use")
    (options, args) = parser.parse_args()
    if options.debug:
        print("Running in debug mode")
        debug = True