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
-
@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')
-
The indentation in your
do_kwargs()
function is incorrect. Your return statement is within the loop, which means that you'll returnobj
after the first iteration of the loop, no matter how many other items there are inkwargs
. Just unindentreturn obj
one level, and it should work as you expect. -
I thought BLE stood for Bluetooth Low Energy but I think in this case it stands for BlackLabelError.
-
@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 -
@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...