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.
Creation of ui Elements - defaults are strange
-
@omz, I didn't write this as a bug because maybe you added something I am not aware about.
But if you create a ui.Button without params you get width and height = 0.
If you create a ui.Table without params, you get a width and height of 100.Maybe you added something to set this globally.
But if not, it would seem reasonable to create the objects as you do in the designer. Eg. Ui.Button() w = 80, h = 32. ui.TableView() w = 200, h = 200
From memory in the past you got values if not like this but close to this.
I get the logic, if you don't specify a frame, then there is none. But it is as practical as if you did that in the Designer
As I say, maybe there is a bigger picture going on here.
-
The button has a size of zero because there is no title set by default.
When you set a title and callsize_to_fit()
, the size will change so, that the content fits.I haven't tested this with other view elements but I guess it's probably the same.
-
I made some more tests. These are the default sizes from the
ui
module: -
ui.Button autosizes upon init, if passed a title or image argument
btn=ui.Button(image=ui.Image.named('iow:alert_32')) btn=ui.Button(title='Submit')
-
Thanks guys. Looks maybe its a storm in a teacup 😬 Personally I would have thought just for consistency and memorising, that the designer and the code creation would use the same defaults. Ok, created ui.Button basically does.
Good to know about the button though. Explains why sometimes testing I get different results. Often getting the placements correct before populating them. Can you the impression that it is behaving erratically or that's something has changed when it's just the sequence in which you do things. Live and learn 👍