-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaddon_preferences.py
78 lines (60 loc) · 3.01 KB
/
addon_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
'''
Copyright (C) 2019 JOSECONSCO
Created by JOSECONSCO (loosely based on 'dynamic enum' blender template and Simple Asset Manager)
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 3 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, see <http://www.gnu.org/licenses/>.
'''
import bpy
import os, platform
from pathlib import Path
from .tsynth_ui import TSYNTH_PT_TextureSynthesis
from .utils import get_addon_preferences, addon_name_lowercase
def check_file_exist(filePath):
"""Retuns absolute file path, and bool - file exist?"""
abspathToFix = Path(bpy.path.abspath(filePath)) # crappy format like c:\\..\\...\\ddada.fbx
outputPathStr = str(abspathToFix.resolve())
if abspathToFix.is_dir():
outputPathStr += '\\'
return outputPathStr, os.path.isfile(outputPathStr)
panels = (
TSYNTH_PT_TextureSynthesis,
)
def update_panel(self, context):
message = "Texture Synthesis: Updating Panel locations has failed"
try:
for panel in panels:
if "bl_rna" in panel.__dict__:
bpy.utils.unregister_class(panel)
for panel in panels:
panel.bl_category = get_addon_preferences().category
bpy.utils.register_class(panel)
except Exception as e:
print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
pass
class TextureSynthPreferences(bpy.types.AddonPreferences):
bl_idname = addon_name_lowercase()
def check_ts_exist(self, context):
tx_executable = "texture-synthesis.exe" if platform.system() == "Windows" else "texture-synthesis"
absPath, ts_exists = check_file_exist(self.text_synth_path)
self['text_synth_path'] = absPath
if ts_exists and os.path.basename(absPath) == tx_executable:
self.display_info = "texture-synthesis.exe found in: " + absPath
else:
self.display_info = "texture-synthesis.exe not found in: " + absPath
text_synth_path: bpy.props.StringProperty(name="Path to texture-synthesis.exe", description="", default="", subtype='FILE_PATH', update=check_ts_exist)
category: bpy.props.StringProperty(name="Tab Category", description="Choose a name for the category of the panel", default="Texture Synthesis", update=update_panel)
display_info: bpy.props.StringProperty(name="Info", description="", default="")
def draw(self, context):
layout = self.layout
col = layout.column()
col.prop(self, "category", text="")
col.prop(self, "text_synth_path", text="")
col.label(text=self.display_info)