~ubuntu-branches/ubuntu/trusty/blender/trusty

« back to all changes in this revision

Viewing changes to release/scripts/addons_contrib/development_class_viewer.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-05-12 20:02:22 UTC
  • mfrom: (14.2.16 sid)
  • Revision ID: package-import@ubuntu.com-20120512200222-lznjs2cxzaq96wua
Tags: 2.63a-1
* New upstream bugfix release
  + debian/patches/: re-worked since source code changed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# ##### BEGIN GPL LICENSE BLOCK #####
2
 
#
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.
7
 
#
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.
12
 
#
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.
16
 
#
17
 
# ##### END GPL LICENSE BLOCK #####
18
 
 
19
 
bl_info = {
20
 
    'name': "Class Viewer",
21
 
    'author': "Mackraken", "batFinger"
22
 
    'version': (0, 1, 2),
23
 
    'blender': (2, 5, 8),
24
 
    'location': "Text Editor > Toolbar, Text Editor > Right Click",
25
 
    'warning': "",
26
 
    'description': "List text's classes and definitions",
27
 
    'wiki_url': "https://sites.google.com/site/aleonserra/home/scripts/class-viewer",
28
 
    'category': "Development"}
29
 
 
30
 
import bpy
31
 
 
32
 
#lists all defs, comment or classes
33
 
#space = current text editor
34
 
#sort = sort result
35
 
#tipo = kind of struct to look for
36
 
#escape = character right next to the class or def name 
37
 
 
38
 
def getfunc(space, sort, tipo="def ", escape= ""):
39
 
    defs = []
40
 
    if space.type=="TEXT_EDITOR":
41
 
        if space.text!=None:
42
 
            txt = space.text
43
 
            
44
 
            for i, l in enumerate(txt.lines):
45
 
                try:
46
 
                    line = l.body
47
 
                except:
48
 
                    line=""
49
 
                
50
 
                if line[0:len(tipo)]==tipo:
51
 
                    end = line.find(escape)
52
 
                    if end==0:
53
 
                        func = line[len(tipo)::]
54
 
                    else:
55
 
                        func = line[len(tipo):end]
56
 
                    defs.append([func, i+1])
57
 
            
58
 
            if sort: defs.sort()
59
 
    
60
 
    return defs
61
 
 
62
 
class TEXT_OT_Jumptoline(bpy.types.Operator):
63
 
    bl_label = "Jump"
64
 
    bl_idname = "text.jumptoline"
65
 
    __doc__ = "Jump to line"
66
 
    line = bpy.props.IntProperty(default=-1)
67
 
    
68
 
    @classmethod
69
 
    def poll(cls, context):
70
 
        if context.area.spaces[0].type!="TEXT_EDITOR":
71
 
            return False
72
 
        else: 
73
 
            return context.area.spaces[0].text!=None
74
 
    
75
 
    def execute(self, context):
76
 
        
77
 
        scn = context.scene
78
 
 
79
 
        if self.line!=-1:
80
 
            bpy.ops.text.jump(line=self.line)
81
 
 
82
 
        return {'FINISHED'}
83
 
 
84
 
 
85
 
 
86
 
class CommentsMenu(bpy.types.Menu):
87
 
    bl_idname = "OBJECT_MT_select_comments"
88
 
    bl_label = "Select"
89
 
    
90
 
    
91
 
    
92
 
    @classmethod
93
 
    def poll(cls, context):
94
 
        if context.area.spaces[0].type!="TEXT_EDITOR":
95
 
            return False
96
 
        else: 
97
 
            return context.area.spaces[0].text!=None
98
 
        
99
 
    def draw(self, context):
100
 
    
101
 
        layout = self.layout
102
 
        space = context.area.spaces[0]
103
 
        
104
 
        items = getfunc(space, 1, "### ", "")
105
 
        
106
 
        for it in items:
107
 
            layout.operator("text.jumptoline",text=it[0]).line = it[1]
108
 
 
109
 
class DefsMenu(bpy.types.Menu):
110
 
    bl_idname = "OBJECT_MT_select_defs"
111
 
    bl_label = "Select"
112
 
    
113
 
    tipo = bpy.props.BoolProperty(default=False)
114
 
    
115
 
    @classmethod
116
 
    def poll(cls, context):
117
 
        if context.area.spaces[0].type!="TEXT_EDITOR":
118
 
            return False
119
 
        else: 
120
 
            return context.area.spaces[0].text!=None
121
 
        
122
 
    def draw(self, context):
123
 
        scn = context.scene
124
 
        layout = self.layout
125
 
        space = context.area.spaces[0]
126
 
        tipo = self.tipo
127
 
        
128
 
        
129
 
        items = getfunc(space, 1, "def ", "(")
130
 
        
131
 
        for it in items:
132
 
            layout.operator("text.jumptoline",text=it[0]).line = it[1]
133
 
                
134
 
class ClassesMenu(bpy.types.Menu):
135
 
    bl_idname = "OBJECT_MT_select_classes"
136
 
    bl_label = "Select"
137
 
    
138
 
    
139
 
    
140
 
    @classmethod
141
 
    def poll(cls, context):
142
 
        if context.area.spaces[0].type!="TEXT_EDITOR":
143
 
            return False
144
 
        else: 
145
 
            return context.area.spaces[0].text!=None
146
 
        
147
 
    def draw(self, context):
148
 
    
149
 
        layout = self.layout
150
 
        space = context.area.spaces[0]
151
 
    
152
 
        
153
 
        
154
 
        items = getfunc(space, 1, "class ", "(")
155
 
        
156
 
        for it in items:
157
 
            layout.operator("text.jumptoline",text=it[0]).line = it[1]
158
 
 
159
 
 
160
 
            
161
 
def GotoComments(self, context): 
162
 
    self.layout.menu("OBJECT_MT_select_comments", text="Comments", icon='PLUGIN')
163
 
    return False
164
 
 
165
 
def GotoDefs(self, context): 
166
 
    self.layout.menu("OBJECT_MT_select_defs", text="Defs", icon='PLUGIN')
167
 
    return False
168
 
 
169
 
def GotoClasses(self, context): 
170
 
    self.layout.menu("OBJECT_MT_select_classes", text="Classes", icon='PLUGIN')
171
 
    return False
172
 
 
173
 
 
174
 
classes = [TEXT_OT_Jumptoline, ClassesMenu, DefsMenu, CommentsMenu]
175
 
 
176
 
 
177
 
def register():
178
 
    for c in classes:
179
 
        bpy.utils.register_class(c)
180
 
        
181
 
    bpy.types.TEXT_MT_toolbox.append(GotoComments)
182
 
    bpy.types.TEXT_MT_toolbox.append(GotoDefs)
183
 
    bpy.types.TEXT_MT_toolbox.append(GotoClasses)
184
 
 
185
 
def unregister():
186
 
    for c in classes:
187
 
        bpy.utils.unregister_class(c)
188
 
        
189
 
        bpy.types.TEXT_MT_toolbox.remove(GotoComments)
190
 
    bpy.types.TEXT_MT_toolbox.remove(GotoDefs)
191
 
    bpy.types.TEXT_MT_toolbox.remove(GotoClasses)
192
 
    
193
 
if __name__ == "__main__":
194
 
    register()