import time
import bpy

def get_context_window():
   for window in bpy.context.window_manager.windows:
      if window:
         return window
   return None

def setStatus(msg:str, immediate:bool=False):
   if immediate:
      bpy.context.workspace.status_text_set(msg)
   else:
      bpy.app.timers.register(lambda: bpy.context.workspace.status_text_set(msg), first_interval=0.0)


# import bpy
# from functools import partial

# def show_progress(area):
#     if show_progress.iteration >= 100:
#         area.header_text_set(None)
#         return
#     else:
#         area.header_text_set(f'Loading {show_progress.iteration}%')
#         show_progress.iteration += 0.5
#         return 0.01

# show_progress.iteration = 0
# bpy.app.timers.register(partial(show_progress, bpy.context.area))

# Start the progress bar
# bpy.context.window_manager.progress_begin(0, 100)

# for i in range(100):
#     # Update the progress bar
#     bpy.context.window_manager.progress_update(i)

#     # Do some work here
#     time.sleep(1)

# # End the progress bar
# bpy.context.window_manager.progress_end()