forked from benrugg/AI-Render
-
Notifications
You must be signed in to change notification settings - Fork 0
/
progress_bar.py
114 lines (94 loc) · 3.54 KB
/
progress_bar.py
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
# Original code by Michel Anders (@varkenvarken). Modified by Ben Rugg (@benrugg).
#
# See:
# https://blog.michelanders.nl/2017/04/how-to-add-progress-indicator-to-the-info-header-in-blender.html
# and
# https://raw.githubusercontent.com/varkenvarken/blenderaddons/master/reportpanel.py
#
# (c) 2017,2021 Michel Anders
#
# 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 3 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.
import bpy
import threading
# function to tag all info areas for redraw
def tag_image_editor_areas_for_redraw(self, context):
window = context.window
if window:
areas = context.window.screen.areas
for area in areas:
if area.type == 'IMAGE_EDITOR':
area.tag_redraw()
# a variable where we can store the original draw funtion
info_header_draw = lambda s,c: None
# function to hide progress bar
def hide_progress_bar():
bpy.context.scene.air_progress = -1
# public functions:
def hide_progress_bar_after_delay(seconds = 4):
timer = threading.Timer(seconds, hide_progress_bar)
timer.start()
def register():
# a value between [0, 100] will show the slider
bpy.types.Scene.air_progress = bpy.props.FloatProperty(
default=-1,
subtype='PERCENTAGE',
precision=0,
min=-1,
soft_min=0,
soft_max=100,
max=101,
update=tag_image_editor_areas_for_redraw,
)
# progress bar label can be configured
bpy.types.Scene.air_progress_label = bpy.props.StringProperty(
default="Progress",
update=tag_image_editor_areas_for_redraw,
)
# add an optional status message before the progress bar
bpy.types.Scene.air_progress_status_message = bpy.props.StringProperty(
default="",
update=tag_image_editor_areas_for_redraw,
)
# save the original draw method of the Info header
global info_header_draw
info_header_draw = bpy.types.IMAGE_HT_tool_header.draw
# create a new draw function
def newdraw(self, context):
global info_header_draw
# first call the original stuff
info_header_draw(self, context)
# then add the prop that acts as a progress indicator, if progress is in the
# range [0, 100]
if (
context.scene.air_progress >= 0 and
context.scene.air_progress <= 100
):
self.layout.separator()
self.layout.label(text=context.scene.air_progress_status_message)
self.layout.prop(
context.scene,
"air_progress",
text=context.scene.air_progress_label,
slider=True,
)
# replace the draw function
bpy.types.IMAGE_HT_tool_header.draw = newdraw
def unregister():
global info_header_draw
bpy.types.IMAGE_HT_tool_header.draw = info_header_draw
del bpy.types.Scene.air_progress
del bpy.types.Scene.air_progress_label
del bpy.types.Scene.air_progress_status_message