Manually calling repaint()

Hello again,

As was suggested to me in an earlier post, I am using two methods (reDraw(bytes) and repaint()) to paint paintable canvases.

I use reDraw(bytes) to apply a dynamic property to the paintable canvas which contains the byte data, and then repaint() uses the byte data to draw the image.

However, after changing the byte data to"None" (to display a blank image) it seems that my manual call of “repaint()” is not working (no errors, none of my print statements in repaint execute).

I have tried calling it from various locations such as from within the component itself (self.repaint()) and externally as well (event.source.parent.getComponent(“blah blah”).repaint()) and it seems that neither works.

It is not until repaint() is called automatically (for example when I scroll the screen) that the image updates to my “no image” default. Is there any reason that manually calling repaint may not work?

There are a number of contexts where scripts cannot output to the console – I believe repaint() is one of them. Consider using system.util.getLogger() and convert your print statements to calls. Also, within your repaint event, use try: – except: to pick up any exceptions and send those to your logger as well.

Thanks for your response.

However I have the same issue with and no extra data is being provided through error handling. When repaint() is called automatically the print statements and everything works, it’s just my manual call that doesn’t seem to be working.

Here’s what the output looks like:

Function reDraw(bytes)

_ … _
_ else:_
_“drawing blank image”)_
_ self.putClientProperty(“img-bytes-cached”,None)_
_ try:_
_ self.repaint()_
_ except BaseException, ex:_
_ system.gui.messageBox(ex)_
_“reDraw called repaint()”)_
Function repaint()“repaint() called”)
_ …_
_ …_

drawing blank image
reDraw called repaint()

after scrolling the screen I’ll see:
repaint() called
repaint() called
repaint() called
… etc

Get rid of the call to system.gui.messageBox(). Use

Actually, do this:

   import sys

You may be getting a Java exception that doesn’t subclass from python’s BaseException.

1 Like

I like creating a an integer custom property on the painntable canvas called Refresh.
Inside the scripting of the canvas, I “use” that Refresh property. Whenever I want to refresh, I increment the value of Refresh.


You keep talking about the “repaint” method. Do you really mean the paintable canvas’s “repaint” event script? They are not the same thing.

Yes I am talking about the paintable canvas “repaint” event script. I have more experience in Java than ignition so I figured they are the same or at least very similar in function. I am curious as to why I can’t call it manually. I have a functioning workaround, but I’d still like to know.

Ok. Technically, you can call “repaint” manually. In fact, you are! It’s just that it doesn’t do anything useful, and you’re not calling what you think you’re calling. You’re calling the “repaint” method on java.awt.Component, a method that all components happen to have. This method simply tells the repaint manager to repaint the component at some later time. This is partially why your console printing method won’t work like you think it should - it’s not synchronous.

The “paintable canvas” component of ours has a “repaint” event, which is totally not the same thing. This is an event that the canvas component fires when its “paintComponent” method is called (which you can’t call - it’s called by Swing).

Long story short: the best way to use the paintable canvas is to have some custom property (or properties) that govern what the paintable canvas should be painting. Every time you change a custom property the paintable canvas paints itself. calling self.repaint() should schedule it for painting too, if it’s eligible for painting at the moment, but, you really shouldn’t need to call this by hand.


That makes sense, thanks for the explanation :slight_smile: