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
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
932efb0
Update docs and core API for OptionContainer.
freakboy3742 Jun 19, 2023
58bdf2e
Core tests converted to Pytest, with 100% coverage.
freakboy3742 Jun 19, 2023
ec6176d
Cocoa implementation to 100% coverage.
freakboy3742 Jun 20, 2023
f8eb53f
GTK optioncontainer coverage to 100%.
freakboy3742 Jun 20, 2023
fbdf363
Introduce a small explicit delay to work around intermittent test fai…
freakboy3742 Jun 20, 2023
4792170
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 Jun 20, 2023
b6d05f9
Lower the horizontal limit that identifies full width.
freakboy3742 Jun 20, 2023
53abedd
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 Jun 22, 2023
49b81b2
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 Jun 26, 2023
15624b5
Merge branch 'audit-splitcontainer' into audit-optioncontainer
freakboy3742 Jun 26, 2023
00b46fb
Merge branch 'main' into audit-optioncontainer
freakboy3742 Jul 17, 2023
eac7feb
Merge branch 'main' into audit-optioncontainer
freakboy3742 Jul 26, 2023
a46e14c
Merge branch 'main' into audit-optioncontainer
freakboy3742 Jul 26, 2023
7747857
Merge branch 'main' into audit-optioncontainer
freakboy3742 Aug 1, 2023
76e8887
Correct some spelling errors.
freakboy3742 Aug 1, 2023
02f7533
Merge branch 'main' into audit-optioncontainer
freakboy3742 Aug 3, 2023
125ddf2
Documentation fixes
mhsmith Aug 9, 2023
d4b6209
Winforms OptionContainer to 100%
mhsmith Aug 9, 2023
7f222a5
Add implementation of tab_enabled for cocoa.
freakboy3742 Aug 9, 2023
fc22290
Add protection against future removal of a private method.
freakboy3742 Aug 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 9 additions & 12 deletions core/src/toga/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ def __repr__(self):
items = ", ".join(repr(option.text) for option in self)
return f"<OptionList {items}>"

def __getitem__(self, item: int | str | OptionItem) -> OptionItem:
def __getitem__(self, index: int | str | OptionItem) -> OptionItem:
"""Obtain a specific tab of content."""
return self._options[self.index(item)]
return self._options[self.index(index)]

def __delitem__(self, index: int | str | OptionItem):
"""Remove the specified tab of content.

The currently selected item cannot be deleted.
"""
"""Same as :any:`remove`."""
self.remove(index)

def remove(self, index: int | str | OptionItem):
Expand All @@ -95,16 +92,12 @@ def remove(self, index: int | str | OptionItem):
# Refresh the widget
self.interface.refresh()

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.


def __len__(self) -> int:
"""The number of tabs of content in the OptionContainer."""
return len(self._options)

def index(self, value: str | int | OptionItem):
"""Find the index of the tab that matches the given specifier
"""Find the index of the tab that matches the given value.

:param value: The value to look for. An integer is returned as-is;
if an :any:`OptionItem` is provided, that item's index is returned;
Expand Down Expand Up @@ -231,7 +224,11 @@ def content(self) -> OptionList:

@property
def current_tab(self) -> OptionItem:
"""The currently selected tab of content."""
"""The currently selected tab of content.

The getter of this property always returns an ``OptionItem``. The setter also
accepts an ``int`` index, or a ``str`` label.
"""
index = self._impl.get_current_tab_index()
if index is None:
return None
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@

autoclass_content = "both"
autodoc_preserve_defaults = True
autodoc_default_options = {
"members": True,
"undoc-members": True,
}
Comment on lines +70 to +73
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.


# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 0 additions & 2 deletions docs/reference/api/containers/box.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,3 @@ Reference
---------

.. autoclass:: toga.Box
:members:
:undoc-members:
22 changes: 9 additions & 13 deletions docs/reference/api/containers/optioncontainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ Usage
pasta = toga.Box()

container = toga.OptionContainer(
content=[("Pizza", first), ("Pasta", second)]
content=[("Pizza", pizza), ("Pasta", pasta)]
)

# Add another tab of content
salad = toga.Box()
container.add("Salad", third)
container.content.append("Salad", salad)

When retrieving or deleting items, or when specifying the
currently selected item, you can specify an item using:
Expand All @@ -40,8 +40,8 @@ currently selected item, you can specify an item using:

.. code-block:: python

# Make the second tab in the container new content
container.insert(1, "Soup", toga.Box())
# Insert a new second tab
container.content.insert(1, "Soup", toga.Box())
# Make the third tab the currently active tab
container.current_tab = 2
# Delete the second tab
Expand All @@ -51,8 +51,8 @@ currently selected item, you can specify an item using:

.. code-block:: python

# Insert content at the index currently occupied by a tab labeled "Pasta"
container.insert("Pasta", "Soup", toga.Box())
# Insert a tab at the index currently occupied by a tab labeled "Pasta"
container.content.insert("Pasta", "Soup", toga.Box())
# Make the tab labeled "Pasta" the currently active tab
container.current_tab = "Pasta"
# Delete tab labeled "Pasta"
Expand All @@ -65,7 +65,7 @@ currently selected item, you can specify an item using:
# Get a reference to the "Pasta" tab
pasta_tab = container.content["Pasta"]
# Insert content at the index currently occupied by the pasta tab
container.insert(pasta_tab, "Soup", toga.Box())
container.content.insert(pasta_tab, "Soup", toga.Box())
# Make the pasta tab the currently active tab
container.current_tab = pasta_tab
# Delete the pasta tab
Expand All @@ -75,13 +75,9 @@ Reference
---------

.. autoclass:: toga.OptionContainer
:members:
:undoc-members: app, window
:exclude-members: app, window

.. autoclass:: toga.widgets.optioncontainer.OptionList
:members:
:undoc-members:
:special-members: __getitem__, __delitem__

.. autoclass:: toga.widgets.optioncontainer.OptionItem
:members:
:undoc-members: refresh
2 changes: 0 additions & 2 deletions docs/reference/api/containers/scrollcontainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,4 @@ Reference
---------

.. autoclass:: toga.ScrollContainer
:members:
:undoc-members:
:exclude-members: window, app
2 changes: 0 additions & 2 deletions docs/reference/api/containers/splitcontainer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,4 @@ Reference
---------

.. autoclass:: toga.SplitContainer
:members:
:undoc-members:
:exclude-members: HORIZONTAL, VERTICAL, window, app
2 changes: 0 additions & 2 deletions docs/reference/api/widgets/widget.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ Reference
---------

.. autoclass:: toga.Widget
:members:
:undoc-members:
:inherited-members:
2 changes: 1 addition & 1 deletion docs/reference/data/widgets_by_platform.csv
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Widget,General Widget,:class:`~toga.Widget`,The base widget,|y|,|y|,|y|,|y|,|y|,
Box,Layout Widget,:class:`~toga.Box`,Container for components,|y|,|y|,|y|,|y|,|y|,|b|
ScrollContainer,Layout Widget,:class:`~toga.ScrollContainer`,A container that can display a layout larger than the area of the container,|y|,|y|,|y|,|y|,|y|,
SplitContainer,Layout Widget,:class:`~toga.SplitContainer`,A container that divides an area into two panels with a movable border,|y|,|y|,|y|,,,
OptionContainer,Layout Widget,:class:`~toga.OptionContainer`,A container that can display multiple labeled tabs of content.,|b|,|b|,|b|,,,
OptionContainer,Layout Widget,:class:`~toga.OptionContainer`,A container that can display multiple labeled tabs of content,|y|,|y|,|y|,,,
App Paths,Resource,:class:`~toga.paths.Paths`,A mechanism for obtaining platform-appropriate filesystem locations for an application.,|y|,|y|,|y|,|y|,|y|,
Font,Resource,:class:`~toga.Font`,Fonts,|b|,|b|,|b|,|b|,|b|,
Command,Resource,:class:`~toga.Command`,Command,|b|,|b|,|b|,,|b|,
Expand Down