Here is my way of doing this. I wrote this when 7.0 came out, so I would expect there are quite a few upgrades.
The benefit of this method is the toast notification will pop up outside of the Ignition window, so if the user is browsing the web, watching porn, etc, this will pop up on top of that.
Call the method with path.to.createNotifier()
notifiers = []
def createNotifier(title="Hello", bodyText="World", time = 5000, bgColor=None, textColor=None):
from javax.swing import JFrame,JLabel,JTextArea,JButton
from javax.swing.border import LineBorder
from java.awt import Dimension,Color,Font
from java.awt.geom import RoundRectangle2D
from net.miginfocom.swing import MigLayout
from com.inductiveautomation.ignition.client.images import PathIcon
from java.lang import Runnable
if not bgColor:
bgColor = Color.BLACK
if not textColor:
textColor = Color.WHITE
frame = JFrame(title)
frame.setAlwaysOnTop(True)
frame.setUndecorated(True)
frame.setMinimumSize(Dimension(300, 50))
frame.setMaximumSize(Dimension(300, 50))
frame.setSize(Dimension(300, 50))
frame.setFocusableWindowState(False)
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
frame.setOpacity(0.75)
pane = frame.getContentPane()
pane.setLayout(MigLayout("insets 5"))
pane.setBorder(LineBorder(Color(90, 90, 90)))
pane.setOpaque(True)
pane.setBackground(bgColor)
header = JLabel(title)
header.setForeground(textColor)
header.setFont(Font("Dialog", Font.PLAIN, 20))
body = JTextArea(bodyText)
body.setForeground(textColor)
body.setBackground(bgColor)
body.setFont(Font("Dialog", Font.PLAIN, 16))
body.setLineWrap(True)
body.setWrapStyleWord(True)
body.setEditable(False)
body.setOpaque(True)
pane.add(header);
def closeFrame(evt=None,frame=frame):
notifiers.remove(frame)
frame.dispose()
if len(notifiers):
orderNotifiers()
if time <= 0:
icon = PathIcon(frame,"Builtin/icons/16/delete2.png",16,16,True,True)
button = JButton(icon,actionPerformed=closeFrame)
button.setContentAreaFilled(False)
button.setBorder(None)
pane.add(button,"dock east,gap 5 5 5 5,alignx center,aligny center")
frame.pack()
body.setSize(frame.getWidth(), 1)
pane.add(body, "newline,span,push")
frame.pack()
shape = RoundRectangle2D.Float(0.0, 0.0,frame.getWidth(), frame.getHeight(), 15.0, 15.0)
frame.setShape(shape)
frame.setVisible(True)
notifiers.append(frame)
if time > 0:
system.util.invokeLater(closeFrame, time)
if len(notifiers):
orderNotifiers()
def orderNotifiers():
from java.awt import Toolkit
gc = getApp().getGraphicsConfiguration()
if gc:
sb = gc.getBounds()
x = sb.x + sb.width - 10
y = sb.y + 10
else:
ss = Toolkit.getDefaultToolkit().getScreenSize()
x = ss.width - 10
y = 10
for f in notifiers:
f.setLocation(x - f.getWidth(), y)
y += f.getHeight() + 10
def getApp():
from com.inductiveautomation.factorypmi.application import FPMIApp
return FPMIApp.getInstance()