2009-11-01 15:21:20 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
2009-11-03 07:23:02 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
2009-11-03 07:23:02 +00:00
|
|
|
#
|
2009-11-01 15:21:20 +00:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-11-01 15:21:20 +00:00
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
2009-10-31 20:16:59 +00:00
|
|
|
|
2009-10-31 23:35:56 +00:00
|
|
|
# <pep8 compliant>
|
2009-07-16 00:50:27 +00:00
|
|
|
import bpy
|
2009-11-06 23:53:40 +00:00
|
|
|
from bpy.props import *
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
class CONSOLE_HT_header(bpy.types.Header):
|
2009-10-31 13:31:23 +00:00
|
|
|
bl_space_type = 'CONSOLE'
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
def draw(self, context):
|
|
|
|
sc = context.space_data
|
|
|
|
# text = sc.text
|
|
|
|
layout = self.layout
|
|
|
|
|
|
|
|
row = layout.row(align=True)
|
|
|
|
row.template_header()
|
|
|
|
|
|
|
|
if context.area.show_menus:
|
|
|
|
sub = row.row(align=True)
|
|
|
|
|
|
|
|
if sc.console_type == 'REPORT':
|
2009-11-23 00:27:30 +00:00
|
|
|
sub.menu("CONSOLE_MT_report")
|
2009-10-29 20:55:45 +00:00
|
|
|
else:
|
2009-11-23 00:27:30 +00:00
|
|
|
sub.menu("CONSOLE_MT_console")
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-11-23 00:27:30 +00:00
|
|
|
layout.separator()
|
|
|
|
layout.prop(sc, "console_type", expand=True)
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
if sc.console_type == 'REPORT':
|
|
|
|
row = layout.row(align=True)
|
2009-11-23 00:27:30 +00:00
|
|
|
row.prop(sc, "show_report_debug", text="Debug")
|
|
|
|
row.prop(sc, "show_report_info", text="Info")
|
|
|
|
row.prop(sc, "show_report_operator", text="Operators")
|
|
|
|
row.prop(sc, "show_report_warn", text="Warnings")
|
|
|
|
row.prop(sc, "show_report_error", text="Errors")
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
row = layout.row()
|
|
|
|
row.enabled = sc.show_report_operator
|
2009-11-23 00:27:30 +00:00
|
|
|
row.operator("console.report_replay")
|
2009-10-29 20:55:45 +00:00
|
|
|
else:
|
|
|
|
row = layout.row(align=True)
|
2009-11-23 00:27:30 +00:00
|
|
|
row.operator("console.autocomplete", text="Autocomplete")
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
class CONSOLE_MT_console(bpy.types.Menu):
|
2009-10-31 13:31:23 +00:00
|
|
|
bl_label = "Console"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-10-29 20:55:45 +00:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
layout.column()
|
2009-11-23 00:27:30 +00:00
|
|
|
layout.operator("console.clear")
|
|
|
|
layout.operator("console.copy")
|
|
|
|
layout.operator("console.paste")
|
|
|
|
layout.menu("CONSOLE_MT_language")
|
2009-12-04 17:54:48 +00:00
|
|
|
|
2009-12-03 16:28:50 +00:00
|
|
|
layout.separator()
|
2009-12-04 17:54:48 +00:00
|
|
|
|
2009-12-03 16:28:50 +00:00
|
|
|
layout.operator("screen.area_dupli")
|
|
|
|
layout.operator("screen.screen_full_area")
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-12-04 17:54:48 +00:00
|
|
|
|
2009-07-19 00:49:44 +00:00
|
|
|
class CONSOLE_MT_report(bpy.types.Menu):
|
2009-10-31 13:31:23 +00:00
|
|
|
bl_label = "Report"
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2009-10-29 20:55:45 +00:00
|
|
|
def draw(self, context):
|
|
|
|
layout = self.layout
|
|
|
|
layout.column()
|
2009-11-23 00:27:30 +00:00
|
|
|
layout.operator("console.select_all_toggle")
|
|
|
|
layout.operator("console.select_border")
|
|
|
|
layout.operator("console.report_delete")
|
|
|
|
layout.operator("console.report_copy")
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2009-11-14 13:35:44 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
class CONSOLE_MT_language(bpy.types.Menu):
|
|
|
|
bl_label = "Languages..."
|
|
|
|
|
|
|
|
def draw(self, context):
|
2009-11-17 12:21:41 +00:00
|
|
|
import sys
|
2009-11-21 00:05:43 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
layout = self.layout
|
|
|
|
layout.column()
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-17 12:21:41 +00:00
|
|
|
# Collect modules with 'console_*.execute'
|
2009-11-06 23:53:40 +00:00
|
|
|
languages = []
|
2009-11-17 12:21:41 +00:00
|
|
|
for modname, mod in sys.modules.items():
|
|
|
|
if modname.startswith("console_") and hasattr(mod, "execute"):
|
|
|
|
languages.append(modname.split('_', 1)[-1])
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
languages.sort()
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
for language in languages:
|
2009-11-23 11:43:38 +00:00
|
|
|
layout.operator("console.language", text=language[0].upper() + language[1:]).language = language
|
2009-07-19 00:49:44 +00:00
|
|
|
|
2009-11-14 13:35:44 +00:00
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
def add_scrollback(text, text_type):
|
2009-10-29 20:55:45 +00:00
|
|
|
for l in text.split('\n'):
|
|
|
|
bpy.ops.console.scrollback_append(text=l.replace('\t', ' '),
|
|
|
|
type=text_type)
|
|
|
|
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-11-05 11:17:09 +00:00
|
|
|
class ConsoleExec(bpy.types.Operator):
|
2010-02-11 20:33:04 +00:00
|
|
|
'''Execute the current console line as a python expression'''
|
2009-10-31 13:31:23 +00:00
|
|
|
bl_idname = "console.execute"
|
|
|
|
bl_label = "Console Execute"
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
|
|
|
|
2009-11-18 01:30:28 +00:00
|
|
|
module = __import__("console_" + sc.language)
|
2009-11-17 12:21:41 +00:00
|
|
|
execute = getattr(module, "execute", None)
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
if execute:
|
2009-11-17 12:21:41 +00:00
|
|
|
return execute(context)
|
2009-10-29 20:55:45 +00:00
|
|
|
else:
|
2009-11-06 23:53:40 +00:00
|
|
|
print("Error: bpy.ops.console.execute_" + sc.language + " - not found")
|
2009-12-24 19:50:43 +00:00
|
|
|
return {'FINISHED'}
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
2009-11-05 11:17:09 +00:00
|
|
|
class ConsoleAutocomplete(bpy.types.Operator):
|
2010-02-11 20:33:04 +00:00
|
|
|
'''Evaluate the namespace up until the cursor and give a list of options or complete the name if there is only one'''
|
2009-10-31 13:31:23 +00:00
|
|
|
bl_idname = "console.autocomplete"
|
|
|
|
bl_label = "Console Autocomplete"
|
2009-07-16 00:50:27 +00:00
|
|
|
|
2009-10-29 20:55:45 +00:00
|
|
|
def poll(self, context):
|
2009-11-06 23:53:40 +00:00
|
|
|
return context.space_data.console_type != 'REPORT'
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
2009-11-19 23:59:37 +00:00
|
|
|
module = __import__("console_" + sc.language)
|
2009-11-17 12:21:41 +00:00
|
|
|
autocomplete = getattr(module, "autocomplete", None)
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
if autocomplete:
|
2009-11-17 12:21:41 +00:00
|
|
|
return autocomplete(context)
|
2009-11-06 23:53:40 +00:00
|
|
|
else:
|
|
|
|
print("Error: bpy.ops.console.autocomplete_" + sc.language + " - not found")
|
2009-12-24 19:50:43 +00:00
|
|
|
return {'FINISHED'}
|
2009-10-29 20:55:45 +00:00
|
|
|
|
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
class ConsoleBanner(bpy.types.Operator):
|
2009-12-24 19:50:43 +00:00
|
|
|
'''Print a message whem the terminal initializes'''
|
2009-11-06 23:53:40 +00:00
|
|
|
bl_idname = "console.banner"
|
2009-12-24 19:50:43 +00:00
|
|
|
bl_label = "Console Banner"
|
2009-10-29 20:55:45 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
# default to python
|
|
|
|
if not sc.language:
|
|
|
|
sc.language = 'python'
|
|
|
|
|
2009-11-21 00:05:43 +00:00
|
|
|
module = __import__("console_" + sc.language)
|
2009-11-17 12:21:41 +00:00
|
|
|
banner = getattr(module, "banner", None)
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
if banner:
|
2009-11-17 12:21:41 +00:00
|
|
|
return banner(context)
|
2009-11-06 23:53:40 +00:00
|
|
|
else:
|
|
|
|
print("Error: bpy.ops.console.banner_" + sc.language + " - not found")
|
2009-12-24 19:50:43 +00:00
|
|
|
return {'FINISHED'}
|
2009-07-16 00:50:27 +00:00
|
|
|
|
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
class ConsoleLanguage(bpy.types.Operator):
|
|
|
|
'''Set the current language for this console'''
|
|
|
|
bl_idname = "console.language"
|
2009-12-24 19:50:43 +00:00
|
|
|
bl_label = "Console Language"
|
2009-11-14 13:35:44 +00:00
|
|
|
language = StringProperty(name="Language", maxlen=32, default="")
|
2009-11-05 11:17:09 +00:00
|
|
|
|
|
|
|
def execute(self, context):
|
|
|
|
sc = context.space_data
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
# defailt to python
|
2009-11-19 17:12:08 +00:00
|
|
|
sc.language = self.properties.language
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
bpy.ops.console.banner()
|
2009-11-07 22:07:46 +00:00
|
|
|
|
2009-11-06 23:53:40 +00:00
|
|
|
# insert a new blank line
|
|
|
|
bpy.ops.console.history_append(text="", current_character=0,
|
|
|
|
remove_duplicates=True)
|
2009-11-05 11:17:09 +00:00
|
|
|
|
2009-12-24 19:50:43 +00:00
|
|
|
return {'FINISHED'}
|
2009-11-05 11:17:09 +00:00
|
|
|
|
|
|
|
|
2010-02-14 11:21:21 +00:00
|
|
|
classes = [
|
|
|
|
CONSOLE_HT_header,
|
|
|
|
CONSOLE_MT_console,
|
|
|
|
CONSOLE_MT_report,
|
|
|
|
CONSOLE_MT_language,
|
|
|
|
|
|
|
|
# Stubs that call the language operators
|
|
|
|
ConsoleExec,
|
|
|
|
ConsoleAutocomplete,
|
|
|
|
ConsoleBanner,
|
|
|
|
|
|
|
|
# Set the language and call the banner
|
|
|
|
ConsoleLanguage]
|
|
|
|
|
|
|
|
|
|
|
|
def register():
|
|
|
|
register = bpy.types.register
|
|
|
|
for cls in classes:
|
|
|
|
register(cls)
|
|
|
|
|
2010-02-22 23:32:58 +00:00
|
|
|
|
2010-02-14 11:21:21 +00:00
|
|
|
def unregister():
|
|
|
|
unregister = bpy.types.unregister
|
|
|
|
for cls in classes:
|
|
|
|
unregister(cls)
|
2010-02-16 09:55:07 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
register()
|