def print_python(self, ast, early=False): self.indent() code = ast.code.source if code[0] == '\n': code = code[1:] self.write("python") if early: self.write(" early") if ast.hide: self.write(" hide") if hasattr(ast, "store") and ast.store != "store": self.write(" in ") # Strip prepended "store." self.write(ast.store[6:]) self.write(":") self.indent_level += 1 for line in split_logical_lines(code): self.indent() self.write(line) self.indent_level -= 1 else: self.write("$ %s" % code)
def print_python(self, ast): self.indent() code = ast.code.source if code[0] == "\n": self.write("python:") with self.increase_indent(): self.write_lines(split_logical_lines(code[1:])) else: self.write("$ %s" % code)
def print_python(self, ast): self.indent() code = ast.code.source if code[0] == '\n': self.write("python:") with self.increase_indent(): self.write_lines(split_logical_lines(code[1:])) else: self.write("$ %s" % code)
def print_python(self, header, code): # This function handles any statement which is a block but couldn't logically be # Translated to a screen statement. # # Ren'Py's line numbers are really, really buggy. Here's a summary: # If we're not directly under the root screen, and a keyword for our # parent follows us, then all of our line numbers will be equal to the # line number of that keyword. # If we're not directly under the root screen, and no keywords for our # parent follow us, then header.lineno is the line number of whatever # it is that preceded us (which is completely useless). # If we're directly under the root "screen", then header.lineno is the # line that "$" or "python:" appeared on. # If we're not a child followed by a keyword, and "$" was used, then # code[0].lineno is the line that the code actually starts on, but if # "python:" was used, then all of code's line numbers will be 1 greater # than the line each one should be. source = self.to_source( ast.Module(body=code, lineno=code[0].lineno, col_offset=0)).rstrip() lines = source.splitlines() if len(split_logical_lines(source)) == 1 and ( not self.match_line_numbers or (not self.is_root and code[0].lineno < self.linenumber + 3) or header.lineno >= code[0].lineno): # This is only one logical line, so it's possible that it was $, # and either it's not in the root (so we don't know what the # original source used), or it is in the root and we know it used $. # Also, if we don't know for sure what was used, but we have enough # room to use a "python" block, then use it instead, since it'll # result in everything taking up one fewer line (since it'll use # one more, but start two sooner). self.advance_to_line(code[0].lineno) self.indent() self.write("$ %s" % lines[0]) for line in lines[1:]: self.indent() self.write(line) else: # Either this is more than one logical line, so it has to be a # python block, or it was in the root and we can tell that it was # originally a python block. if self.is_root: self.advance_to_line(header.lineno) self.indent() self.write("python:") self.advance_to_line(code[0].lineno - 1) self.indent_level += 1 for line in lines: self.indent() self.write(line) self.indent_level -= 1
def print_python(self, ast): self.indent() # Extract the source code from the slast.SLPython object. If it starts with a # newline, print it as a python block, else, print it as a $ statement code = ast.code.source if code[0] == "\n": code = code[1:] self.write("python:") with self.increase_indent(): self.write_lines(split_logical_lines(code)) else: self.write("$ %s" % code)
def print_python(self, header, code): # This function handles any statement which is a block but couldn't logically be # Translated to a screen statement. # # Ren'Py's line numbers are really, really buggy. Here's a summary: # If we're not directly under the root screen, and a keyword for our # parent follows us, then all of our line numbers will be equal to the # line number of that keyword. # If we're not directly under the root screen, and no keywords for our # parent follow us, then header.lineno is the line number of whatever # it is that preceded us (which is completely useless). # If we're directly under the root "screen", then header.lineno is the # line that "$" or "python:" appeared on. # If we're not a child followed by a keyword, and "$" was used, then # code[0].lineno is the line that the code actually starts on, but if # "python:" was used, then all of code's line numbers will be 1 greater # than the line each one should be. source = self.to_source(ast.Module(body=code, lineno=code[0].lineno, col_offset=0)).rstrip() lines = source.splitlines() if len(split_logical_lines(source)) == 1 and (not self.match_line_numbers or (not self.is_root and code[0].lineno < self.linenumber + 3) or header.lineno >= code[0].lineno): # This is only one logical line, so it's possible that it was $, # and either it's not in the root (so we don't know what the # original source used), or it is in the root and we know it used $. # Also, if we don't know for sure what was used, but we have enough # room to use a "python" block, then use it instead, since it'll # result in everything taking up one fewer line (since it'll use # one more, but start two sooner). self.advance_to_line(code[0].lineno) self.indent() self.write("$ %s" % lines[0]) for line in lines[1:]: self.indent() self.write(line) else: # Either this is more than one logical line, so it has to be a # python block, or it was in the root and we can tell that it was # originally a python block. if self.is_root: self.advance_to_line(header.lineno) self.indent() self.write("python:") self.advance_to_line(code[0].lineno - 1) self.indent_level += 1 for line in lines: self.indent() self.write(line) self.indent_level -= 1