Skip to content

Commit 34e3932

Browse files
committed
Fix: Incorrect way to use bpy.types.AddonPreferences (#229)
(cherry picked from commit 2a6d35d)
1 parent 36c2850 commit 34e3932

File tree

2 files changed

+60
-26
lines changed

2 files changed

+60
-26
lines changed

src/screencast_keys/common.py

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,44 @@ def reload_image(filepath, image_name):
8888
image.preview_ensure()
8989
image.gl_load()
9090

91-
if "use_custom_mouse_image" not in prefs:
92-
return
93-
if not prefs["use_custom_mouse_image"]:
94-
return
95-
96-
if "custom_mouse_image_base" in prefs:
97-
reload_image(prefs["custom_mouse_image_base"],
98-
CUSTOM_MOUSE_IMG_BASE_NAME)
99-
if "custom_mouse_image_left_mouse" in prefs:
100-
reload_image(prefs["custom_mouse_image_left_mouse"],
101-
CUSTOM_MOUSE_IMG_LMOUSE_NAME)
102-
if "custom_mouse_image_right_mouse" in prefs:
103-
reload_image(prefs["custom_mouse_image_right_mouse"],
104-
CUSTOM_MOUSE_IMG_RMOUSE_NAME)
105-
if "custom_mouse_image_middle_mouse" in prefs:
106-
reload_image(prefs["custom_mouse_image_middle_mouse"],
107-
CUSTOM_MOUSE_IMG_MMOUSE_NAME)
91+
# From Blender 5.0, the specification of bpy.types.AddonPreferences
92+
# is changed. This change does not allow dict based accesses.
93+
if compat.check_version(5, 0, 0) >= 0:
94+
if "use_custom_mouse_image" not in dir(prefs):
95+
return
96+
if not prefs.use_custom_mouse_image:
97+
return
98+
99+
if "custom_mouse_image_base" in dir(prefs):
100+
reload_image(prefs.custom_mouse_image_base,
101+
CUSTOM_MOUSE_IMG_BASE_NAME)
102+
if "custom_mouse_image_left_mouse" in dir(prefs):
103+
reload_image(prefs.custom_mouse_image_left_mouse,
104+
CUSTOM_MOUSE_IMG_LMOUSE_NAME)
105+
if "custom_mouse_image_right_mouse" in dir(prefs):
106+
reload_image(prefs.custom_mouse_image_right_mouse,
107+
CUSTOM_MOUSE_IMG_RMOUSE_NAME)
108+
if "custom_mouse_image_middle_mouse" in dir(prefs):
109+
reload_image(prefs.custom_mouse_image_middle_mouse,
110+
CUSTOM_MOUSE_IMG_MMOUSE_NAME)
111+
else:
112+
if "use_custom_mouse_image" not in prefs:
113+
return
114+
if not prefs["use_custom_mouse_image"]:
115+
return
116+
117+
if "custom_mouse_image_base" in prefs:
118+
reload_image(prefs["custom_mouse_image_base"],
119+
CUSTOM_MOUSE_IMG_BASE_NAME)
120+
if "custom_mouse_image_left_mouse" in prefs:
121+
reload_image(prefs["custom_mouse_image_left_mouse"],
122+
CUSTOM_MOUSE_IMG_LMOUSE_NAME)
123+
if "custom_mouse_image_right_mouse" in prefs:
124+
reload_image(prefs["custom_mouse_image_right_mouse"],
125+
CUSTOM_MOUSE_IMG_RMOUSE_NAME)
126+
if "custom_mouse_image_middle_mouse" in prefs:
127+
reload_image(prefs["custom_mouse_image_middle_mouse"],
128+
CUSTOM_MOUSE_IMG_MMOUSE_NAME)
108129

109130
ensure_custom_mouse_images()
110131

src/screencast_keys/preferences.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,28 @@ def remove_image(image_name):
146146

147147

148148
def update_custom_mouse_image_size(self, _):
149-
if "use_custom_mouse_image_size" not in self:
150-
return
151-
152-
if not self["use_custom_mouse_image_size"]:
153-
return
154-
155-
if common.CUSTOM_MOUSE_IMG_BASE_NAME in bpy.data.images:
156-
image = bpy.data.images[common.CUSTOM_MOUSE_IMG_BASE_NAME]
157-
self["custom_mouse_size"] = image.size
149+
# From Blender 5.0, the specification of bpy.types.AddonPreferences
150+
# is changed. This change does not allow dict based accesses.
151+
if compat.check_version(5, 0, 0) >= 0:
152+
if "use_custom_mouse_image_size" not in dir(self):
153+
return
154+
155+
if not self.use_custom_mouse_image_size:
156+
return
157+
158+
if common.CUSTOM_MOUSE_IMG_BASE_NAME in bpy.data.images:
159+
image = bpy.data.images[common.CUSTOM_MOUSE_IMG_BASE_NAME]
160+
self.custom_mouse_size = image.size
161+
else:
162+
if "use_custom_mouse_image_size" not in self:
163+
return
164+
165+
if not self["use_custom_mouse_image_size"]:
166+
return
167+
168+
if common.CUSTOM_MOUSE_IMG_BASE_NAME in bpy.data.images:
169+
image = bpy.data.images[common.CUSTOM_MOUSE_IMG_BASE_NAME]
170+
self["custom_mouse_size"] = image.size
158171

159172

160173
@BlClassRegistry()

0 commit comments

Comments
 (0)