diff urwid_satext/sat_widgets.py @ 66:287ff3e1edd1

removed trailing spaces
author Goffi <goffi@goffi.org>
date Sat, 21 Dec 2013 16:51:14 +0100
parents 090f3e0754d3
children c270867a80f9
line wrap: on
line diff
--- a/urwid_satext/sat_widgets.py	Mon Mar 25 13:10:57 2013 +0100
+++ b/urwid_satext/sat_widgets.py	Sat Dec 21 16:51:14 2013 +0100
@@ -41,7 +41,7 @@
                     - the text to complete
                     - if there was already a completion, a dict with
                         - 'completed':last completion
-                        - 'completion_pos': cursor position where the completion starts 
+                        - 'completion_pos': cursor position where the completion starts
                         - 'position': last completion cursor position
                       this dict must be used (and can be filled) to find next completion)
                    and which return the full text completed"""
@@ -57,7 +57,7 @@
         elif key == 'ctrl k':
             self._delete_highlighted()
             self.set_edit_text(self.edit_text[:self.edit_pos])
-        elif key == 'ctrl w':    
+        elif key == 'ctrl w':
             before = self.edit_text[:self.edit_pos]
             pos = before.rstrip().rfind(" ")+1
             self.set_edit_text(before[:pos] + self.edit_text[self.edit_pos:])
@@ -83,7 +83,7 @@
             except AttributeError:
                 #No completion method defined
                 pass
-        return super(AdvancedEdit, self).keypress(size, key) 
+        return super(AdvancedEdit, self).keypress(size, key)
 
 class Password(AdvancedEdit):
     """Edit box which doesn't show what is entered (show '*' or other char instead)"""
@@ -110,7 +110,7 @@
 
     def render(self, size, focus=False):
         return super(Password, self).render(size, focus)
-       
+
 class ModalEdit(AdvancedEdit):
     """AdvancedEdit with vi-like mode management
     - there is a new 'mode' property wich can be changed with properties
@@ -140,7 +140,7 @@
             if self._modes[key][0] == value:
                 mode_key = key
                 break
-        
+
         mode, caption = self._modes[mode_key]
         self._mode = mode
         self.set_caption(caption)
@@ -158,7 +158,7 @@
         if self._mode == 'NORMAL' and key in self._modes:
             self.mode = self._modes[key][0]
             return
-        return super(ModalEdit, self).keypress(size, key) 
+        return super(ModalEdit, self).keypress(size, key)
 
 class SurroundedText(urwid.FlowWidget):
     """Text centered on a repeated character (like a Divider, but with a text in the center)"""
@@ -182,7 +182,7 @@
 class SelectableText(urwid.WidgetWrap):
     """Text which can be selected with space"""
     signals = ['change']
-    
+
     def __init__(self, text, align='left', header='', focus_attr='default_focus', selected_text=None, selected=False, data=None):
         """@param text: same as urwid.Text's text parameter
         @param align: same as urwid.Text's align parameter
@@ -254,7 +254,7 @@
             txt_list.append(txt)
         self._w.base_widget.set_text(txt_list)
 
-    
+
     def setState(self, selected, invisible=False):
         """Change state
         @param selected: boolean state value
@@ -266,7 +266,7 @@
         self._invalidate()
         if not invisible:
             self._emit("change", self.__selected)
-   
+
     def getState(self):
         return self.__selected
 
@@ -283,9 +283,9 @@
         if is_mouse_press(event) and button == 1:
             self.setState(not self.__selected)
             return True
-        
+
         return False
-   
+
     def render(self, size, focus=False):
         attr_list = self._w.base_widget._attrib
         if not focus:
@@ -312,7 +312,7 @@
 
 class ClickableText(SelectableText):
     signals = SelectableText.signals + ['click']
-    
+
     def setState(self, selected, invisible=False):
         super(ClickableText,self).setState(False,True)
         if not invisible:
@@ -324,7 +324,7 @@
         self.label = label
         self.left_border = left_border
         self.right_border = right_border
-        super(CustomButton, self).__init__([left_border, label, right_border]) 
+        super(CustomButton, self).__init__([left_border, label, right_border])
         self.size = len(self.get_text())
         if on_press:
             urwid.connect_signal(self, 'click', on_press, user_data)
@@ -349,7 +349,7 @@
         @param options: list of strings used for options
         @param style: list of string:
             - 'single' if only one must be selected
-            - 'no_first_select' nothing selected when list is first displayed 
+            - 'no_first_select' nothing selected when list is first displayed
             - 'can_select_none' if we can select nothing
         @param align: alignement of text inside the list
         @param on_click: method called when click signal is emited
@@ -361,13 +361,13 @@
         self.align = align
         self.option_type = option_type
         self.first_display = True
-        
+
         if on_click:
             urwid.connect_signal(self, 'click', on_click, user_data)
-        
+
         if on_change:
             urwid.connect_signal(self, 'change', on_change, user_data)
-        
+
         self.content = urwid.SimpleListWalker([])
         self.list_box = urwid.ListBox(self.content)
         urwid.WidgetWrap.__init__(self, self.list_box)
@@ -443,7 +443,7 @@
         display_widget = self.getDisplayWidget()
         self._set_w(display_widget)
         self._emit('change')
-        self.first_display = False 
+        self.first_display = False
 
     def selectValue(self, value):
         """Select the first item which has the given value"""
@@ -462,17 +462,17 @@
 
     def __init__(self, options, style=[], max_height=5, align='left', option_type = SelectableText, on_click=None, on_change=None, user_data=None):
         self.genericList = GenericList(options, style, align, option_type, on_click, on_change, user_data)
-        self.max_height = max_height 
+        self.max_height = max_height
 
     def selectable(self):
         return True
 
     def keypress(self, size, key):
         return self.displayWidget(size,True).keypress(size, key)
-        
+
     def unselectAll(self, invisible=False):
         return self.genericList.unselectAll(invisible)
-    
+
     def deleteValue(self, value):
         return self.genericList.deleteValue(value)
 
@@ -493,13 +493,13 @@
 
     def render(self, size, focus=False):
         return self.displayWidget(size, focus).render(size, focus)
-    
+
     def rows(self, size, focus=False):
         return self.displayWidget(size, focus).rows(size, focus)
 
     def displayWidget(self, size, focus):
         list_size = sum([wid.rows(size, focus) for wid in self.genericList.content])
-        height = min(list_size,self.max_height) or 1 
+        height = min(list_size,self.max_height) or 1
         return urwid.BoxAdapter(self.genericList, height)
 
 ## MISC ##
@@ -516,7 +516,7 @@
         self.columns = urwid.Columns([('fixed',6,self.waitNotifs),self.message,('fixed',4,self.progress)])
         urwid.WidgetWrap.__init__(self, urwid.AttrMap(self.columns,'notifs'))
         self.notifs = []
-    
+
     def __modQueue(self):
         """must be called each time the notifications queue is changed"""
         self.waitNotifs.set_text(('notifs',"(%i)" % len(self.notifs) if self.notifs else ''))
@@ -584,7 +584,7 @@
 class MenuBox(urwid.WidgetWrap):
     """Show menu items of a category in a box"""
     signals = ['click']
-    
+
     def __init__(self,parent,items):
         self.parent = parent
         self.selected = None
@@ -598,7 +598,7 @@
 
     def getValue(self):
         return self.selected
-   
+
     def keypress(self, size, key):
         if key=='up':
             if self.listBox.get_focus()[1] == 0:
@@ -607,7 +607,7 @@
             self.parent.keypress(size,'up')
             self.parent.keypress(size,key)
         return super(MenuBox,self).keypress(size,key)
-    
+
     def mouse_event(self, size, event, button, x, y, focus):
         if button == 3:
             self.parent.keypress(size,'up')
@@ -633,14 +633,14 @@
         self.save_bottom = None
         col_rol = ColumnsRoller()
         urwid.WidgetWrap.__init__(self, urwid.AttrMap(col_rol,'menubar'))
-    
+
     def selectable(self):
         return True
 
     def getMenuSize(self):
         """return the current number of categories in this menu"""
         return len(self.menu_keys)
-   
+
     def setOrigX(self, orig_x):
         self.x_orig = orig_x
 
@@ -656,8 +656,8 @@
         self.save_bottom = self.loop.widget
         menu_box = MenuBox(self,[item[0] for item in self.menu[menu_key]])
         urwid.connect_signal(menu_box, 'click', self.onItemClick)
-        
-        self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None) 
+
+        self.loop.widget = urwid.Overlay(urwid.AttrMap(menu_box,'menubar'),self.save_bottom,('fixed left', columns),max_len+2,('fixed top',1),None)
 
     def keypress(self, size, key):
         if key == 'down':
@@ -666,9 +666,9 @@
             if  self.save_bottom:
                 self.loop.widget = self.save_bottom
                 self.save_bottom = None
-            
+
         return self._w.base_widget.keypress(size, key)
-    
+
     def checkShortcuts(self, key):
         for shortcut in self.shortcuts.keys():
             if key == shortcut:
@@ -704,11 +704,11 @@
         if callback:
             self.keypress(None,'up')
             callback((category, item))
-    
+
     def onCategoryClick(self, button):
         self.__buildOverlay(button.get_label(),
-                            self.x_orig + self._w.base_widget.getStartCol(button)) 
-        
+                            self.x_orig + self._w.base_widget.getStartCol(button))
+
 
 class MenuRoller(urwid.WidgetWrap):
 
@@ -720,10 +720,10 @@
         self.selected = 0
         self.name_list = []
         self.menus = {}
-             
-        self.columns = urwid.Columns([urwid.Text(''),urwid.Text('')]) 
+
+        self.columns = urwid.Columns([urwid.Text(''),urwid.Text('')])
         urwid.WidgetWrap.__init__(self, self.columns)
-        
+
         for menu_tuple in menus_list:
             name,menu = menu_tuple
             self.addMenu(name, menu)
@@ -731,7 +731,7 @@
     def __showSelected(self):
         """show menu selected"""
         name_txt = u'\u21c9 '+self.name_list[self.selected]+u' \u21c7 '
-        current_name = ClickableText(name_txt) 
+        current_name = ClickableText(name_txt)
         name_len = len(name_txt)
         current_menu = self.menus[self.name_list[self.selected]]
         current_menu.setOrigX(name_len)
@@ -775,7 +775,7 @@
         for menu in self.name_list:
             key = self.menus[menu].checkShortcuts(key)
         return key
-        
+
 
 ## DIALOGS ##
 
@@ -783,7 +783,7 @@
 
     def __init__(self, widgets_lst, title, style=[], **kwargs):
         frame_header = urwid.AttrMap(urwid.Text(title,'center'),'title')
-       
+
         buttons = None
 
         if "OK/CANCEL" in style:
@@ -833,7 +833,7 @@
 ## CONTAINERS ##
 
 class ColumnsRoller(urwid.FlowWidget):
-    
+
     def __init__(self, widget_list = None, focus_column=0):
         self.widget_list = widget_list or []
         self.focus_column = focus_column
@@ -859,7 +859,7 @@
             return self.widget_list[self.focus_column][1].selectable()
         except IndexError:
             return False
-    
+
     def keypress(self, size, key):
         if key=='left':
             if self.focus_column>0:
@@ -892,7 +892,7 @@
         _prev = _next = False
         start_wid = 0
         end_wid = len(self.widget_list)-1
-        
+
         total_wid = sum([w[0] for w in self.widget_list])
         while total_wid > maxcol:
             if self.focus_column == end_wid:
@@ -907,11 +907,11 @@
                     _next = True
                 total_wid-=self.widget_list[end_wid][0]
                 end_wid-=1
-        
+
         cols_left = maxcol - total_wid
         self.__start = start_wid #we need to keep it for getStartCol
         return _prev,_next,start_wid,end_wid,cols_left
-        
+
 
     def mouse_event(self, size, event, button, x, y, focus):
         (maxcol,)=size
@@ -924,7 +924,7 @@
             if x==maxcol-1 and _next:
                 self.keypress(size,'right')
                 return True
-            
+
             current_pos = 1 if _prev else 0
             idx = 0
             while current_pos<x and idx<len(self.widget_list):
@@ -934,20 +934,20 @@
                     self._invalidate()
                     if not hasattr(widget,'mouse_event'):
                         return False
-                    return widget.mouse_event((width,0), event, button, 
+                    return widget.mouse_event((width,0), event, button,
                         x-current_pos, 0, focus)
 
                 current_pos+=self.widget_list[idx][0]
                 idx+=1
-        
+
         return False
-    
+
     def render(self, size, focus=False):
         if not self.widget_list:
             return SolidCanvas(" ", size[0], 1)
 
         _prev,_next,start_wid,end_wid,cols_left = self.__calculate_limits(size)
-        
+
         idx=start_wid
         render = []
 
@@ -972,7 +972,7 @@
         ret = urwid.Frame.keypress(self, size, key)
         if not ret:
             return
-        
+
         if key == 'tab':
             focus_list = ('header','body','footer')
             focus_idx = focus_list.index(self.focus_part)
@@ -983,7 +983,7 @@
                 if widget!=None and widget.selectable():
                     self.set_focus(focus_name)
 
-        return ret 
+        return ret
 
 class TabsContainer(urwid.WidgetWrap):
     signals = ['click']
@@ -1045,7 +1045,7 @@
         """Add a widget on the bottom of the tab (will be displayed on all pages)
         @param widget: FlowWidget"""
         self._w.footer = widget
-    
+
 
 ## DECORATORS ##
 class LabelLine(urwid.LineBox):
@@ -1059,7 +1059,7 @@
 class VerticalSeparator(urwid.WidgetDecoration, urwid.WidgetWrap):
     def __init__(self, original_widget, left_char = u"│", right_char = ''):
         """Draw a separator on left and/or right of original_widget."""
-        
+
         widgets = [original_widget]
         if left_char:
             widgets.insert(0, ('fixed', 1, urwid.SolidFill(left_char)))
@@ -1069,4 +1069,4 @@
         urwid.WidgetDecoration.__init__(self, original_widget)
         urwid.WidgetWrap.__init__(self, columns)
 
-        
+