Forum Archive

Get the value of a custom attribute in a ui.button

FrankenApps

I've built a little gui, which consist of a custom view and a button inside of it. I want to change the image of the button, which I've set via a custom attribute like so:

{'image':ui.Image.named('res/buttons/blueoff.png').with_rendering_mode(ui.RENDERING_MODE_ORIGINAL)}

when I detect a touch on my custom view. I know how to change the picture, but before I would need to get the path of the current image, e.g.'res/buttons/blueoff.png'.

I have tried the following, but it gives none:

class ButtonWrapper(ui.View):
    imageSrc = ''

    def touch_began(self, touch):
        imageSrc = self.subviews[0].image.name
        print(imageSrc)

Only to clarify, if I do

def touch_began(self,touch):
    image = self.subviews[0].image
    print(image)

I get back the image (obviously as a object, and not the path I want) I'd like to access.

cvp

@FrankenApps this works

import ui
b = ui.Button()
b.background_image = ui.Image.named('iob:alert_256')
print(b.background_image.name)
FrankenApps

Thank you,
but this is not quite what I was looking for...
I ended up declaring another custom attribute which contains the path. It will result in a bit more work in the UI Designer, but at least it works.

JonB

ui.Images are not guaranteed to have a full path associated within them, since they don't necessarily correspond to a file. a separate attribute for the path is the right approach ... or image index (into a list of image paths) could also work