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