Where is this code? In the paint method? If so, break it up so your db query runs separately (on some propertyChange) to obtain and set the client property. Say, on your Documents table, have a propertyChange that does most of the work, but only on image change, like so:
if event.propertyName == 'id':
from javax.imageio import ImageIO
from java.io import ByteArrayInputStream
blob = system.db.runPrepQuery(“SELECT file FROM magna_silao.documents where id= ?”, [event.newValue])
bytes = blob[0][0]
image = ImageIO.read(ByteArrayInputStream(bytes))
canvas = event.source.parent.getComponent("Paintable canvas")
canvas.putClientProperty("cached-image", image)
canvas.repaint()
Then your paint event only has to paint, and only if the cached image has been processed:
image = self.getClientProperty(“cached-image”)
if image:
event.graphics.drawImage(image, 0, 0, event.source)
Note that painting can be called really often – any time the anything obscures the canvas or updated. Or various window/container events.
{ Also, when pasting code or other plain text in the forum, use a line with just three backquotes above the code, and again below the code, so it formats nicely. }