diff options
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r-- | release/scripts/modules/bpy_types.py | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py index ee9115b6643..29b53aedf78 100644 --- a/release/scripts/modules/bpy_types.py +++ b/release/scripts/modules/bpy_types.py @@ -150,7 +150,11 @@ class Object(bpy_types.ID): class WindowManager(bpy_types.ID): __slots__ = () - def popup_menu(self, draw_func, title="", icon='NONE'): + def popup_menu( + self, draw_func, *, + title="", + icon='NONE', + ): import bpy popup = self.popmenu_begin__internal(title, icon=icon) @@ -176,7 +180,11 @@ class WindowManager(bpy_types.ID): finally: self.popover_end__internal(popup, keymap=keymap) - def popup_menu_pie(self, event, draw_func, title="", icon='NONE'): + def popup_menu_pie( + self, event, draw_func, *, + title="", + icon='NONE', + ): import bpy pie = self.piemenu_begin__internal(title, icon=icon, event=event) @@ -392,7 +400,7 @@ class EditBone(StructRNA, _GenericBone, metaclass=StructMetaPropGroup): self.tail = self.head + vec self.roll = other.roll - def transform(self, matrix, scale=True, roll=True): + def transform(self, matrix, *, scale=True, roll=True): """ Transform the the bones head, tail, roll and envelope (when the matrix has a scale component). @@ -560,9 +568,17 @@ class Text(bpy_types.ID): self.write(string) def as_module(self): - from os.path import splitext + import bpy + from os.path import splitext, join from types import ModuleType - mod = ModuleType(splitext(self.name)[0]) + name = self.name + mod = ModuleType(splitext(name)[0]) + # This is a fake file-path, set this since some scripts check `__file__`, + # error messages may include this as well. + # NOTE: the file path may be a blank string if the file hasn't been saved. + mod.__dict__.update({ + "__file__": join(bpy.data.filepath, name), + }) # TODO: We could use Text.compiled (C struct member) # if this is called often it will be much faster. exec(self.as_string(), mod.__dict__) @@ -657,16 +673,14 @@ class Gizmo(StructRNA): use_blend = color[3] < 1.0 if use_blend: - # TODO: wrap GPU_blend from GPU state. - from bgl import glEnable, glDisable, GL_BLEND - glEnable(GL_BLEND) + gpu.state.blend_set('ALPHA') with gpu.matrix.push_pop(): gpu.matrix.multiply_matrix(matrix) batch.draw() if use_blend: - glDisable(GL_BLEND) + gpu.state.blend_set('NONE') @staticmethod def new_custom_shape(type, verts): @@ -733,7 +747,7 @@ class Operator(StructRNA, metaclass=RNAMeta): return delattr(properties, attr) return super().__delattr__(attr) - def as_keywords(self, ignore=()): + def as_keywords(self, *, ignore=()): """Return a copy of the properties as a dictionary""" ignore = ignore + ("rna_type",) return {attr: getattr(self, attr) @@ -923,7 +937,7 @@ class Menu(StructRNA, _GenericUI, metaclass=RNAMeta): # Perform a "natural sort", so 20 comes after 3 (for example). files.sort( key=lambda file_path: - tuple(int(t) if t.isdigit() else t for t in re.split("(\d+)", file_path[0].lower())), + tuple(int(t) if t.isdigit() else t for t in re.split(r"(\d+)", file_path[0].lower())), ) col = layout.column(align=True) |