Show progress bar during report loading

The whole point is to use system.util.invokeLater and system.util.invokeAsynchronous.
On my template, I created a custom property progressValue:


Then in my template button, I update THAT custom property:

On my window where the template is, that template has now property progressValue:

And the Progress Bar Value property

is binded to that template property:

1 Like

yes its working fine… but i have scripts in mouse clicked … once its running my window getting hang and once its fully executed i am getting data in report. so only asked whether its possible use your script in-between in my script…

It doesn’t matter if it is in actionPerformed or mouseClicked.
The point is that YOU must construct your button script inside a function (like I did; def longProcess)
and then call that function at the end with system.util.invokeAsynchronous.
Inside your function, you must use system.util.invokeLater to update the template custom property.

Ok thanks i will try out

Maybe something like this:

def longProcess(rootContainer = event.source.parent):
	SelectedReport = system.tag.read("[default]Common/Dynamic Report/Selected_Report").value
	plantname = system.tag.read("[client]Plant_Name").value
	Header_kWh = system.tag.read("[default]Common/Dynamic Report/Report_header_m2_MeterConsumption").value
	Header_kWhTON = system.tag.read("[default]Common/Dynamic Report/Report_header_kWhTON_MeterConsumption").value
	plant = plantname.replace(" Line", "")
	params = {"plantname":plantname}
	Database = system.db.runNamedQuery(project = "Metriks_Dev", path = "EMS/EM_DynamicReport_DB_Select", parameters = params)
	Database = Database.getValueAt(0,0)
	Unit =  event.source.parent.getComponent('Dropdown_Unit').selectedStringValue
	if SelectedReport == "Meter Consumption Report" and plantname!= "Robertsbridge Line":
		first = event.source.parent.getComponent('Popup Calendar_StartDate').date
		second = event.source.parent.getComponent('Popup Calendar_EndDate').date
	
		start = event.source.parent.getComponent('Popup Calendar_StartDate').date
		event.source.parent.parent.StartDate = start
		end = event.source.parent.getComponent('Popup Calendar_EndDate').date
		event.source.parent.parent.EndDate = end
		endTime = second
		startTime = first
		ReportDS = system.tag.read('[default]Common/Dynamic Report/Report_header_name').value
		ReportDS = system.dataset.clearDataset(ReportDS)
		if Unit == 'kWh':
			TagUnit = 'Total_Consumption_kWh'
			path = "EMS/EM_DynamicReport_kwhm2_MeterConsumption"
			system.tag.write('[default]Common/Dynamic Report/Report_header_MeterConsumption',Header_kWh)
		if Unit == 'kWh/T':
			TagUnit = 'Total_Consumption_kWh_TON'
			path = "EMS/EM_DynamicReport_kwhTON_MeterConsumption"
			system.tag.write('[default]Common/Dynamic Report/Report_header_MeterConsumption',Header_kWhTON)
	
					
		Site_Electric = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/Total_Consumption/'+TagUnit+''
		params = {"database":Database, "tagpath": Site_Electric, "startDate":startTime,"endDate":endTime}
		print '...site electric.....'
		print params
		dataSet = system.db.runNamedQuery(project = "Metriks_Dev", path = path, parameters = params)
		delta = dataSet.getValueAt(0, 0)
		print delta
		newRow = ["Site_Electric","-","-","-",delta]
		ReportDS = system.dataset.addRow(ReportDS, newRow)
		Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'
		results = system.tag.browse(Path, {"tagType":"Folder","recursive":False}).results
		for result in results:
			if result.get("name"):
				Workshops = str(result['name'])
				Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/Total_Consumption/'+TagUnit+''
				params = {"database":Database, "tagpath": Path, "startDate":startTime,"endDate":endTime}
				dataSet = system.db.runNamedQuery(project = "Metriks_Dev", path = path, parameters = params)
				delta = dataSet.getValueAt(0, 0)
				newRow = [Workshops,"-","-","-",delta]
				ReportDS = system.dataset.addRow(ReportDS, newRow)
				Path = Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'	
				Workshop = system.tag.browse(Path, {"tagType":"Folder","recursive":False}).results
				for result in Workshop:
					Areas = str(result['name'])
					Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'+Areas+'/Total_Consumption/'+TagUnit+''
					params = {"database":Database, "tagpath": Path, "startDate":startTime,"endDate":endTime}
					dataSet = system.db.runNamedQuery(project = "Metriks_Dev", path = path, parameters = params)
					delta = dataSet.getValueAt(0, 0)
					newRow = ["-",Areas,"-","-",delta]
					ReportDS = system.dataset.addRow(ReportDS, newRow)
					Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'+Areas+'/'	
					Area = system.tag.browse(Path, {"tagType":"Folder","recursive":False}).results
					for result in Area:
						ProcessSteps = str(result['name'])
						Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'+Areas+'/'+ProcessSteps+'/Total_Consumption/'+TagUnit+''
						params = {"database":Database, "tagpath": Path, "startDate":startTime,"endDate":endTime}
						dataSet = system.db.runNamedQuery(project = "Metriks_Dev", path = path, parameters = params)
						delta = dataSet.getValueAt(0, 0)
						newRow = ["-","-",ProcessSteps,"-",delta]
						ReportDS = system.dataset.addRow(ReportDS, newRow)
						Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'+Areas+'/'+ProcessSteps+'/'			
						PS = system.tag.browse(Path, {"tagType":"Folder","recursive":False}).results			
						for result in PS:
							Equipments = str(result['name'])
							Path = '[MQTT Engine]Edge Nodes/'+plant+'/Energy/Reports/Static Reports/Electric/'+Workshops+'/'+Areas+'/'+ProcessSteps+'/'+Equipments+'/Total_Consumption/'+TagUnit+''
							params = {"database":Database, "tagpath": Path, "startDate":startTime,"endDate":endTime}
							dataSet = system.db.runNamedQuery(project = "Metriks_Dev", path = path, parameters = params)
							delta = dataSet.getValueAt(0, 0)
							newRow = ["-","-","-",Equipments,delta]
							ReportDS = system.dataset.addRow(ReportDS, newRow)
							
							progress = ??????????????
							#Here is progress send back to the template custom property
							#progress must be calculated somewhere before this call
							def sendBack(progress = progress, rootContainer = rootContainer):
								rootContainer.progressValue = progress
							# Now we'll send our results back to the UI.
							system.util.invokeLater(sendBack)
							
						system.tag.write('[default]Common/Dynamic Report/Report_header_name',ReportDS)
						window = system.gui.getParentWindow(event)
						window.getComponentForPath("Root Container.Report Viewer").reportPath = '' 
						window.getComponentForPath("Root Container.Report Viewer").reportPath = 'Meter Consumption Report'

system.util.invokeAsynchronous(longProcess) #Note that this is 'longProcess' instead of 'longProcess()'

But you must find the place where and how to calculate the progress and what it will represent…

1 Like

Another way of doing it is to use the animation features of the Progress Bar and let it continuously cycle until the long running process is complete.

Add a custom property ‘ShowProgress’ to the Progress Bar.
Then setup the Styles property something like this:

Then run this code:

def Complete():
	# stop the progress bar animation
	event.source.parent.getComponent('Progress Bar').ShowProgress = False

def RunTask():
	import time
	# long running task
	time.sleep(3)
	system.util.invokeLater(Complete)

# start the progress bar animation
event.source.parent.getComponent('Progress Bar').ShowProgress = True
system.util.invokeAsynchronous(RunTask)

1 Like

Psst! There’s an “Indeterminate” setting for that…

1 Like

True. There’s always a few options to achieve the same thing. The code is the same and that’s the point I was trying to make.