Merging r46456 through r46468 from trunk into soc-2011-tomato
[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(align=True)
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.clear")
45         layout.operator("console.clear_line")
46         layout.operator("console.copy")
47         layout.operator("console.paste")
48         layout.menu("CONSOLE_MT_language")
49
50         layout.separator()
51
52         layout.operator("screen.area_dupli")
53         layout.operator("screen.screen_full_area")
54
55
56 class CONSOLE_MT_language(Menu):
57     bl_label = "Languages..."
58
59     def draw(self, context):
60         import sys
61
62         layout = self.layout
63         layout.column()
64
65         # Collect modules with 'console_*.execute'
66         languages = []
67         for modname, mod in sys.modules.items():
68             if modname.startswith("console_") and hasattr(mod, "execute"):
69                 languages.append(modname.split('_', 1)[-1])
70
71         languages.sort()
72
73         for language in languages:
74             layout.operator("console.language", text=language[0].upper() + language[1:]).language = language
75
76
77 def add_scrollback(text, text_type):
78     for l in text.split('\n'):
79         bpy.ops.console.scrollback_append(text=l.replace('\t', '    '),
80             type=text_type)
81
82 if __name__ == "__main__":  # only for live edit.
83     bpy.utils.register_module(__name__)