comparison frontends/sortilege/statusbar.py @ 0:c4bc297b82f0

sat: - first public release, initial commit
author goffi@necton2
date Sat, 29 Aug 2009 13:34:59 +0200
parents
children a5b5fb5fc9fd
comparison
equal deleted inserted replaced
-1:000000000000 0:c4bc297b82f0
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 """
5 sortilege: a SAT frontend
6 Copyright (C) 2009 Jérôme Poisson (goffi@goffi.org)
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 def echo(message):
28 return
29 os.system('echo "'+str(message)+'" >> /tmp/toto')
30
31 class StatusBar(Window):
32 """This class manage the edition of text"""
33
34 def __init__(self, parent, code="utf-8"):
35 self.__parent=parent
36 self.__code=code
37 self.__items=set()
38
39 Window.__init__(self, self.__parent, 1, self.__parent.getmaxyx()[1], self.__parent.getmaxyx()[0]-2,0, code=code)
40
41 def __len__(self):
42 return len(self.__items)
43
44 def resizeAdapt(self):
45 """Adapt window size to self.__parent size.
46 Must be called when self.__parent is resized."""
47 self.resize(1, self.__parent.getmaxyx()[1], self.__parent.getmaxyx()[0]-2,0)
48 self.update()
49
50 def update(self):
51 if self.isHidden():
52 echo ("status bar hidden")
53 return
54 echo ("update status bar")
55 Window.update(self)
56 x=0
57 for item in self.__items:
58 pitem="[%s] " % item
59 self.addYXStr(0, x, pitem, curses.A_REVERSE)
60 x = x + len(pitem)
61 if x>=self.rWidth:
62 break
63 self.addYXStr(0, x, (self.rWidth-x)*" ", curses.A_REVERSE)
64 self.noutrefresh()
65
66 def clear_text(self):
67 """Clear the text of the edit box"""
68 del(self.__items[:])
69
70 def add_item(self, item):
71 self.__items.add(item)
72 self.update()
73
74 def remove_item(self, item):
75 if item in self.__items:
76 self.__items.remove(item)
77 self.update()