# HG changeset patch # User Goffi # Date 1395411662 -3600 # Node ID 6c2a1b349416eea207975f3c1e386754e893b832 # Parent 8ff5638250803da34376ad28e4442c25e45ccb2f TabsContainer now accept any box widget as tab content diff -r 8ff563825080 -r 6c2a1b349416 urwid_satext/sat_widgets.py --- a/urwid_satext/sat_widgets.py Fri Mar 21 15:20:59 2014 +0100 +++ b/urwid_satext/sat_widgets.py Fri Mar 21 15:21:02 2014 +0100 @@ -1142,6 +1142,7 @@ class TabsContainer(urwid.WidgetWrap): + """ Container which can contain multiple box widgets associated to named tabs """ signals = ['click'] def __init__(self): @@ -1157,7 +1158,7 @@ return return self._w.keypress(size,key) - def __buttonClicked(self, button, invisible=False): + def _buttonClicked(self, button, invisible=False): """Called when a button on the tab is changed, change the page @param button: button clicked @@ -1177,27 +1178,32 @@ if not invisible: self._emit('click') - def __appendButton(self, name): + def _appendButton(self, name): """Append a button to the frame header, and link it to the page change method""" - button = CustomButton(name, self.__buttonClicked, left_border = '', right_border=' | ') + button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ') self._buttons_cont.addWidget(button, button.getSize()) if len(self._buttons_cont.widget_list) == 1: #first button: we set the focus and the body - self._buttons_cont.set_focus(0) - self.__buttonClicked(button,True) + self._buttons_cont.focus_position = 0 + self._buttonClicked(button,True) def addTab(self,name,content=None): """Add a page to the container @param name: name of the page (what appear on the tab) - @param content: content of the page + @param content: content of the page: + - if None create and empty Listbox + - if it is a list instance, create a ListBox with the list in a body + - else it must be a box widget which will be used instead of the ListBox @return: ListBox (content of the page)""" - if content is None: - content = [] - listbox = urwid.ListBox(urwid.SimpleListWalker(content)) - self.tabs.append([name,listbox]) - self.__appendButton(name) - return listbox + if content is None or isinstance(content, list): + tab = urwid.ListBox(urwid.SimpleListWalker(content or [])) + else: + tab = content + + self.tabs.append([name, tab]) + self._appendButton(name) + return tab def addFooter(self, widget): """Add a widget on the bottom of the tab (will be displayed on all pages)