Page 1 of 1

CopyFile and Progressbar

Posted: Wed Mar 04, 2026 10:55 pm
by walkero
Hello guys.
I am having a RapaGUI window with a progressbar, which I am trying to fill up while CopyFile is copying files. I do this on Linux with Gnome 3.
I use the Callback for CopyFile, but it seems that while the CopyFile is working, although I get the right information in DebugMessages (copied and filesize), it seems that RapaGUI is freezed. I even get a Linux window that asks me to terminate the application, as it seems frozen.

Here is the callback I am using

Code: Select all

Function p_CopyCallback(msg)
	Switch msg.action
	Case #COPYFILE_STATUS:
		Local percent = Ceil(msg.copied / msg.filesize * 100)
		moai.Set("prgbarCopy", "Level", percent)
		DebugPrint("Now copying", FilePart(msg.source), "to", PathPart(msg.destination), ": ", msg.Copied, " of ", msg.Filesize)
	EndSwitch
	Return(False)
EndFunction
which I call like:

Code: Select all

CopyFile(FullPath(srcPath$, fname$), destPath$, {Callback = p_CopyCallback})
Currently, the progressbar get to 100 when the copy of the file is finished. It freezes there and then updates when the next copy is complete.
Does anyone know if I need to do something else to have it working properly, showing the progressbar moving while the file is copied?

Re: CopyFile and Progressbar

Posted: Thu Mar 05, 2026 8:51 pm
by plouf
Yes
You should update rapagui view e.g. progressbar
with RunCallback()

Re: CopyFile and Progressbar

Posted: Thu Mar 05, 2026 10:23 pm
by plouf
hm you are right, CopyFile() it self is an exception and updates itself
i try following example and progressbar works (windows 11)

Code: Select all

@REQUIRE "RapaGUI"
filesource$="H:\\Users\\plouf\\Downloads\\a.exe"
filedest$ = "h:\\"

moai.CreateApp([[
<?xml version="1.0" encoding="iso-8859-1"?>
<application>
	 <window title="Test program">
			<vgroup>
		    <button id="copyfile">Copy File</button>
				<progressbar id="busybar1" max="100"/>
			</vgroup>
	 </window>
</application>
]])

Function p_EventFunc(msg)
	If msg.id="copyfile"
		CopyFile(filesource$, filedest$, {CallBack = p_CopyCallback})
	EndIf
EndFunction


Function p_CopyCallback(msg)
	If msg.action = #COPYFILE_STATUS
		percent = Ceil(msg.copied / msg.filesize * 100)
		moai.Set("busybar1","level",percent)
	EndIf
EndFunction	

InstallEventHandler({RapaGUI = p_EventFunc})

Repeat
	WaitEvent
Forever 

Re: CopyFile and Progressbar

Posted: Sat Mar 07, 2026 11:25 am
by walkero
Thank you plouf for your reply.
On Manjaro with Gnome 3 your example doesn't work. It starts the copy of the file and the progress bar remains empty It fills to the 100% when the copy is finished. Which is exactly what my code does as well.

Re: CopyFile and Progressbar

Posted: Sun Mar 08, 2026 4:23 pm
by airsoftsoftwair
walkero wrote: Sat Mar 07, 2026 11:25 am On Manjaro with Gnome 3 your example doesn't work. It starts the copy of the file and the progress bar remains empty It fills to the 100% when the copy is finished. Which is exactly what my code does as well.
You must use RunCallback() to make this work everywhere. Even if plouf's version works correctly on Windows, it's not a safe approach for all platforms. Set the "Async" tag to TRUE in CopyFile() and then use RunCallback() to repeatedly run a callback that calls ContinueAsyncOperation() and updates the progress bar until the copy operation is finished. This is the only safe way to do it because it's the only method that returns control to the main loop so that the GUI can update itself. If you just update the progress bar from a CopyFile() status callback, the main loop won't get any chance to update the GUI.

Re: CopyFile and Progressbar

Posted: Tue Mar 24, 2026 9:29 pm
by walkero
Thank you guys for your help. I did it how airsoftsoftwair proposed to be done and it works now.