comparison urwid_satext/sat_widgets.py @ 77:e1655ba45fae

MenuRoller doesn't propagate key pressed anymore if it manage a 'up' or 'down' event
author Goffi <goffi@goffi.org>
date Fri, 21 Mar 2014 15:35:10 +0100
parents 6c2a1b349416
children 56c02f4731f9
comparison
equal deleted inserted replaced
76:6c2a1b349416 77:e1655ba45fae
792 792
793 for menu_tuple in menus_list: 793 for menu_tuple in menus_list:
794 name,menu = menu_tuple 794 name,menu = menu_tuple
795 self.addMenu(name, menu) 795 self.addMenu(name, menu)
796 796
797 def __showSelected(self): 797 def _showSelected(self):
798 """show menu selected""" 798 """show menu selected"""
799 name_txt = u'\u21c9 '+self.name_list[self.selected]+u' \u21c7 ' 799 name_txt = u'\u21c9 '+self.name_list[self.selected]+u' \u21c7 '
800 current_name = ClickableText(name_txt) 800 current_name = ClickableText(name_txt)
801 name_len = len(name_txt) 801 name_len = len(name_txt)
802 current_menu = self.menus[self.name_list[self.selected]] 802 current_menu = self.menus[self.name_list[self.selected]]
806 806
807 def keypress(self, size, key): 807 def keypress(self, size, key):
808 if key=='up': 808 if key=='up':
809 if self.columns.get_focus_column()==0 and self.selected > 0: 809 if self.columns.get_focus_column()==0 and self.selected > 0:
810 self.selected -= 1 810 self.selected -= 1
811 self.__showSelected() 811 self._showSelected()
812 return
812 elif key=='down': 813 elif key=='down':
813 if self.columns.get_focus_column()==0 and self.selected < len(self.name_list)-1: 814 if self.columns.get_focus_column()==0 and self.selected < len(self.name_list)-1:
814 self.selected += 1 815 self.selected += 1
815 self.__showSelected() 816 self._showSelected()
817 return
816 elif key=='right': 818 elif key=='right':
817 if self.columns.get_focus_column()==0 and \ 819 if self.columns.get_focus_column()==0 and \
818 (isinstance(self.columns.contents[1][0], urwid.Text) or \ 820 (isinstance(self.columns.contents[1][0], urwid.Text) or \
819 self.menus[self.name_list[self.selected]].getMenuSize()==0): 821 self.menus[self.name_list[self.selected]].getMenuSize()==0):
820 return #if we have no menu or the menu is empty, we don't go the right column 822 return #if we have no menu or the menu is empty, we don't go the right column
825 name = name_param or '' 827 name = name_param or ''
826 if name not in self.name_list: 828 if name not in self.name_list:
827 self.name_list.append(name) 829 self.name_list.append(name)
828 self.menus[name] = menu 830 self.menus[name] = menu
829 if self.name_list[self.selected] == name: 831 if self.name_list[self.selected] == name:
830 self.__showSelected() #if we are on the menu, we update it 832 self._showSelected() #if we are on the menu, we update it
831 833
832 def removeMenu(self, name): 834 def removeMenu(self, name):
833 if name in self.name_list: 835 if name in self.name_list:
834 self.name_list.remove(name) 836 self.name_list.remove(name)
835 if name in self.menus.keys(): 837 if name in self.menus.keys():
836 del self.menus[name] 838 del self.menus[name]
837 self.selected = 0 839 self.selected = 0
838 self.__showSelected() 840 self._showSelected()
839 841
840 def checkShortcuts(self, key): 842 def checkShortcuts(self, key):
841 for menu in self.name_list: 843 for menu in self.name_list:
842 key = self.menus[menu].checkShortcuts(key) 844 key = self.menus[menu].checkShortcuts(key)
843 return key 845 return key