def render_step(self): line = deepcopy(self.code_box.listing.lines[self.position - 1]) self.undo_line = line token = line.parts[-1][0] if self._inside_string(line): # inside a multi-line string, don't reparse, just append parts = deepcopy(line.parts) parts[-1] = CodePart(token, parts[-1].text + self.source) replace_line = CodeLine(parts, line.lexer) else: # not inside a string if token_is_a(token, String): # last token is a string, parse the source and append source_line = parse_source(self.source, line.lexer)[0] new_parts = line.parts + source_line.parts replace_line = CodeLine(new_parts, line.lexer) else: # last token isn't a string, reparse the whole line text = line.text + self.source replace_line = parse_source(text, line.lexer)[0] if self.cursor: replace_line.parts.append(CodePart(Token, '\u2588')) self.code_box.listing.replace_line(self.position, replace_line)
def steps(self): lines = parse_source(self.code.source, self.code.lexer) steps = [ steplib.InsertRows(self.code_box, self.position, lines), ] return steps
def render(self, manager, skip=False): if self.state == self.State.DONE: return manager.state = manager.State.SLEEPING delay = self.DELAY if self.state == self.State.BEFORE: # first time through, setup our append and undo lines self.position = 1 if self.code: self.code_lines = parse_source(self.code.source, self.code.lexer) elif self.code_box_to_copy: self.code_lines = deepcopy(self.code_box_to_copy.listing.lines) else: self.code_lines = [] self.undo_lines = deepcopy(self.code_box.listing.lines) self.state = self.State.DELETING # intentional fall through # If we're in skip mode, need to keep doing the work while True: if self.state == self.State.DELETING: if self.position >= len(self.code_box.listing.lines): # wiped everything, delete the empty boxes and go into # append mode self.code_box.listing.clear() self.state = self.State.APPENDING delay = self.BETWEEN_DELAY else: line = BlankCodeLine() self.code_box.listing.replace_line(self.position, line) self.position += 1 else: # state == APPENDING try: line = self.code_lines.pop(0) self.code_box.listing.insert_lines(0, [ line, ]) except IndexError: manager.state = manager.State.ACTIVE self.state = self.State.DONE if self.auto_forward: manager.screen.set_alarm('auto_forward_alarm', 0) return if not skip: # Not skipping, do the loop only once and get out break # ask to be woken back up for the next step self.animation_alarm_handle = manager.screen.set_alarm( 'animation_alarm', delay)
def steps(self): steps = [] lines = parse_source(self.code.source, self.code.lexer) for count, line in enumerate(lines): if self.position == 0: # Append to end line_steps = self._line_to_steps(line, 0, -1) else: # Append to position spot = self.position + count line_steps = self._line_to_steps(line, spot, spot) steps.extend(line_steps) return steps
def append_code(self, code): """Parses contents of a :class:`Code` object and appends it to this box. Has a side effect of changing the listing's colour palette to that of the code object sent in.""" lines = parse_source(code.source, code.lexer) self.insert_lines(0, lines)