-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
806 lines (653 loc) · 24 KB
/
utils.py
File metadata and controls
806 lines (653 loc) · 24 KB
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
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
"""
Various shortcut/utility functions\\
Generally either does one specific thing without any context
"""
import bpy
from zpy import Get, Is
def clear_console():
import os
os.system("cls")
def line():
from inspect import currentframe
cf = currentframe()
return cf.f_back.f_lineno
def file_line(levels=0):
line = Get.line(levels)
file = Get.file(levels)
# return f"line #{line} in {file}"
function = Get.stack(levels + 2)
return f"line #{line} in {function}"
def clean_custom(src):
"""Delete empty custom prop entries"""
from idprop.types import IDPropertyArray, IDPropertyGroup
for (name, value) in src.items():
if isinstance(value, IDPropertyGroup) and not value:
del (src[name])
def copy_driver(driver, src, attr):
"""Insert a driver onto the src.attr and copy the paramaters of driver"""
new = src.driver_add(attr)
new.extrapolation = driver.extrapolation
# new.group = driver.group # Drivers don't use groups
ndriver = new.driver
odriver = driver.driver
ndriver.type = odriver.type
while new.keyframe_points:
new.keyframe_points.remove(new.keyframe_points[0], fast=True)
while new.modifiers:
new.modifiers.remove(new.modifiers[0])
while ndriver.variables:
ndriver.variables.remove(ndriver.variables[0])
for ov in odriver.variables:
nv = ndriver.variables.new()
nv.name = ov.name
nv.type = ov.type
ot = ov.targets[0]
nt = nv.targets[0]
nt.bone_target = ot.bone_target
nt.data_path = ot.data_path
if nv.type == 'SINGLE_PROP':
nt.id_type = ot.id_type
# nt.id_data = ot.id_data # Not writable
nt.id = ot.id
nt.rotation_mode = ot.rotation_mode
nt.transform_space = ot.transform_space
nt.transform_type = ot.transform_type
attribs = (
'co', 'easing', 'interpolation', 'type',
'handle_left', 'handle_left_type', 'handle_right', 'handle_right_type',
'select_control_point', 'select_left_handle', 'select_right_handle',
)
new.keyframe_points.add(len(driver.keyframe_points))
for (newk, k) in zip(new.keyframe_points, driver.keyframe_points):
# newk = new.keyframe_points.insert(k.co[0] + 1, k.co[1], keyframe_type=k.type)
# newk.co[0] = k.co[0]
# Now copy attributes from k, to newk
for var in attribs:
setattr(newk, var, getattr(k, var))
ndriver.use_self = odriver.use_self
ndriver.expression = odriver.expression
return new
def debug(*value, sep=' ', end='\n', file=None, flush=False, line=True, **args):
"""
Method to leave print functions without DEFINITELY leaving them
As in using an arg labeled "debug" will allow using
a global variable to determine whether or not to print
"""
if file is None:
from sys import stdout
file = stdout
if 'debug' in args:
skip = not args['debug']
elif 'class' in args and 'level' in args:
skip = not getattr(args['class'], args['level'], None)
else:
skip = False
if skip:
return
def pop(arg, val):
if arg in args:
return args.pop(arg)
else:
return val
try:
# if not value:
# print(f"(Line #{Get.line(1)} in {Get.stack(2)}", sep=sep, end=end, flush=flush)
# elif 'line' in args:
# print(f"({file_line(1)})\t", *value, sep=sep, end=end, flush=flush)
if not value:
value = [utils.file_line(1)]
elif line:
value = [f"({utils.file_line(1)})\t", *value]
# else:
print(*value, sep=sep, end=end, flush=flush)
except:
error("Bad properties in debugger")
class debug_timer():
"""create a callable timer, to keep track of time pasted since last call"""
def __init__(self):
from datetime import datetime
self.time = datetime.now()
def __call__(self):
from datetime import datetime
now = datetime.now()
elapsed = (now - self.time)
self.time = now
hour = minute = 0
second = elapsed.seconds
micro = elapsed.microseconds
# seconds and microseconds are the variables of datetime after math
# otherwise has day/hour/minute/second/microsecond
while 3600 <= second: # Hours
hour += 1
second -= 3600
while 60 <= second: # Minutes
minute += 1
second -= 60
log = str()
if hour:
log += f'{hour}:'
if minute:
log += f'{minute}:'
if second:
log += f"{second}."
if log:
log += f"{micro}"
elif micro:
log += f"{micro / 1000} ms" # micro to milli
else:
log = 'None'
return "Time lapsed: " + log
class draw_status():
def __init__(self, draw_function):
def draw(self, context):
draw_function(self, context)
self.draw = draw
def start(self, context, wipe_text=True):
if wipe_text:
context.window.workspace.status_text_set("")
bpy.types.STATUSBAR_HT_header.prepend(self.draw)
return self
def stop(self, context, restore_text=True):
if restore_text:
context.window.workspace.status_text_set(None)
bpy.types.STATUSBAR_HT_header.remove(self.draw)
return self
def draw_keymaps(context, layout, km_kmi: "dict / load_modules.keymaps"):
""""""
from rna_keymap_ui import draw_kmi
wm = context.window_manager
kc = wm.keyconfigs.addon
# kc = wm.keyconfigs.user
for keymap, kmis in km_kmi.items():
layout.context_pointer_set('keymap', keymap)
row = layout.row()
row.alignment = 'LEFT'
row.emboss = 'PULLDOWN_MENU'
row.prop(keymap, 'show_expanded_items', text=keymap.name)
# row.prop(keymap, "show_expanded_items", text="", emboss=False)
# row.label(text=keymap.name)
if keymap.show_expanded_items:
col = layout.column()
# for kmi in keymap.keymap_items:
# if kmi in kmis:
# draw_kmi(["ADDON", "USER", "DEFAULT"], kc, keymap, kmi, col, 0)
for kmi in kmis:
draw_kmi(['ADDON'], kc, keymap, kmi, col, 0)
def error(*logs):
from sys import stderr, exc_info, exc_info
from traceback import TracebackException
def print_exception(etype, value, tb, limit=None, file=None, chain=True):
if file is None:
file = stderr
on_line = False
for line in TracebackException(
type(value), value, tb, limit=limit).format(chain=chain):
end = ""
tb = exc_info()[2]
if line.startswith('Traceback'):
line = f"Error in "
elif line.startswith(' File "') and __package__ in line:
filename = __package__ + line.split(' File "')[1].split('"')[0].split(__package__)[1]
(line_no, function) = line.split(f' line ')[1], ''
if ', ' in line_no:
(line_no, function) = line_no.split(', ', 1)
line = f"{filename}\nline #{line_no} {function}"
print(line, file=file, end="")
print(*logs)
def print_exc(limit=None, file=None, chain=True):
print_exception(*exc_info(), limit=limit, file=file, chain=chain)
print_exc()
def find_op(idname):
"""Try to find if an operator is valid"""
import bpy
try:
op = eval(f'bpy.ops.{idname}')
if hasattr(op, 'get_rna_type'): # 2.8 and 2.7 daily
op.get_rna_type()
elif hasattr(op, 'get_rna'): # 2.7
op.get_rna()
else:
return
# debug(f"ERROR WARNING: Can't register keymap! "
# f"No valid confirmation check for operator [{idname!r}]")
return op
except:
# debug(f"ERROR: Can't register keymap, operator not found [{idname!r}]")
return
def flip_name(name, split=False, only_split=False):
if len(name) < 3:
if split:
return (name, "", "", "")
else:
return name
is_set = False
prefix = replace = previous = suffix = number = str()
# /* We first check the case with a .### extension, let's find the last period */
if (Is.digit(name[-1]) and ("." in name)):
index = name.rsplit(".", 1)
if Is.digit(index[1]):
name = index[0]
number = '.' + index[1]
del index
# /* first case; separator . - _ with extensions r R l L */
if ((len(name) > 1) and (name[-2] in (' .-_'))):
is_set = True
previous = name[-2:]
sep = name[-2]
if name[-1] == 'l':
prefix = name[:-2]
replace = sep + 'r'
elif name[-1] == 'r':
prefix = name[:-2]
replace = sep + 'l'
elif name[-1] == 'L':
prefix = name[:-2]
replace = sep + 'R'
elif name[-1] == 'R':
prefix = name[:-2]
replace = sep + 'L'
else:
is_set = False
previous = ""
# /* case; beginning with r R l L, with separator after it */
if ((not is_set) and (len(name) > 1) and (name[1] in (' .-_'))):
is_set = True
previous = name[:2]
sep = name[1]
if name[0] == 'l':
replace = 'r' + sep
suffix = name[2:]
elif name[0] == 'r':
replace = 'l' + sep
suffix = name[2:]
elif name[0] == 'L':
replace = 'R' + sep
suffix = name[2:]
elif name[0] == 'R':
replace = 'L' + sep
suffix = name[2:]
else:
is_set = False
previous = ""
if (not is_set):
prefix = name
# /* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
if name.lower().startswith("right") or name.lower().endswith("right"):
index = name.lower().index("right")
replace = name[index:index + 5]
previous = replace
(prefix, suffix) = name.split(replace, 1)
if replace[0] == "r":
replace = "left"
elif replace[1] == "I":
replace = "LEFT"
else:
replace = "Left"
elif name.lower().startswith("left") or name.lower().endswith("left"):
index = name.lower().index("left")
replace = name[index:index + 4]
previous = replace
(prefix, suffix) = name.split(replace, 1)
if replace[0] == "l":
replace = "right"
elif replace[1] == "E":
replace = "RIGHT"
else:
replace = "Right"
if only_split:
return (prefix, previous, suffix, number)
elif split:
return (prefix, replace, suffix, number)
else:
return prefix + replace + suffix + number
def layer(*ins, max=32):
"""Get a layer array with only the specified layers enabled"""
layers = [False] * max
for i in ins:
layers[i] = True
return tuple(layers)
def lerp(current, target, factor=1.0, falloff=False):
"""
Blend between two values\\
current <to> target
"""
if falloff:
factor = utils.proportional(factor, mode=falloff)
def blend(current, target):
if (Is.digit(current) and Is.digit(target)) and not \
(Is.string(current) or Is.string(target)):
return (current * (1.0 - factor) + target * factor)
elif (factor):
return target
else:
return current
if (Is.matrix(current) and Is.matrix(target)):
return current.lerp(target, factor)
elif (Is.iterable(current) and Is.iterable(target)) and not \
(Is.string(current) or Is.string(target)):
# Assume the items are tuple/list/set. Not dict (but dicts can merge)
merge = list()
for (s, o) in zip(current, target):
merge.append(blend(s, o))
return merge
else:
return blend(current, target)
def matrix_from_tuple(tuple):
from mathutils import Matrix
if len(tuple) == 16:
return Matrix((tuple[0:4], tuple[4:8], tuple[8:12], tuple[12:16]))
def matrix_to_tuple(matrix):
return tuple(y for x in matrix.col for y in x)
# return tuple(y for x in matrix for y in x)
def matrix_to_transforms(matrix, euler='XYZ'):
location = matrix.to_translation()
rotation_quaternion = matrix.to_quaternion()
axis = matrix.to_quaternion().to_axis_angle()
rotation_axis_angle = (*axis[0], axis[1])
rotation_euler = matrix.to_euler(euler)
scale = matrix.to_scale()
matrix = type('', (), dict(
location=location,
rotation_quaternion=rotation_quaternion,
rotation_axis_angle=rotation_axis_angle,
rotation_euler=rotation_euler,
scale=scale,
))
return matrix
def merge_vertex_groups(ob, vg_A_name, vg_B_name,
remove: 'keep or remove (vg B)' = False):
"""Get both groups and add them into third"""
vgroup_A = ob.vertex_groups.get(vg_A_name)
vgroup_B = ob.vertex_groups.get(vg_B_name)
if not vgroup_B:
return
elif not vgroup_A:
if remove:
# The goal group doesn't exist, so just rename the other group
vgroup_B.name = vg_A_name
return
else:
ob.vertex_groups.new(name=vg_A_name)
vgroup_A = ob.vertex_groups[vg_A_name]
# The new tmp group to start layering the old weights
vgroup = ob.vertex_groups.new(name="TMP" + vg_A_name + "+" + vg_B_name)
for (id, vert) in enumerate(ob.data.vertices):
available_groups = [vg_elem.group for vg_elem in vert.groups]
A = B = 0
if vgroup_A.index in available_groups:
A = vgroup_A.weight(id)
if vgroup_B.index in available_groups:
B = vgroup_B.weight(id)
# only add to vertex group is weight is > 0
sum = A + B
if sum > 0:
vgroup.add([id], sum, 'REPLACE')
if remove:
ob.vertex_groups.remove(vgroup_B)
# Now that its weights were transferred, replace the target group
ob.vertex_groups.remove(vgroup_A)
vgroup.name = vg_A_name
def multiply_matrix(*matrices):
from mathutils import Matrix, Vector
merge = Matrix()
for mat in matrices:
sym = '*' if Is.digit(mat) else '@'
merge = eval(f'{merge!r} {sym} {mat!r}')
return merge
def multiply_list(*vectors):
"""multiply a list of numbers together (such as Vectors)"""
sets = dict()
for tup in vectors:
for (index, val) in enumerate(tup):
if index not in sets:
sets[index] = list()
sets[index].append(val)
merge = list()
for (index, items) in sets.items():
value = items.pop(0)
while items:
value *= items.pop(0)
merge.append(value)
return merge
def name_split_hash(name):
"""Get the original name without the added hash"""
split = name.rsplit('-')
if Is.digit(split[-1]):
name = split[0]
return name
# @classmethod
def poll_workspace(self, context):
# bl_space_type = 'PROPERTIES'
# bl_region_type = 'WINDOW'
# bl_context = ".workspace"
"""Only display a panel if it's in the workspace"""
# return context.area.type != 'VIEW_3D'
return context.area.type == 'PROPERTIES'
def prefs(name: "__package__" = None) ->\
"return prefs or prefs.addons[name].preferences":
"""
return the current addon's preferences property
"""
if hasattr(bpy.utils, '_preferences'): # 2.8
prefs = bpy.utils._preferences
# context.user_preferences
elif hasattr(bpy.utils, '_user_preferences'): # 2.7
prefs = bpy.utils._user_preferences
# context.preferences
else:
prefs = None
if name is None:
return prefs
else:
if name in prefs.addons:
return prefs.addons[name].preferences
else:
return prefs.addons[name.split('.')[0]].preferences
def proportional(dist, mode: "string or context" = None, rng: "Random Seed" = None):
"""Convert a number (from 0-1) to its proportional equivalent"""
from math import sqrt
from random import random
if not (0 <= dist <= 1):
return dist
if not Is.string(mode) and mode is not None:
mode = mode.scene.tool_settings.proportional_edit_falloff
if mode == 'SHARP':
return dist * dist
elif mode == 'SMOOTH':
return 3.0 * dist * dist - 2.0 * dist * dist * dist
elif mode == 'ROOT':
return sqrt(dist)
elif mode == 'LINEAR':
return dist
elif mode == 'CONSTANT':
return 1.0
elif mode == 'SPHERE':
return sqrt(2 * dist - dist * dist)
elif mode == 'RANDOM':
if (rng is None):
rng = random()
return rng * dist
elif mode == 'INVERSE_SQUARE':
return dist * (2.0 - dist)
else:
# default equivalent to constant
return 1
def register_collection(cls, **kwargs):
"""
register a class, then return a pointer of a Pointer property\\
kwargs are optional additional paramenter to insert in the type\\
"""
kwargs.setdefault('options', {'LIBRARY_EDITABLE'})
kwargs.setdefault('override', {'LIBRARY_OVERRIDABLE', 'USE_INSERTION'})
# 'NO_PROPERTY_NAME', # Do not use the names of the items, only their indices in the collection
if hasattr(cls, 'is_registered') and (not cls.is_registered):
bpy.utils.register_class(cls)
cls_registered = bpy.props.CollectionProperty(type=cls, **kwargs)
return cls_registered
def register_pointer(cls, **kwargs):
"""
register a class, then return a pointer of a Pointer property\\
kwargs are optional additional paramenter to insert in the type\\
"""
kwargs.setdefault('options', {'LIBRARY_EDITABLE'})
kwargs.setdefault('override', {'LIBRARY_OVERRIDABLE'})
if hasattr(cls, 'is_registered') and (not cls.is_registered):
bpy.utils.register_class(cls)
cls_registered = bpy.props.PointerProperty(type=cls, **kwargs)
return cls_registered
# https://docs.blender.org/api/blender2.8/bpy.app.timers.html
def register_timer(wait, function, *args, use_threading=False, **keywords):
"""
Start a function on a looped timer\\
(or run it outside the function it was called in)\\
Default wait for 2.8 is 0.0\\
Default in 2.7 = 0.01
"""
import bpy
import threading
import time
import functools
def looper(*args, **keywords):
try:
exit = function(*args, **keywords) # Digit for new wait
if use_threading:
while exit is not None:
if exit is not None:
time.sleep(exit)
exit = function(*args, **keywords) # Digit for new wait
else:
return (exit, None)[exit is None]
except:
utils.error(
f"\n\tError with register_timer({function}) @ line#" +
utils.line(),
)
return
if use_threading:
timer = threading.Timer(
wait, looper, args=args, kwargs=keywords)
timer.start()
else:
bpy.app.timers.register(
functools.partial(looper, *args, **keywords),
first_interval=wait)
def rotate_matrix(matrix, angles_in_degrees: "float or tuple (x, y, z)"):
from math import radians
from mathutils import Matrix
for (angle, axis) in zip(angles_in_degrees, ('X', 'Y', 'Z')):
# define the rotation
rot_mat = Matrix.Rotation(radians(angle), 4, axis)
# decompose world_matrix's components, and from them assemble 4x4 matrices
orig_loc, orig_rot, orig_scale = matrix.decompose()
orig_loc_mat = Matrix.Translation(orig_loc)
orig_rot_mat = orig_rot.to_matrix().to_4x4()
orig_scale_mat = utils.multiply_matrix(
Matrix.Scale(orig_scale[0], 4, (1, 0, 0)),
Matrix.Scale(orig_scale[1], 4, (0, 1, 0)),
Matrix.Scale(orig_scale[2], 4, (0, 0, 1)),
)
# assemble the new matrix
matrix = utils.multiply_matrix(orig_loc_mat, rot_mat, orig_rot_mat, orig_scale_mat)
return matrix
def scale_range(OldValue, OldMin, OldMax, NewMin, NewMax):
"""Convert a number in a range, relatively to a different range"""
if Is.iterable(OldValue):
NewValues = list()
for (index, OldValue) in enumerate(OldValue):
OldRange = (OldMax[index] - OldMin[index])
NewRange = (NewMax[index] - NewMin[index])
if (OldRange == 0):
NewValue = NewMin[index]
else:
NewValue = (((OldValue - OldMin[index]) * NewRange) / OldRange) + NewMin[index]
NewValues.append(NewValue)
return NewValues
OldRange = (OldMax - OldMin)
NewRange = (NewMax - NewMin)
if (OldRange == 0):
NewValue = NewMin
else:
NewValue = (((OldValue - OldMin) * NewRange) / OldRange) + NewMin
return NewValue
def string(*args):
"""return a list of items as a merged string"""
string = str()
for i in args:
string += str(i)
return string
def subtract_vertex_groups(ob, vg_A_name, vg_B_name):
"""Remove vertex influence of group A from group B"""
vgroup_A = ob.vertex_groups.get(vg_A_name)
vgroup_B = ob.vertex_groups.get(vg_B_name)
if None in (vgroup_A, vgroup_B):
return
for (id, vert) in enumerate(ob.data.vertices):
available_groups = [vg.group for vg in vert.groups]
if not (vgroup_A.index in available_groups and
vgroup_B.index in available_groups):
continue
A = vgroup_A.weight(id)
B = vgroup_B.weight(id)
sum = B - A
if sum <= 0: # Remove vertex from group
vgroup_B.remove([id])
else: # lower the weight of influence of group on vertex
vgroup_B.add([id], sum, 'REPLACE')
def update(context):
"""Try to update the context"""
scn = getattr(context, 'scene', None)
view = getattr(context, 'view_layer', None)
dps = getattr(context, 'evaluated_depsgraph_get', print)()
if dps is None:
dps = getattr(context, 'depsgraph', None)
if hasattr(view, 'update'):
view.update()
elif hasattr(scn, 'update'):
scn.update()
elif hasattr(dps, 'update'):
dps.update()
else:
# Display error window
assert None, (
"utils.update()!"
"\ncontext can't find an updater for the scene!"
)
def update_keyframe_points(context):
"""# The select operator(s) are bugged, and can fail to update selected keys, so"""
# if (context.area.type == 'DOPESHEET_EDITOR'):
# bpy.ops.transform.transform(mode='TIME_TRANSLATE')
# else:
# bpy.ops.transform.transform()
# Dopesheet's operator doesn't work, so always use graph's
area = context.area.type
if area != 'GRAPH_EDITOR':
context.area.type = 'GRAPH_EDITOR'
snap = context.space_data.auto_snap
context.space_data.auto_snap = 'NONE'
bpy.ops.transform.transform()
context.space_data.auto_snap = snap
if area != 'GRAPH_EDITOR':
context.area.type = area
class progress:
"""Displays the little black box with 4 numbers as counter"""
def start(context, min=0, max=9999):
context.window_manager.progress_begin(min, max)
def update(context, value=1):
context.window_manager.progress_update(value)
def end(context):
context.window_manager.progress_end()
class Preferences:
def draw(self, context):
layout = self.layout
self.draw_keymaps(context)
def draw_keymaps(self, context):
layout = self.layout
# cls = self.__class__
if self.keymaps:
# layout.label(text="Keymaps:")
layout.prop(self, 'show_keymaps', text="Keymaps:")
if self.show_keymaps:
utils.draw_keymaps(context, layout, self.keymaps)
keymaps = None
show_keymaps: bpy.props.BoolProperty()
utils = type('', (), globals())