0
+ − 1 #!/usr/bin/python
+ − 2 # -*- coding: utf-8 -*-
+ − 3
+ − 4 """
+ − 5 sortilege: a SAT frontend
57
+ − 6 Copyright (C) 2009, 2010 Jérôme Poisson (goffi@goffi.org)
0
+ − 7
+ − 8 This program is free software: you can redistribute it and/or modify
+ − 9 it under the terms of the GNU General Public License as published by
+ − 10 the Free Software Foundation, either version 3 of the License, or
+ − 11 (at your option) any later version.
+ − 12
+ − 13 This program is distributed in the hope that it will be useful,
+ − 14 but WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ − 16 GNU General Public License for more details.
+ − 17
+ − 18 You should have received a copy of the GNU General Public License
+ − 19 along with this program. If not, see <http://www.gnu.org/licenses/>.
+ − 20 """
+ − 21
+ − 22
+ − 23 import curses
+ − 24 from window import Window
+ − 25 import os
+ − 26
+ − 27 class StatusBar ( Window ):
+ − 28 """This class manage the edition of text"""
+ − 29
+ − 30 def __init__ ( self , parent , code = "utf-8" ):
+ − 31 self . __parent = parent
+ − 32 self . __code = code
+ − 33 self . __items = set ()
+ − 34
+ − 35 Window . __init__ ( self , self . __parent , 1 , self . __parent . getmaxyx ()[ 1 ], self . __parent . getmaxyx ()[ 0 ] - 2 , 0 , code = code )
+ − 36
+ − 37 def __len__ ( self ):
+ − 38 return len ( self . __items )
+ − 39
+ − 40 def resizeAdapt ( self ):
+ − 41 """Adapt window size to self.__parent size.
+ − 42 Must be called when self.__parent is resized."""
+ − 43 self . resize ( 1 , self . __parent . getmaxyx ()[ 1 ], self . __parent . getmaxyx ()[ 0 ] - 2 , 0 )
+ − 44 self . update ()
+ − 45
+ − 46 def update ( self ):
+ − 47 if self . isHidden ():
+ − 48 return
+ − 49 Window . update ( self )
+ − 50 x = 0
+ − 51 for item in self . __items :
+ − 52 pitem = "[ %s ] " % item
+ − 53 self . addYXStr ( 0 , x , pitem , curses . A_REVERSE )
+ − 54 x = x + len ( pitem )
+ − 55 if x >= self . rWidth :
+ − 56 break
+ − 57 self . addYXStr ( 0 , x , ( self . rWidth - x ) * " " , curses . A_REVERSE )
+ − 58 self . noutrefresh ()
+ − 59
+ − 60 def clear_text ( self ):
+ − 61 """Clear the text of the edit box"""
+ − 62 del ( self . __items [:])
+ − 63
+ − 64 def add_item ( self , item ):
+ − 65 self . __items . add ( item )
+ − 66 self . update ()
+ − 67
+ − 68 def remove_item ( self , item ):
+ − 69 if item in self . __items :
+ − 70 self . __items . remove ( item )
+ − 71 self . update ()