1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 "name": "Edit Operator Source",
22 "author": "scorpion81",
24 "blender": (2, 78, 0),
25 "location": "Text Editor > Edit > Edit Operator",
26 "description": "Opens source file of chosen operator, if it is an add-on one",
28 "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.6/"
29 "Py/Scripts/Development/Edit_Operator_Source",
30 "category": "Development"}
35 from bpy
.types
import (
39 from bpy
.props
import EnumProperty
43 opid
= opname
.split(".")
44 opmod
= getattr(bpy
.ops
, opid
[0])
45 op
= getattr(opmod
, opid
[1])
46 id = op
.get_rna().bl_rna
.identifier
47 clazz
= getattr(bpy
.types
, id)
51 def getmodule(opname
):
53 clazz
= getclazz(opname
)
54 modn
= clazz
.__module
__
57 line
= inspect
.getsourcelines(clazz
)[1]
63 if modn
== 'bpy.types':
66 elif modn
!= '__main__':
67 mod
= sys
.modules
[modn
].__file
__
72 return mod
, line
, addon
78 for opmodname
in opsdir
:
79 opmod
= getattr(bpy
.ops
, opmodname
)
82 name
= opmodname
+ "." + o
83 clazz
= getclazz(name
)
84 if (clazz
.__module
__ != 'bpy.types'):
88 # add own operator name too, since its not loaded yet when this is called
89 allops
.append("text.edit_operator")
94 return [(y
, y
, "", x
) for x
, y
in enumerate(l
)]
97 class EditOperator(Operator
):
98 bl_idname
= "text.edit_operator"
99 bl_label
= "Edit Operator"
100 bl_description
= "Opens the source file of operators chosen from Menu"
111 def invoke(self
, context
, event
):
112 context
.window_manager
.invoke_search_popup(self
)
113 return {'PASS_THROUGH'}
115 def execute(self
, context
):
117 path
, line
, addon
= getmodule(self
.op
)
119 for t
in bpy
.data
.texts
:
120 if t
.filepath
== path
:
123 bpy
.ops
.text
.jump(ctx
, line
=line
)
128 self
.report({'INFO'},
129 "Opened file: " + path
)
130 bpy
.ops
.text
.open(filepath
=path
)
131 bpy
.ops
.text
.jump(line
=line
)
135 self
.report({'WARNING'},
136 "Found no source file for " + self
.op
)
141 class EditOperatorPanel(Panel
):
142 bl_idname
= "DEVEDIT_PT_operator"
143 bl_space_type
= 'TEXT_EDITOR'
144 bl_region_type
= 'UI'
145 bl_label
= "Edit Operator"
147 def draw(self
, context
):
149 layout
.operator("text.edit_operator")
153 bpy
.utils
.register_class(EditOperator
)
154 bpy
.utils
.register_class(EditOperatorPanel
)
158 bpy
.utils
.unregister_class(EditOperatorPanel
)
159 bpy
.utils
.unregister_class(EditOperator
)
162 if __name__
== "__main__":