Main index > About new desklets > image ID out of range

By ZeroDivide (Desklet Author), on Sun Mar 6 18:02:51 2005: image ID out of range.

I'm working on a few system monitors and can't seem to figure out why i'm getting errors with adesklets.free_image()
If anyone can give me a clue I would greatly appreciate it.

btw.. im using adesklets 0.4.3

error msg

Code:

Traceback (most recent call last):
  File "./test.py", line 43, in ?
    Events(dirname(__file__)).pause()
  File "./test.py", line 14, in __init__
    adesklets.Events_handler.__init__(self)
  File "/usr/lib/python2.3/site-packages/adesklets/events_handler.py", line 157, in __init__
    self.ready()
  File "./test.py", line 39, in ready
    self.load_images()
  File "./test.py", line 32, in load_images
    adesklets.free_image(l)
  File "/usr/lib/python2.3/site-packages/adesklets/commands.py", line 686, in free_image
    return comm.out()
  File "/usr/lib/python2.3/site-packages/adesklets/commands_handler.py", line 103, in out
    raise ADESKLETSError(4,message)
adesklets.error_handler.ADESKLETSError: adesklets command error - image ID 6 out of range



test code

Code:

#! /usr/bin/env python

import adesklets
from os.path import dirname

class Events(adesklets.Events_handler):
        
        def __init__(self, basedir):
                if len(basedir)==0:
                        self.basedir='.'
                else:
                        self.basedir=basedir

                adesklets.Events_handler.__init__(self)

        
        def load_images(self):
                tl=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                tr=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                bl=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                br=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                l=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                r=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                t=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                b=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
                
                
                adesklets.free_image(tl)
                adesklets.free_image(tr)
                adesklets.free_image(bl)
                adesklets.free_image(br)
                adesklets.free_image(l)
                adesklets.free_image(r)
                adesklets.free_image(t)
                adesklets.free_image(b)
                

        def ready(self):
                self.load_images()
                adesklets.window_resize(100,100)
                adesklets.window_show()

Events(dirname(__file__)).pause()

By syfou (Core Developer & Desklet Author), on Sun Mar 6 21:50:05 2005.

I should have mentionned this in the documentation - all of adesklets objects (fonts, images, color ranges, polygons, etc), are stored in stacks (one stack per object type). Python's IDs are nothing more than the initial position of given objects inside the relevant stack, and therefore will become invalid if a same-type object below them get freed.

For instance, if you start with a clean state, all you have in the stack of images is the window's foreground (ID 0) and background (ID 1). When you create two other images from Python like so:

Code:


tl=adesklets.load_image('%s/%s' % (self.basedir, 'image.png'))
tr=adesklets.load_image('%s/%s' % (self.basedir, 'image.png')) 



You get: tl==2 and tr==3. No trouble here until you try to free images. Whenever you do:

Code:


adesklets.free_image(tl)



The stack starts collapsing, and what was once image ID#3 (tr) is now image ID#2, hence the image XX out of range message you are experiencing. In your case, you could as well perform:

Code:


for i in range(8):
        adesklets.free_image(tl)

By ZeroDivide (Desklet Author), on Mon Mar 7 00:18:51 2005.

Thanks for your explanation syfou, that cleared it right up.

It shouldn't be too long now before I have a somewhat viable cpu monitor working. :)


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.