Welcome to mirror list, hosted at ThFree Co, Russian Federation.

selection_restrictor.py « space_view3d_display_tools - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e58164095e793049dc388a6bed9cb9ee7bb22ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####


bl_info = {
    "name": "Selection Restrictor",
    "author": "Ales Sidenko",
    "version": (0, 1, 1),
    "location": "3d viewer header",
    "warning": "",
    "description": "This addon helps to restrict the selection of objects by type. "
                   "Please email me if you find a bug (sidenkoai@gmail.com)",
    "category": "3D View"
    }

import bpy
from bpy.types import (
        Menu,
        Operator,
        )
from bpy.props import (
        BoolProperty,
        StringProperty,
        )

from bpy.app.handlers import persistent

mesh = 'OBJECT_DATA'
curve = 'OUTLINER_OB_CURVE'
arm = 'OUTLINER_OB_ARMATURE'
empty = 'OUTLINER_OB_EMPTY'
cam = 'OUTLINER_OB_CAMERA'
lamp = 'OUTLINER_OB_LIGHT'
lat = 'OUTLINER_OB_LATTICE'
font = 'OUTLINER_OB_FONT'
meta = 'OUTLINER_OB_META'
surf = 'OUTLINER_OB_SURFACE'
speak = 'OUTLINER_OB_SPEAKER'

show = 'TRIA_RIGHT'
show_restrictor = False
hide = True


# checking properties in scene to update icons when opening file
# or switching between scenes (executing in end of script)

@persistent
def check_restrictors(dummy):
    global mesh
    global curve
    global arm
    global empty
    global cam
    global lamp
    global lat
    global font
    global meta
    global surf
    global speak
    global show

    global meshrestrictorenabled
    global curverestrictorenabled
    global armrestrictorenabled
    global emptyrestrictorenabled
    global camrestrictorenabled
    global lamprestrictorenabled
    global latrestrictorenabled
    global fontrestrictorenabled
    global metarestrictorenabled
    global surfrestrictorenabled
    global speakrestrictorenabled

    # show restrictors?
    if bpy.context.scene.get('show_restrictor') is not None:
        show_restrictor = False
        show = 'TRIA_RIGHT'
    else:
        show_restrictor = True
        show = 'TRIA_DOWN'

    # mesh
    if bpy.context.scene.get('meshrestrictor') is None:
        meshrestrictorenabled = True
        mesh = 'OBJECT_DATA'
    else:
        meshrestrictorenabled = False
        mesh = 'MESH_CUBE'
    # curve
    if bpy.context.scene.get('curverestrictor') is None:
        curverestrictorenabled = True
        curve = 'OUTLINER_OB_CURVE'
    else:
        curverestrictorenabled = False
        curve = 'CURVE_DATA'
    # armature
    if bpy.context.scene.get('armrestrictor') is None:
        armrestrictorenabled = True
        arm = 'OUTLINER_OB_ARMATURE'
    else:
        armrestrictorenabled = False
        arm = 'ARMATURE_DATA'

    # empty
    if bpy.context.scene.get('emptyrestrictor') is None:
        emptyrestrictorenabled = True
        empty = 'OUTLINER_OB_EMPTY'
    else:
        emptyrestrictorenabled = False
        empty = 'EMPTY_DATA'

    # camera
    if bpy.context.scene.get('camrestrictor') is None:
        camrestrictorenabled = True
        cam = 'OUTLINER_OB_CAMERA'
    else:
        camrestrictorenabled = False
        cam = 'CAMERA_DATA'
    # lamp
    if bpy.context.scene.get('lamprestrictor') is None:
        lamprestrictorenabled = True
        lamp = 'OUTLINER_OB_LIGHT'
    else:
        lamprestrictorenabled = False
        lamp = 'LIGHT_DATA'

    # lattice
    if bpy.context.scene.get('latrestrictor') is None:
        latrestrictorenabled = True
        lat = 'OUTLINER_OB_LATTICE'
    else:
        latrestrictorenabled = False
        lat = 'LATTICE_DATA'

    # text
    if bpy.context.scene.get('fontrestrictor') is None:
        fontrestrictorenabled = True
        font = 'OUTLINER_OB_FONT'
    else:
        fontrestrictorenabled = False
        font = 'FONT_DATA'

    # metaballs
    if bpy.context.scene.get('metarestrictor') is None:
        metarestrictorenabled = True
        meta = 'OUTLINER_OB_META'
    else:
        metarestrictorenabled = False
        meta = 'META_DATA'

    # surfaces
    if bpy.context.scene.get('surfrestrictor') is None:
        surfrestrictorenabled = True
        surf = 'OUTLINER_OB_SURFACE'
    else:
        surfrestrictorenabled = False
        surf = 'SURFACE_DATA'

    # sounds
    if bpy.context.scene.get('speakrestrictor') is None:
        speakrestrictorenabled = True
        speak = 'OUTLINER_OB_SPEAKER'
    else:
        speakrestrictorenabled = False
        speak = 'SPEAKER'
    return{'FINISHED'}


# Show / Hide buttons

class RestrictorShow(Operator):
    bl_idname = "restrictor.show"
    bl_label = "Show/Hide Selection Restrictors"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Show/Hide Selection Restrictors"

    hide: StringProperty()

    def execute(self, context):
        global show

        if bpy.context.scene.get('show_restrictor') is None:
            bpy.context.scene['show_restrictor'] = 1
            show = 'TRIA_DOWN'
        else:
            if bpy.context.scene.get('show_restrictor') is not None:
                del bpy.context.scene['show_restrictor']
                show = 'TRIA_RIGHT'

        return {'FINISHED'}


# Ignore the restrictor for selected objects

class IgnoreRestrictors(Operator):
    bl_idname = "ignore.restrictors"
    bl_label = "Ignore Restrictor by Selected Objects"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Ignore or do not ignore Restrictor by selected objects"
    ignore: BoolProperty()

    def execute(self, context):
        if self.ignore is True:
            for ob in bpy.context.selected_objects:
                ob['ignore_restrictors'] = 1
        else:
            for ob in bpy.context.selected_objects:
                if ob.get('ignore_restrictors') is not None:
                    del ob["ignore_restrictors"]
            bpy.ops.refresh.restrictors()

        return{'FINISHED'}


# Enable or Disable restrictors

# Restrictor Mesh

class RestrictorMesh(Operator):
    bl_idname = "restrictor.mesh"
    bl_label = "restrictor meshes"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Meshes selection restrictor"
    mesh: StringProperty()

    def execute(self, context):
        global mesh
        global meshrestrictorenabled
        if bpy.context.scene.get('meshrestrictor') is not None:
            meshrestrictorenabled = True
            if bpy.context.scene.get('meshrestrictor') is not None:
                del bpy.context.scene['meshrestrictor']
            mesh = 'OBJECT_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'MESH':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            meshrestrictorenabled = False
            bpy.context.scene['meshrestrictor'] = 1
            mesh = 'MESH_CUBE'
            for ob in bpy.context.scene.objects:
                if ob.type == 'MESH':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Curves

class RestrictorCurve(Operator):
    bl_idname = "restrictor.curve"
    bl_label = "restrictor curves"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Curves selection restrictor"

    def execute(self, context):
        global curve
        global curverestrictorenabled

        if bpy.context.scene.get('curverestrictor') is not None:
            curverestrictorenabled = True
            if bpy.context.scene.get('curverestrictor') is not None:
                del bpy.context.scene['curverestrictor']
            curve = 'OUTLINER_OB_CURVE'
            for ob in bpy.context.scene.objects:
                if ob.type == 'CURVE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            curverestrictorenabled = False
            bpy.context.scene['curverestrictor'] = 1
            curve = 'CURVE_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'CURVE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Armatures

class RestrictorArm(Operator):
    bl_idname = "restrictor.arm"
    bl_label = "restrictor armatures"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Armatures selection restrictor"

    def execute(self, context):
        global arm
        global armrestrictorenabled

        if bpy.context.scene.get('armrestrictor') is not None:
            armrestrictorenabled = True
            if bpy.context.scene.get('armrestrictor') is not None:
                del bpy.context.scene['armrestrictor']
            arm = 'OUTLINER_OB_ARMATURE'
            for ob in bpy.context.scene.objects:
                if ob.type == 'ARMATURE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            armrestrictorenabled = False
            bpy.context.scene['armrestrictor'] = 1
            arm = 'ARMATURE_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'ARMATURE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Empties

class RestrictorEmpty(Operator):
    bl_idname = "restrictor.empty"
    bl_label = "Restrictor Empties"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Empties selection restrictor"

    def execute(self, context):
        global empty
        global emptyrestrictorenabled

        if bpy.context.scene.get('emptyrestrictor') is not None:
            emptyrestrictorenabled = True
            if bpy.context.scene.get('emptyrestrictor') is not None:
                del bpy.context.scene['emptyrestrictor']
            empty = 'OUTLINER_OB_EMPTY'
            for ob in bpy.context.scene.objects:
                if ob.type == 'EMPTY':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            emptyrestrictorenabled = False
            bpy.context.scene['emptyrestrictor'] = 1
            empty = 'EMPTY_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'EMPTY':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Cameras

class RestrictorCam(Operator):
    bl_idname = "restrictor.cam"
    bl_label = "restrictor cameras"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Cameras selection restrictor"

    def execute(self, context):
        global cam
        global camrestrictorenabled

        if bpy.context.scene.get('camrestrictor') is not None:
            camrestrictorenabled = True
            if bpy.context.scene.get('camrestrictor') is not None:
                del bpy.context.scene['camrestrictor']
            cam = 'OUTLINER_OB_CAMERA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'CAMERA':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            camrestrictorenabled = False
            bpy.context.scene['camrestrictor'] = 1
            cam = 'CAMERA_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'CAMERA':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Lamps

class RestrictorLamp(Operator):
    bl_idname = "restrictor.light"
    bl_label = "Restrictor Lamps"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Lamps selection restrictor"

    def execute(self, context):
        global lamp
        global lamprestrictorenabled

        if bpy.context.scene.get('lamprestrictor') is not None:
            lamprestrictorenabled = True
            if bpy.context.scene.get('lamprestrictor') is not None:
                del bpy.context.scene['lamprestrictor']
            lamp = 'OUTLINER_OB_LIGHT'
            for ob in bpy.context.scene.objects:
                if ob.type == 'LIGHT':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            lamprestrictorenabled = False
            bpy.context.scene['lamprestrictor'] = 1
            lamp = 'LIGHT_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'LIGHT':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Lattice

class RestrictorLat(Operator):
    bl_idname = "restrictor.lat"
    bl_label = "Restrictor Lattices"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Lattices selection restrictor"

    def execute(self, context):
        global lat
        global latrestrictorenabled

        if bpy.context.scene.get('latrestrictor') is not None:
            latrestrictorenabled = True
            if bpy.context.scene.get('latrestrictor') is not None:
                del bpy.context.scene['latrestrictor']
            lat = 'OUTLINER_OB_LATTICE'
            for ob in bpy.context.scene.objects:
                if ob.type == 'LATTICE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False
        else:
            latrestrictorenabled = False
            bpy.context.scene['latrestrictor'] = 1
            lat = 'LATTICE_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'LATTICE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor Font

class RestrictorFont(Operator):
    bl_idname = "restrictor.font"
    bl_label = "Restrictor Font"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Text selection restrictor"

    def execute(self, context):
        global font
        global fontrestrictorenabled

        if bpy.context.scene.get('fontrestrictor') is not None:
            fontrestrictorenabled = True
            if bpy.context.scene.get('fontrestrictor') is not None:
                del bpy.context.scene['fontrestrictor']
            font = 'OUTLINER_OB_FONT'
            for ob in bpy.context.scene.objects:
                if ob.type == 'FONT':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False
        else:
            fontrestrictorenabled = False
            bpy.context.scene['fontrestrictor'] = 1
            font = 'FONT_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'FONT':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Metaballs

class RestrictorMeta(Operator):
    bl_idname = "restrictor.meta"
    bl_label = "restrictor metaballs"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Metaballs selection restrictor"

    def execute(self, context):
        global meta
        global metarestrictorenabled

        if bpy.context.scene.get('metarestrictor') is not None:
            metarestrictorenabled = True
            if bpy.context.scene.get('metarestrictor') is not None:
                del bpy.context.scene['metarestrictor']
            meta = 'OUTLINER_OB_META'
            for ob in bpy.context.scene.objects:
                if ob.type == 'META':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False
        else:
            metarestrictorenabled = False
            bpy.context.scene['metarestrictor'] = 1
            meta = 'META_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'META':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Surfaces

class RestrictorSurf(Operator):
    bl_idname = "restrictor.surf"
    bl_label = "Restrictor Surfaces"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Surfaces selection restrictor"

    def execute(self, context):
        global surf
        global surfrestrictorenabled

        if bpy.context.scene.get('surfrestrictor') is not None:
            surfrestrictorenabled = True
            if bpy.context.scene.get('surfrestrictor') is not None:
                del bpy.context.scene['surfrestrictor']
            surf = 'OUTLINER_OB_SURFACE'
            for ob in bpy.context.scene.objects:
                if ob.type == 'SURFACE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False
        else:
            surfrestrictorenabled = False
            bpy.context.scene['surfrestrictor'] = 1
            surf = 'SURFACE_DATA'
            for ob in bpy.context.scene.objects:
                if ob.type == 'SURFACE':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# Restrictor for Speakers

class RestrictorSound(Operator):
    bl_idname = "restrictor.speak"
    bl_label = "Restrictor Speakers"
    bl_description = "Sounds selection restrictor"
    bl_option = {'REGISTER', 'UNDO'}

    def execute(self, context):
        global speak
        global speakrestrictorenabled

        if bpy.context.scene.get('speakrestrictor') is not None:
            speakrestrictorenabled = True
            if bpy.context.scene.get('speakrestrictor') is not None:
                del bpy.context.scene['speakrestrictor']
            speak = 'OUTLINER_OB_SPEAKER'
            for ob in bpy.context.scene.objects:
                if ob.type == 'SPEAKER':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False

        else:
            speakrestrictorenabled = False
            bpy.context.scene['speakrestrictor'] = 1
            speak = 'SPEAKER'
            for ob in bpy.context.scene.objects:
                if ob.type == 'SPEAKER':
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = True
                        ob.select = False

        return{'FINISHED'}


# refresh restrictors for newly created objects

class RefreshRestrictors(Operator):
    bl_idname = "refresh.restrictors"
    bl_label = "Refresh Selection Restrictors"
    bl_option = {'REGISTER', 'UNDO'}
    bl_description = "Refresh restrictors"

    def execute(self, context):
        global mesh
        global curve
        global arm
        global empty
        global cam
        global lamp
        global lat
        global font
        global meta
        global surf
        global speak

        datas = {
            'meshrestrictor': ("OBJECT_DATA", "MESH_CUBE", "MESH"),
            'curverestrictor': ("OUTLINER_OB_CURVE", "CURVE_DATA", "CURVE"),
            'armrestrictor': ("OUTLINER_OB_ARMATURE", "ARMATURE_DATA", "ARMATURE"),
            'emptyrestrictor': ("OUTLINER_OB_EMPTY", "EMPTY_DATA", "EMPTY"),
            'camrestrictor': ("OUTLINER_OB_CAMERA", "CAMERA_DATA", "CAMERA"),
            'lamprestrictor': ("OUTLINER_OB_LIGHT", "LIGHT_DATA", "LIGHT"),
            'latrestrictor': ("OUTLINER_OB_LATTICE", "LATTICE", "LATTICE"),
            'fontrestrictor': ("OUTLINER_OB_FONT", "FONT", "FONT"),
            'metarestrictor': ("OUTLINER_OB_META", "META_DATA", "META"),
            'surfrestrictor': ("SURFACE", "SURFACE_DATA", "SURFACE"),
            'speakrestrictor': ("OUTLINER_OB_SPEAKER", "SPEAKER", "SPEAKER"),
            }

        for prop, values in datas.items():
            icon_i, icon_a, types = values
            get_props = bpy.context.scene.get(prop)

            gl_icon = icon_a if get_props else icon_i

            for ob in bpy.context.scene.objects:
                if ob.type == types:
                    if ob.get('ignore_restrictors') is None:
                        ob.hide_select = False if get_props is None else True
                        if get_props is None:
                            ob.select = False

            mesh = gl_icon if types == "MESH" else mesh
            curve = gl_icon if types == "CURVE" else curve
            arm = gl_icon if types == "ARMATURE" else arm
            empty = gl_icon if types == "EMPTY" else empty
            cam = gl_icon if types == "CAMERA" else cam
            lamp = gl_icon if types == "LIGHT" else lamp
            lat = gl_icon if types == "LATTICE" else lat
            font = gl_icon if types == "FONT" else font
            meta = gl_icon if types == "META" else meta
            surf = gl_icon if types == "SURFACE" else surf
            speak = gl_icon if types == "SPEAKER" else speak

        return{'FINISHED'}


class RestrictorSelection(Menu):
    """Restrict Selection"""
    bl_label = "Selection"
    bl_idname = "RestrictorSelection"

    def draw(self, context):
        global mesh
        global curve
        global arm
        global empty
        global cam
        global lamp
        global lat
        global font
        global meta
        global surf
        global speak
        global show_buttons
        global show

        layout = self.layout

        layout.operator("restrictor.mesh", icon=mesh, text="Mesh")
        layout.operator("restrictor.curve", icon=curve, text="Curve")
        layout.operator("restrictor.arm", icon=arm, text="Armature")
        layout.operator("restrictor.empty", icon=empty, text="Empty")
        layout.operator("restrictor.cam", icon=cam, text="Camera")
        layout.operator("restrictor.light", icon=lamp, text="Lamp")
        layout.operator("restrictor.lat", icon=lat, text="Lattice")
        layout.operator("restrictor.font", icon=font, text="Font")
        layout.operator("restrictor.meta", icon=meta, text="MetaBall")
        layout.operator("restrictor.surf", icon=surf, text="Surface")
        layout.operator("restrictor.speak", icon=speak, text="Speaker")
        layout.separator()
        layout.operator("ignore.restrictors", icon='GHOST_ENABLED', text="Enable").ignore = True
        layout.operator("ignore.restrictors", icon='GHOST_DISABLED', text="Disable").ignore = False
        layout.operator("refresh.restrictors", icon='FILE_REFRESH', text="Refresh")


def view3d_select_menu(self, context):
    self.layout.menu(RestrictorSelection.bl_idname)


def register():
    bpy.types.VIEW3D_HT_header.append(view3d_select_menu)


def unregister():
    bpy.types.VIEW3D_HT_header.remove(view3d_select_menu)

    bpy.utils.unregister_class(RefreshRestrictors)


if __name__ == "__main__":
    register()

# update icons when opening file and updating scene data
# I don't know what does "updating scene data" mean
# But I've added it here to refresh icons while switching scenes
bpy.app.handlers.load_post.append(check_restrictors)
bpy.app.handlers.scene_update_post.append(check_restrictors)