rna UI api rename...
[blender.git] / release / scripts / io / netrender / ui.py
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 import bpy
20 import sys, os
21 import http, http.client, http.server, urllib
22 import subprocess, shutil, time, hashlib
23
24 import netrender
25 import netrender.slave as slave
26 import netrender.master as master
27
28 from netrender.utils import *
29
30 VERSION = b"0.3"
31
32 PATH_PREFIX = "/tmp/"
33
34 QUEUED = 0
35 DISPATCHED = 1
36 DONE = 2
37 ERROR = 3
38
39 class RenderButtonsPanel(bpy.types.Panel):
40         bl_space_type = "PROPERTIES"
41         bl_region_type = "WINDOW"
42         bl_context = "render"
43         # COMPAT_ENGINES must be defined in each subclass, external engines can add themselves here
44         
45         def poll(self, context):
46                 rd = context.scene.render_data
47                 return (rd.use_game_engine==False) and (rd.engine in self.COMPAT_ENGINES)
48
49 # Setting panel, use in the scene for now.
50 @rnaType
51 class RENDER_PT_network_settings(RenderButtonsPanel):
52         bl_label = "Network Settings"
53         COMPAT_ENGINES = set(['NET_RENDER'])
54
55         def draw(self, context):
56                 layout = self.layout
57
58                 scene = context.scene
59                 rd = scene.render_data
60                 
61                 layout.active = True
62                 
63                 split = layout.split()
64                 
65                 col = split.column()
66                 col.prop(scene.network_render, "mode")
67                 col.prop(scene.network_render, "path")
68                 col.prop(scene.network_render, "server_address")
69                 col.prop(scene.network_render, "server_port")
70                 
71                 if scene.network_render.mode == "RENDER_MASTER":
72                         col.prop(scene.network_render, "server_broadcast")
73                 else:
74                         col.operator("render.netclientscan", icon="ICON_FILE_REFRESH", text="")
75
76 @rnaType
77 class RENDER_PT_network_job(RenderButtonsPanel):
78         bl_label = "Job Settings"
79         COMPAT_ENGINES = set(['NET_RENDER'])
80         
81         def poll(self, context):
82                 scene = context.scene
83                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
84
85         def draw(self, context):
86                 layout = self.layout
87
88                 scene = context.scene
89                 rd = scene.render_data
90                 
91                 layout.active = True
92                 
93                 split = layout.split()
94                 
95                 col = split.column()
96                 col.operator("render.netclientanim", icon='ICON_RENDER_ANIMATION')
97                 col.operator("render.netclientsend", icon="ICON_FILE_BLEND")
98                 col.operator("render.netclientweb", icon="ICON_QUESTION")
99                 col.prop(scene.network_render, "job_name")
100                 row = col.row()
101                 row.prop(scene.network_render, "priority")
102                 row.prop(scene.network_render, "chunks")
103
104 @rnaType
105 class RENDER_PT_network_slaves(RenderButtonsPanel):
106         bl_label = "Slaves Status"
107         COMPAT_ENGINES = set(['NET_RENDER'])
108         
109         def poll(self, context):
110                 scene = context.scene
111                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
112
113         def draw(self, context):
114                 layout = self.layout
115                 
116                 scene = context.scene
117                 netsettings = scene.network_render
118
119                 row = layout.row()
120                 row.template_list(netsettings, "slaves", netsettings, "active_slave_index", rows=2)
121
122                 sub = row.column(align=True)
123                 sub.operator("render.netclientslaves", icon="ICON_FILE_REFRESH", text="")
124                 sub.operator("render.netclientblacklistslave", icon="ICON_ZOOMOUT", text="")
125                 
126                 if len(netrender.slaves) == 0 and len(netsettings.slaves) > 0:
127                         while(len(netsettings.slaves) > 0):
128                                 netsettings.slaves.remove(0)
129                 
130                 if netsettings.active_slave_index >= 0 and len(netsettings.slaves) > 0:
131                         layout.separator()
132                         
133                         slave = netrender.slaves[netsettings.active_slave_index]
134
135                         layout.label(text="Name: " + slave.name)
136                         layout.label(text="Address: " + slave.address[0])
137                         layout.label(text="Seen: " + time.ctime(slave.last_seen))
138                         layout.label(text="Stats: " + slave.stats)
139
140 @rnaType
141 class RENDER_PT_network_slaves_blacklist(RenderButtonsPanel):
142         bl_label = "Slaves Blacklist"
143         COMPAT_ENGINES = set(['NET_RENDER'])
144         
145         def poll(self, context):
146                 scene = context.scene
147                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
148         
149         def draw(self, context):
150                 layout = self.layout
151                 
152                 scene = context.scene
153                 netsettings = scene.network_render
154
155                 row = layout.row()
156                 row.template_list(netsettings, "slaves_blacklist", netsettings, "active_blacklisted_slave_index", rows=2)
157
158                 sub = row.column(align=True)
159                 sub.operator("render.netclientwhitelistslave", icon="ICON_ZOOMOUT", text="")
160
161                 if len(netrender.blacklist) == 0 and len(netsettings.slaves_blacklist) > 0:
162                         while(len(netsettings.slaves_blacklist) > 0):
163                                 netsettings.slaves_blacklist.remove(0)
164                 
165                 if netsettings.active_blacklisted_slave_index >= 0 and len(netsettings.slaves_blacklist) > 0:
166                         layout.separator()
167                         
168                         slave = netrender.blacklist[netsettings.active_blacklisted_slave_index]
169
170                         layout.label(text="Name: " + slave.name)
171                         layout.label(text="Address: " + slave.address[0])
172                         layout.label(text="Seen: " + time.ctime(slave.last_seen))
173                         layout.label(text="Stats: " + slave.stats)
174
175 @rnaType
176 class RENDER_PT_network_jobs(RenderButtonsPanel):
177         bl_label = "Jobs"
178         COMPAT_ENGINES = set(['NET_RENDER'])
179         
180         def poll(self, context):
181                 scene = context.scene
182                 return super().poll(context) and scene.network_render.mode == "RENDER_CLIENT"
183         
184         def draw(self, context):
185                 layout = self.layout
186                 
187                 scene = context.scene
188                 netsettings = scene.network_render
189
190                 row = layout.row()
191                 row.template_list(netsettings, "jobs", netsettings, "active_job_index", rows=2)
192
193                 sub = row.column(align=True)
194                 sub.operator("render.netclientstatus", icon="ICON_FILE_REFRESH", text="")
195                 sub.operator("render.netclientcancel", icon="ICON_ZOOMOUT", text="")
196                 sub.operator("render.netclientcancelall", icon="ICON_PANEL_CLOSE", text="")
197                 sub.operator("render.netclientdownload", icon='ICON_RENDER_ANIMATION', text="")
198
199                 if len(netrender.jobs) == 0 and len(netsettings.jobs) > 0:
200                         while(len(netsettings.jobs) > 0):
201                                 netsettings.jobs.remove(0)
202                 
203                 if netsettings.active_job_index >= 0 and len(netsettings.jobs) > 0:
204                         layout.separator()
205                         
206                         job = netrender.jobs[netsettings.active_job_index]
207
208                         layout.label(text="Name: %s" % job.name)
209                         layout.label(text="Length: %04i" % len(job))
210                         layout.label(text="Done: %04i" % job.results[DONE])
211                         layout.label(text="Error: %04i" % job.results[ERROR])
212
213 @rnaType
214 class NetRenderSettings(bpy.types.IDPropertyGroup):
215         pass
216
217 @rnaType
218 class NetRenderSlave(bpy.types.IDPropertyGroup):
219         pass
220
221 @rnaType
222 class NetRenderJob(bpy.types.IDPropertyGroup):
223         pass
224
225 bpy.types.Scene.PointerProperty(attr="network_render", type=NetRenderSettings, name="Network Render", description="Network Render Settings")
226
227 NetRenderSettings.StringProperty( attr="server_address",
228                                 name="Server address",
229                                 description="IP or name of the master render server",
230                                 maxlen = 128,
231                                 default = "[default]")
232
233 NetRenderSettings.IntProperty( attr="server_port",
234                                 name="Server port",
235                                 description="port of the master render server",
236                                 default = 8000,
237                                 min=1,
238                                 max=65535)
239
240 NetRenderSettings.BoolProperty( attr="server_broadcast",
241                                 name="Broadcast server address",
242                                 description="broadcast server address on local network",
243                                 default = True)
244
245 default_path = os.environ.get("TEMP", None)
246
247 if not default_path:
248         if os.name == 'nt':
249                 default_path = "c:/tmp/"
250         else:
251                 default_path = "/tmp/"
252 elif not default_path.endswith(os.sep):
253         default_path += os.sep
254
255 NetRenderSettings.StringProperty( attr="path",
256                                 name="Path",
257                                 description="Path for temporary files",
258                                 maxlen = 128,
259                                 default = default_path)
260
261 NetRenderSettings.StringProperty( attr="job_name",
262                                 name="Job name",
263                                 description="Name of the job",
264                                 maxlen = 128,
265                                 default = "[default]")
266
267 NetRenderSettings.IntProperty( attr="chunks",
268                                 name="Chunks",
269                                 description="Number of frame to dispatch to each slave in one chunk",
270                                 default = 5,
271                                 min=1,
272                                 max=65535)
273
274 NetRenderSettings.IntProperty( attr="priority",
275                                 name="Priority",
276                                 description="Priority of the job",
277                                 default = 1,
278                                 min=1,
279                                 max=10)
280
281 NetRenderSettings.StringProperty( attr="job_id",
282                                 name="Network job id",
283                                 description="id of the last sent render job",
284                                 maxlen = 64,
285                                 default = "")
286
287 NetRenderSettings.IntProperty( attr="active_slave_index",
288                                 name="Index of the active slave",
289                                 description="",
290                                 default = -1,
291                                 min= -1,
292                                 max=65535)
293
294 NetRenderSettings.IntProperty( attr="active_blacklisted_slave_index",
295                                 name="Index of the active slave",
296                                 description="",
297                                 default = -1,
298                                 min= -1,
299                                 max=65535)
300
301 NetRenderSettings.IntProperty( attr="active_job_index",
302                                 name="Index of the active job",
303                                 description="",
304                                 default = -1,
305                                 min= -1,
306                                 max=65535)
307
308 NetRenderSettings.EnumProperty(attr="mode",
309                                                 items=(
310                                                                                 ("RENDER_CLIENT", "Client", "Act as render client"),
311                                                                                 ("RENDER_MASTER", "Master", "Act as render master"),
312                                                                                 ("RENDER_SLAVE", "Slave", "Act as render slave"),
313                                                                         ),
314                                                 name="Network mode",
315                                                 description="Mode of operation of this instance",
316                                                 default="RENDER_CLIENT")
317
318 NetRenderSettings.CollectionProperty(attr="slaves", type=NetRenderSlave, name="Slaves", description="")
319 NetRenderSettings.CollectionProperty(attr="slaves_blacklist", type=NetRenderSlave, name="Slaves Blacklist", description="")
320 NetRenderSettings.CollectionProperty(attr="jobs", type=NetRenderJob, name="Job List", description="")
321
322 NetRenderSlave.StringProperty( attr="name",
323                                 name="Name of the slave",
324                                 description="",
325                                 maxlen = 64,
326                                 default = "")
327
328 NetRenderJob.StringProperty( attr="name",
329                                 name="Name of the job",
330                                 description="",
331                                 maxlen = 128,
332                                 default = "")