Get the selected tab in a enthought traits application

P

petmertens

Hi,

I have a traits application with a tabbed group:

Group(
Group(label="a", dock='tab'),
Group(label="b", dock='tab'),
layout='tabbed')

Beneath the tabbed group, there is button which should perform some action depending on the selected tab.
So I would like to know which of both tabs, 'a' or 'b', is selected (i.e. active).

Any ideas?

Thanks
 
S

shi

Any ideas?

I think you will have more chance for an answer in a more specialized
list, e.g. the enthought-dev mailing list, which is also accessible via
gmane:

http:// dir.gmane.org / gmane.comp.python.enthought.devel

Stefaan.
 
P

petmertens

Here's the answer:

from enthought.traits.api import HasTraits, Str, List, Button, Any
from enthought.traits.ui.api import View, Item
from enthought.traits.ui.api import ListEditor

class A(HasTraits):
StringA = Str

view = View(Item('StringA'))

class B(HasTraits):
StringB = Str

view = View(Item('StringB'))

class C(HasTraits):
MyList = List(HasTraits)
MyButton = Button(label="Test")
SelectedTab = Any

def _MyButton_fired(self):
if self.SelectedTab == self.MyList[0]:
print self.MyList[0].StringA
if self.SelectedTab == self.MyList[1]:
print self.MyList[1].StringB

view = View(Item('MyList', style='custom', show_label=False,
editor=ListEditor(use_notebook=True, deletable=False, dock_style='tab', selected='SelectedTab')),
Item('MyButton', show_label=False))

a = A()
b = B()
c = C()
c.MyList = [a, b]

c.configure_traits()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top