Cleanup: Python code-style (addons, wm)
This commit is contained in:
@@ -77,8 +77,8 @@ def modules_refresh(module_cache=addons_fake_modules):
|
|||||||
ModuleType = type(ast)
|
ModuleType = type(ast)
|
||||||
try:
|
try:
|
||||||
file_mod = open(mod_path, "r", encoding='UTF-8')
|
file_mod = open(mod_path, "r", encoding='UTF-8')
|
||||||
except OSError as e:
|
except OSError as ex:
|
||||||
print("Error opening file %r: %s" % (mod_path, e))
|
print("Error opening file %r: %s" % (mod_path, ex))
|
||||||
return None
|
return None
|
||||||
|
|
||||||
with file_mod:
|
with file_mod:
|
||||||
@@ -89,10 +89,10 @@ def modules_refresh(module_cache=addons_fake_modules):
|
|||||||
while not l.startswith("bl_info"):
|
while not l.startswith("bl_info"):
|
||||||
try:
|
try:
|
||||||
l = line_iter.readline()
|
l = line_iter.readline()
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError as ex:
|
||||||
if not error_encoding:
|
if not error_encoding:
|
||||||
error_encoding = True
|
error_encoding = True
|
||||||
print("Error reading file as UTF-8:", mod_path, e)
|
print("Error reading file as UTF-8:", mod_path, ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if len(l) == 0:
|
if len(l) == 0:
|
||||||
@@ -101,10 +101,10 @@ def modules_refresh(module_cache=addons_fake_modules):
|
|||||||
lines.append(l)
|
lines.append(l)
|
||||||
try:
|
try:
|
||||||
l = line_iter.readline()
|
l = line_iter.readline()
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError as ex:
|
||||||
if not error_encoding:
|
if not error_encoding:
|
||||||
error_encoding = True
|
error_encoding = True
|
||||||
print("Error reading file as UTF-8:", mod_path, e)
|
print("Error reading file as UTF-8:", mod_path, ex)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
data = "".join(lines)
|
data = "".join(lines)
|
||||||
@@ -182,9 +182,11 @@ def modules_refresh(module_cache=addons_fake_modules):
|
|||||||
mod = None
|
mod = None
|
||||||
|
|
||||||
if mod is None:
|
if mod is None:
|
||||||
mod = fake_module(mod_name,
|
mod = fake_module(
|
||||||
mod_path,
|
mod_name,
|
||||||
force_support=force_support)
|
mod_path,
|
||||||
|
force_support=force_support,
|
||||||
|
)
|
||||||
if mod:
|
if mod:
|
||||||
module_cache[mod_name] = mod
|
module_cache[mod_name] = mod
|
||||||
|
|
||||||
@@ -200,9 +202,12 @@ def modules(module_cache=addons_fake_modules, *, refresh=True):
|
|||||||
modules._is_first = False
|
modules._is_first = False
|
||||||
|
|
||||||
mod_list = list(module_cache.values())
|
mod_list = list(module_cache.values())
|
||||||
mod_list.sort(key=lambda mod: (mod.bl_info["category"],
|
mod_list.sort(
|
||||||
mod.bl_info["name"],
|
key=lambda mod: (
|
||||||
))
|
mod.bl_info["category"],
|
||||||
|
mod.bl_info["name"],
|
||||||
|
)
|
||||||
|
)
|
||||||
return mod_list
|
return mod_list
|
||||||
modules._is_first = True
|
modules._is_first = True
|
||||||
|
|
||||||
@@ -220,8 +225,10 @@ def check(module_name):
|
|||||||
loaded_default = module_name in _user_preferences.addons
|
loaded_default = module_name in _user_preferences.addons
|
||||||
|
|
||||||
mod = sys.modules.get(module_name)
|
mod = sys.modules.get(module_name)
|
||||||
loaded_state = ((mod is not None) and
|
loaded_state = (
|
||||||
getattr(mod, "__addon_enabled__", Ellipsis))
|
(mod is not None) and
|
||||||
|
getattr(mod, "__addon_enabled__", Ellipsis)
|
||||||
|
)
|
||||||
|
|
||||||
if loaded_state is Ellipsis:
|
if loaded_state is Ellipsis:
|
||||||
print("Warning: addon-module %r found module "
|
print("Warning: addon-module %r found module "
|
||||||
|
@@ -59,8 +59,8 @@ rna_relative_prop = BoolProperty(
|
|||||||
def context_path_validate(context, data_path):
|
def context_path_validate(context, data_path):
|
||||||
try:
|
try:
|
||||||
value = eval("context.%s" % data_path) if data_path else Ellipsis
|
value = eval("context.%s" % data_path) if data_path else Ellipsis
|
||||||
except AttributeError as e:
|
except AttributeError as ex:
|
||||||
if str(e).startswith("'NoneType'"):
|
if str(ex).startswith("'NoneType'"):
|
||||||
# One of the items in the rna path is None, just ignore this
|
# One of the items in the rna path is None, just ignore this
|
||||||
value = Ellipsis
|
value = Ellipsis
|
||||||
else:
|
else:
|
||||||
@@ -159,11 +159,12 @@ class BRUSH_OT_active_index_set(Operator):
|
|||||||
description="Brush number",
|
description="Brush number",
|
||||||
)
|
)
|
||||||
|
|
||||||
_attr_dict = {"sculpt": "use_paint_sculpt",
|
_attr_dict = {
|
||||||
"vertex_paint": "use_paint_vertex",
|
"sculpt": "use_paint_sculpt",
|
||||||
"weight_paint": "use_paint_weight",
|
"vertex_paint": "use_paint_vertex",
|
||||||
"image_paint": "use_paint_image",
|
"weight_paint": "use_paint_weight",
|
||||||
}
|
"image_paint": "use_paint_image",
|
||||||
|
}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
attr = self._attr_dict.get(self.mode)
|
attr = self._attr_dict.get(self.mode)
|
||||||
@@ -1018,11 +1019,12 @@ class WM_OT_doc_view_manual(Operator):
|
|||||||
|
|
||||||
if url is None:
|
if url is None:
|
||||||
self.report(
|
self.report(
|
||||||
{'WARNING'},
|
{'WARNING'},
|
||||||
"No reference available %r, "
|
"No reference available %r, "
|
||||||
"Update info in 'rna_manual_reference.py' "
|
"Update info in 'rna_manual_reference.py' "
|
||||||
"or callback to bpy.utils.manual_map()" %
|
"or callback to bpy.utils.manual_map()" %
|
||||||
self.doc_id)
|
self.doc_id
|
||||||
|
)
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
else:
|
else:
|
||||||
import webbrowser
|
import webbrowser
|
||||||
@@ -1112,7 +1114,7 @@ class WM_OT_properties_edit(Operator):
|
|||||||
"use_soft_limits": self.use_soft_limits,
|
"use_soft_limits": self.use_soft_limits,
|
||||||
"soft_range": (self.soft_min, self.soft_max),
|
"soft_range": (self.soft_min, self.soft_max),
|
||||||
"hard_range": (self.min, self.max),
|
"hard_range": (self.min, self.max),
|
||||||
}
|
}
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
from rna_prop_ui import (
|
from rna_prop_ui import (
|
||||||
@@ -1233,8 +1235,9 @@ class WM_OT_properties_edit(Operator):
|
|||||||
self.soft_min = prop_ui.get("soft_min", self.min)
|
self.soft_min = prop_ui.get("soft_min", self.min)
|
||||||
self.soft_max = prop_ui.get("soft_max", self.max)
|
self.soft_max = prop_ui.get("soft_max", self.max)
|
||||||
self.use_soft_limits = (
|
self.use_soft_limits = (
|
||||||
self.min != self.soft_min or
|
self.min != self.soft_min or
|
||||||
self.max != self.soft_max)
|
self.max != self.soft_max
|
||||||
|
)
|
||||||
|
|
||||||
# store for comparison
|
# store for comparison
|
||||||
self._cmp_props = self._cmp_props_get()
|
self._cmp_props = self._cmp_props_get()
|
||||||
@@ -1603,8 +1606,8 @@ class WM_OT_keyconfig_import(Operator):
|
|||||||
shutil.copy(self.filepath, path)
|
shutil.copy(self.filepath, path)
|
||||||
else:
|
else:
|
||||||
shutil.move(self.filepath, path)
|
shutil.move(self.filepath, path)
|
||||||
except Exception as e:
|
except Exception as ex:
|
||||||
self.report({'ERROR'}, "Installing keymap failed: %s" % e)
|
self.report({'ERROR'}, "Installing keymap failed: %s" % ex)
|
||||||
return {'CANCELLED'}
|
return {'CANCELLED'}
|
||||||
|
|
||||||
# sneaky way to check we're actually running the code.
|
# sneaky way to check we're actually running the code.
|
||||||
@@ -1838,12 +1841,14 @@ class WM_OT_addon_enable(Operator):
|
|||||||
info_ver = info.get("blender", (0, 0, 0))
|
info_ver = info.get("blender", (0, 0, 0))
|
||||||
|
|
||||||
if info_ver > bpy.app.version:
|
if info_ver > bpy.app.version:
|
||||||
self.report({'WARNING'},
|
self.report(
|
||||||
("This script was written Blender "
|
{'WARNING'},
|
||||||
"version %d.%d.%d and might not "
|
"This script was written Blender "
|
||||||
"function (correctly), "
|
"version %d.%d.%d and might not "
|
||||||
"though it is enabled" %
|
"function (correctly), "
|
||||||
info_ver))
|
"though it is enabled" %
|
||||||
|
info_ver
|
||||||
|
)
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
@@ -99,17 +99,21 @@ def register():
|
|||||||
register_class(cls)
|
register_class(cls)
|
||||||
|
|
||||||
# space_userprefs.py
|
# space_userprefs.py
|
||||||
from bpy.props import StringProperty, EnumProperty
|
from bpy.props import (
|
||||||
|
EnumProperty,
|
||||||
|
StringProperty,
|
||||||
|
)
|
||||||
from bpy.types import WindowManager
|
from bpy.types import WindowManager
|
||||||
|
|
||||||
def addon_filter_items(self, context):
|
def addon_filter_items(self, context):
|
||||||
import addon_utils
|
import addon_utils
|
||||||
|
|
||||||
items = [('All', "All", "All Add-ons"),
|
items = [
|
||||||
('User', "User", "All Add-ons Installed by User"),
|
('All', "All", "All Add-ons"),
|
||||||
('Enabled', "Enabled", "All Enabled Add-ons"),
|
('User', "User", "All Add-ons Installed by User"),
|
||||||
('Disabled', "Disabled", "All Disabled Add-ons"),
|
('Enabled', "Enabled", "All Enabled Add-ons"),
|
||||||
]
|
('Disabled', "Disabled", "All Disabled Add-ons"),
|
||||||
|
]
|
||||||
|
|
||||||
items_unique = set()
|
items_unique = set()
|
||||||
|
|
||||||
@@ -121,26 +125,27 @@ def register():
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
WindowManager.addon_search = StringProperty(
|
WindowManager.addon_search = StringProperty(
|
||||||
name="Search",
|
name="Search",
|
||||||
description="Search within the selected filter",
|
description="Search within the selected filter",
|
||||||
options={'TEXTEDIT_UPDATE'},
|
options={'TEXTEDIT_UPDATE'},
|
||||||
)
|
)
|
||||||
WindowManager.addon_filter = EnumProperty(
|
WindowManager.addon_filter = EnumProperty(
|
||||||
items=addon_filter_items,
|
items=addon_filter_items,
|
||||||
name="Category",
|
name="Category",
|
||||||
description="Filter add-ons by category",
|
description="Filter add-ons by category",
|
||||||
)
|
)
|
||||||
|
|
||||||
WindowManager.addon_support = EnumProperty(
|
WindowManager.addon_support = EnumProperty(
|
||||||
items=[('OFFICIAL', "Official", "Officially supported"),
|
items=[
|
||||||
('COMMUNITY', "Community", "Maintained by community developers"),
|
('OFFICIAL', "Official", "Officially supported"),
|
||||||
('TESTING', "Testing", "Newly contributed scripts (excluded from release builds)")
|
('COMMUNITY', "Community", "Maintained by community developers"),
|
||||||
],
|
('TESTING', "Testing", "Newly contributed scripts (excluded from release builds)")
|
||||||
name="Support",
|
],
|
||||||
description="Display support level",
|
name="Support",
|
||||||
default={'OFFICIAL', 'COMMUNITY'},
|
description="Display support level",
|
||||||
options={'ENUM_FLAG'},
|
default={'OFFICIAL', 'COMMUNITY'},
|
||||||
)
|
options={'ENUM_FLAG'},
|
||||||
|
)
|
||||||
# done...
|
# done...
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user