forked from crftwr/cfiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcfiler_statusbar.py
54 lines (39 loc) · 1.63 KB
/
cfiler_statusbar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import ckit
from ckit.ckit_const import *
#--------------------------------------------------------------------
class StatusBarLayer:
def __init__( self, priority ):
self.priority = priority
def paint( self, window, x, y, width, height ):
attr = ckit.Attribute( fg=ckit.getColor("bar_fg"))
window.putString( x, y, width, height, attr, " " * width )
class SimpleStatusBarLayer(StatusBarLayer):
def __init__( self, priority=-1, message="" ):
StatusBarLayer.__init__( self, priority )
self.message = message
self.error = False
def setMessage( self, message, error=False ):
self.message = message
self.error = error
def paint( self, window, x, y, width, height ):
s = " %s " % ( self.message )
s = ckit.adjustStringWidth( window, s, width )
if self.error:
attr = ckit.Attribute(fg=ckit.getColor("bar_error_fg"))
else:
attr = ckit.Attribute( fg=ckit.getColor("bar_fg"))
window.putString( x, y, width, height, attr, s )
class StatusBar:
def __init__(self):
self.layer_list = []
def registerLayer( self, layer ):
self.layer_list.append(layer)
self.layer_list.sort( key = lambda layer: layer.priority )
def unregisterLayer( self, layer ):
self.layer_list.remove(layer)
def paint( self, window, x, y, width, height ):
if len(self.layer_list)>0:
self.layer_list[0].paint( window, x, y, width, height )
else:
attr = ckit.Attribute( fg=ckit.getColor("bar_fg"))
window.putString( x, y, width, height, attr, " " * width )