Make vision client icon in taskbar flash when a tag changes

Hello,
I am trying to make the icon on the taskbar flash during any tag change. This is to notify the user when the vision client is minimized that some change has happened in the background.

1 Like

You would use something like this:

from java.awt import Window
from javax.swing import SwingUtilities

allWindows = system.gui.getOpenedWindows()

if len(allWindows)>0:
    topWindow = SwingUtilities.getAncestorOfClass(Window, allWindows[0])
    topWindow.toFront()

but you would want to have some property change scripts and maybe put this in a custom method to call whenever. This will allow you to only notify for updates of tags on the page based on what you configure to actually fire this event.

credit:

1 Like

This works quite well and definitely meets the OPs requirements for a solution. Although, for this use case, I would write it like this:

# Written for the property change event handler of a component
# ...with a tag bound custom property named tagValue
if event.propertyName == 'tagValue':
	from javax.swing import JFrame, SwingUtilities
		
	# Get the parent window's JFrame, and bring it to the front
	window = SwingUtilities.getAncestorOfClass(JFrame, system.gui.getParentWindow(event))
	window.toFront()

Result:
Flashing Task Bar

The only limitation I found when I tested this is that if the window already has focus, the icon doesn't flash. With Vision, I often like to customize my desktop icons, and one thing I like about it is that the window icon always matches the taskbar icon, so an alternative flashing effect can be created by simply having a brighter version of the existing icon or some alternate icon, and swapping them out at a steady frequency. Moreover, this flashing effect will occur whether or not the window has focus.
Example:

# Wrtten for a propertyChange event handler of a component
# ...with a tag bound custom property named tagValue
if event.propertyName == 'tagValue':
	from javax.swing import JFrame, SwingUtilities
	from com.inductiveautomation.ignition.client.images import ImageLoader
	
	
	# Get the main window's JFrame
	window = SwingUtilities.getAncestorOfClass(JFrame, system.gui.getParentWindow(event))
	
	# Get the standard window icon, and some other icon (Perhaps just a brighter version of the existing one)
	iconOne = window.iconImage
	iconTwo = ImageLoader.getInstance().loadImage('Builtin/icons/48/warning.png')
	
	def toggleIcons():
		if window.iconImage == iconOne:
			window.iconImage = iconTwo
		else:
			window.iconImage = iconOne
	
	
	# Schedule the icon swaps 200ms apart to create a flashing effect
	for multiplier in xrange(10):
		system.util.invokeLater(toggleIcons, multiplier * 200)
	
	# Restore the original icon
	window.iconImage = iconOne

Result:
Flashing Icon

2 Likes