equal
deleted
inserted
replaced
22 #: Padding between prefix/suffix and label |
22 #: Padding between prefix/suffix and label |
23 self.padding = 1 |
23 self.padding = 1 |
24 |
24 |
25 self.color = 'default' |
25 self.color = 'default' |
26 self.color_active = 'default on red' |
26 self.color_active = 'default on red' |
|
27 self.color_highlight = 'default on yellow' |
27 self.highlight = False |
28 self.highlight = False |
28 |
29 |
29 self.sig_clicked = Signal() |
30 self.sig_clicked = Signal() |
30 |
31 |
31 self.label = label |
32 self.label = label |
45 Widget.set_theme(self, theme) |
46 Widget.set_theme(self, theme) |
46 self.color = theme.button |
47 self.color = theme.button |
47 self.color_active = theme.button_active |
48 self.color_active = theme.button_active |
48 |
49 |
49 def _get_color(self): |
50 def _get_color(self): |
|
51 if self.highlight: |
|
52 return self.color_highlight |
50 if self.has_focus(): |
53 if self.has_focus(): |
51 return self.color_active |
54 return self.color_active |
52 return self.color |
55 return self.color |
53 |
56 |
54 def draw(self, buffer): |
57 def draw(self, buffer): |
69 buffer.puts(' ' * rpad, pos) |
72 buffer.puts(' ' * rpad, pos) |
70 pos += rpad |
73 pos += rpad |
71 # suffix |
74 # suffix |
72 buffer.puts(self.suffix, pos) |
75 buffer.puts(self.suffix, pos) |
73 |
76 |
74 def on_mousedown(self, ev): |
77 def mousedown_event(self, ev): |
75 self.highlight = True |
78 self.highlight = True |
76 self.redraw() |
79 #self.redraw() |
77 |
80 |
78 def on_mouseup(self, ev): |
81 def mouseup_event(self, ev): |
79 self.highlight = False |
82 self.highlight = False |
80 self.redraw() |
83 #self.redraw() |
|
84 self.sig_clicked() |
81 |
85 |
82 if self.enclose(ev.px, ev.py): |
86 def keypress_event(self, ev): |
83 self.emit('click') |
|
84 |
|
85 def on_keypress(self, ev): |
|
86 if ev.keyname == 'enter': |
87 if ev.keyname == 'enter': |
87 self.emit('click') |
88 self.sig_clicked() |
88 |
89 |
89 def _divide_padding(self, pad): |
90 def _divide_padding(self, pad): |
90 # default is 'left' |
91 # default is 'left' |
91 lpad, rpad = 0, pad |
92 lpad, rpad = 0, pad |
92 if self.align == 'center': |
93 if self.align == 'center': |