Ejemplo n.º 1
0
    def _start_print(self, file_path=None, directory=None):
        # start comms thread to stream the file
        # set comms.ping_pong to False for fast stream mode
        if file_path is None:
            file_path = self.app.gcode_file
        if directory is None:
            directory = self.last_path

        Logger.info('MainWindow: printing file: {}'.format(file_path))

        try:
            self.nlines = Comms.file_len(
                file_path)  # get number of lines so we can do progress and ETA
            Logger.debug('MainWindow: number of lines: {}'.format(self.nlines))
        except Exception:
            Logger.warning('MainWindow: exception in file_len: {}'.format(
                traceback.format_exc()))
            self.nlines = None

        self.start_print_time = datetime.datetime.now()
        self.display('>>> Running file: {}, {} lines'.format(
            file_path, self.nlines))

        if self.app.comms.stream_gcode(
                file_path, progress=lambda x: self.display_progress(x)):
            self.display('>>> Run started at: {}'.format(
                self.start_print_time.strftime('%x %X')))
        else:
            self.display('WARNING Unable to start print')
            return

        self.set_last_file(directory, file_path)

        self.ids.print_but.text = 'Pause'
        self.is_printing = True
        self.paused = False