-
-
Notifications
You must be signed in to change notification settings - Fork 202
Expand file tree
/
Copy path__init__.py
More file actions
144 lines (105 loc) · 4.84 KB
/
Copy path__init__.py
File metadata and controls
144 lines (105 loc) · 4.84 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
# 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
# MERCHANTIBILITY 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/>.
bl_info = {
"name": "Sollumz",
"author": "Skylumz, Colton and alexguirre",
"description": "Grand Theft Auto V modding suite for Blender",
"blender": (4, 0, 0),
"version": (2, 8, 3),
"category": "Import-Export",
"doc_url": "https://docs.sollumz.org/",
"tracker_url": "https://github.com/Sollumz/Sollumz/issues",
}
def reload_sollumz_modules():
import sys
print("Reloading Sollumz modules")
global sollumz_debug, auto_load, dependencies, bpy
dependencies.reload_dependencies()
# Remove the packages imported in this module from the scope, so they are loaded again when imported below
del sollumz_debug
del auto_load
del dependencies
del bpy
# Remove from `sys.modules` all Sollumz modules, so they are loaded again by auto_load
sz_module_prefix = f"{__package__}."
module_names = list(sys.modules.keys())
for name in module_names:
if name.startswith(sz_module_prefix):
del sys.modules[name]
if "bpy" in locals():
# If an imported name already exists before imports, it means that the addon has been reloaded by Blender.
# Blender only reloads the main __init__.py file, so we reload all our modules now.
reload_sollumz_modules()
# Imports need to be here, not at the top of the file, to handle reload
import bpy # noqa: E402, F811
from . import sollumz_debug # noqa: E402, F811
from . import auto_load # noqa: E402, F811
from . import dependencies # noqa: E402, F811
sollumz_debug.init_debug() # first in case we need to debug initialization code
def register():
check_blender_version()
check_single_sollumz_instance()
dependencies.mount_dependencies()
dependencies.register_minimal()
if dependencies.has_required_dependencies():
# Setup szio library
import mathutils
import szio.types
szio.types.use_math_types(mathutils.Vector, mathutils.Quaternion, mathutils.Matrix)
import logging
from . import logger
szio_logger = logging.getLogger("szio")
while szio_logger.handlers:
szio_logger.removeHandler(szio_logger.handlers[0])
szio_logger.addHandler(logger.LoggingHandlerRedirectToSollumzLogger())
szio_logger.setLevel(logging.INFO)
# Initialize all sollumz modules
auto_load.register()
# WorkSpaceTools need to be registered after normal modules so the keymaps
# detect the registered operators
from . import sollumz_tool
sollumz_tool.register_tools()
def unregister():
if dependencies.has_required_dependencies():
from . import sollumz_tool
sollumz_tool.unregister_tools()
auto_load.unregister()
dependencies.unregister_minimal()
def check_blender_version():
if "bl_info" not in globals():
# When installed as extension Blender deletes the `bl_info` variable.
# For extensions, Blender already checks the required minimum version specified in the manifest and doesn't
# allow enabling the extension if it isn't compatible. Don't need to check again.
return
required_version = bl_info["blender"]
if bpy.app.version < required_version:
required_version_str = ".".join(map(str, required_version))
raise_fatal_error(
title="Incompatible Blender Version",
message=f"Sollumz requires Blender {required_version_str} or newer. Please update your Blender version.",
)
def check_single_sollumz_instance():
if hasattr(bpy.types.Object, "sollum_type"):
raise_fatal_error(
title="Conflicting Sollumz Versions",
message="Only one version of Sollumz can be active at a time. Please disable any other installed versions in 'Preferences > Add-ons'.",
)
def raise_fatal_error(title: str, message: str):
"""Fatal error that doesn't allow the add-on to be initialized."""
def _draw_error_popup(self, context):
self.layout.label(text=message)
def _show_error_popup():
bpy.context.window_manager.popup_menu(_draw_error_popup, title=title, icon="ERROR")
bpy.app.timers.register(_show_error_popup, first_interval=0.0)
# Raise an error so Blender doesn't actually enable the add-on
raise ImportError(f"{title}. \n{message}")