Skip to content

Commit

Permalink
Resolves issue beeware#197
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayof committed Jul 10, 2017
1 parent 0e659a7 commit 8c4ea2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/cocoa/toga_cocoa/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

from ..container import Container
from ..libs import *
from ..utils import process_callback
from .base import WidgetMixin


class TogaTabViewDelegate(NSObject):
@objc_method
def tabView_didSelectTabViewItem_(self, view, item) -> None:
pass
# print ("Select tab view item")
id_tab_view = item.identifier.split('-')[2]
process_callback(self._interface._update_current_tab_view(id_tab_view))


class OptionContainer(OptionContainerInterface, WidgetMixin):
Expand All @@ -23,13 +24,16 @@ def create(self):
self._impl = NSTabView.alloc().init()

self._delegate = TogaTabViewDelegate.alloc().init()
self._delegate.interface = self
self._delegate._interface = self

self._impl.setDelegate_(self._delegate)

# Add the layout constraints
self._add_constraints()

def _update_current_tab_view(self, value):
self._selected = value

def _add_content(self, label, container, widget):
item = NSTabViewItem.alloc().initWithIdentifier_('%s-Tab-%s' % (id(self), id(widget)))
item.setLabel_(label)
Expand Down
14 changes: 14 additions & 0 deletions src/core/toga/interface/widgets/optioncontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, id=None, style=None, content=None):

super().__init__(id=id, style=style, content=content)
self._containers = []
self._selected = None

def _configure(self, content):
if content:
Expand Down Expand Up @@ -51,6 +52,19 @@ def add(self, label, widget):

self._add_content(label, container, widget)

@property
def selected(self):
"""
The current id of the tab view selected
:rtype: ``int``
"""
return self._selected

@selected.setter
def selected(self, value):
self._selected = value

def _update_child_layout(self):
for label, container, widget in self._containers:
container._update_layout()

0 comments on commit 8c4ea2b

Please sign in to comment.