blender/release/ui/space_text.py
Brecht Van Lommel b4d46e5ded UI: Layout Engine
* Buttons are now created first, and after that the layout is computed.
  This means the layout engine now works at button level, and makes it
  easier to write templates. Otherwise you had to store all info and
  create the buttons later.
* Added interface_templates.c as a separate file to put templates in.
  These can contain regular buttons, and can be put in a Free layout,
  which means you can specify manual coordinates, but still get nested
  correct inside other layouts.

* API was changed to allow better nesting. Previously items were added
  in the last added layout specifier, i.e. one level up in the layout
  hierarchy. This doesn't work well in always, so now when creating things
  like rows or columns it always returns a layout which you have to add
  the items in. All py scripts were updated to follow this.

* Computing the layout now goes in two passes, first estimating the
  required width/height of all nested layouts, and then in the second
  pass using the results of that to decide on the actual locations.

* Enum and array buttons now follow the direction of the layout, i.e.
  they are vertical or horizontal depending if they are in a column or row.
* Color properties now get a color picker, and only get the additional
  RGB sliders with Expand=True.
* File/directory string properties now get a button next to them for
  opening the file browse, though this is not implemented yet.
* Layout items can now be aligned, set align=True when creating a column,
  row, etc.
* Buttons now get a minimum width of one icon (avoids squashing icon
  buttons).

* Moved some more space variables into Style.
2009-05-15 11:19:59 +00:00

147 lines
3.7 KiB
Python

import bpy
# temporary
ICON_LINENUMBERS_OFF = 588
ICON_WORDWRAP_OFF = 584
ICON_SYNTAX_OFF = 586
ICON_TEXT = 120
ICON_HELP = 1
ICON_SCRIPTPLUGINS = 1
class TEXT_HT_header(bpy.types.Header):
__space_type__ = "TEXT_EDITOR"
__idname__ = "TEXT_HT_header"
def draw(self, context):
st = context.space_data
text = st.text
layout = self.layout
layout.template_header(context)
if context.area.show_menus:
row = layout.row(align=True)
row.itemM(context, "TEXT_MT_text")
if text:
row.itemM(context, "TEXT_MT_edit")
row.itemM(context, "TEXT_MT_format")
if text and text.modified:
row = layout.row()
# row.color(redalert)
row.itemO("TEXT_OT_resolve_conflict", text="", icon=ICON_HELP)
row = layout.row(align=True)
row.itemR(st, "line_numbers", text="", icon=ICON_LINENUMBERS_OFF)
row.itemR(st, "word_wrap", text="", icon=ICON_WORDWRAP_OFF)
row.itemR(st, "syntax_highlight", text="", icon=ICON_SYNTAX_OFF)
# row.itemR(st, "do_python_plugins", text="", icon=ICON_SCRIPTPLUGINS)
layout.template_header_ID(context, st, "text", new="TEXT_OT_new", open="TEXT_OT_open", unlink="TEXT_OT_unlink")
if text:
row = layout.row()
if text.filename != "":
if text.dirty:
row.itemL(text="File: *" + text.filename + " (unsaved)")
else:
row.itemL(text="File: " + text.filename)
else:
if text.library:
row.itemL(text="Text: External")
else:
row.itemL(text="Text: Internal")
class TEXT_PT_properties(bpy.types.Panel):
__space_type__ = "TEXT_EDITOR"
__region_type__ = "UI"
__label__ = "Properties"
def draw(self, context):
st = context.space_data
layout = self.layout
flow = layout.column_flow()
flow.itemR(st, "line_numbers", icon=ICON_LINENUMBERS_OFF)
flow.itemR(st, "word_wrap", icon=ICON_WORDWRAP_OFF)
flow.itemR(st, "syntax_highlight", icon=ICON_SYNTAX_OFF)
flow = layout.column_flow()
flow.itemR(st, "font_size")
flow.itemR(st, "tab_width")
class TEXT_PT_find(bpy.types.Panel):
__space_type__ = "TEXT_EDITOR"
__region_type__ = "UI"
__label__ = "Find"
def draw(self, context):
st = context.space_data
layout = self.layout
# find
col = layout.column(align=True)
row = col.row()
row.itemR(st, "find_text", text="")
row.itemO("TEXT_OT_find_set_selected", text="", icon=ICON_TEXT)
col.itemO("TEXT_OT_find")
# replace
col = layout.column(align=True)
row = col.row()
row.itemR(st, "replace_text", text="")
row.itemO("TEXT_OT_replace_set_selected", text="", icon=ICON_TEXT)
col.itemO("TEXT_OT_replace")
# mark
layout.itemO("TEXT_OT_mark_all")
# settings
row = layout.row()
row.itemR(st, "find_wrap", text="Wrap")
row.itemR(st, "find_all", text="All")
class TEXT_MT_text(bpy.types.Menu):
__space_type__ = "TEXT_EDITOR"
__label__ = "Text"
def draw(self, context):
layout = self.layout
st = context.space_data
text = st.text
layout.column()
layout.itemO("TEXT_OT_new")
layout.itemO("TEXT_OT_open")
if text:
layout.itemO("TEXT_OT_reload")
layout.column()
layout.itemO("TEXT_OT_save")
layout.itemO("TEXT_OT_save_as")
if text.filename != "":
layout.itemO("TEXT_OT_make_internal")
layout.column()
layout.itemO("TEXT_OT_run_script")
#ifndef DISABLE_PYTHON
# XXX if(BPY_is_pyconstraint(text))
# XXX uiMenuItemO(head, 0, "TEXT_OT_refresh_pyconstraints");
#endif
#ifndef DISABLE_PYTHON
# XXX layout.column()
# XXX uiDefIconTextBlockBut(block, text_template_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Script Templates", 0, yco-=20, 120, 19, "");
# XXX uiDefIconTextBlockBut(block, text_plugin_scriptsmenu, NULL, ICON_RIGHTARROW_THIN, "Text Plugins", 0, yco-=20, 120, 19, "");
#endif
bpy.types.register(TEXT_HT_header)
bpy.types.register(TEXT_PT_properties)
bpy.types.register(TEXT_PT_find)
bpy.types.register(TEXT_MT_text)