1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456
|
#!BPY
"""
Name: 'BPy Doc Browser'
Blender: 232
Group: 'System'
Tip: 'Browse BPython (scripting API) modules doc strings.'
"""
__author__ = "Daniel Dunbar"
__url__ = ("blender", "elysiun")
__version__ = "1.0"
__bpydoc__ = """\
The "Doc Browser" lets users navigate the documentation strings of part of
the Blender Python API.
It doesn't give access yet to object method functions and variables, only to
module functions, but still it is a handy reference.
Hotkeys:<br>
Page Up / Page Down: scroll 5 lines at a time;<br>
Up / Down arrow keys or mouse wheel: scroll one line at a time.
Notes:<br>
Everyone interested in the bpython api is also invited to read "The Blender
Python API Reference" doc, available online ("Python Scripting Reference"
entry in Blender's Help menu).
"""
# $Id: doc_browser.py,v 1.4 2006/06/11 21:35:14 ianwill Exp $
#
# --------------------------------------------------------------------------
# ***** BEGIN GPL LICENSE BLOCK *****
#
# Copyright (C) 2004: Daniel Dunbar, ddunbar _at_ diads.com
#
# 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ***** END GPL LICENCE BLOCK *****
# --------------------------------------------------------------------------
#####
# Blender help browser
# By Daniel Dunbar,
#
# This should function as a self-explanatory (interface, not code)
# (mostly) help browser. The code is wacky and nasty and or fun,
# but mainly bad, just cause it works doesn't mean its readable!
#
# TEEHEE!
#
# The row_draw function could easily be made into a more generic
# and usefull table drawing function...
#
import Blender
from types import ListType, IntType, FloatType, StringType, ModuleType
from Blender.Draw import *
from Blender.BGL import *
# Simple version check, since I use the
# buffer calls... DONT use this code,
# assume everyone has 1.73+, and force
# them to upgrade if they dont
try:
a= BufList
version= 172
except:
version= 173
# I could have used the split from the string module,
# but some people might not have it
def split(str, on):
out= [""]
for s in str:
if s in on: out.append("")
else: out[-1]= out[-1]+s
if out[-1]=="": del(out[-1])
return out
last_sort= 1; direction= 1
def sort_browselist(type):
global browselist
global last_sort, direction
if (type==last_sort): direction= -direction
else: direction= 1
last_sort= type
if (direction==1):
def byname(x, y): return cmp(x[0],y[0]);
def bytype(x, y): return cmp(x[1],y[1])
def bydata(x, y): return cmp(x[2],y[2])
else:
def byname(x, y): return cmp(y[0],x[0]);
def bytype(x, y): return cmp(y[1],x[1])
def bydata(x, y): return cmp(y[2],x[2])
if (type==1): browselist.sort(byname)
elif (type==2): browselist.sort(bytype)
elif (type==3): browselist.sort(bydata)
selected= -1
def view_doc(num):
global selected, selected_page
if (selected==num): selected= -1
else: selected= num
selected_page= 0
function_filter= 0
def toggle_function_filter():
global function_filter
function_filter= not function_filter
make_browselist()
def view_page(dir):
global selected_page
selected_page= selected_page + dir
browse_scrollstart= 0
def browse_module(num):
global browsing, selected, browse_scrollstart
if (num>=0): newstr= browsing.val + "." + browselist[num][0]
else:
modules= split(browsing.val, ".")
newstr= ""
for m in modules[:-1]:
newstr= newstr+m
try:
browsing= Create(newstr)
make_browselist()
except:
browsing= Create('Blender')
make_browselist()
browse_scrollstart= 0
scrolling= 0
selected= -1
def make_browselist():
global browselist
browselist= []
module= eval(browsing.val)
items= dir(module)
for item_name in items:
if (item_name[:2]=='__'): continue
data= [item_name, 'None', '', '']
item= eval(item_name,module.__dict__)
t= type(item)
if (t==IntType): data[1]= 'Int'; data[2]= `item`
elif (t==FloatType): data[1]= 'Float'; data[2]= `item`
elif (t==StringType): data[1]= 'String'
elif (t==ModuleType): data[1]= 'Module'
elif (callable(item)):
data[1]= 'Function'
doc= item.__doc__
if (doc): data[3]= doc
if (function_filter and data[1]!='Function'): continue
browselist.append(data)
browsing= Create('Blender')
make_browselist()
BROWSE_EVT= 1
SORT_BYNAME= 2
SORT_BYTYPE= 3
SORT_BYDATA= 4
DOC_PAGE_UP= 5
DOC_PAGE_DOWN= 6
BACK_MODULE= 7
CLOSE_VIEW= 8
FILTER_DISPLAY= 9
#SCROLLBAR= 10
VIEW_DOC= 100
BROWSE_MODULE= 10000
scr= Create(0)
browse_scrollstart= 0
winrect= [0.0, 0.0, 0.0, 0.0]
def draw():
global browsing, winrect, scr, browse_scrollstart
# Blender doesn't give us direct access to
# the window size yet, but it does set the
# GL scissor box for it, so we can get the
# size from that.
if (version<173):
size= Buffer(GL_FLOAT, None, 4)
glGetFloat(GL_SCISSOR_BOX, size)
size= BufList(size)
else:
size= Buffer(GL_FLOAT, 4)
glGetFloatv(GL_SCISSOR_BOX, size)
size= size.list
winrect= size[:]
size[0]= size[1]= 0.0
# Shrink the size to make a nice frame
# (also a good technique so you can be sure you are clipping things properly)
size[0], size[1]= int(size[0]+10), int(size[1]+10)
size[2], size[3]= int(size[2]-12), int(size[3]-10)
glClearColor(0.6, 0.5, 0.3, 0.0)
glClear(GL_COLOR_BUFFER_BIT)
# The frame
glColor3f(0.4, 0.5, 0.2)
glRectf(size[0], size[1], size[2], size[3])
# Window header
glColor3f(0.2, 0.2, 0.4)
glRectf(size[0], size[3]-25, size[2], size[3])
glColor3f(0.6, 0.6, 0.6)
glRasterPos2f(size[0]+15, size[3]-17)
Text("Zr's Help Browser")
Button("Filter", FILTER_DISPLAY, size[2]-400, size[3]-22, 45, 18)
Button("Back", BACK_MODULE, size[2]-300, size[3]-22, 45, 18)
browsing= String("Browse: ", BROWSE_EVT, size[2]-250, size[3]-22, 245, 18, browsing.val, 30)
# The real table
def row_draw(rect, data, cols, cell_colors, text_colors):
if (len(data)!=len(cols)):
print "Must have same length data and columns"
return
if (type(cell_colors)!=ListType): cell_colors= [cell_colors]
if (type(text_colors)!=ListType): text_colors= [text_colors]
sx= rect[0]
for i in range(len(data)):
d= data[i]
c= cols[i]
c, align= c[0], c[1]
if (type(c)==FloatType): c= c*(rect[2]-rect[0])
ex= sx + c
color= cell_colors[i%len(cell_colors)]
apply(glColor3f, color)
glRectf(sx, rect[1], ex, rect[3])
color= text_colors[i%len(text_colors)]
apply(glColor3f, color)
if (type(d)==StringType):
str_width= len(d)*8
if (align=='left'): glRasterPos2f(sx+3, rect[1]+5)
elif (align=='center'): glRasterPos2f((sx+ex)/2 - str_width/2 +3, rect[1]+5)
elif (align=='right'): glRasterPos2f(ex - str_width -3, rect[1]+5)
Text(d)
else:
d(map(int,[sx, rect[1], ex, rect[3]]))
sx= ex
# Some colors
black= (0.0, 0.0, 0.0)
white= (1.0, 1.0, 1.0)
red= (0.8, 0.1, 0.1)
gray0= (0.17, 0.17, 0.17)
gray1= (0.25, 0.25, 0.25)
gray2= (0.33, 0.33, 0.33)
gray3= (0.41, 0.41, 0.41)
gray4= (0.49, 0.49, 0.49)
gray5= (0.57, 0.57, 0.57)
gray6= (0.65, 0.65, 0.65)
cols= [[.3, 'left'], [.2, 'left'], [.4, 'right'], [.1, 'center']]
header= [size[0]+20, size[3]-60, size[2]-40, size[3]-40]
def sort_byname(co): Button("Name",SORT_BYNAME, co[0]+3, co[1], co[2]-co[0]-4, 19)
def sort_bytype(co): Button("Type",SORT_BYTYPE, co[0]+3, co[1], co[2]-co[0]-4, 19)
def sort_bydata(co): Button("Data",SORT_BYDATA, co[0]+3, co[1], co[2]-co[0]-4, 19)
row_draw(header, [sort_byname, sort_bytype, sort_bydata,'Link'], cols, [gray0, gray1], gray6)
if (selected!=-1):
table= [size[0]+20, size[1]+220, size[2]-40, size[3]-60]
else:
table= [size[0]+20, size[1]+20, size[2]-40, size[3]-60]
row_height= 25
items= (table[3]-table[1])/row_height
items= 10
if (items>len(browselist)): items= len(browselist)
end= len(browselist)-items
#if (end>0):
# scr= Scrollbar(SCROLLBAR, table[2]+5, table[1], 20, table[3]-table[1], scr.val, 0.0, end, 0, "Page Up/Down scrolls list.")
row= table
row[1]= row[3]-row_height
start= browse_scrollstart
if (start+items>len(browselist)): items= len(browselist)-start
for i in range(items):
i= start+i
data= browselist[i][:]
if (i%2): colors= [gray1, gray2]
else: colors= [gray2, gray3]
# Strange pythonic code
def view_doc(co,num=i):
Button("Doc",VIEW_DOC+num, co[0]+3, co[1]+2, co[2]-co[0]-4, 19)
def browse_module(co,num=i):
Button("Browse",BROWSE_MODULE+num, co[0]+3, co[1]+2, co[2]-co[0]-4, 19)
if (data[1]=='Function'):
if data[3]:
data[3]= view_doc
tcolor= black
else:
tcolor= red
data[2]= 'NO DOC STRING'
data[3]= ''
else:
if (data[1]=='Module'): data[3]= browse_module
else: data[3]= ''
tcolor= black
row_draw(row, data, cols, colors, tcolor)
row[1]= row[1]-row_height
row[3]= row[3]-row_height
if (selected!=-1):
table= [size[0]+20, size[1]+20, size[2]-40, size[1]+180]
apply(glColor3f, gray5)
glRectf(table[0], table[3], table[2], table[3]+20)
apply(glColor3f, gray2)
glRectf(table[0], table[1], table[2], table[3])
apply(glColor3f, black)
glRasterPos2f(table[0]+3, table[3]+5)
Text("Function: " + browsing.val + "." + browselist[selected][0])
Button("Close", CLOSE_VIEW, table[2]-50, table[3], 45, 18)
row_height= 20
view_lines= int((table[3]-table[1])/row_height)-1
lines= split(browselist[selected][3], "\n")
doc_lines= len(lines)
sindex= view_lines*selected_page
eindex= view_lines*(selected_page+1)
if (sindex>0):
sindex= sindex-1
eindex= eindex-1
lines= lines[sindex:eindex]
y= table[3]-20
for line in lines:
glRasterPos2f(table[0]+3, y)
Text(line)
y= y-20
if (sindex): Button("Page up", DOC_PAGE_UP, table[2]-100, table[3]-20, 90, 18)
if (eindex<doc_lines): Button("Page down", DOC_PAGE_DOWN, table[2]-100, table[1]+5, 90, 18)
lmouse= [0, 0]
def fit_scroll():
global browse_scrollstart, browselist
if (browse_scrollstart<0): browse_scrollstart= 0
elif (browse_scrollstart>=len(browselist)): browse_scrollstart= len(browselist)-1
def event(evt, val):
global browse_scrollstart
if (evt==QKEY or evt==ESCKEY): Exit()
elif val:
if (evt in [PAGEUPKEY, PAGEDOWNKEY]):
if (evt==PAGEUPKEY): browse_scrollstart= browse_scrollstart-5
else: browse_scrollstart= browse_scrollstart+5
elif (evt in [UPARROWKEY, WHEELUPMOUSE]):
browse_scrollstart -= 1
elif (evt in [DOWNARROWKEY, WHEELDOWNMOUSE]):
browse_scrollstart += 1
else: return
fit_scroll()
Redraw()
def bevent(evt):
if (evt==BROWSE_EVT): make_browselist()
elif (evt==SORT_BYNAME): sort_browselist(1)
elif (evt==SORT_BYTYPE): sort_browselist(2)
elif (evt==SORT_BYDATA): sort_browselist(3)
elif (evt==DOC_PAGE_UP): view_page(-1)
elif (evt==DOC_PAGE_DOWN): view_page(1)
elif (evt==BACK_MODULE): browse_module(-1)
elif (evt==CLOSE_VIEW): view_doc(-1)
elif (evt==FILTER_DISPLAY): toggle_function_filter()
#elif (evt==SCROLLBAR):
# global browse_scrollstart
# browse_scrollstart= int(scr.val)
elif (evt>=BROWSE_MODULE): browse_module(evt-BROWSE_MODULE)
elif (evt>=VIEW_DOC): view_doc(evt-VIEW_DOC)
Redraw()
Register(draw, event, bevent)
|