equal
deleted
inserted
replaced
7 """Clickable button.""" |
7 """Clickable button.""" |
8 |
8 |
9 def __init__(self, label='btn'): |
9 def __init__(self, label='btn'): |
10 """Create button with given label, size according to label.""" |
10 """Create button with given label, size according to label.""" |
11 Widget.__init__(self) |
11 Widget.__init__(self) |
|
12 self.allow_focus = True |
12 |
13 |
13 #: Button label. |
14 #: Button label. |
14 self._label = '' |
15 self._label = '' |
15 #: Text or graphics to be added before label |
16 #: Text or graphics to be added before label |
16 self.prefix = '[' |
17 self.prefix = '[' |
19 #: How should label be aligned if button has excess space - center | left | right |
20 #: How should label be aligned if button has excess space - center | left | right |
20 self.align = 'center' |
21 self.align = 'center' |
21 #: Padding between prefix/suffix and label |
22 #: Padding between prefix/suffix and label |
22 self.padding = 1 |
23 self.padding = 1 |
23 |
24 |
24 self.allow_focus = True |
|
25 |
|
26 self.color = 'default' |
25 self.color = 'default' |
27 self.color_highlighted = 'default on red' |
26 self.color_active = 'default on red' |
28 self.highlight = False |
27 self.highlight = False |
29 |
28 |
30 self.sig_clicked = Signal() |
29 self.sig_clicked = Signal() |
31 |
30 |
32 self.label = label |
31 self.label = label |
43 self.sizereq.update(w, 1) |
42 self.sizereq.update(w, 1) |
44 |
43 |
45 def set_theme(self, theme): |
44 def set_theme(self, theme): |
46 Widget.set_theme(self, theme) |
45 Widget.set_theme(self, theme) |
47 self.color = theme.button |
46 self.color = theme.button |
48 self.color_highlighted = theme.button_active |
47 self.color_active = theme.button_active |
49 |
48 |
50 def _get_color(self): |
49 def _get_color(self): |
51 if self.highlight: # or self.has_focus(): |
50 if self.has_focus(): |
52 return self.color_highlighted |
51 return self.color_active |
53 return self.color |
52 return self.color |
54 |
53 |
55 def draw(self, buffer): |
54 def draw(self, buffer): |
56 Widget.draw(self, buffer) |
55 Widget.draw(self, buffer) |
57 pad = self.width - len(self.label) - len(self.prefix) - len(self.suffix) |
56 pad = self.width - len(self.label) - len(self.prefix) - len(self.suffix) |