-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinit_validation.py
More file actions
79 lines (62 loc) · 2.98 KB
/
Copy pathinit_validation.py
File metadata and controls
79 lines (62 loc) · 2.98 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
import bpy
from bpy.props import StringProperty
import blend4avango
from .b4a_bin_suffix import get_platform_data
class B4AInitErrorMessage(bpy.types.Operator):
bl_idname = "B4A.init_error_message"
bl_label = "Blend4Avango initialization error!"
bl_options = {"INTERNAL"}
message = StringProperty(name="Message string")
def execute(self, context):
# NOTE: disable addon if binaries are incompatible
if __package__ in bpy.context.user_preferences.addons:
bpy.ops.wm.addon_disable(module=__package__)
return {'FINISHED'}
def cancel(self, context):
# NOTE: disable addon if binaries are incompatible
if __package__ in bpy.context.user_preferences.addons:
bpy.ops.wm.addon_disable(module=__package__)
def invoke(self, context, event):
wm = context.window_manager
context.window.cursor_set("DEFAULT")
return wm.invoke_props_dialog(self, 450)
def draw(self, context):
self.layout.label(self.message, icon="ERROR")
class B4AVersionMismatchMessage(bpy.types.Operator):
bl_idname = "b4a.version_mismatch_message"
bl_label = "Warning: Blender version mismatch."
bl_options = {"INTERNAL"}
message = StringProperty(name="Message string")
def execute(self, context):
return {'FINISHED'}
def invoke(self, context, event):
wm = context.window_manager
context.window.cursor_set("DEFAULT")
return wm.invoke_props_dialog(self, 450)
def draw(self, context):
self.layout.label(self.message, icon="ERROR")
@bpy.app.handlers.persistent
def validate_version(arg):
if (bpy.app.version[0] != blend4web.bl_info["blender"][0]
or bpy.app.version[1] != blend4web.bl_info["blender"][1]):
message = "Blender " \
+ ".".join(map(str, blend4web.bl_info["blender"][:-1])) \
+ " is recommended for the Blend4Avango addon. Current version is " \
+ ".".join(map(str, bpy.app.version[:-1]))
# remove callback before another scene update aroused by init_error_message
if validate_version in bpy.app.handlers.scene_update_pre:
bpy.app.handlers.scene_update_pre.remove(validate_version)
bpy.ops.B4A.version_mismatch_message("INVOKE_DEFAULT", message=message)
@bpy.app.handlers.persistent
def bin_invalid_message(arg):
# remove callback before another scene update aroused by init_error_message
if bin_invalid_message in bpy.app.handlers.scene_update_pre:
bpy.app.handlers.scene_update_pre.remove(bin_invalid_message)
platform_data = get_platform_data()
message = "Addon is not compatible with \"" \
+ platform_data["system_name"] + " x" + platform_data["arch_bits"] \
+ "\" platform."
bpy.ops.B4A.init_error_message("INVOKE_DEFAULT", message=message)
# NOTE: register class permanently to held it even after disabling an addon
bpy.utils.register_class(B4AInitErrorMessage)
bpy.utils.register_class(B4AVersionMismatchMessage)