[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [15678] branches/soc-2008-quorn: Updated the textplugin_outliner.py plug-in to use the new Draw. PupTreeMenu and updated this menu to support titles.
Ian Thompson
quornian at googlemail.com
Mon Jul 21 21:11:38 CEST 2008
Revision: 15678
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=15678
Author: quorn
Date: 2008-07-21 21:11:38 +0200 (Mon, 21 Jul 2008)
Log Message:
-----------
Updated the textplugin_outliner.py plug-in to use the new Draw.PupTreeMenu and updated this menu to support titles.
Modified Paths:
--------------
branches/soc-2008-quorn/release/scripts/textplugin_outliner.py
branches/soc-2008-quorn/source/blender/python/api2_2x/doc/Draw.py
branches/soc-2008-quorn/source/blender/src/toolbox.c
Modified: branches/soc-2008-quorn/release/scripts/textplugin_outliner.py
===================================================================
--- branches/soc-2008-quorn/release/scripts/textplugin_outliner.py 2008-07-21 18:12:02 UTC (rev 15677)
+++ branches/soc-2008-quorn/release/scripts/textplugin_outliner.py 2008-07-21 19:11:38 UTC (rev 15678)
@@ -16,62 +16,118 @@
except ImportError:
OK = False
-def do_long_menu(title, items):
+def make_menu(items, eventoffs):
n = len(items)
if n < 20:
- return Draw.PupMenu(title+'%t|'+'|'.join(items))
+ return [(items[i], i+1+eventoffs) for i in range(len(items))]
letters = []
- check = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ_' # Cannot start 0-9 so just letters
+ check = 'abcdefghijklmnopqrstuvwxyz_' # Names cannot start 0-9
for c in check:
for item in items:
- if item[0].upper() == c:
+ if item[0].lower() == c:
letters.append(c)
break
- i = Draw.PupMenu(title+'%t|'+'|'.join(letters))
- if i < 1:
- return i
-
- c = letters[i-1]
- newitems = []
-
+ dict = {}
i = 0
for item in items:
i += 1
- if item[0].upper() == c:
- newitems.append(item+'%x'+str(i))
+ c = item[0].lower()
+ if not dict.has_key(c): dict[c] = []
+ dict[c].append((item, i+eventoffs))
- return Draw.PupMenu(title+'%t|'+'|'.join(newitems))
+ subs = []
+ for c in letters:
+ subs.append((c, dict[c]))
+
+ return subs
+def find_word(txt, word):
+ i = 0
+ for line in txt.asLines():
+ c = line.find(word)
+ if c != -1:
+ txt.setCursorPos(i, c)
+ break
+ i += 1
+
def main():
txt = bpy.data.texts.active
if not txt:
return
+ # Identify word under cursor
+ if get_context(txt) == CTX_NORMAL:
+ line, c = current_line(txt)
+ start = c-1
+ end = c
+ while start >= 0:
+ if not line[start].lower() in 'abcdefghijklmnopqrstuvwxyz0123456789_':
+ break
+ start -= 1
+ while end < len(line):
+ if not line[end].lower() in 'abcdefghijklmnopqrstuvwxyz0123456789_':
+ break
+ end += 1
+ word = line[start+1:end]
+ if word in KEYWORDS:
+ word = None
+ else:
+ word = None
+
+ script = get_cached_descriptor(txt)
items = []
- i = Draw.PupMenu('Outliner%t|Classes|Defs|Variables')
- if i < 1: return
+ desc = None
- script = get_cached_descriptor(txt)
- if i == 1:
- type = script.classes
- elif i == 2:
- type = script.defs
- elif i == 3:
- type = script.vars
- else:
+ tmp = script.classes.keys()
+ tmp.sort(cmp = suggest_cmp)
+ class_menu = make_menu(tmp, len(items))
+ class_menu_length = len(tmp)
+ items.extend(tmp)
+
+ tmp = script.defs.keys()
+ tmp.sort(cmp = suggest_cmp)
+ defs_menu = make_menu(tmp, len(items))
+ defs_menu_length = len(tmp)
+ items.extend(tmp)
+
+ tmp = script.vars.keys()
+ tmp.sort(cmp = suggest_cmp)
+ vars_menu = make_menu(tmp, len(items))
+ vars_menu_length = len(tmp)
+ items.extend(tmp)
+
+ menu = [('Outliner%t', 0),
+ ('Classes', class_menu),
+ ('Functions', defs_menu),
+ ('Variables', vars_menu)]
+ if word:
+ menu.extend([None, ('Locate', [(word, -10)])])
+
+ i = Draw.PupTreeMenu(menu)
+ if i == -1:
return
- items.extend(type.keys())
- items.sort(cmp = suggest_cmp)
- i = do_long_menu('Outliner', items)
- if i < 1:
- return
- try:
- desc = type[items[i-1]]
- except:
- desc = None
+ # Chosen to search for word under cursor
+ if i == -10:
+ if script.classes.has_key(word):
+ desc = script.classes[word]
+ elif script.defs.has_key(word):
+ desc = script.defs[word]
+ elif script.vars.has_key(word):
+ desc = script.vars[word]
+ else:
+ find_word(txt, word)
+ return
+ else:
+ i -= 1
+ if i < class_menu_length:
+ desc = script.classes[items[i]]
+ elif i < class_menu_length + defs_menu_length:
+ desc = script.defs[items[i]]
+ elif i < class_menu_length + defs_menu_length + vars_menu_length:
+ desc = script.vars[items[i]]
if desc:
txt.setCursorPos(desc.lineno-1, 0)
Modified: branches/soc-2008-quorn/source/blender/python/api2_2x/doc/Draw.py
===================================================================
--- branches/soc-2008-quorn/source/blender/python/api2_2x/doc/Draw.py 2008-07-21 18:12:02 UTC (rev 15677)
+++ branches/soc-2008-quorn/source/blender/python/api2_2x/doc/Draw.py 2008-07-21 19:11:38 UTC (rev 15678)
@@ -357,12 +357,14 @@
"""
Create a popup menu tree.
- Each item in the list is a menu item - (str, event), separator - None or submenu - (str, [...]).
+ Each item in the list is: a menu item - (str, event); a separator - None;
+ or submenu - (str, [...]).
- Submenus list uses the same syntax as the menu list.
+ Submenus list uses the same syntax as the menu list. To add a title to the
+ main menu, end the first entry str with '%t' - the event is ignored.
Example::
- result = Draw.PupTreeMenu( [ ("Menu Item 1", 10), ("Menu Item 2", 12), ("SubMenu", [("Menu Item 3", 100), ("MenuItem4", 101) ] ) ] )
+ result = Draw.PupTreeMenu( [ ("Title%t", 0), ("Menu Item 1", 10), ("Menu Item 2", 12), ("SubMenu", [("Menu Item 3", 100), ("MenuItem4", 101) ] ) ] )
@type menu: string
@param menu: A menu list
Modified: branches/soc-2008-quorn/source/blender/src/toolbox.c
===================================================================
--- branches/soc-2008-quorn/source/blender/src/toolbox.c 2008-07-21 18:12:02 UTC (rev 15677)
+++ branches/soc-2008-quorn/source/blender/src/toolbox.c 2008-07-21 19:11:38 UTC (rev 15678)
@@ -2277,7 +2277,7 @@
uiBlock *block;
uiBut *but;
TBitem *menu;
- int dx=96;
+ int dx=96, first=1, len;
short event, mval[2];
long ypos = -5;
@@ -2298,11 +2298,17 @@
/* Add the menu */
for (menu = generic_menu; menu->icon != -1; menu++) {
- if(strcmp(menu->name, "SEPR")==0) {
+ if (first && (len=strlen(menu->name)) > 2 && menu->name[len-2]=='%' && menu->name[len-1]=='t') {
+ menu->name[len-2] = '\0';
+ uiSetCurFont(block, UI_HELVB);
+ uiDefIconTextBut(block, LABEL, 0, ICON_BLANK1, menu->name, mval[0]+tb_mainx,mval[1]+tb_mainy+ypos+5, dx, 19, NULL, 0.0, 0.0, 0, 0, "");
+ uiSetCurFont(block, UI_HELV);
+ ypos-=20;
+ } else if(strcmp(menu->name, "SEPR")==0) {
uiDefBut(block, SEPR, 0, "", mval[0]+tb_mainx,mval[1]+tb_mainy+ypos+5, dx, 6, NULL, 0.0, 0.0, 0, 0, "");
ypos-=6;
} else {
- if (menu->poin) {
+ if (menu->poin) {
but=uiDefIconTextBlockBut(block, tb_makemenu, menu->poin, ICON_RIGHTARROW_THIN, menu->name, mval[0]+tb_mainx,mval[1]+tb_mainy+ypos+5, dx, 19, "");
uiButSetFlag(but, UI_MAKE_RIGHT);
@@ -2313,6 +2319,7 @@
}
ypos-=20;
}
+ first= 0;
}
uiBlockSetButmFunc(block, menu->poin, NULL);
More information about the Bf-blender-cvs
mailing list