UI: Move Extensions repositories popover to header
[blender-addons-contrib.git] / render_renderslot.py
blobecd068c05a1fef88c9e7e53106f66607b72a78cb
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 #####
19 import bpy
20 from bpy.types import Operator
21 from bpy.props import IntProperty, BoolProperty
22 from sys import platform
23 from bpy.app.handlers import persistent
26 bl_info = {
27 "name": "KTX RenderSlot",
28 "description": "Display/select renderslot in the render tab",
29 "author": "Roel Koster, @koelooptiemanna, irc:kostex",
30 "version": (1, 3, 4),
31 "blender": (2, 80, 0),
32 "location": "Properties Editor > Render > Render",
33 "warning": "",
34 "doc_url": "https://github.com/kostex/blenderscripts/",
35 "tracker_url": "https://developer.blender.org/maniphest/task/edit/form/2/",
36 "category": "Render"}
39 nullpath = '/nul' if platform == 'win32' else '/dev/null'
42 class OccupiedSlots:
43 data = '00000000'
46 class KTXRENDERSLOT_Prefs(bpy.types.AddonPreferences):
47 bl_idname = __name__
49 advanced_mode : bpy.props.BoolProperty(
50 name="Advanced Mode",
51 description="Gives the addon some advanced options",
52 default=False)
54 def draw(self, context):
55 layout = self.layout
56 layout.prop(self, "advanced_mode")
59 class KTXRENDERSLOT_OT_Select(Operator):
60 bl_label = "Select Render Slot"
61 bl_idname = "ktxrenderslot.select"
62 bl_description = ("Select Render Slot\n"
63 "Note: Dot next to number means slot has image data\n"
64 "[x] is active slot")
66 number : IntProperty()
68 def execute(self, context):
69 bpy.data.images['Render Result'].render_slots.active_index = self.number
71 return {'FINISHED'}
74 @persistent
75 def checkslots(scene):
76 img = bpy.data.images['Render Result']
77 active = img.render_slots.active_index
78 slots = ''
79 for i in range(0,len(img.render_slots)):
80 img.render_slots.active_index = i
81 try:
82 img.save_render(nullpath)
83 slots = slots + '1'
84 except RuntimeError:
85 slots = slots + '0'
87 if scene.ktx_auto_advance_slot:
88 active += 1
89 if active == len(img.render_slots):
90 img.render_slots.new()
91 slots = slots + '0'
93 scene.ktx_occupied_render_slots.data = slots
94 img.render_slots.active_index = active
97 def ui(self, context):
98 scn = context.scene
99 layout = self.layout
100 row = layout.row(align=True)
101 row.alignment = 'LEFT'
102 img = bpy.data.images['Render Result']
103 active = img.render_slots.active_index
104 if bpy.context.preferences.addons[__name__].preferences.advanced_mode:
105 row.prop(scn, 'ktx_auto_advance_slot', text='Auto Advance')
106 items = 0
107 row = layout.row(align=True)
108 row.alignment = 'EXPAND'
109 for i in range(0,len(img.render_slots)):
110 is_active = bool(i == active)
111 test_active = bool(scn.ktx_occupied_render_slots.data[i] == '1')
112 icons = "LAYER_ACTIVE" if test_active else "BLANK1"
113 label = "[{}]".format(str(i + 1)) if is_active else str(i + 1)
114 row.operator('ktxrenderslot.select', text=label, icon=icons).number = i
115 items+=1
116 if items == 8:
117 items=0
118 row = layout.row(align=True)
119 row.alignment = 'EXPAND'
122 classes = (
123 KTXRENDERSLOT_OT_Select,
124 KTXRENDERSLOT_Prefs
128 def register():
129 from bpy.utils import register_class
131 bpy.types.RENDER_PT_context.prepend(ui)
132 bpy.types.Scene.ktx_auto_advance_slot = BoolProperty(default=False, description="Auto Advance to Next Slot after a Render")
133 bpy.types.Scene.ktx_occupied_render_slots = OccupiedSlots
135 bpy.app.handlers.render_post.append(checkslots)
137 for cls in classes:
138 register_class(cls)
141 def unregister():
142 from bpy.utils import unregister_class
144 bpy.types.RENDER_PT_context.remove(ui)
145 del bpy.types.Scene.ktx_occupied_render_slots
146 del bpy.types.Scene.ktx_auto_advance_slot
148 bpy.app.handlers.render_post.remove(checkslots)
150 for cls in classes:
151 unregister_class(cls)
154 if __name__ == "__main__":
155 register()