-
-
Notifications
You must be signed in to change notification settings - Fork 685
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
freakboy3742
merged 20 commits into
beeware:main
from
freakboy3742:audit-optioncontainer
Aug 10, 2023
Merged
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
932efb0
Update docs and core API for OptionContainer.
freakboy3742 58bdf2e
Core tests converted to Pytest, with 100% coverage.
freakboy3742 ec6176d
Cocoa implementation to 100% coverage.
freakboy3742 f8eb53f
GTK optioncontainer coverage to 100%.
freakboy3742 fbdf363
Introduce a small explicit delay to work around intermittent test fai…
freakboy3742 4792170
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 b6d05f9
Lower the horizontal limit that identifies full width.
freakboy3742 53abedd
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 49b81b2
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 15624b5
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 00b46fb
Merge branch 'main' into audit-optioncontainer
freakboy3742 eac7feb
Merge branch 'main' into audit-optioncontainer
freakboy3742 a46e14c
Merge branch 'main' into audit-optioncontainer
freakboy3742 7747857
Merge branch 'main' into audit-optioncontainer
freakboy3742 76e8887
Correct some spelling errors.
freakboy3742 02f7533
Merge branch 'main' into audit-optioncontainer
freakboy3742 125ddf2
Documentation fixes
mhsmith d4b6209
Winforms OptionContainer to 100%
mhsmith 7f222a5
Add implementation of tab_enabled for cocoa.
freakboy3742 fc22290
Add protection against future removal of a private method.
freakboy3742 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The OptionContainer widget now has 100% test coverage, and complete API documentation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The ability to increment and decrement the current OptionContainer tab was removed. Instead of `container.current_tab += 1`, use `container.current_tab = container.current_tab.index + 1` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
``OptionContainer.add()``, ``OptionContainer.remove()`` and ``OptionContainer.insert()`` have been removed, due to being ambiguous with base widget methods of the same name. Use the ``OptionContainer.content.append()``, ``OptionContainer.content.remove()`` and ``OptionContainer.content.insert()`` APIs instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The ``on_select`` handler for OptionContainer no longer receives the ``option`` argument providing the selected tab. Use ``current_tab`` to obtain the currently selected tab. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from toga_cocoa.libs import NSTabView | ||
|
||
from .base import SimpleProbe | ||
|
||
|
||
class OptionContainerProbe(SimpleProbe): | ||
native_class = NSTabView | ||
disabled_tab_selectable = False | ||
|
||
# 2023-06-20: This makes no sense, but here we are. If you render an NSTabView with | ||
# a size constraint of (300, 200), and then ask for the frame size of the native | ||
# widget, you get (314, 216). | ||
# | ||
# If you draw the widget at the origin of a window, the widget reports a frame | ||
# origin of (-7, -6). | ||
# | ||
# If you draw an NSTabView the full size of a 640x480 window, the box containing the | ||
# widget is 640x452, but the widget reports a frame of 654x458 @ (-7, -6). | ||
# | ||
# If you set the NSTabView to be 300x200, then draw a 300 px box below and a 200px | ||
# box beside the NSTabView to act as rulers, the rulers are the same size as the | ||
# NSTabView. | ||
# | ||
# I can't find any way to reverse engineer the magic left=7, right=7, top=6, | ||
# bottom=10 offsets from other properties of the NSTabView. So, we'll hard code them | ||
# and | ||
LEFT_OFFSET = 7 | ||
RIGHT_OFFSET = 7 | ||
TOP_OFFSET = 6 | ||
BOTTOM_OFFSET = 10 | ||
|
||
@property | ||
def width(self): | ||
return self.native.frame.size.width - self.LEFT_OFFSET - self.RIGHT_OFFSET | ||
|
||
@property | ||
def height(self): | ||
return self.native.frame.size.height - self.TOP_OFFSET - self.BOTTOM_OFFSET | ||
|
||
def select_tab(self, index): | ||
self.native.selectTabViewItemAtIndex(index) | ||
|
||
def tab_enabled(self, index): | ||
# There appears to be no public method for this. | ||
return self.native.tabViewItemAtIndex(index)._isTabEnabled() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 theis
method, but left theset
method alone, and added a comment saying "it's handled by the delegate" even though it actually isn't. This is very confusing.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.