author | Radek Brich <radek.brich@devl.cz> |
Sun, 22 Feb 2015 09:53:13 +0100 | |
changeset 119 | dd91747504dd |
parent 118 | 8c7970520632 |
permissions | -rw-r--r-- |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
1 |
from tuikit.core.widget import Widget |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
2 |
from tuikit.core.signal import Signal |
18
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
3 |
|
0 | 4 |
|
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
5 |
class TextBox(Widget): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
6 |
|
112 | 7 |
"""Multiline text view/edit widget.""" |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
8 |
|
62
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
9 |
def __init__(self, text=''): |
2f61931520c9
Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents:
45
diff
changeset
|
10 |
Widget.__init__(self) |
109
105b1affc3c2
Update keypress propagation. Allow focus change by tab key. Add log property to Widget for smart logging.
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
11 |
self.allow_focus = True |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
12 |
|
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
13 |
# Text content, splitted as lines |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
14 |
self._lines = [] |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
15 |
self.text = text |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
16 |
|
112 | 17 |
self._cursor_visible = True |
113 | 18 |
# This variable remembers horizontal cursor position |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
19 |
# for the case when cursor moves to shorter line. |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
20 |
self.cursor_column = 0 |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
21 |
# selection - line and column of selection start |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
22 |
self.sel_line = 0 |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
23 |
self.sel_column = 0 |
0 | 24 |
|
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
25 |
#self.add_events('scroll', Event) |
0 | 26 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
27 |
@property |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
28 |
def text(self): |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
29 |
return '\n'.join(self._lines) |
0 | 30 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
31 |
@text.setter |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
32 |
def text(self, value): |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
33 |
self._lines = value.split('\n') |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
34 |
maxlen = max([len(line) for line in self._lines]) |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
35 |
self.sizereq.update(w=maxlen, h=len(self._lines)) |
0 | 36 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
37 |
@property |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
38 |
def cur_line(self): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
39 |
return self._lines[self._cursor.y] |
3
33ec838dc021
Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
40 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
41 |
@cur_line.setter |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
42 |
def cur_line(self, value): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
43 |
self._lines[self._cursor.y] = value |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
44 |
|
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
45 |
def draw(self, buffer): |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
46 |
exposed = self.exposed(buffer) |
119
dd91747504dd
Redraw widgets on request. Add scrollbar demo.
Radek Brich <radek.brich@devl.cz>
parents:
118
diff
changeset
|
47 |
with buffer.attr(self.theme.clr_normal): |
96
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
48 |
buffer.fill() |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
49 |
end_y = min(len(self._lines), exposed.y + exposed.h) |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
50 |
for j in range(exposed.y, end_y): |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
51 |
line = self._lines[j] |
68c562e0eb1f
Add TextBox, text editor demo. Update demobase.
Radek Brich <radek.brich@devl.cz>
parents:
77
diff
changeset
|
52 |
buffer.puts(line, 0, j) |
0 | 53 |
|
111 | 54 |
def keypress_event(self, ev): |
55 |
if ev.keyname and not ev.mods: |
|
56 |
consumed = True |
|
57 |
if ev.keyname == 'left': self.move_left() |
|
58 |
elif ev.keyname == 'right': self.move_right() |
|
59 |
elif ev.keyname == 'home': self.move_home() |
|
60 |
elif ev.keyname == 'end': self.move_end() |
|
61 |
elif ev.keyname == 'up': self.move_up() |
|
62 |
elif ev.keyname == 'down': self.move_down() |
|
63 |
elif ev.keyname == 'pageup': self.move_pageup() |
|
64 |
elif ev.keyname == 'pagedown': self.move_pagedown() |
|
65 |
elif ev.keyname == 'backspace': self.backspace() |
|
66 |
elif ev.keyname == 'delete': self.del_char() |
|
67 |
elif ev.keyname == 'enter': self.add_newline(move=True) |
|
68 |
else: |
|
69 |
consumed = False |
|
70 |
if consumed: |
|
71 |
return True |
|
72 |
if ev.mods: |
|
73 |
consumed = True |
|
74 |
mk = ev.mod_key() |
|
75 |
if mk == 'ctrl+home': self.move_top() |
|
76 |
elif mk == 'ctrl+end': self.move_bottom() |
|
77 |
else: |
|
78 |
consumed = False |
|
79 |
if consumed: |
|
80 |
return True |
|
0 | 81 |
|
111 | 82 |
if ev.char and not ev.keyname: |
83 |
self.add_char(ev.char) |
|
0 | 84 |
self.move_right() |
111 | 85 |
return True |
0 | 86 |
|
118
8c7970520632
Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
87 |
def mousedown_event(self, ev): |
8c7970520632
Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
88 |
y = ev.pos.y |
8c7970520632
Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
89 |
x = min(ev.pos.x, len(self._lines[y])) |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
90 |
self._cursor.update(x=x, y=y) |
118
8c7970520632
Add mouse events, event demo.
Radek Brich <radek.brich@devl.cz>
parents:
113
diff
changeset
|
91 |
#self.redraw() |
0 | 92 |
|
45
43b2279b06e1
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents:
43
diff
changeset
|
93 |
def on_mousewheel(self, ev): |
0 | 94 |
if ev.button == 4: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
95 |
# wheel up |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
96 |
self.emit('scrollreq', -5) |
0 | 97 |
if ev.button == 5: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
98 |
# wheel down |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
99 |
self.emit('scrollreq', +5) |
0 | 100 |
self.redraw() |
101 |
||
102 |
def move_left(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
103 |
if self._cursor.x > 0: |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
104 |
self._cursor.x -= 1 |
0 | 105 |
else: |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
106 |
if self._cursor.y > 0: |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
107 |
self._cursor.y -= 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
108 |
self._cursor.x = len(self.cur_line) |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
109 |
self.cursor_column = self._cursor.x |
0 | 110 |
|
111 |
def move_right(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
112 |
if self._cursor.x < len(self.cur_line): |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
113 |
self._cursor.x += 1 |
0 | 114 |
else: |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
115 |
if self._cursor.y < len(self._lines) - 1: |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
116 |
self._cursor.y += 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
117 |
self._cursor.x = 0 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
118 |
self.cursor_column = self._cursor.x |
0 | 119 |
|
120 |
def move_home(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
121 |
self._cursor.x = 0 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
122 |
self.cursor_column = self._cursor.x |
0 | 123 |
|
124 |
def move_end(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
125 |
self._cursor.x = len(self.cur_line) |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
126 |
self.cursor_column = self._cursor.x |
0 | 127 |
|
128 |
def move_up(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
129 |
if self._cursor.y > 0: |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
130 |
self._cursor.y -= 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
131 |
self._update_cursor_x() |
0 | 132 |
|
133 |
def move_down(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
134 |
if self._cursor.y < len(self._lines) - 1: |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
135 |
self._cursor.y += 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
136 |
self._update_cursor_x() |
0 | 137 |
|
138 |
def move_pageup(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
139 |
if self._cursor.y >= self.view_height - 1: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
140 |
self.emit('scrollreq', - (self.view_height - 1)) |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
141 |
self._cursor.y -= self.view_height - 1 |
0 | 142 |
else: |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
143 |
self._cursor.y = 0 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
144 |
self._update_cursor_x() |
0 | 145 |
|
146 |
def move_pagedown(self): |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
147 |
if len(self._lines) - self._cursor.y > (self.view_height - 1): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
148 |
self.emit('scrollreq', (self.view_height - 1)) |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
149 |
self._cursor.y += self.view_height - 1 |
0 | 150 |
else: |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
151 |
self._cursor.y = len(self._lines) - 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
152 |
self._update_cursor_x() |
0 | 153 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
154 |
def move_top(self): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
155 |
self._cursor.y = 0 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
156 |
self._update_cursor_x() |
3
33ec838dc021
Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
157 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
158 |
def move_bottom(self): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
159 |
self._cursor.y = len(self._lines) - 1 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
160 |
self._update_cursor_x() |
3
33ec838dc021
Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
0
diff
changeset
|
161 |
|
0 | 162 |
def add_char(self, c): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
163 |
ln = self.cur_line |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
164 |
sx = self._cursor.x |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
165 |
self.cur_line = ln[:sx] + c + ln[sx:] |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
166 |
self.cursor_column = sx |
0 | 167 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
168 |
def add_newline(self, move=False): |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
169 |
ln = self.cur_line |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
170 |
sx = self._cursor.x |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
171 |
self.cur_line = ln[sx:] |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
172 |
self._lines.insert(self._cursor.y, ln[:sx]) |
112 | 173 |
self.sizereq.update(h=len(self._lines)) |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
174 |
if move: |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
175 |
self.move_right() |
0 | 176 |
|
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
177 |
def add_line(self, text): |
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
178 |
ln = self.cur_line |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
179 |
sx = self._cursor.x |
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
180 |
self.cur_line = ln[sx:] |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
181 |
self._lines.insert(self._cursor.y, ln[:sx] + text) |
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
182 |
self.cursor_column = 0 |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
183 |
self._cursor.x = 0 |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
184 |
self._cursor.y += 1 |
112 | 185 |
w = max(self.sizereq.w, len(ln[:sx] + text)) |
186 |
self.sizereq.update(w=w, h=len(self._lines)) |
|
76
fa5301e58eca
Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents:
74
diff
changeset
|
187 |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
188 |
def backspace(self): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
189 |
if self._cursor.y > 0 or self._cursor.x > 0: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
190 |
self.move_left() |
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
191 |
self.del_char() |
0 | 192 |
|
193 |
def del_char(self): |
|
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
194 |
ln = self.cur_line |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
195 |
sx = self._cursor.x |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
196 |
if sx == len(self.cur_line): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
197 |
if self._cursor.y + 1 < len(self._lines): |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
198 |
self.cur_line += self._lines[self._cursor.y+1] |
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
199 |
del self._lines[self._cursor.y+1] |
112 | 200 |
self.sizereq.update(h=len(self._lines)) |
0 | 201 |
else: |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
202 |
self.cur_line = ln[:sx] + ln[sx+1:] |
18
e6c3a5ee91aa
Eliminate relative imports.
Radek Brich <radek.brich@devl.cz>
parents:
9
diff
changeset
|
203 |
|
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
204 |
def _update_cursor_x(self): |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
205 |
if self.cursor_column > len(self.cur_line): |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
206 |
self._cursor.x = len(self.cur_line) |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
207 |
else: |
104
742e504ec053
Update TextBox: Replace "spot" with "cursor".
Radek Brich <radek.brich@devl.cz>
parents:
97
diff
changeset
|
208 |
self._cursor.x = self.cursor_column |
74
23767a33a781
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).
Radek Brich <radek.brich@devl.cz>
parents:
62
diff
changeset
|
209 |