Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusion around style properties which accept NONE values #1502

Open
mhsmith opened this issue Jun 13, 2022 · 3 comments
Open

Confusion around style properties which accept NONE values #1502

mhsmith opened this issue Jun 13, 2022 · 3 comments
Labels
bug A crash or error in behavior. documentation An improvement required in the project's documentation.

Comments

@mhsmith
Copy link
Member

mhsmith commented Jun 13, 2022

Reported on Discord by "willow <3", and verified by me.

The Pack documentation says that none is allowed as the value of several properties. However, I can't find any tests for this, and it doesn't actually work.

For example, if you call Pack(visibility="none"), you get this error:

Traceback (most recent call last):
  File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 178, in setter
    value = choices.validate(value)
  File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 57, in validate
    raise ValueError("'{0}' is not a valid initial value".format(value))
ValueError: 'None' is not a valid initial value

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\smith\cygwin\git\beeware\toga\src\winforms\toga_winforms\app.py", line 216, in run_app
    self.create()
  File "c:\users\smith\cygwin\git\beeware\toga\src\winforms\toga_winforms\app.py", line 113, in create
    self.interface.startup()
  File "C:\Users\smith\cygwin\git\beeware\beeware-chaquopy-test\src\helloworld\app.py", line 21, in startup
    style=Pack(visibility="none")),
  File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 73, in __init__
    self.update(**style)
  File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 97, in update
    setattr(self, name, value)
  File "c:\users\smith\cygwin\.venv\bw-dev\lib\site-packages\travertino\declaration.py", line 180, in setter
    raise ValueError("Invalid value '{}' for property '{}'; Valid values are: {}".format(
ValueError: Invalid value 'none' for property 'visibility'; Valid values are: hidden, none, visible

Passing a Python None gives the same error message, except for the capitalization of 'none'.

It looks like the problem is that the string "none" is being converted to a Python None, and then compared to the available choices, one of which is the string "none".

However, in the case of visibility, for consistency with CSS, instead of none it would be better to use hidden, which is already implemented and tested, but not documented.

Environment:

  • Operating System: Windows 10
  • Python version: 3.8.7
  • Software versions:
    • Briefcase: 0.3.7 main branch
    • Toga: 0.3.0.dev35 main branch
@mhsmith mhsmith added the bug A crash or error in behavior. label Jun 13, 2022
@mhsmith
Copy link
Member Author

mhsmith commented Jun 13, 2022

This also affects the properties display, width and height. And they have some additional documentation issues:

display, as far as I can see, isn't actually implemented. But if display="none" was intended to mean the same as the CSS property of the same name, then the last sentence ("Space will be allocated for the element as if it were there, but the element itself will not be visible.") should be removed.

width and height are documented to have an initial value of none, but they actually have an initial value of 0. However, it looks like the layout algorithm treats 0 as meaning "as large as possible", so that should be documented.

@freakboy3742 freakboy3742 added up-for-grabs documentation An improvement required in the project's documentation. labels Jun 13, 2022
@freakboy3742
Copy link
Member

Thanks for formalising the report from Discord. There's a couple of co-morbid issues here:

  1. Are the declarations allowing valid syntax? Clearly not - but I think the actual bug here might be at the level of Travertino, not Toga. Toga currently defines NONE as valid for visibility, and display; width and height are controlled by this declaration.

None handling should be happening here, but there's clearly some interaction going on with the rest of that code - my immediate guess is that the problem is this line, and the == value comparison.

  1. Are the declarations implementing the correct behaviour? You've highlighted 2 cases (display=None, and width/height=0) which both seem suspect.

  2. Is the documentation correct? This might change depending on how (2) is resolved, but as it stands, it looks like there's a problem here, as well. At the very least, the documentation for display isn't as intended; we are trying to be "CSS lite", so display=None should be "don't allocate space".

@mhsmith mhsmith changed the title NONE cannot be used as the value of a style property Confusion around style properties which accept NONE values Feb 20, 2023
@mhsmith
Copy link
Member Author

mhsmith commented Feb 20, 2023

The initial error was fixed by beeware/travertino#33, but the other issues still remain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A crash or error in behavior. documentation An improvement required in the project's documentation.
Projects
None yet
Development

No branches or pull requests

2 participants