space_console.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. # <pep8 compliant>
  19. import bpy
  20. from bpy.types import Header, Menu
  21. class CONSOLE_HT_header(Header):
  22. bl_space_type = 'CONSOLE'
  23. def draw(self, context):
  24. layout = self.layout.row()
  25. layout.template_header()
  26. CONSOLE_MT_editor_menus.draw_collapsible(context, layout)
  27. layout.operator("console.autocomplete", text="Autocomplete")
  28. class CONSOLE_MT_editor_menus(Menu):
  29. bl_idname = "CONSOLE_MT_editor_menus"
  30. bl_label = ""
  31. def draw(self, _context):
  32. layout = self.layout
  33. layout.menu("CONSOLE_MT_console")
  34. class CONSOLE_MT_console(Menu):
  35. bl_label = "Console"
  36. def draw(self, _context):
  37. layout = self.layout
  38. layout.operator("console.indent")
  39. layout.operator("console.unindent")
  40. layout.separator()
  41. layout.operator("console.clear")
  42. layout.operator("console.clear_line")
  43. layout.separator()
  44. layout.operator("console.copy_as_script")
  45. layout.operator("console.copy")
  46. layout.operator("console.paste")
  47. layout.menu("CONSOLE_MT_language")
  48. layout.separator()
  49. layout.menu("INFO_MT_area")
  50. class CONSOLE_MT_language(Menu):
  51. bl_label = "Languages..."
  52. def draw(self, _context):
  53. import sys
  54. layout = self.layout
  55. layout.column()
  56. # Collect modules with 'console_*.execute'
  57. languages = []
  58. for modname, mod in sys.modules.items():
  59. if modname.startswith("console_") and hasattr(mod, "execute"):
  60. languages.append(modname.split("_", 1)[-1])
  61. languages.sort()
  62. for language in languages:
  63. layout.operator("console.language",
  64. text=language.title(),
  65. translate=False).language = language
  66. def add_scrollback(text, text_type):
  67. for l in text.split("\n"):
  68. bpy.ops.console.scrollback_append(text=l.expandtabs(4),
  69. type=text_type)
  70. classes = (
  71. CONSOLE_HT_header,
  72. CONSOLE_MT_editor_menus,
  73. CONSOLE_MT_console,
  74. CONSOLE_MT_language,
  75. )
  76. if __name__ == "__main__": # only for live edit.
  77. from bpy.utils import register_class
  78. for cls in classes:
  79. register_class(cls)