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