Get the value of a custom attribute in a ui.button
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:
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.
I have tried the following, but it gives none:
class ButtonWrapper(ui.View): imageSrc = '' def touch_began(self, touch): imageSrc = self.subviews.image.name print(imageSrc)
Only to clarify, if I do
def touch_began(self,touch): image = self.subviews.image print(image)
I get back the image (obviously as a object, and not the path I want) I'd like to access.
@FrankenApps this works
import ui b = ui.Button() b.background_image = ui.Image.named('iob:alert_256') print(b.background_image.name)
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.
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