4
Name: 'ID Property Browser'
7
Tooltip: 'Browse ID properties'
10
__author__ = "Joe Eagar"
11
__version__ = "0.3.108"
12
__email__ = "joeedh@gmail.com"
15
Allows browsing, creating and editing of ID Properties
16
for various ID block types such as mesh, scene, object,
20
# --------------------------------------------------------------------------
21
# ID Property Browser.
22
# --------------------------------------------------------------------------
23
# ***** BEGIN GPL LICENSE BLOCK *****
25
# This program is free software; you can redistribute it and/or
26
# modify it under the terms of the GNU General Public License
27
# as published by the Free Software Foundation; either version 2
28
# of the License, or (at your option) any later version.
30
# This program is distributed in the hope that it will be useful,
31
# but WITHOUT ANY WARRANTY; without even the implied warranty of
32
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33
# GNU General Public License for more details.
35
# You should have received a copy of the GNU General Public License
36
# along with this program; if not, write to the Free Software Foundation,
37
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39
# ***** END GPL LICENCE BLOCK *****
40
# --------------------------------------------------------------------------
44
from Blender.BGL import *
45
from Blender.Types import IDGroupType, IDArrayType
48
def IsInRectWH(mx, my, x, y, wid, hgt):
49
if mx >= x and mx <= x + wid:
50
if my >= y and my <= y + hgt:
68
#max limit for string input button
74
#IDTypeModules entries are of form [module, active_object_index, module_name]
75
IDTypeModules = [[Scene, 0, "Scenes"], [Object, 0, "Objects"], [Mesh, 0, "Meshes"]]
76
IDTypeModules += [[Material, 0, "Materials"], [Texture, 0, "Textures"]]
77
IDTypeModules += [[Image, 0, "Images"]]
88
pb = self.parentbrowser
96
y = y + height - itemhgt - pad
98
Draw.PushButton("Back", Button_Back, x, y, 40, 20)
103
for i in xrange(len(self.array)):
105
if type(self.array[0]) == float:
106
st = "%.5f" % self.array[i]
107
else: st = str(self.array[i])
109
b = Draw.String("", ButStart+i, x, y, cellwid, itemhgt, st, 30)
112
if x + cellwid + pad > width:
116
def Button(self, bval):
117
if bval == Button_Back:
118
self.parentbrowser.state = State_Normal
119
self.parentbrowser.array = 0
123
elif bval >= ButStart:
125
st = self.buts[i].val
127
if type(self.array[0]) == float:
132
elif type(self.array[0]) == int:
141
def Evt(self, evt, val):
142
if evt == Draw.ESCKEY:
145
class IDPropertyBrowser:
156
parents = 0 #list stack of parent groups
170
type = 0 # attach buildin type() method to class
171
# since oddly it's not available to button
174
def __init__(self, idgroup, mat, x, y, wid, hgt):
181
self.mousecursor = [0, 0]
186
def DrawBox(self, glmode, x, y, width, height):
189
glVertex2f(x+width, y)
190
glVertex2f(x+width, y+height)
191
glVertex2f(x, y+height)
197
#first draw outlining box :)
199
self.DrawBox(GL_LINE_LOOP, self.x, self.y, self.width, self.height)
201
itemhgt = self.itemhgt
204
y = self.y + self.height - itemhgt - pad
206
if self.state == State_InArray:
212
for p in self.group.iteritems():
215
#-------do top buttons----------#
217
Draw.PushButton("New", Button_New, x, y, 40, 20)
219
#do the menu button for all materials
222
blocks = IDTypeModules[self.IDList][0].Get()
226
if m.name == self.idblock.name:
228
st += m.name + " %x" + str(i) + "|"
231
self.menubut = Draw.Menu(st, Button_MatMenu, x, y, 100, 20, mi)
237
for e in IDTypeModules:
238
st += e[2] + " %x" + str(i+1) + "|"
241
cur = self.IDList + 1
242
self.idmenu = Draw.Menu(st, Button_TypeMenu, x, y, 100, 20, cur)
244
y -= self.itemhgt + self.pad
248
#-----------do property items---------#
250
while y > self.y - 20 - pad and i < len(plist):
253
if i == self.active_item:
254
glColor3f(0.5, 0.4, 0.3)
255
self.DrawBox(GL_POLYGON, x+pad, y, self.width-pad*2, itemhgt)
258
self.DrawBox(GL_LINE_LOOP, x+pad, y, self.width-pad*2, itemhgt)
260
glRasterPos2f(x+pad*2, y+5)
261
Draw.Text(str(k)) #str(self.mousecursor) + " " + str(self.active_item)) #p.name)
262
tlen = Draw.GetStringWidth(str(k))
266
b = Draw.String("", ButStart+i, x+pad*5+tlen, y, 200, itemhgt, p, strmax)
268
elif type_p in [int, float]:
269
#only do precision to 5 points on floats
274
b = Draw.String("", ButStart+i, x+pad*5+tlen, y, 75, itemhgt, st, strmax)
277
glRasterPos2f(x+pad*2 +tlen+10, y+5)
278
if type_p == Types.IDArrayType:
279
Draw.Text('(array, click to edit)')
280
elif type_p == Types.IDGroupType:
281
Draw.Text('(group, click to edit)')
284
self.buts.append(None)
286
Draw.PushButton("Del", ButDelStart+i, x+self.width-35, y, 30, 20)
289
y -= self.itemhgt + self.pad
291
if len(self.parents) != 0:
292
Draw.PushButton("Back", Button_Back, x, y, 40, 20)
297
itemhgt = self.itemhgt
301
y = self.y + self.height - itemhgt - pad - itemhgt
304
for p in self.group.iteritems():
307
self.active_item = -1
309
while y > self.y and i < len(plist):
311
if IsInRectWH(m[0], m[1], x, y, self.width-pad, itemhgt):
315
y -= self.itemhgt + self.pad
317
def EventIn(self, evt, val):
318
if self.state == State_InArray:
319
self.array.Evt(evt, val)
321
if evt == Draw.ESCKEY:
323
if evt == Draw.MOUSEX or evt == Draw.MOUSEY:
324
size = Buffer(GL_FLOAT, 4)
325
glGetFloatv(GL_SCISSOR_BOX, size)
326
if evt == Draw.MOUSEX:
327
self.mousecursor[0] = val - size[0]
329
self.mousecursor[1] = val - size[1]
339
if evt == Draw.LEFTMOUSE and val == 1:
340
plist = list(self.group.iteritems())
342
if a >= 0 and a < len(plist):
345
basictypes = [IDGroupType, float, str, int]
346
if type(p[1]) == IDGroupType:
347
self.parents.append(self.group)
349
self.active_item = -1
351
elif type(p[1]) == IDArrayType:
352
self.array = IDArrayBrowser()
353
self.array.array = p[1]
354
self.array.parentbrowser = self
355
self.state = State_InArray
358
if evt == Draw.TKEY and val == 1:
360
self.prop['float'] = 0.0
362
self.prop['string'] = "hi!"
363
self.prop['float array'] = [0, 0, 1.0, 0]
364
self.prop['int array'] = [0, 0, 0, 0]
365
self.prop.data['a subgroup'] = {"int": 0, "float": 0.0, "anothergroup": {"a": 0.0, "intarr": [0, 0, 0, 0]}}
368
Draw.PupMenu("Can only do T once per block, the test names are already taken!")
371
def Button(self, bval):
373
if self.state == State_InArray:
374
self.array.Button(bval)
377
if bval == Button_MatMenu:
380
val = self.idindex = self.menubut.val - 1
382
block = IDTypeModules[i][0].Get()[val]
384
self.prop = block.properties
385
self.group = self.prop
386
self.active_item = -1
390
if bval == Button_TypeMenu:
391
i = IDTypeModules[self.idmenu.val-1]
392
if len(i[0].Get()) == 0:
393
Draw.PupMenu("Error%t|There are no " + i[2] + "!")
396
IDTypeModules[self.IDList][1] = self.idindex
397
self.IDList = self.idmenu.val-1
398
val = self.idindex = IDTypeModules[self.IDList][1]
400
block = IDTypeModules[i][0].Get()[val]
402
self.prop = block.properties
403
self.group = self.prop
404
self.active_item = -1
408
if bval >= ButDelStart:
409
plist = [p for p in self.group]
410
prop = plist[bval - ButDelStart]
414
elif bval >= ButStart:
415
plist = list(self.group.iteritems())
417
prop = plist[bval - ButStart]
420
if self.type(prop[1]) == str:
421
self.group[prop[0]] = self.buts[bval - ButStart].val
422
elif self.type(prop[1]) == int:
423
i = self.buts[bval - ButStart].val
426
self.group[prop[0]] = i
431
elif self.type(prop[1]) == float:
432
f = self.buts[bval - ButStart].val
435
self.group[prop[0]] = f
441
elif bval == Button_Back:
442
self.group = self.parents[len(self.parents)-1]
443
self.parents.pop(len(self.parents)-1)
446
elif bval == Button_New:
447
name = Draw.Create("untitled")
448
stype = Draw.Create(0)
449
gtype = Draw.Create(0)
450
ftype = Draw.Create(0)
451
itype = Draw.Create(0)
452
atype = Draw.Create(0)
455
block.append(("Name: ", name, 0, 30, "Click to type in the name of the new ID property"))
457
block.append(("String", stype))
458
block.append(("Subgroup", gtype))
459
block.append(("Float", ftype))
460
block.append(("Int", itype))
461
block.append(("Array", atype))
463
retval = Blender.Draw.PupBlock("New IDProperty", block)
464
if retval == 0: return
476
name = name + "." + str(i).zfill(3)
482
self.group[name] = ""
484
self.group[name] = {}
486
self.group[name] = 0.0
488
self.group[name] = 0 #newProperty("Int", name, 0)
490
arrfloat = Draw.Create(1)
491
arrint = Draw.Create(0)
492
arrlen = Draw.Create(3)
495
block.append(("Float", arrfloat, "Make a float array"))
496
block.append(("Int", arrint, "Make an integer array"))
497
block.append(("Len", arrlen, 2, 200))
499
if Blender.Draw.PupBlock("Array Properties", block):
507
self.group[name] = [tmpl] * arrlen.val
511
Draw.Register(self.Draw, self.EventIn, self.Button)
515
size = Window.GetAreaSize()
516
browser = IDPropertyBrowser(scenes[0].properties, scenes[0], 2, 2, size[0], size[1])
519
#a = prop.newProperty("String", "hwello!", "bleh")
520
#b = prop.newProperty("Group", "subgroup")