comparison urwid_satext/sat_widgets.py @ 76:6c2a1b349416

TabsContainer now accept any box widget as tab content
author Goffi <goffi@goffi.org>
date Fri, 21 Mar 2014 15:21:02 +0100
parents 8ff563825080
children e1655ba45fae
comparison
equal deleted inserted replaced
75:8ff563825080 76:6c2a1b349416
1140 1140
1141 return ret 1141 return ret
1142 1142
1143 1143
1144 class TabsContainer(urwid.WidgetWrap): 1144 class TabsContainer(urwid.WidgetWrap):
1145 """ Container which can contain multiple box widgets associated to named tabs """
1145 signals = ['click'] 1146 signals = ['click']
1146 1147
1147 def __init__(self): 1148 def __init__(self):
1148 self._current_tab = None 1149 self._current_tab = None
1149 self._buttons_cont = ColumnsRoller() 1150 self._buttons_cont = ColumnsRoller()
1155 if key=='tab': 1156 if key=='tab':
1156 self._w.keypress(size,key) 1157 self._w.keypress(size,key)
1157 return 1158 return
1158 return self._w.keypress(size,key) 1159 return self._w.keypress(size,key)
1159 1160
1160 def __buttonClicked(self, button, invisible=False): 1161 def _buttonClicked(self, button, invisible=False):
1161 """Called when a button on the tab is changed, 1162 """Called when a button on the tab is changed,
1162 change the page 1163 change the page
1163 @param button: button clicked 1164 @param button: button clicked
1164 @param invisible: emit signal only if False""" 1165 @param invisible: emit signal only if False"""
1165 tab_name = button.get_label() 1166 tab_name = button.get_label()
1175 self._current_tab.set_label(self._current_tab.get_label()) 1176 self._current_tab.set_label(self._current_tab.get_label())
1176 self._current_tab = button 1177 self._current_tab = button
1177 if not invisible: 1178 if not invisible:
1178 self._emit('click') 1179 self._emit('click')
1179 1180
1180 def __appendButton(self, name): 1181 def _appendButton(self, name):
1181 """Append a button to the frame header, 1182 """Append a button to the frame header,
1182 and link it to the page change method""" 1183 and link it to the page change method"""
1183 button = CustomButton(name, self.__buttonClicked, left_border = '', right_border=' | ') 1184 button = CustomButton(name, self._buttonClicked, left_border = '', right_border=' | ')
1184 self._buttons_cont.addWidget(button, button.getSize()) 1185 self._buttons_cont.addWidget(button, button.getSize())
1185 if len(self._buttons_cont.widget_list) == 1: 1186 if len(self._buttons_cont.widget_list) == 1:
1186 #first button: we set the focus and the body 1187 #first button: we set the focus and the body
1187 self._buttons_cont.set_focus(0) 1188 self._buttons_cont.focus_position = 0
1188 self.__buttonClicked(button,True) 1189 self._buttonClicked(button,True)
1189 1190
1190 def addTab(self,name,content=None): 1191 def addTab(self,name,content=None):
1191 """Add a page to the container 1192 """Add a page to the container
1192 @param name: name of the page (what appear on the tab) 1193 @param name: name of the page (what appear on the tab)
1193 @param content: content of the page 1194 @param content: content of the page:
1195 - if None create and empty Listbox
1196 - if it is a list instance, create a ListBox with the list in a body
1197 - else it must be a box widget which will be used instead of the ListBox
1194 @return: ListBox (content of the page)""" 1198 @return: ListBox (content of the page)"""
1195 if content is None: 1199 if content is None or isinstance(content, list):
1196 content = [] 1200 tab = urwid.ListBox(urwid.SimpleListWalker(content or []))
1197 listbox = urwid.ListBox(urwid.SimpleListWalker(content)) 1201 else:
1198 self.tabs.append([name,listbox]) 1202 tab = content
1199 self.__appendButton(name) 1203
1200 return listbox 1204 self.tabs.append([name, tab])
1205 self._appendButton(name)
1206 return tab
1201 1207
1202 def addFooter(self, widget): 1208 def addFooter(self, widget):
1203 """Add a widget on the bottom of the tab (will be displayed on all pages) 1209 """Add a widget on the bottom of the tab (will be displayed on all pages)
1204 @param widget: FlowWidget""" 1210 @param widget: FlowWidget"""
1205 self._w.footer = widget 1211 self._w.footer = widget