-
Notifications
You must be signed in to change notification settings - Fork 2
/
preferences.py
531 lines (499 loc) · 16.9 KB
/
preferences.py
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
# SPDX-License-Identifier: GPL-2.0-or-later
import bpy
import os
from bpy.types import AddonPreferences
from bpy.props import (
StringProperty,
BoolProperty,
IntProperty,
EnumProperty,
)
from . icons import load_icons
from . import global_variables as gv
from . operators.ui_ops import add_hotkey, remove_hotkey
def _update_icons(self, context):
load_icons()
def _lib_item_per_page_update(self, context):
wm = context.window_manager
gbh_lib = wm.gbh_lib
gbh_lib.lib_page_index = 0
def update_shortcut(self, context):
remove_hotkey()
add_hotkey()
class GBHPreferences(AddonPreferences):
bl_idname = __package__
scriptdir = bpy.path.abspath(os.path.dirname(__file__))
automatic_update_check: BoolProperty(
name="Automatic Update Check",
default=True,
)
presets_place_at_cursor_location: BoolProperty(
name="Place at Cursor Location",
default=False,
)
update_latest_version: StringProperty()
last_update_check: StringProperty(default="Never")
update_available: BoolProperty(
default=False,
)
update_check_interval: EnumProperty(
name="Update Check Interval",
items=[
("24", "Daily", ""),
("168", "Weekly", ""),
("336", "Biweekly", ""),
("720", "Monthly", ""),
],
default="168"
)
panel_update_switch: BoolProperty(
name="Update Panel Toggle",
default=True,
)
panel_rig_switch: BoolProperty(
name="Rigging Panel Toggle",
default=True,
)
panel_convert_switch: BoolProperty(
name="Convert Panel Toggle",
default=True,
)
panel_lib_switch: BoolProperty(
name="Library Panel Toggle",
default=True,
)
panel_hair_cards_switch: BoolProperty(
name="Hair Cards Panel Toggle",
default=True,
)
panel_info_switch: BoolProperty(
name="Info Panel Toggle",
default=True,
)
lib_user_folder: StringProperty(
name="User's Assets Folder",
subtype="DIR_PATH",
description="Select personal files directory",
)
lib_item_per_page: IntProperty(
name="Library Items Per Page",
default=4,
min=3,
max=20,
update=_lib_item_per_page_update,
)
lib_scale: EnumProperty(
name="Library Icons Scale",
items=[
("3", "Small", ""),
("5", "Medium", ""),
("8", "Large", ""),
],
default="3"
)
lib_list_view: BoolProperty(
name="Library View Mode",
default=True,
)
lib_add_to_active_object: BoolProperty(
name="Add Node Groups to Active Object",
description="Add node groups to active objects in viewport instead of adding them only to hair object",
default=False,
)
icon_color: EnumProperty(
items=[
("white", "White", "", 2),
("black", "Black", "", 1),
],
name="Icons Color",
default="white",
update=_update_icons,
)
hc_auto_add_pass: BoolProperty(
name="Add and Rename Render Passes on Render",
default=True,
)
hc_frame_digits: IntProperty(
name="Number of Frame Digits in Suffix",
description="Number of frame digits added to rendered file name",
default=2,
min=1,
max=10,
)
keys = (
("NONE", "Select key", ""),
("LEFTMOUSE", "LEFTMOUSE", ""),
("MIDDLEMOUSE", "MIDDLEMOUSE", ""),
("RIGHTMOUSE", "RIGHTMOUSE", ""),
("BUTTON4MOUSE", "BUTTON4MOUSE", ""),
("BUTTON5MOUSE", "BUTTON5MOUSE", ""),
("BUTTON6MOUSE", "BUTTON6MOUSE", ""),
("BUTTON7MOUSE", "BUTTON7MOUSE", ""),
("MOUSEMOVE", "MOUSEMOVE", ""),
("INBETWEEN_MOUSEMOVE", "INBETWEEN_MOUSEMOVE", ""),
("TRACKPADPAN", "TRACKPADPAN", ""),
("TRACKPADZOOM", "TRACKPADZOOM", ""),
("MOUSEROTATE", "MOUSEROTATE", ""),
("WHEELUPMOUSE", "WHEELUPMOUSE", ""),
("WHEELDOWNMOUSE", "WHEELDOWNMOUSE", ""),
("WHEELINMOUSE", "WHEELINMOUSE", ""),
("WHEELOUTMOUSE", "WHEELOUTMOUSE", ""),
("A", "A", ""),
("B", "B", ""),
("C", "C", ""),
("D", "D", ""),
("E", "E", ""),
("F", "F", ""),
("G", "G", ""),
("H", "H", ""),
("I", "I", ""),
("J", "J", ""),
("K", "K", ""),
("L", "L", ""),
("M", "M", ""),
("N", "N", ""),
("O", "O", ""),
("P", "P", ""),
("Q", "Q", ""),
("R", "R", ""),
("S", "S", ""),
("T", "T", ""),
("U", "U", ""),
("V", "V", ""),
("W", "W", ""),
("X", "X", ""),
("Y", "Y", ""),
("Z", "Z", ""),
("ZERO", "ZERO", ""),
("ONE", "ONE", ""),
("TWO", "TWO", ""),
("THREE", "THREE", ""),
("FOUR", "FOUR", ""),
("FIVE", "FIVE", ""),
("SIX", "SIX", ""),
("SEVEN", "SEVEN", ""),
("EIGHT", "EIGHT", ""),
("NINE", "NINE", ""),
("LEFT_CTRL", "LEFT_CTRL", ""),
("LEFT_ALT", "LEFT_ALT", ""),
("LEFT_SHIFT", "LEFT_SHIFT", ""),
("RIGHT_ALT", "RIGHT_ALT", ""),
("RIGHT_CTRL", "RIGHT_CTRL", ""),
("RIGHT_SHIFT", "RIGHT_SHIFT", ""),
("OSKEY", "OSKEY", ""),
("GRLESS", "GRLESS", ""),
("ESC", "ESC", ""),
("TAB", "TAB", ""),
("RET", "RET", ""),
("SPACE", "SPACE", ""),
("LINE_FEED", "LINE_FEED", ""),
("BACK_SPACE", "BACK_SPACE", ""),
("DEL", "DEL", ""),
("SEMI_COLON", "SEMI_COLON", ""),
("PERIOD", "PERIOD", ""),
("COMMA", "COMMA", ""),
("QUOTE", "QUOTE", ""),
("ACCENT_GRAVE", "ACCENT_GRAVE", ""),
("MINUS", "MINUS", ""),
("SLASH", "SLASH", ""),
("BACK_SLASH", "BACK_SLASH", ""),
("EQUAL", "EQUAL", ""),
("LEFT_BRACKET", "LEFT_BRACKET", ""),
("RIGHT_BRACKET", "RIGHT_BRACKET", ""),
("LEFT_ARROW", "LEFT_ARROW", ""),
("DOWN_ARROW", "DOWN_ARROW", ""),
("RIGHT_ARROW", "RIGHT_ARROW", ""),
("UP_ARROW", "UP_ARROW", ""),
("NUMPAD_1", "NUMPAD_1", ""),
("NUMPAD_2", "NUMPAD_2", ""),
("NUMPAD_3", "NUMPAD_3", ""),
("NUMPAD_4", "NUMPAD_4", ""),
("NUMPAD_5", "NUMPAD_5", ""),
("NUMPAD_6", "NUMPAD_6", ""),
("NUMPAD_7", "NUMPAD_7", ""),
("NUMPAD_8", "NUMPAD_8", ""),
("NUMPAD_9", "NUMPAD_9", ""),
("NUMPAD_0", "NUMPAD_0", ""),
("NUMPAD_PERIOD", "NUMPAD_PERIOD", ""),
("NUMPAD_SLASH", "NUMPAD_SLASH", ""),
("NUMPAD_ASTERIX", "NUMPAD_ASTERIX", ""),
("NUMPAD_MINUS", "NUMPAD_MINUS", ""),
("NUMPAD_ENTER", "NUMPAD_ENTER", ""),
("NUMPAD_PLUS", "NUMPAD_PLUS", ""),
("F1", "F1", ""),
("F2", "F2", ""),
("F3", "F3", ""),
("F4", "F4", ""),
("F5", "F5", ""),
("F6", "F6", ""),
("F7", "F7", ""),
("F8", "F8", ""),
("F9", "F9", ""),
("F10", "F10", ""),
("F11", "F11", ""),
("F12", "F12", ""),
("F13", "F13", ""),
("F14", "F14", ""),
("F15", "F15", ""),
("F16", "F16", ""),
("F17", "F17", ""),
("F18", "F18", ""),
("F19", "F19", ""),
("PAUSE", "PAUSE", ""),
("INSERT", "INSERT", ""),
("HOME", "HOME", ""),
("PAGE_UP", "PAGE_UP", ""),
("PAGE_DOWN", "PAGE_DOWN", ""),
("END", "END", ""),
("MEDIA_PLAY", "MEDIA_PLAY", ""),
("MEDIA_STOP", "MEDIA_STOP", ""),
("MEDIA_FIRST", "MEDIA_FIRST", ""),
("MEDIA_LAST", "MEDIA_LAST", ""),
("TEXTINPUT", "TEXTINPUT", ""),
("WINDOW_DEACTIVATE", "WINDOW_DEACTIVATE", ""),
("TIMER", "TIMER", ""),
("TIMER0", "TIMER0", ""),
("TIMER1", "TIMER1", ""),
("TIMER2", "TIMER2", ""),
("TIMER_JOBS", "TIMER_JOBS", ""),
("TIMER_AUTOSAVE", "TIMER_AUTOSAVE", ""),
("TIMER_REPORT", "TIMER_REPORT", ""),
("TIMERREGION", "TIMERREGION", ""),
("NDOF_MOTION", "NDOF_MOTION", ""),
("NDOF_BUTTON_MENU", "NDOF_BUTTON_MENU", ""),
("NDOF_BUTTON_FIT", "NDOF_BUTTON_FIT", ""),
("NDOF_BUTTON_TOP", "NDOF_BUTTON_TOP", ""),
("NDOF_BUTTON_BOTTOM", "NDOF_BUTTON_BOTTOM", ""),
("NDOF_BUTTON_LEFT", "NDOF_BUTTON_LEFT", ""),
("NDOF_BUTTON_RIGHT", "NDOF_BUTTON_RIGHT", ""),
("NDOF_BUTTON_FRONT", "NDOF_BUTTON_FRONT", ""),
("NDOF_BUTTON_BACK", "NDOF_BUTTON_BACK", ""),
("NDOF_BUTTON_ISO1", "NDOF_BUTTON_ISO1", ""),
("NDOF_BUTTON_ISO2", "NDOF_BUTTON_ISO2", ""),
("NDOF_BUTTON_ROLL_CW", "NDOF_BUTTON_ROLL_CW", ""),
("NDOF_BUTTON_ROLL_CCW", "NDOF_BUTTON_ROLL_CCW", ""),
("NDOF_BUTTON_SPIN_CW", "NDOF_BUTTON_SPIN_CW", ""),
("NDOF_BUTTON_SPIN_CCW", "NDOF_BUTTON_SPIN_CCW", ""),
("NDOF_BUTTON_TILT_CW", "NDOF_BUTTON_TILT_CW", ""),
("NDOF_BUTTON_TILT_CCW", "NDOF_BUTTON_TILT_CCW", ""),
("NDOF_BUTTON_ROTATE", "NDOF_BUTTON_ROTATE", ""),
("NDOF_BUTTON_PANZOOM", "NDOF_BUTTON_PANZOOM", ""),
("NDOF_BUTTON_DOMINANT", "NDOF_BUTTON_DOMINANT", ""),
("NDOF_BUTTON_PLUS", "NDOF_BUTTON_PLUS", ""),
("NDOF_BUTTON_MINUS", "NDOF_BUTTON_MINUS", ""),
("NDOF_BUTTON_ESC", "NDOF_BUTTON_ESC", ""),
("NDOF_BUTTON_ALT", "NDOF_BUTTON_ALT", ""),
("NDOF_BUTTON_SHIFT", "NDOF_BUTTON_SHIFT", ""),
("NDOF_BUTTON_CTRL", "NDOF_BUTTON_CTRL", ""),
("NDOF_BUTTON_1", "NDOF_BUTTON_1", ""),
("NDOF_BUTTON_2", "NDOF_BUTTON_2", ""),
("NDOF_BUTTON_3", "NDOF_BUTTON_3", ""),
("NDOF_BUTTON_4", "NDOF_BUTTON_4", ""),
("NDOF_BUTTON_5", "NDOF_BUTTON_5", ""),
("NDOF_BUTTON_6", "NDOF_BUTTON_6", ""),
("NDOF_BUTTON_7", "NDOF_BUTTON_7", ""),
("NDOF_BUTTON_8", "NDOF_BUTTON_8", ""),
("NDOF_BUTTON_9", "NDOF_BUTTON_9", ""),
("NDOF_BUTTON_10", "NDOF_BUTTON_10", ""),
("NDOF_BUTTON_A", "NDOF_BUTTON_A", ""),
("NDOF_BUTTON_B", "NDOF_BUTTON_B", ""),
("NDOF_BUTTON_C", "NDOF_BUTTON_C", "")
)
shortcut_panel_key: EnumProperty(
items=keys,
name="Key",
description="Key",
default="H",
update=update_shortcut,
)
shortcut_panel_alt: BoolProperty(
name="Alt",
default=False,
update=update_shortcut,
)
shortcut_panel_shift: BoolProperty(
name="Shift",
default=True,
update=update_shortcut,
)
shortcut_panel_ctrl: BoolProperty(
name="Ctrl",
default=True,
update=update_shortcut,
)
shortcut_rig_key: EnumProperty(
items=keys,
name="Key",
description="Key",
default="A",
update=update_shortcut,
)
shortcut_rig_alt: BoolProperty(
name="Alt",
default=False,
update=update_shortcut,
)
shortcut_rig_shift: BoolProperty(
name="Shift",
default=True,
update=update_shortcut,
)
shortcut_rig_ctrl: BoolProperty(
name="Ctrl",
default=True,
update=update_shortcut,
)
def draw(self, context):
layout = self.layout
wm = bpy.context.window_manager
gbh_update = wm.gbh_update
update_section = layout.column(align=True)
box = update_section.box()
col = box.column()
col.label(text="Add-on Updates:")
row = col.row()
update_button = row.row()
update_button.scale_y = 1.3
if gv.update_checking:
update_button.enabled = False
update_button.operator("gbh.update_check", icon="FILE_REFRESH", text="Checking for Updates...")
elif self.update_available:
update_button.operator(
"gbh.update_check",
text="",
icon="FILE_REFRESH"
)
update_button.operator(
"wm.url_open",
icon="IMPORT",
text=f"Download GBH Tool {self.update_latest_version}"
).url = gv.ULR_UPDATE
sub_row = update_button.row()
sub_row.scale_x = 0.6
sub_row.operator(
"wm.url_open",
icon="INFO",
text="Changelog"
).url = gv.ULR_UPDATE_INFO
else:
update_button.operator("gbh.update_check", icon="FILE_REFRESH")
row = col.row()
row.prop(self, "automatic_update_check")
row = row.row()
row.enabled = self.automatic_update_check
row.prop(self, "update_check_interval", text="")
row = col.row()
row.label(text=f"Last Update Check: {self.last_update_check}")
col = col.column()
col.label(text=f"Last Update Check Report: {gbh_update.update_report}")
box = update_section.box()
col = box.column()
col.label(text="Get Preview Builds:")
col = box.column()
row = col.row()
row.label(text="GBH Tool Update Branches")
row.prop(gbh_update, "update_branches", text="")
col.label(text=f"Latest Commit: {gbh_update.update_latest_commit}")
if gbh_update.update_branches != "NA":
update_url = f"{gv.URL_GITHUB}/archive/refs/heads/{gbh_update.update_branches}.zip"
col.operator(
"wm.url_open",
icon="IMPORT",
text=f'Download Latest Build from "{gbh_update.update_branches}" Branch'
).url = update_url
col.label(
text="Installing preview builds will most likely break your Blender installation, so please use them with caution!",
icon="ERROR")
col.label(text="Remove the current GBH Tool installation before proceeding.", icon="ERROR")
col.label(text="Make a backup of Blender's data folder before proceeding!", icon="ERROR")
col.operator(
"gbh.open_folder",
text="Open Blender's Data Folder",
icon="TOOL_SETTINGS"
).path = gv.DIR_BLENDER_DATA_FOLDER
box = layout.box()
col = box.column()
col.label(text="Toggle Panels:")
panels = [
"panel_update_switch",
"panel_rig_switch",
"panel_convert_switch",
"panel_lib_switch",
"panel_hair_cards_switch",
"panel_info_switch"
]
for panel in panels:
col.prop(self, panel)
box = layout.box()
col = box.column()
col.label(text="Shortcuts:")
col.label(text="Panel Toggle Pie Menu Shortcut:")
row = col.row()
row.prop(self, "shortcut_panel_key")
row = row.row()
row.scale_x = 0.6
row.prop(self, "shortcut_panel_ctrl", toggle=True)
row.prop(self, "shortcut_panel_shift", toggle=True)
row.prop(self, "shortcut_panel_alt", toggle=True)
col = box.column()
col.label(text="Rig Pie Menu Shortcut:")
row = col.row()
row.prop(self, "shortcut_rig_key")
row = row.row()
row.scale_x = 0.6
row.prop(self, "shortcut_rig_ctrl", toggle=True)
row.prop(self, "shortcut_rig_shift", toggle=True)
row.prop(self, "shortcut_rig_alt", toggle=True)
box = layout.box()
row = box.row()
row.label(text="Library Settings:")
row = box.row()
row.label(text="Icons Color:")
row.prop(self, "icon_color", text="")
row = box.row()
row.label(text="Library Items Per Page:")
row.prop(self, "lib_item_per_page", text="")
gbh_library = bpy.context.preferences.filepaths.asset_libraries.get("GBH Library")
if not gbh_library:
row = box.row()
row.operator(
"gbh.gbh_to_asset_browser",
icon="ADD"
).add = True
if gbh_library:
row = box.row()
row.operator(
"gbh.gbh_to_asset_browser",
text="Remove GBH Assets from Blender's Asset Browser",
icon="REMOVE"
).add = False
box = layout.box()
split = box.split()
split.label(text="Add-on's Installation Folder:")
col = split.column()
col.operator(
"gbh.open_folder",
text="Open Presets Folder",
icon="PRESET"
).path = gv.DIR_PRESETS
col.operator(
"gbh.open_folder",
text="Open Library Folder",
icon="ASSET_MANAGER"
).path = gv.DIR_LIBRARY
col.operator(
"gbh.open_folder",
text="Open Textures Folder",
icon="TEXTURE"
).path = gv.DIR_TEXTURES
classes = (
GBHPreferences,
)
def register():
from bpy.utils import register_class
for cls in classes:
register_class(cls)
def unregister():
from bpy.utils import unregister_class
for cls in reversed(classes):
unregister_class(cls)