pystage.convert

class pystage.convert.code_writer.CodeWriter(project, templates, language='core')

Bases: object

Helper class to write code templates

get_id()

Helper to create unique names.

get_opcode_function(block)

Get core API function for a block.

Use the function metadata to determine the correct core API function based on a given block, using opcode and params.

Parameters

block (dict) – A block from the intermediate code representation.

get_sprite_or_stage(name=None)
get_sprite_var(name=None)
get_translated_call(block, language)
get_translated_function(block, language)

Get translated API function for a block.

Use the function metadata to determine the correct translated API function based on a given block, using opcode and params.

Parameters

block (dict) – A block from the intermediate code representation.

get_translated_template(block, language)
global_backdrop(name, quoted=True)
global_costume(name, quoted=True)
global_sound(name: str, quoted=True)
process(block)
render(block, text, context={})
render_comments()
set_sprite(name)
pystage.convert.code_writer.quoted(value)
pystage.convert.code_writer.resolve(value)
pystage.convert.code_writer.unquoted(value)
class pystage.convert.sb3.DictClass

Bases: collections.OrderedDict

A dictionary that can be accessed via dot notation for convenience.

pystage.convert.sb3.get_block(block, blocks, stage)

Recursively turns the sb3 structure into our intermediate representation.

pystage.convert.sb3.get_input_value(i, stage)

Extracts values from sb3 input representations.

pystage.convert.sb3.get_intermediate(data, name)
pystage.convert.sb3.get_python(project, language='core')
pystage.convert.sb3.logger = <Logger pystage.convert.sb3 (WARNING)>

For the conversion, we create a simplified version of the block trees that is used in the code template functions.

pystage.convert.sb3.print_python(project, language='core')
pystage.convert.sb3.to_filename(name: str)
pystage.convert.sb3.unique_global_name(name, ext)
Rules:
  • Every template ends at the indent_level where it started.

  • At the end of block code add a blank line.

  • New functions (hat blocks) add a newline at the beginning to get to 2 blank lines.