Mercurial > urwid-satext
comparison frontends/primitivus/custom_widgets.py @ 19:0b83dd2b15d1
Primitivus: misc improvments on TabsContainer/FocusFrame
- FocusFrame: better management of keypress
- TabsContainer: new addFooter method, to add a widget on the bottom of the container
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 09 Aug 2010 21:58:28 +0800 |
parents | bdc83e857093 |
children | 333a62fab0e3 |
comparison
equal
deleted
inserted
replaced
18:bdc83e857093 | 19:0b83dd2b15d1 |
---|---|
814 | 814 |
815 class FocusFrame(urwid.Frame): | 815 class FocusFrame(urwid.Frame): |
816 """Frame which manage 'tab' key""" | 816 """Frame which manage 'tab' key""" |
817 | 817 |
818 def keypress(self, size, key): | 818 def keypress(self, size, key): |
819 ret = urwid.Frame.keypress(self, size, key) | |
820 if not ret: | |
821 return | |
822 | |
819 if key == 'tab': | 823 if key == 'tab': |
820 focus_list = ('header','body','footer') | 824 focus_list = ('header','body','footer') |
821 focus_idx = focus_list.index(self.focus_part) | 825 focus_idx = focus_list.index(self.focus_part) |
822 for i in range(2): | 826 for i in range(2): |
823 focus_idx = (focus_idx + 1) % len(focus_list) | 827 focus_idx = (focus_idx + 1) % len(focus_list) |
824 focus_name = focus_list[focus_idx] | 828 focus_name = focus_list[focus_idx] |
825 widget = getattr(self,'_'+focus_name) | 829 widget = getattr(self,'_'+focus_name) |
826 if widget!=None and widget.selectable(): | 830 if widget!=None and widget.selectable(): |
827 self.set_focus(focus_name) | 831 self.set_focus(focus_name) |
828 | 832 |
829 return urwid.Frame.keypress(self, size, key) | 833 return ret |
830 | 834 |
831 class TabsContainer(urwid.WidgetWrap): | 835 class TabsContainer(urwid.WidgetWrap): |
832 signals = ['click'] | 836 signals = ['click'] |
833 | 837 |
834 def __init__(self): | 838 def __init__(self): |
835 #self._current_tab = 0 | 839 #self._current_tab = 0 |
836 self._buttons_cont = ColumnsRoller() | 840 self._buttons_cont = ColumnsRoller() |
837 self.tabs = [] | 841 self.tabs = [] |
838 self.__frame = urwid.Frame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) | 842 self.__frame = FocusFrame(urwid.Filler(urwid.Text('')),urwid.Pile([self._buttons_cont,urwid.Divider(u"─")])) |
839 urwid.WidgetWrap.__init__(self, self.__frame) | 843 urwid.WidgetWrap.__init__(self, self.__frame) |
840 | 844 |
841 """def selectable(self): | |
842 return True | |
843 | |
844 def keypress(self, size, key): | 845 def keypress(self, size, key): |
845 return key""" | 846 if key=='tab': |
847 self._w.keypress(size,key) | |
848 return | |
849 return self._w.keypress(size,key) | |
846 | 850 |
847 def __buttonClicked(self, button, invisible=False): | 851 def __buttonClicked(self, button, invisible=False): |
848 """Called when a button on the tab is changed, | 852 """Called when a button on the tab is changed, |
849 change the page | 853 change the page |
850 @param button: button clicked | 854 @param button: button clicked |
878 listbox = urwid.ListBox(urwid.SimpleListWalker(content)) | 882 listbox = urwid.ListBox(urwid.SimpleListWalker(content)) |
879 self.tabs.append([name,listbox]) | 883 self.tabs.append([name,listbox]) |
880 self.__appendButton(name) | 884 self.__appendButton(name) |
881 return listbox | 885 return listbox |
882 | 886 |
887 def addFooter(self, widget): | |
888 """Add a widget on the bottom of the tab (will be displayed on all pages) | |
889 @param widget: FlowWidget""" | |
890 self._w.footer = widget | |
891 | |
892 | |
883 ## DECORATORS ## | 893 ## DECORATORS ## |
884 class LabelLine(urwid.LineBox): | 894 class LabelLine(urwid.LineBox): |
885 """Like LineBox, but with a Label centered in the top line""" | 895 """Like LineBox, but with a Label centered in the top line""" |
886 | 896 |
887 def __init__(self, original_widget, label_widget): | 897 def __init__(self, original_widget, label_widget): |