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 elements creation

    Pythonista
    3
    5
    2110
    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

      @omz, I think you are the only one that can answer this. I am sorry I know you are busy, but really this drives me crazy, more than crazy. When working with the ui I spend much time tracking down errors that are not really my errors. I am passing a value as a kwarg, and it's ignored.

      So then I thought ok, I will just write stubs for all the elements to make sure all kwargs are set. Then now I get the problem below. Setting the bg_color seems to effect the outcome of a object creation. But really, when it's like this, it's not possible to win. Combinations of this and that adds up. If I am wrong, then I apologise, but it seems pretty straight fwd.
      But everytime I get result in the ui I am not expecting, I don't know what to trust.

      If you Un-comment the line below, the title is gone. You would not expect setting the background color would change that. So many weird things happen though.

      import ui
      
      def do_kwargs(obj, *args, **kwargs):
      	for k, v in kwargs.iteritems():
      		if hasattr(obj, k):
      			setattr(obj, k, v)
      		return obj
      			
      def Button(*args, **kwargs):
      	return do_kwargs(ui.Button(), *args, **kwargs)
      	
      if __name__ == '__main__':
      	btn = Button(title = 'Ian', bg_color = 'white')
      	#btn = Button(title = 'Ian')
      	btn.present('sheet')
      
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by

        The indentation in your do_kwargs() function is incorrect. Your return statement is within the loop, which means that you'll return obj after the first iteration of the loop, no matter how many other items there are in kwargs. Just unindent return obj one level, and it should work as you expect.

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

          I thought BLE stood for Bluetooth Low Energy but I think in this case it stands for BlackLabelError.

          1 Reply Last reply Reply Quote 1
          • Phuket2
            Phuket2 last edited by

            @ccc, I have bet you have been saving that one up 😬
            But you are right it was a BLE. But I had just finished tracking down stupid mistakes I made forgetting what works when passed to ui the objects.
            Then I thought, ok. No more tricky stuff, don't try to impove anything, just write the stubs, just to handle all the kwargs.

            But the fact I made the mistake goes to my point. It more than just some missing argument handling, it comes down to confidence. When they silently fail, can be hard to track down. Because of using layout and a series of objects all interacting together. All me misusing uiRects, bounds, frame etc...

            I was just frustrated that's all. And it was on my last few drinks for the night 😱
            @omz sorry.....

            Love the BLE reference though.
            Kisses

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

              @Phuket2 said:

              @omz sorry.....

              Haha, no worries! :)

              To be honest, I'm not really happy with the way ui.View handles keyword arguments either (completely ignoring keywords that aren't handled). It was a bit easier to implement at the time, though I actually might have learned a thing or two since then, so it's quite possible that I'll change it...

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