Jump to content

Displaying Animation Dialog While Executing a Process


---
 Share

Recommended Posts

Hello everyone,

I'm facing an issue while attempting to implement a feature in my Python application. The desired outcome is to have a process running a specific task, while the frontend presents a GIF animation dialog to the user. I've extracted each frame of the GIF, stored them in a list, and used a dialog with a timer to display the animation.

def get_gif_frames(gif_path):
	gif = imageio.get_reader(gif_path)
	frames = [Image.fromarray(frame) for frame in gif]
	return frames

def convert_frames_to_bytes(frames):
	frame_bytes_list = []

	for frame in frames:
		buffered = io.BytesIO()
		frame.save(buffered, format="PNG")
		frame_bytes_list.append(buffered.getvalue())

	return frame_bytes_list

gif_path = gom.app.resource[":cloud_update/data.gif"]
frames = get_gif_frames(gif_path)
frame_bytes_list = convert_frames_to_bytes(frames)
DIALOG=gom.script.sys.create_user_defined_dialog (dialog={
	"content": [
		[
			{
				"columns": 1,
				"data": "AAAAAA==",
				"file_name": "",
				"height": 0,
				"keep_aspect": True,
				"keep_original_size": True,
				"name": "image",
				"rows": 1,
				"system_image": "system_message_warning",
				"tooltip": {
					"id": "",
					"text": "",
					"translatable": True
				},
				"type": "image",
				"use_system_image": False,
				"width": 0
			}
		]
	],
	"control": {
		"id": "Empty"
	},
	"embedding": "",
	"position": "",
	"size": {
		"height": 121,
		"width": 236
	},
	"sizemode": "automatic",
	"style": "",
	"title": {
		"id": "",
		"text": "Dialog Title",
		"translatable": True
	}
})

frame = 0
DIALOG.timer.enabled = True
DIALOG.timer.interval = 20

def dialog_event_handler (widget):
	global frame
	if str(widget) == 'timer'
		if frame == len(frame_bytes_list)-1:
			frame = 0
		
		DIALOG.image.data = frame_bytes_list[frame]
		frame += 1
		
DIALOG.handler = dialog_event_handler
gom.script.sys.show_user_defined_dialog (dialog=DIALOG)

## process start ##
## here            ##
## process finish ##
gom.script.sys.close_user_defined_dialog (dialog=DIALOG)

However, I've noticed that the info dialog does not seem to respond to the timer, preventing the frontend from displaying the animation. Is it possible to achieve this using the dialog module? If so, could you provide guidance on how to make it work?

Thank you in advance for your assistance.

Link to comment
Share on other sites

 Share

×
×
  • Create New...