Merged changes in the trunk up to revision 54421.
[blender.git] / release / scripts / startup / bl_ui / space_console.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20 import bpy
21 from bpy.types import Header, Menu
22
23
24 class CONSOLE_HT_header(Header):
25     bl_space_type = 'CONSOLE'
26
27     def draw(self, context):
28         layout = self.layout.row()
29
30         layout.template_header()
31
32         if context.area.show_menus:
33             layout.menu("CONSOLE_MT_console")
34
35         layout.operator("console.autocomplete", text="Autocomplete")
36
37
38 class CONSOLE_MT_console(Menu):
39     bl_label = "Console"
40
41     def draw(self, context):
42         layout = self.layout
43
44         layout.operator("console.indent")
45         layout.operator("console.unindent")
46
47         layout.separator()
48
49         layout.operator("console.clear")
50         layout.operator("console.clear_line")
51
52         layout.separator()
53
54         layout.operator("console.copy_as_script")
55         layout.operator("console.copy")
56         layout.operator("console.paste")
57         layout.menu("CONSOLE_MT_language")
58
59         layout.separator()
60
61         layout.operator("screen.area_dupli")
62         layout.operator("screen.screen_full_area")
63
64
65 class CONSOLE_MT_language(Menu):
66     bl_label = "Languages..."
67
68     def draw(self, context):
69         import sys
70
71         layout = self.layout
72         layout.column()
73
74         # Collect modules with 'console_*.execute'
75         languages = []
76         for modname, mod in sys.modules.items():
77             if modname.startswith("console_") and hasattr(mod, "execute"):
78                 languages.append(modname.split("_", 1)[-1])
79
80         languages.sort()
81
82         for language in languages:
83             layout.operator("console.language",
84                             text=language.title(),
85                             translate=False).language = language
86
87
88 def add_scrollback(text, text_type):
89     for l in text.split("\n"):
90         bpy.ops.console.scrollback_append(text=l.replace('\t', '    '),
91                                           type=text_type)
92
93 if __name__ == "__main__":  # only for live edit.
94     bpy.utils.register_module(__name__)