← All ideas

Give "ProgressBar" for widget addon's etc.

Right now many add-ons processing and computing something, but GUI not showing the status and progress around. Eg. updating addon, ot other process can have "ProgressBar" but API must offer option to access for this addon and put on some place by selector/layout.

Still don't know why RCS not have category for API, add-on

100%

Development Status: Open

Upvote 1 Downvote 0
ManBlender
1 May 2024

1 Comment

Lauloque

We have UILayout.progress() , it was added in 4.0: #109882 .

Usage Example:

demo gif

import bpy


class ModalTimerOperator(bpy.types.Operator):
    bl_idname = "wm.modal_timer_operator"
    bl_label = "Modal Timer Operator"

    _timer = None

    def modal(self, context, event):
        [a.tag_redraw() for a in context.screen.areas]
        if self._timer.time_duration > 3:
            context.window_manager.progress = 1
            return {'FINISHED'}
        context.window_manager.progress = self._timer.time_duration / 3
        return {'PASS_THROUGH'}

    def execute(self, context):
        wm = context.window_manager
        self._timer = wm.event_timer_add(0.1, window=context.window)
        wm.modal_handler_add(self)
        return {'RUNNING_MODAL'}


def progress_bar(self, context):
    row = self.layout.row()
    row.progress(
        factor=context.window_manager.progress,
        type="BAR",
        text="Operation in progress..." if context.window_manager.progress < 1 else "Operation Finished !"
    )
    row.scale_x = 2


def register():
    bpy.types.WindowManager.progress = bpy.props.FloatProperty()
    bpy.utils.register_class(ModalTimerOperator)
    bpy.types.TEXT_HT_header.append(progress_bar)


if __name__ == "__main__":
    register()
    bpy.ops.wm.modal_timer_operator()

Source: Using new layout.progress() function in 4.0 - Coding / Python Support - Blender Artists Community


Before that we could show progress under the mouse cursor using WindowManager.progress_*

Usage example:

demo gif

import bpy, time
wm = bpy.context.window_manager

tot = 100
wm.progress_begin(0, tot)
for i in range(tot):
    wm.progress_update(i)
    time.sleep(0.03)
wm.progress_end()

Source: python - How to show to the user a progression in a script? - Blender Stack Exchange

3