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 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523
|
#!BPY
"""
Name: 'ID Property Browser'
Blender: 242
Group: 'Help'
Tooltip: 'Browse ID properties'
"""
__author__ = "Joe Eagar"
__version__ = "0.3.108"
__email__ = "joeedh@gmail.com"
__bpydoc__ = """\
Allows browsing, creating and editing of ID Properties
for various ID block types such as mesh, scene, object,
etc.
"""
# --------------------------------------------------------------------------
# ID Property Browser.
# --------------------------------------------------------------------------
# ***** 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.
#
# 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 *****
# --------------------------------------------------------------------------
from Blender import *
from Blender.BGL import *
from Blender.Types import IDGroupType, IDArrayType
import Blender
def IsInRectWH(mx, my, x, y, wid, hgt):
if mx >= x and mx <= x + wid:
if my >= y and my <= y + hgt:
return 1
return 0
Button_Back = 1
Button_New = 2
Button_MatMenu = 3
Button_TypeMenu = 4
ButStart = 55
IDP_String = 0
IDP_Int = 1
IDP_Float = 2
IDP_Array = 5
IDP_Group = 6
ButDelStart = 255
#max limit for string input button
strmax = 100
State_Normal = 0
State_InArray = 1
#IDTypeModules entries are of form [module, active_object_index, module_name]
IDTypeModules = [[Scene, 0, "Scenes"], [Object, 0, "Objects"], [Mesh, 0, "Meshes"]]
IDTypeModules += [[Material, 0, "Materials"], [Texture, 0, "Textures"]]
IDTypeModules += [[Image, 0, "Images"]]
class IDArrayBrowser:
array = 0
parentbrowser = 0
buts = 0
def __init__(self):
self.buts = []
def Draw(self):
pb = self.parentbrowser
x = pb.x
y = pb.y
width = pb.width
height = pb.height
pad = pb.pad
itemhgt = pb.itemhgt
cellwid = 65
y = y + height - itemhgt - pad
Draw.PushButton("Back", Button_Back, x, y, 40, 20)
y -= itemhgt + pad
self.buts = []
Draw.BeginAlign()
for i in xrange(len(self.array)):
st = ""
if type(self.array[0]) == float:
st = "%.5f" % self.array[i]
else: st = str(self.array[i])
b = Draw.String("", ButStart+i, x, y, cellwid, itemhgt, st, 30)
self.buts.append(b)
x += cellwid + pad
if x + cellwid + pad > width:
x = 0
y -= itemhgt + pad
Draw.EndAlign()
def Button(self, bval):
if bval == Button_Back:
self.parentbrowser.state = State_Normal
self.parentbrowser.array = 0
self.buts = []
Draw.Draw()
self.array = 0
elif bval >= ButStart:
i = bval - ButStart
st = self.buts[i].val
n = 0
if type(self.array[0]) == float:
try:
n = int(st)
except:
return
elif type(self.array[0]) == int:
try:
n = float(st)
except:
return
self.array[i] = n
Draw.Draw()
def Evt(self, evt, val):
if evt == Draw.ESCKEY:
Draw.Exit()
class IDPropertyBrowser:
width = 0
height = 0
x = 0
y = 0
scrollx = 0
scrolly = 0
itemhgt = 22
pad = 2
group = 0
parents = 0 #list stack of parent groups
active_item = -1
mousecursor = 0
_i = 0
buts = []
state = 0
array = 0
prop = 0
IDList = 0
idindex = 0
idblock = 0
type = 0 # attach buildin type() method to class
# since oddly it's not available to button
# callbacks! EEK! :(
def __init__(self, idgroup, mat, x, y, wid, hgt):
self.group = idgroup
self.prop = idgroup
self.x = x
self.y = y
self.width = wid
self.height = hgt
self.mousecursor = [0, 0]
self.parents = []
self.idblock = mat
self.type = type
def DrawBox(self, glmode, x, y, width, height):
glBegin(glmode)
glVertex2f(x, y)
glVertex2f(x+width, y)
glVertex2f(x+width, y+height)
glVertex2f(x, y+height)
glEnd()
def Draw(self):
global IDTypeModules
#first draw outlining box :)
glColor3f(0, 0, 0)
self.DrawBox(GL_LINE_LOOP, self.x, self.y, self.width, self.height)
itemhgt = self.itemhgt
pad = self.pad
x = self.x
y = self.y + self.height - itemhgt - pad
if self.state == State_InArray:
self.array.Draw()
return
plist = []
self.buts = []
for p in self.group.iteritems():
plist.append(p)
#-------do top buttons----------#
Draw.BeginAlign()
Draw.PushButton("New", Button_New, x, y, 40, 20)
x += 40 + pad
#do the menu button for all materials
st = ""
blocks = IDTypeModules[self.IDList][0].Get()
i = 1
mi = 0
for m in blocks:
if m.name == self.idblock.name:
mi = i
st += m.name + " %x" + str(i) + "|"
i += 1
self.menubut = Draw.Menu(st, Button_MatMenu, x, y, 100, 20, mi)
x += 100 + pad
st = ""
i = 0
for e in IDTypeModules:
st += e[2] + " %x" + str(i+1) + "|"
i += 1
cur = self.IDList + 1
self.idmenu = Draw.Menu(st, Button_TypeMenu, x, y, 100, 20, cur)
x = self.x
y -= self.itemhgt + self.pad
Draw.EndAlign()
#-----------do property items---------#
i = 0
while y > self.y - 20 - pad and i < len(plist):
k = plist[i][0]
p = plist[i][1]
if i == self.active_item:
glColor3f(0.5, 0.4, 0.3)
self.DrawBox(GL_POLYGON, x+pad, y, self.width-pad*2, itemhgt)
glColor3f(0, 0, 0)
self.DrawBox(GL_LINE_LOOP, x+pad, y, self.width-pad*2, itemhgt)
glRasterPos2f(x+pad*2, y+5)
Draw.Text(str(k)) #str(self.mousecursor) + " " + str(self.active_item)) #p.name)
tlen = Draw.GetStringWidth(str(k))
type_p = type(p)
if type_p == str:
b = Draw.String("", ButStart+i, x+pad*5+tlen, y, 200, itemhgt, p, strmax)
self.buts.append(b)
elif type_p in [int, float]:
#only do precision to 5 points on floats
st = ""
if type_p == float:
st = "%.5f" % p
else: st = str(p)
b = Draw.String("", ButStart+i, x+pad*5+tlen, y, 75, itemhgt, st, strmax)
self.buts.append(b)
else:
glRasterPos2f(x+pad*2 +tlen+10, y+5)
if type_p == Types.IDArrayType:
Draw.Text('(array, click to edit)')
elif type_p == Types.IDGroupType:
Draw.Text('(group, click to edit)')
self.buts.append(None)
Draw.PushButton("Del", ButDelStart+i, x+self.width-35, y, 30, 20)
i += 1
y -= self.itemhgt + self.pad
if len(self.parents) != 0:
Draw.PushButton("Back", Button_Back, x, y, 40, 20)
x = x + 40 + pad
def SetActive(self):
m = self.mousecursor
itemhgt = self.itemhgt
pad = self.pad
x = self.x + pad
y = self.y + self.height - itemhgt - pad - itemhgt
plist = []
for p in self.group.iteritems():
plist.append(p)
self.active_item = -1
i = 0
while y > self.y and i < len(plist):
p = plist[i]
if IsInRectWH(m[0], m[1], x, y, self.width-pad, itemhgt):
self.active_item = i
i += 1
y -= self.itemhgt + self.pad
def EventIn(self, evt, val):
if self.state == State_InArray:
self.array.Evt(evt, val)
if evt == Draw.ESCKEY:
Draw.Exit()
if evt == Draw.MOUSEX or evt == Draw.MOUSEY:
size = Buffer(GL_FLOAT, 4)
glGetFloatv(GL_SCISSOR_BOX, size)
if evt == Draw.MOUSEX:
self.mousecursor[0] = val - size[0]
else:
self.mousecursor[1] = val - size[1]
del size
self.SetActive()
self._i += 1
if self._i == 5:
Draw.Draw()
self._i = 0
if evt == Draw.LEFTMOUSE and val == 1:
plist = list(self.group.iteritems())
a = self.active_item
if a >= 0 and a < len(plist):
p = plist[a]
basictypes = [IDGroupType, float, str, int]
if type(p[1]) == IDGroupType:
self.parents.append(self.group)
self.group = p[1]
self.active_item = -1
Draw.Draw()
elif type(p[1]) == IDArrayType:
self.array = IDArrayBrowser()
self.array.array = p[1]
self.array.parentbrowser = self
self.state = State_InArray
Draw.Draw()
if evt == Draw.TKEY and val == 1:
try:
self.prop['float'] = 0.0
self.prop['int'] = 1
self.prop['string'] = "hi!"
self.prop['float array'] = [0, 0, 1.0, 0]
self.prop['int array'] = [0, 0, 0, 0]
self.prop.data['a subgroup'] = {"int": 0, "float": 0.0, "anothergroup": {"a": 0.0, "intarr": [0, 0, 0, 0]}}
Draw.Draw()
except:
Draw.PupMenu("Can only do T once per block, the test names are already taken!")
def Button(self, bval):
global IDTypeModules
if self.state == State_InArray:
self.array.Button(bval)
return
if bval == Button_MatMenu:
global IDTypeModules
val = self.idindex = self.menubut.val - 1
i = self.IDList
block = IDTypeModules[i][0].Get()[val]
self.idblock = block
self.prop = block.properties
self.group = self.prop
self.active_item = -1
self.parents = []
Draw.Draw()
if bval == Button_TypeMenu:
i = IDTypeModules[self.idmenu.val-1]
if len(i[0].Get()) == 0:
Draw.PupMenu("Error%t|There are no " + i[2] + "!")
return
IDTypeModules[self.IDList][1] = self.idindex
self.IDList = self.idmenu.val-1
val = self.idindex = IDTypeModules[self.IDList][1]
i = self.IDList
block = IDTypeModules[i][0].Get()[val]
self.idblock = block
self.prop = block.properties
self.group = self.prop
self.active_item = -1
self.parents = []
Draw.Draw()
if bval >= ButDelStart:
plist = [p for p in self.group]
prop = plist[bval - ButDelStart]
del self.group[prop]
Draw.Draw()
elif bval >= ButStart:
plist = list(self.group.iteritems())
prop = plist[bval - ButStart]
print prop
if self.type(prop[1]) == str:
self.group[prop[0]] = self.buts[bval - ButStart].val
elif self.type(prop[1]) == int:
i = self.buts[bval - ButStart].val
try:
i = int(i)
self.group[prop[0]] = i
except:
Draw.Draw()
return
Draw.Draw()
elif self.type(prop[1]) == float:
f = self.buts[bval - ButStart].val
try:
f = float(f)
self.group[prop[0]] = f
except:
Draw.Draw()
return
Draw.Draw()
elif bval == Button_Back:
self.group = self.parents[len(self.parents)-1]
self.parents.pop(len(self.parents)-1)
Draw.Draw()
elif bval == Button_New:
name = Draw.Create("untitled")
stype = Draw.Create(0)
gtype = Draw.Create(0)
ftype = Draw.Create(0)
itype = Draw.Create(0)
atype = Draw.Create(0)
block = []
block.append(("Name: ", name, 0, 30, "Click to type in the name of the new ID property"))
block.append("Type")
block.append(("String", stype))
block.append(("Subgroup", gtype))
block.append(("Float", ftype))
block.append(("Int", itype))
block.append(("Array", atype))
retval = Blender.Draw.PupBlock("New IDProperty", block)
if retval == 0: return
name = name.val
i = 1
stop = 0
while stop == 0:
stop = 1
for p in self.group:
if p == name:
d = name.rfind(".")
if d != -1:
name = name[:d]
name = name + "." + str(i).zfill(3)
i += 1
stop = 0
type = "String"
if stype.val:
self.group[name] = ""
elif gtype.val:
self.group[name] = {}
elif ftype.val:
self.group[name] = 0.0
elif itype.val:
self.group[name] = 0 #newProperty("Int", name, 0)
elif atype.val:
arrfloat = Draw.Create(1)
arrint = Draw.Create(0)
arrlen = Draw.Create(3)
block = []
block.append("Type")
block.append(("Float", arrfloat, "Make a float array"))
block.append(("Int", arrint, "Make an integer array"))
block.append(("Len", arrlen, 2, 200))
if Blender.Draw.PupBlock("Array Properties", block):
if arrfloat.val:
tmpl = 0.0
elif arrint.val:
tmpl = 0
else:
return
self.group[name] = [tmpl] * arrlen.val
def Go(self):
Draw.Register(self.Draw, self.EventIn, self.Button)
scenes = Scene.Get()
size = Window.GetAreaSize()
browser = IDPropertyBrowser(scenes[0].properties, scenes[0], 2, 2, size[0], size[1])
browser.Go()
#a = prop.newProperty("String", "hwello!", "bleh")
#b = prop.newProperty("Group", "subgroup")
#for p in prop:
#print p.name
|