Images


ImageDemo

Default image support in appJar assumes no extra libraries. That means it should only support .GIF and .PPM images.
However, code is included to allow the use of .PNG and .JPG files. appJar will convert these to .GIF files, before loading.
Converting image files is SLOW, so it's best to stick to .GIF files!

Getting the path for images right can be TRICKY
It's therefore best to put images in the same folder as your Python code.
Or, create an image folder and set it using the .setImageLocation(location) function.

Add Images

app.startLabelFrame("Simple", 0, 0)
app.addImage("simple", "balloons.gif")
app.stopLabelFrame()

Change Images

def changePic(btn):
    if btn == "Reload":
        app.reloadImage("reload", "balloons.gif")

app.startLabelFrame("Reload", 1, 1)
app.setSticky("ew")
app.addImage("reload", "balloons.gif")
app.addButton("Reload", changePic)
app.stopLabelFrame()
clicked = False
def changePic(btn):
    if btn == "clickme":
        global clicked
        if clicked: app.setImage("clickme", "balloons.gif")
        else: app.setImage("clickme", "balloons2.png")
        clicked = not clicked

app.startLabelFrame("Click Me", 0, 2)
app.addImage("clickme", "balloons.gif")
app.setImageSubmitFunction("clickme", changePic)
app.stopLabelFrame()
app.startLabelFrame("Mouse Over", 0, 1)
app.addImage("mo_1", "balloons.gif")
app.setImageMouseOver("mo_1", "balloons2.png")
app.stopLabelFrame()
def changePic(btn):
    if btn == "Zoom":
        app.zoomImage("Zoom", int(app.getSpinBox("Zoom")))

Change Image Animation

If an image is animated, it's possible to control it.

def changePic(btn):
    if btn == "Stop":
        global animated
        if animated:
            app.stopAnimation("animated")
            app.setButton("Stop", "Start")
        else:
            app.startAnimation("animated")
            app.setButton("Stop", "Stop")
        animated = not animated

app.startLabelFrame("Animated", 1, 2)
app.setSticky("ew")
app.addImage("animated", "animated_balloons.gif")
app.addButton("Stop", changePic)
app.stopLabelFrame()

Set Background Images

It's also possible to add a background image to your GUI.
If you have lots of grouped widgets, this can look quite UGLY, as all of the widgets are drawn on top.

Image Caching

appJar employs an image caching mechanism, to speed up image processing.
Every time an image is loaded, it's added to the cache.
The next time an image of the same filename is referenced, it will be loaded from the cache.
This speeds up processes such as mouse-overs, or setting images back-and-forth.

Animatd images also have their own internal cache, storing each version of the image.

appJar attempts to preload mouse over images and animated images, to improve smoothness.

If there's ever a need to clear the image cache (maybe reduce memory footprint), call: .clearImageCache()