comparison urwid_satext/sat_widgets.py @ 111:1cdf4a00b68d

TabsContainer: allow to select a tab when adding it
author souliane <souliane@mailoo.org>
date Sat, 22 Aug 2015 09:26:32 +0200
parents 436076392538
children 77ccc1dd2261
comparison
equal deleted inserted replaced
110:436076392538 111:1cdf4a00b68d
1423 self._current_tab.set_label(self._current_tab.get_label()) 1423 self._current_tab.set_label(self._current_tab.get_label())
1424 self._current_tab = button 1424 self._current_tab = button
1425 if not invisible: 1425 if not invisible:
1426 self._emit('click') 1426 self._emit('click')
1427 1427
1428 def _appendButton(self, name): 1428 def _appendButton(self, name, selected=False):
1429 """Append a button to the frame header, 1429 """Append a button to the frame header, and link it to the page change method.
1430 and link it to the page change method""" 1430
1431 @param name (unicode): button name
1432 @param selected (bool): set to True to select this tab
1433 """
1431 button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ') 1434 button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ')
1432 self._buttons_cont.addWidget(button, button.getSize()) 1435 self._buttons_cont.addWidget(button, button.getSize())
1433 if len(self._buttons_cont.widget_list) == 1: 1436 count = len(self._buttons_cont.widget_list)
1434 #first button: we set the focus and the body 1437 if selected or count == 1:
1435 self._buttons_cont.focus_position = 0 1438 # first/selected button: we set the focus and the body
1436 self._buttonClicked(button,True) 1439 self.selectTab(count - 1)
1437 1440
1438 def addTab(self,name,content=None): 1441 def addTab(self, name, content=None, selected=False):
1439 """Add a page to the container 1442 """Add a page to the container
1443
1440 @param name: name of the page (what appear on the tab) 1444 @param name: name of the page (what appear on the tab)
1441 @param content: content of the page: 1445 @param content: content of the page:
1442 - if None create and empty Listbox 1446 - if None create and empty Listbox
1443 - if it is a list instance, create a ListBox with the list in a body 1447 - if it is a list instance, create a ListBox with the list in a body
1444 - else it must be a box widget which will be used instead of the ListBox 1448 - else it must be a box widget which will be used instead of the ListBox
1449 @param selected (bool): set to True to select this tab
1445 @return: ListBox (content of the page)""" 1450 @return: ListBox (content of the page)"""
1446 if content is None or isinstance(content, list): 1451 if content is None or isinstance(content, list):
1447 tab = urwid.ListBox(urwid.SimpleListWalker(content or [])) 1452 tab = urwid.ListBox(urwid.SimpleListWalker(content or []))
1448 else: 1453 else:
1449 tab = content 1454 tab = content
1450 1455
1451 self.tabs.append([name, tab]) 1456 self.tabs.append([name, tab])
1452 self._appendButton(name) 1457 self._appendButton(name, selected)
1453 return tab 1458 return tab
1454 1459
1455 def addFooter(self, widget): 1460 def addFooter(self, widget):
1456 """Add a widget on the bottom of the tab (will be displayed on all pages) 1461 """Add a widget on the bottom of the tab (will be displayed on all pages)
1457 @param widget: FlowWidget""" 1462 @param widget: FlowWidget"""
1458 self._w.footer = widget 1463 self._w.footer = widget
1464
1465 def selectTab(self, index):
1466 """Select a tab.
1467
1468 @param index (int): index of the tab to select
1469 """
1470 self._buttons_cont.focus_position = index
1471 self._buttonClicked(self._buttons_cont.widget_list[index][1], True)
1459 1472
1460 1473
1461 class HighlightColumns(urwid.AttrMap): 1474 class HighlightColumns(urwid.AttrMap):
1462 """ Decorated columns which highlight all or some columns """ 1475 """ Decorated columns which highlight all or some columns """
1463 1476