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

Add optionscontainer abilities #1117

Merged
merged 26 commits into from
Nov 29, 2020

Conversation

saroad2
Copy link
Member

@saroad2 saroad2 commented Oct 21, 2020

Added missing abilities in the OptionContainer class:

  • Get current tab and current tab index
  • Set current tab programmatically
  • Get widget from a tab.

Implemented those abilities in WIndows only.

Also added missing unit tests in order to increase coverage in optioncontainer.py. I wanted to get to 100% coverage, but it seems like nobody uses lines 69 and 93. If it's not in use, we can delete those methods.

PR Checklist:

  • All new features have been tested
  • All new features have been documented
  • I have read the CONTRIBUTING.md file
  • I will abide by the code of conduct

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned on Gitter, something about this was grating against me - and I think I've worked out what it is.

It's the _index suffix, and having that index suffix as an attribute that runs in parallel to a current_tab attribute. To me, having 2 attributes for one "concept" (the currently selected tab) is messy.

My preference here would be to have a single current_tab attribute, defined as a descriptor of the "current tab" concept.

This would make the end-user API something like:

# increment tab
myoptioncontainer.current_tab += 1

# decrement tab
myoptioncontainer.current_tab -= 1

# set index of current tab
myoptioncontainer.current_tab = 1

# Get the current tab widget
content = myoptioncontainer.current_tab

# Get the current tab index
index = myoptioncontainer.current_tab.index

# Set index of current tab explicitly;
myoptioncontainer.current_tab.index = 1

# Get current tab, the long way
content = myoptioncontainer.content[myoptioncontainer.current_tab.index]

Going down this path also allows for current_tab to expose a richer API in future. For example, we could allow setting the current tabs by label:

myoptioncontainer.current_tab = "Important"

To be clear - I'm not suggesting this as a requirement for this iteration of the patch; only that it's an option if we make the current tab a rich descriptor, rather than exposing 2 different attributes.

src/core/toga/widgets/optioncontainer.py Outdated Show resolved Hide resolved
src/core/toga/widgets/optioncontainer.py Outdated Show resolved Hide resolved
@saroad2
Copy link
Member Author

saroad2 commented Nov 1, 2020

Fixed the issues presented in the code review 💪

Copy link
Member

@freakboy3742 freakboy3742 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good now, and works well for the Windows case; however it's causing a hard crash on startup with the OptionContainer example on Linux and macOS. It looks like it's a bootstrapping problem with the value of 'current tab' when the app is starting up; I had a quick poke around and couldn't find an obvious fix, though. I'll try to take a closer look later today after I've unpacked a few more boxes :-)

@freakboy3742
Copy link
Member

@saroad2 Finally got to the bottom of the problem with Cocoa, and I've fleshed out the GTK implementation as well. If you get a chance to verify that I haven't messed up anything you're relying on, let me know; otherwise I'll let this sit for a day or two, test it again, then merge.

@saroad2
Copy link
Member Author

saroad2 commented Nov 29, 2020

Hey @freakboy3742 , I checked in Windows and everything seems to be working!
I think we can merge 😃 !

@freakboy3742 freakboy3742 merged commit d0ebd61 into beeware:master Nov 29, 2020
@saroad2 saroad2 deleted the add_optionscontainer_abilities branch November 29, 2020 12:22
@mhsmith mhsmith mentioned this pull request Aug 9, 2023
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants