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.


    UI: text_color animation

    Pythonista
    1
    1
    1437
    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.
    • lachlantula
      lachlantula last edited by lachlantula

      Hi all,
      I’m developing an application with the ui module, but have realised something that I’m not sure is either intentional or just overlooked; background_color can be animated, whilst text_color can’t.
      Here’s an example. You can see that the text colour-changing is out of sync with the smooth background. The text changes to contrast with the background at the time.

      Here is my code for the colour-changing functionality:

      while True:
          r = lambda: random.randint(0, 255)
          colour = '%02X%02X%02X' % (r(), r(), r())
          def determine_colour2(colour):
              (r, g, b) = (colour[:2], colour[2:4], colour[4:])
              # This next bit is pretty complicated, but its basically just an algorithm to find out what colour is needed for text
              if 1 - (int(r, 16) * 0.299 + int(g, 16) * 0.587 + int(b, 16) * 0.114) / 255 < 0.5:
                  return '333333'
              else:
                  return 'efefef'
          colour2 = determine_colour2(colour)  
          def animation():
              v.background_color = colour
              v['chrome']['logo'].text_color = colour2
          ui.animate(animation, duration = 3)
          time.sleep(3)
      

      If anyone can let me know if I’m doing something wrong or if this functionality isn’t implemented into Pythonista at all, it would be appreciated. Thanks!

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