| 1 | import bpy |
| 2 | |
| 3 | class TextEditorInfo: |
| 4 | def __init__(self): |
| 5 | context = bpy.context |
| 6 | |
| 7 | space = context.space_data |
| 8 | region = context.region |
| 9 | |
| 10 | |
| 11 | text_block = space.text |
| 12 | |
| 13 | self.visible_lines = space.visible_lines |
| 14 | self.top_line_index = space.top |
| 15 | self.text_block = text_block |
| 16 | self.line_index = text_block.current_line_index |
| 17 | self.character_index = text_block.current_character |
| 18 | |
| 19 | self.width = region.width |
| 20 | self.height = region.height |
| 21 | |
| 22 | self.line_height = self.height / self.visible_lines |
| 23 | self.character_width = self.line_height * 0.436 |
| 24 | |
| 25 | self.visible_line_index = self.line_index - self.top_line_index |
| 26 | |
| 27 | self.cursor_position = ( |
| 28 | self.character_width * self.character_index, |
| 29 | self.height - self.line_height * self.visible_line_index - self.line_height / 2 ) |
| 30 | |
| 31 | self.scale = self.line_height / 20 |
| 32 | |
| 33 | def active_text_block_exists(): |
| 34 | return getattr(bpy.context.space_data, "text", None) is not None |