487f006196480115640b94ccd2f5a0323f85fd02
[blender-staging.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         CONSOLE_MT_editor_menus.draw_collapsible(context, layout)
33
34         layout.operator("console.autocomplete", text="Autocomplete")
35
36
37 class CONSOLE_MT_editor_menus(Menu):
38     bl_idname = "CONSOLE_MT_editor_menus"
39     bl_label = ""
40
41     def draw(self, context):
42         self.draw_menus(self.layout, context)
43
44     @staticmethod
45     def draw_menus(layout, context):
46         layout.menu("CONSOLE_MT_console")
47
48
49 class CONSOLE_MT_console(Menu):
50     bl_label = "Console"
51
52     def draw(self, context):
53         layout = self.layout
54
55         layout.operator("console.indent")
56         layout.operator("console.unindent")
57
58         layout.separator()
59
60         layout.operator("console.clear")
61         layout.operator("console.clear_line")
62
63         layout.separator()
64
65         layout.operator("console.copy_as_script")
66         layout.operator("console.copy")
67         layout.operator("console.paste")
68         layout.menu("CONSOLE_MT_language")
69
70         layout.separator()
71
72         layout.operator("screen.area_dupli")
73         layout.operator("screen.screen_full_area")
74         layout.operator("screen.screen_full_area", text="Toggle Fullscreen Area").use_hide_panels = True
75
76
77 class CONSOLE_MT_language(Menu):
78     bl_label = "Languages..."
79
80     def draw(self, context):
81         import sys
82
83         layout = self.layout
84         layout.column()
85
86         # Collect modules with 'console_*.execute'
87         languages = []
88         for modname, mod in sys.modules.items():
89             if modname.startswith("console_") and hasattr(mod, "execute"):
90                 languages.append(modname.split("_", 1)[-1])
91
92         languages.sort()
93
94         for language in languages:
95             layout.operator("console.language",
96                             text=language.title(),
97                             translate=False).language = language
98
99
100 def add_scrollback(text, text_type):
101     for l in text.split("\n"):
102         bpy.ops.console.scrollback_append(text=l.expandtabs(4),
103                                           type=text_type)
104
105
106 classes = (
107     CONSOLE_HT_header,
108     CONSOLE_MT_console,
109     CONSOLE_MT_editor_menus,
110     CONSOLE_MT_language,
111 )
112
113 if __name__ == "__main__":  # only for live edit.
114     from bpy.utils import register_class
115     for cls in classes:
116         register_class(cls)