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.


    [Suggestion] ui.left_button_items and right - Not be None. Either a empty tuple or list or a property access

    Pythonista
    left button suggestion items
    2
    4
    3361
    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.
    • Phuket2
      Phuket2 last edited by Phuket2

      @omz, maybe a lack of my Python ability, but I find it difficult working with ui.left_button_items and ui.right_button_items. I just have to write a lot more code than I feel I need to.

      have to deal with None all the time. Would seem like a empty list would be so much better. Or something so it could be iterated over safely. Maybe I am missing a Python fundamental here dealing with None. But it just seems harder than it needs to be

      Sorry for the crazy tags, but hit the 15 char limit

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

        I never had any issues with them being None, but the fact that they are tuples rather than lists makes it very annoying to add an extra button or replace an existing one. I'd guess that this is a technical limitation though - if it were a list, the "owning" view would not notice when the list is changed, only when it is replaced entirely. This would probably require a custom list subclass to work properly.

        Phuket2 1 Reply Last reply Reply Quote 0
        • Phuket2
          Phuket2 @dgelessus last edited by

          @dgelessus , yes I see your point about the mutable types is a problem. Can't have that. But then could supply a r/o property.

          I guess it's not a big deal. But I think it makes more sense. You can't do a list comp on right_button_items/left without first checking for none.

          The code below works, as long as ui.left_button_items and right_… is not None

          I wanted this because I want to disable all the buttons in the menu. But as well, save their enabled state so I can restore their state correctly.

          Again, not critical. But it just doesn't feel right to write it in a more obscure way if you don't have to.

          import ui
          
          v = ui.View(frame = (0,0,500,500))
          btn_l0 = ui.ButtonItem('left0')
          btn_r0 = ui.ButtonItem('right0')
          v.left_button_items = [btn_l0]
          v.right_button_items = [btn_r0]
          
          btns = [ (btn, btn.enabled) for btn in v.left_button_items + 
          			v.right_button_items if isinstance(btn , ui.ButtonItem)]
          print btns
          v.present('sheet')
          
          
          1 Reply Last reply Reply Quote 0
          • Phuket2
            Phuket2 last edited by

            Anyway would be to propose None is iterable 0 times , LOL, not thought out that comment 😁

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