omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


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

    Pythonista
    3
    4
    2638
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • FrankenApps
      FrankenApps last edited by

      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 1 Reply Last reply Reply Quote 0
      • cvp
        cvp @FrankenApps last edited by

        @FrankenApps this works

        import ui
        b = ui.Button()
        b.background_image = ui.Image.named('iob:alert_256')
        print(b.background_image.name)
        
        1 Reply Last reply Reply Quote 0
        • FrankenApps
          FrankenApps last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • JonB
            JonB last edited by

            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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors