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

Inconsistent behaviour with toga.Selection value attribute between Windows and Android #1723

Closed
IneededAnAccountToDoStuff opened this issue Dec 27, 2022 · 1 comment · Fixed by #1914
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior.

Comments

@IneededAnAccountToDoStuff

Describe the bug

On Windows, when a selection widget is created with a list containing an empty string (eg: toga.Selection(items=['1','a','','4']) ), the widget returns '' for the "value" attribute.

On Android, the selection's "value" attribute is set to None if the selection item is an empty string.

I don't have MacOS, iOS, or Linux devices so I don't know what happens there.

Steps to reproduce

  1. Create Beeware Project
  2. Go to the app.py file
  3. Create a list "list_1" containing an empty string
  4. Create the base app class with the startup function and setup main box + window
  5. In the startup function, create a selection with the items being that of list_1. Store it as a class attribute for future access.
  6. Define a class function that outputs the selection value via print or info_dialog.
  7. Create Button to call the output function
  8. Add Selector & Button to main box
  9. Compile the code for both Windows and Android & launch them.
  10. Select the empty item of the selector
  11. Press the button
  12. Watch as the devices disagree on the value.

Expected behavior

I would expect the selector value attribute to be an empty string as that was what the item was, and that is what the selector widget understands when values are written to it.

Screenshots

The source code I used:

"""
Testing Crashes
"""
import toga
class TestLab(toga.App):
    def startup(self):
        main_box=toga.Box()
        self.select=toga.Selection(items=['A','B','0','','1','+','-'])
        main_box.add(self.select)
        main_box.add(toga.Button('Get',on_press=self.valuedump))
        self.main_window=toga.MainWindow(title=self.formal_name)
        self.main_window.content=main_box
        self.main_window.show()
    async def valuedump(self,widget):
        q=self.select.value
        print('GET',q,type(q))
        self.main_window.info_dialog('Selection Value',f'Value: "{q}"\n Type: {type(q)}')
def main():return TestLab()

On Windows:

A_val
sel_vals
Null_val

On Android:

Screenshot_20221227-171610
Screenshot_20221227-171624
Screenshot_20221227-171635

Environment

Windows 8.1 / Android 11

  • Python version: 3.10.0
    • Briefcase: 3.11
    • Toga: 0.3.0.dev8

Logs

Windows:
briefcase.2022_12_27-17_09_47.run.log

Android:
briefcase.2022_12_27-17_17_14.run.log

Additional context

No response

@IneededAnAccountToDoStuff IneededAnAccountToDoStuff added the bug A crash or error in behavior. label Dec 27, 2022
@freakboy3742
Copy link
Member

Thanks for the report; looks like an edge case that we've missed in testing. The fault is almost certainly with the get_value() handler and the way it's interpreting the return value from the underlying Android API.

@freakboy3742 freakboy3742 added the android The issue relates to Android mobile support. label Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android The issue relates to Android mobile support. bug A crash or error in behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants