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

[widget Audit] toga.OptionContainer #1996

Merged
merged 20 commits into from
Aug 10, 2023

Conversation

freakboy3742
Copy link
Member

@freakboy3742 freakboy3742 commented Jun 19, 2023

Audit of OptionContainer.

Builds on #1984 because of the changes to root containers on Cocoa.

This is a widget that is going to have some weird platform inconsistencies.

  • Cocoa allows tabs to be disabled.
  • GTK doesn't allow tabs to be disabled; every style guide and StackOverflow post seems to suggest GTK prefers to hide content when it's not applicable, rather than marking it disabled. So... we do that.
  • Looking forward, Winforms doesn't allow tabs to be disabled, preferring to make the content disabled.

Removes the ability to increment and decrement the current tab. This was primarily required by typing, so that there is a consistent OptionItem type; but it's also a little odd to have current_tab return an OptionItem object, but accept integer increments.

Removes the add(), append() and insert() APIs from OptionContainer because they collide with the child management APIs. Equivalent APIs exist on the content object.

Removes the option argument from the on_select callback.

There's one very nasty hack in the Cocoa probe; details in the probe implementation.

There's another hack introduced into the unrelated TextInput tests; I was seeing an intermittent (but annoyingly, usually only when I was running the whole test suite) failure because the keyboard event handler wasn't firing.

Fixes #1968.

Audit checklist

  • Core tests ported to pytest
  • Core tests at 100% coverage
  • Core docstrings complete, and in Sphinx format
  • Documentation complete and consistently formatted
  • cocoa backend at 100% coverage
  • winforms backend at 100% coverage
  • gtk backend at 100% coverage
  • iOS backend at 100% coverage
  • android backend at 100% coverage
  • Widget support table updated
  • Widget Issue backlog reviewed

@freakboy3742 freakboy3742 marked this pull request as draft June 19, 2023 03:44
@freakboy3742 freakboy3742 force-pushed the audit-optioncontainer branch 2 times, most recently from 9a38b7f to 19ab0a5 Compare June 19, 2023 05:19
@freakboy3742 freakboy3742 force-pushed the audit-optioncontainer branch from df78011 to 58bdf2e Compare June 19, 2023 06:40
@freakboy3742
Copy link
Member Author

@mhsmith I've flagged #1968 as fixed in the comment so it isn't forgotten, but it appears to be a Windows only problem.

@freakboy3742 freakboy3742 marked this pull request as ready for review July 17, 2023 06:44
@freakboy3742 freakboy3742 force-pushed the audit-optioncontainer branch from e625638 to 76e8887 Compare August 1, 2023 05:09
@freakboy3742 freakboy3742 requested a review from mhsmith August 4, 2023 06:16
Comment on lines +70 to +73
autodoc_default_options = {
"members": True,
"undoc-members": True,
}
Copy link
Member

Choose a reason for hiding this comment

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

I've removed these default options from the other containers and the Widget base class: we can clean up the others in a separate PR.

Comment on lines 98 to 100
def __iter__(self):
"""Obtain an iterator over all tabs in the OptionContainer."""
return iter(self._options)
Copy link
Member

Choose a reason for hiding this comment

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

Every class with __len__ and __getitem__ automatically supports iteration.

raise self.interface.OptionException(
"Currently selected option cannot be disabled"
)

self._disabled_tabs.add(index)
tabview._setTabEnabled(enabled)
Copy link
Member

Choose a reason for hiding this comment

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

#832 added the enable/disable feature using some undocumented APIs _isTabEnabled and _setTabEnabled. #1117 then removed the use of the is method, but left the set method alone, and added a comment saying "it's handled by the delegate" even though it actually isn't. This is very confusing.

Copy link
Member

Choose a reason for hiding this comment

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

My feeling is that if there are some undocumented methods which have worked all this time, then we might as well keep on using them, but wrap them with broad exception handlers in case the methods ever change or disappear in a future version of macOS. That way, we'll still discover such problems as soon as we start running the testbed on the new macOS version, but existing Toga-based apps will only display a warning rather than crash.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah - this is weird. I'm not sure how anyone found the original _setTabEnabled method. I've added 2 layers of protection: catching the AttributeError in case the method disappears; and implementing the (missing, but referenced) delegate method that is strictly responsible for determining whether the tab can be selected.

@mhsmith
Copy link
Member

mhsmith commented Aug 9, 2023

@mhsmith I've flagged #1968 as fixed in the comment so it isn't forgotten, but it appears to be a Windows only problem.

I've confirmed this issue is now fixed.

@@ -4,7 +4,20 @@
from toga_winforms.libs import Color, Point, Size, SystemColors


class Widget:
class Scalable:
Copy link
Member Author

Choose a reason for hiding this comment

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

Any particular reason for making a subclass for this? It's only ever subclassed by Widget, and it's not used as a basis for isolated testing; I'm not sure I see the benefit of a separate base class for this.

Copy link
Member

Choose a reason for hiding this comment

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

It's also subclassed by Window, and used in the position and size methods. This was required by the OptionContainer tests, because they rely on the window being 640x480 CSS pixels.

Copy link
Member Author

@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.

Winforms and docs changes all look good for me, with one minor query about the extra base class; personal preference would be to not introduce the complexity, but I don't feel that strongly about it.

I've also implemented the missing cocoa tab_enabled probe method.

Happy for this to be merged if you are.

@freakboy3742 freakboy3742 merged commit 6327c11 into beeware:main Aug 10, 2023
@freakboy3742 freakboy3742 deleted the audit-optioncontainer branch August 10, 2023 22:08
@mhsmith mhsmith mentioned this pull request Aug 22, 2023
4 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.

WebView inside OptionContainer not resizing when maximising
2 participants