annotate frontends/sortilege/statusbar.py @ 36:6491b7956c80

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