Using Java and Jython in ignition

Please someone show me how to get this to work inside an ignition window.

jython.org/jythonbook/en/1.0 … tions.html

from javax.swing import JButton, JFrame

frame = JFrame('Hello, Jython!',
            defaultCloseOperation = JFrame.EXIT_ON_CLOSE,
            size = (300, 300)
        )

def change_text(event):
    print 'Clicked!'

button = JButton('Click Me!', actionPerformed=change_text)
frame.add(button)
frame.visible = True

Put that in the OnPaint event of a PaintableCanvas component in the designer.

My only option is the repaint event. I get the following error.

Traceback (innermost last):
File “event:repaint”, line 14, in ?
NameError: True

at org.python.core.Py.NameError(Py.java)
at org.python.core.PyFrame.getglobal(PyFrame.java)
at org.python.core.PyFrame.getname(PyFrame.java)
at org.python.pycode._pyx68.f$0(<event:repaint>:14)
at org.python.pycode._pyx68.call_function(<event:repaint>)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at com.inductiveautomation.ignition.common.script.ScriptManager.runCode(ScriptManager.java:395)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.runActions(ActionAdapter.java:139)
at com.inductiveautomation.factorypmi.application.binding.action.ActionAdapter.invoke(ActionAdapter.java:247)
at com.inductiveautomation.factorypmi.application.binding.action.RelayInvocationHandler.invoke(RelayInvocationHandler.java:55)
at $Proxy7.repaint(Unknown Source)
at com.inductiveautomation.factorypmi.application.components.PMIPaintableCanvas.paintComponent(PMIPaintableCanvas.java:122)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at com.inductiveautomation.vision.api.client.components.model.AbstractVisionPanel.paintChildren(AbstractVisionPanel.java:222)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Ignition v7.3.3 (b570)
Java: Sun Microsystems Inc. 1.6.0_29


Jython doesn’t define “True” or “False” as constant variables. Changing frame.visible = True to frame.visible = 1 makes it work.

That worked with 1 instead of True. The script above came from they jython site and they used True in their example. Maybe a JFrame isn’t what I am looking for. I need it to fill the paintable canvas or empty container, not pop out like this JFrame example does.

I am getting frustrated with this. I wish I would have stuck with php or .net. Or even a LogiXML type app. My PLC guy talked me into using this because we could display his PLC info and create a complete data driven application with a GUI that was easily to customize. Other than the cookie cutter stuff here, this is not so easy to customize.

[quote=“ecujak”]That worked with 1 instead of True. The script above came from they jython site and they used True in their example. Maybe a JFrame isn’t what I am looking for. I need it to fill the paintable canvas or empty container, not pop out like this JFrame example does.

I am getting frustrated with this. I wish I would have stuck with php or .net. Or even a LogiXML type app. My PLC guy talked me into using this because we could display his PLC info and create a complete data driven application with a GUI that was easily to customize. Other than the cookie cutter stuff here, this is not so easy to customize.[/quote]

What kind of UIs are you looking to create?

I believe ecujak wants to insert a JButton inside the paintable canvas (not create a new JFame popup). Is it possible do this? Also is it possible to insert a JRadioButton or JCheckBox inside a paintable canvas?

Yes. I am glad someone is seeing what I am looking for. I am not the best communicator, I am sorry.

I want to be able to get a dataset based on whatever query my filters generate. I want to display each record of that dataset in a way that will be user friendly with whatever logic or presentation I want to use. The rigid table view option available out of the box from ignition isn’t going to work for me.

For each record I want to display Buttons(edit, delete, toggle, check box radio, dropdown), text, text boxes, and other items with nice looking formatting and flow based on record by record and item by item logic.

Ignition may be able to do all of this, but if it is… it is not documented very well. There are not very many examples and the examples that are there are only a hint of what is needed.

I don’t need java or jython. If I could just script the building of the components available in ignition, that would be enough.

The problem is right now you cannot dynamically add Ignition components to the runtime. If you don’t use the table you have to add enough components for the max case and make them visible when needed.

Really?

Anyhow, I think you’re a bit off track in how you’re approaching the problem. When you start talking about the paintable canvas, you’re quickly getting into territory where you’re going to have to fend for yourself. Frankly, I don’t know why the paintable canvas is included as part of the standard components- it really requires quite a bit of expertise to use.

Traditionally, what you want to do is accomplish by using break-out edit forms. In other words, you have some sort of selection mechanism (a table, a list, etc.), and then you have components on the window, which reference the current selection. If you have different types of edit scenarios, you can break out the editing to a different window, and open the correct one for the selected type, or create different panels on a screen, and only make the applicable panel visible.

Ultimately, Ignition offers very little support for dynamically generating displays. Better support for this is occasionally requested, but perhaps not as often as you might imagine.

Let me know if this makes sense, or if you don’t think it would work for some reason.

Regards,