author | Radek Brich <radek.brich@devl.cz> |
Wed, 26 Dec 2012 01:00:31 +0100 | |
changeset 40 | 5faa38c10b67 |
parent 34 | e3beacd5e536 |
child 41 | 37b7dfc3eae6 |
permissions | -rw-r--r-- |
21 | 1 |
# -*- coding: utf-8 -*- |
2 |
||
3 |
import math |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
4 |
import logging |
21 | 5 |
|
33
45f1b6d590bd
Refactoring: rename eventsource module to emitter.
Radek Brich <radek.brich@devl.cz>
parents:
32
diff
changeset
|
6 |
from tuikit.emitter import Emitter |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
7 |
from tuikit.widget import Widget |
21 | 8 |
from tuikit.common import Coords |
9 |
||
10 |
||
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
11 |
class TableModel(Emitter): |
21 | 12 |
def __init__(self, list_of_lists): |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
13 |
self.add_events('change') |
21 | 14 |
self.data = list_of_lists |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
15 |
|
21 | 16 |
def getcount(self): |
17 |
'''Get number of rows.''' |
|
18 |
return len(self.data) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
19 |
|
21 | 20 |
def getrows(self, begin, end): |
21 |
'''Get rows from begin to end, including begin, excluding end.''' |
|
22 |
return self.data[begin:end] |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
23 |
|
21 | 24 |
def update(self, row, col, val): |
25 |
self.data[row][col] = val |
|
26 |
||
27 |
||
28 |
class Column: |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
29 |
|
21 | 30 |
'''Columns description.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
31 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
32 |
def __init__(self, title='', header=False, expand=True, sizereq=1, |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
33 |
readonly=False, maxlength=None): |
21 | 34 |
'''Create column with default values.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
35 |
|
21 | 36 |
self.title = title |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
37 |
'''Title is displayed in heading before first row.''' |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
38 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
39 |
self.header = header |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
40 |
'''Header column is highlighted, values in this column cannot be edited.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
41 |
|
21 | 42 |
self.expand = expand |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
43 |
'''If true, this column will autoresize to consume any free space.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
44 |
|
21 | 45 |
self.sizereq = sizereq |
46 |
'''Size request. Meaning depends on value of expand: |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
47 |
|
21 | 48 |
When false, sizereq is number of characters. |
49 |
When true, sizereq is relative size ratio. |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
50 |
|
21 | 51 |
''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
52 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
53 |
self.size = None |
21 | 54 |
'''Computed size of column.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
55 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
56 |
self.index = None |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
57 |
'''Computed index.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
58 |
|
21 | 59 |
self.readonly = readonly |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
60 |
'''If not readonly, values in this column can be changed by user.''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
61 |
|
21 | 62 |
self.maxlength = maxlength |
63 |
'''Maximum length of value (for EditField).''' |
|
64 |
||
65 |
||
66 |
class TableView(Widget): |
|
67 |
def __init__(self, model=None, width=20, height=20): |
|
68 |
Widget.__init__(self, width, height) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
69 |
|
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
70 |
self.allow_focus = True |
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
71 |
|
21 | 72 |
# model |
73 |
self._model = None |
|
74 |
self.setmodel(model) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
75 |
|
21 | 76 |
self.columns = [] |
77 |
self.spacing = 1 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
78 |
self.rowcount = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
79 |
self.headsize = 1 |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
80 |
|
21 | 81 |
self.offset = Coords() |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
82 |
self.acell = Coords() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
83 |
'''Active cell (cursor).''' |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
84 |
|
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
85 |
self.add_events('scroll', 'areasize') |
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
86 |
|
21 | 87 |
def getmodel(self): |
88 |
return self._model |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
89 |
|
21 | 90 |
def setmodel(self, value): |
91 |
if self._model: |
|
92 |
self._model.disconnect('change', self.redraw) |
|
93 |
self._model = value |
|
94 |
if self._model: |
|
95 |
self._model.connect('change', self.redraw) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
96 |
|
21 | 97 |
model = property(getmodel, setmodel) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
98 |
|
21 | 99 |
def addcolumn(self, *args, **kwargs): |
100 |
for col in args: |
|
101 |
self.columns.append(col) |
|
102 |
if len(args) == 0: |
|
103 |
col = Column(**kwargs) |
|
104 |
self.columns.append(col) |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
105 |
|
21 | 106 |
def compute_column_sizes(self): |
107 |
total_space = self.size.w - self.spacing * len(self.columns) |
|
108 |
no_expand_cols = [col for col in self.columns if not col.expand] |
|
109 |
no_expand_size = sum([col.sizereq for col in no_expand_cols]) |
|
110 |
expand_cols = [col for col in self.columns if col.expand] |
|
111 |
expand_num = len(expand_cols) |
|
112 |
expand_size = total_space - no_expand_size |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
113 |
|
21 | 114 |
# compute size of cols without expand |
115 |
for col in no_expand_cols: |
|
116 |
col.size = col.sizereq |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
117 |
|
21 | 118 |
# compute size of cols with expand |
119 |
if no_expand_size > total_space + expand_num: |
|
120 |
for col in expand_cols: |
|
121 |
col.size = 1 |
|
122 |
else: |
|
123 |
total_req = sum([col.sizereq for col in expand_cols]) |
|
124 |
remaining_space = 0. |
|
125 |
for col in expand_cols: |
|
126 |
frac, intp = math.modf(expand_size * col.sizereq / total_req) |
|
127 |
col.size = int(intp) |
|
128 |
remaining_space += frac |
|
129 |
if remaining_space > 0.99: |
|
130 |
remaining_space -= 1. |
|
131 |
col.size += 1 |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
132 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
133 |
# compute indexes |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
134 |
idx = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
135 |
for col in self.columns: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
136 |
if not col.header: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
137 |
col.index = idx |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
138 |
idx += 1 |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
139 |
|
21 | 140 |
def draw_head(self, screen, x, y): |
141 |
screen.pushcolor('strong') |
|
142 |
for col in self.columns: |
|
143 |
screen.puts(x, y, col.title[:col.size]) |
|
144 |
x += col.size + self.spacing |
|
145 |
screen.popcolor() |
|
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
146 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
147 |
def draw_row(self, screen, x, y, row, highlight): |
21 | 148 |
for col, data in zip(self.columns, row): |
149 |
if col.header: |
|
150 |
screen.pushcolor('strong') |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
151 |
elif col.index in highlight: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
152 |
screen.pushcolor('active') |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
153 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
154 |
screen.pushcolor('normal') |
21 | 155 |
screen.puts(x, y, data[:col.size]) |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
156 |
screen.popcolor() |
21 | 157 |
x += col.size + self.spacing |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
158 |
|
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
159 |
def _handle_draw(self, screen, x, y): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
160 |
super()._handle_draw(screen, x, y) |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
161 |
screen.pushcolor('normal') |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
162 |
self.rowcount = self.model.getcount() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
163 |
numrows = min(self.rowcount - self.offset.y, self.size.h - self.headsize) |
21 | 164 |
rows = self.model.getrows(self.offset.y, self.offset.y + numrows) |
165 |
self.compute_column_sizes() |
|
166 |
self.draw_head(screen, x, y) |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
167 |
y += self.headsize |
21 | 168 |
for row in rows: |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
169 |
highlight = [] |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
170 |
if self.offset.y + rows.index(row) == self.acell.y: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
171 |
highlight.append(self.acell.x) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
172 |
self.draw_row(screen, x, y, row, highlight) |
21 | 173 |
y += 1 |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
174 |
screen.popcolor() |
21 | 175 |
|
40
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
176 |
def _handle_keypress(self, keyname, char): |
5faa38c10b67
Add ScrollView widget. Update Emitter, rename "on_event" methods to "_handle_event". Update VScrollbar, Layout.
Radek Brich <radek.brich@devl.cz>
parents:
34
diff
changeset
|
177 |
super()._handle_keypress(keyname, char) |
21 | 178 |
if keyname: |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
179 |
if keyname == 'up': self.move_up() |
21 | 180 |
if keyname == 'down': self.move_down() |
181 |
if keyname == 'left': self.move_left() |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
182 |
if keyname == 'right': self.move_right() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
183 |
if keyname == 'pageup': self.move_pageup() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
184 |
if keyname == 'pagedown': self.move_pagedown() |
21 | 185 |
self.redraw() |
186 |
||
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
187 |
def set_yofs(self, yofs): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
188 |
if yofs > self.rowcount - (self.height - self.headsize): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
189 |
yofs = self.rowcount - (self.height - self.headsize) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
190 |
if yofs < 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
191 |
yofs = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
192 |
self.offset.y = yofs |
34
e3beacd5e536
Update event propagation, keypress event, focusing.
Radek Brich <radek.brich@devl.cz>
parents:
33
diff
changeset
|
193 |
self.emit('scroll') |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
194 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
195 |
def move_up(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
196 |
if self.acell.y > 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
197 |
self.acell.y -= 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
198 |
if self.acell.y < self.offset.y: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
199 |
self.set_yofs(self.acell.y) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
200 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
201 |
return False |
32
088b92ffb119
Clean up, refactoring. Rename EventSource to Emitter, begin merging emit() method with handle().
Radek Brich <radek.brich@devl.cz>
parents:
22
diff
changeset
|
202 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
203 |
def move_down(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
204 |
log=logging.getLogger('tuikit') |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
205 |
log.debug('height %d', self.height) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
206 |
if self.acell.y < self.rowcount - 1: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
207 |
self.acell.y += 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
208 |
if self.acell.y > self.offset.y + (self.height - self.headsize - 1): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
209 |
self.set_yofs(self.acell.y - (self.height - self.headsize - 1)) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
210 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
211 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
212 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
213 |
def move_pageup(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
214 |
if self.acell.y >= self.height - self.headsize - 1: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
215 |
self.acell.y -= self.height - self.headsize - 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
216 |
self.set_yofs(self.offset.y - (self.height - self.headsize - 1)) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
217 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
218 |
self.acell.y = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
219 |
self.set_yofs(0) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
220 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
221 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
222 |
def move_pagedown(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
223 |
if self.acell.y <= self.rowcount - (self.height - self.headsize - 1): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
224 |
self.acell.y += self.height - self.headsize - 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
225 |
self.set_yofs(self.offset.y + (self.height - self.headsize - 1)) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
226 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
227 |
self.acell.y = self.rowcount - 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
228 |
self.set_yofs(self.acell.y) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
229 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
230 |
def move_left(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
231 |
if self.acell.x > 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
232 |
self.acell.x -= 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
233 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
234 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
235 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
236 |
def move_right(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
237 |
if self.acell.x < len([col for col in self.columns if not col.header]) - 1: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
238 |
self.acell.x += 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
239 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
240 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
241 |