author | Radek Brich <radek.brich@devl.cz> |
Fri, 14 Dec 2012 10:20:14 +0100 | |
changeset 32 | 088b92ffb119 |
parent 22 | 6ca8b2d221c3 |
child 33 | 45f1b6d590bd |
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 |
|
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
|
6 |
from tuikit.eventsource import Emitter |
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 |
|
21 | 70 |
# model |
71 |
self._model = None |
|
72 |
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
|
73 |
|
21 | 74 |
self.columns = [] |
75 |
self.spacing = 1 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
76 |
self.rowcount = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
77 |
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
|
78 |
|
21 | 79 |
self.offset = Coords() |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
80 |
self.acell = Coords() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
81 |
'''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
|
82 |
|
21 | 83 |
self.connect('draw', self.on_draw) |
84 |
self.connect('keypress', self.on_keypress) |
|
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
|
85 |
|
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 |
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
|
87 |
|
21 | 88 |
def getmodel(self): |
89 |
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
|
90 |
|
21 | 91 |
def setmodel(self, value): |
92 |
if self._model: |
|
93 |
self._model.disconnect('change', self.redraw) |
|
94 |
self._model = value |
|
95 |
if self._model: |
|
96 |
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
|
97 |
|
21 | 98 |
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
|
99 |
|
21 | 100 |
def addcolumn(self, *args, **kwargs): |
101 |
for col in args: |
|
102 |
self.columns.append(col) |
|
103 |
if len(args) == 0: |
|
104 |
col = Column(**kwargs) |
|
105 |
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
|
106 |
|
21 | 107 |
def compute_column_sizes(self): |
108 |
total_space = self.size.w - self.spacing * len(self.columns) |
|
109 |
no_expand_cols = [col for col in self.columns if not col.expand] |
|
110 |
no_expand_size = sum([col.sizereq for col in no_expand_cols]) |
|
111 |
expand_cols = [col for col in self.columns if col.expand] |
|
112 |
expand_num = len(expand_cols) |
|
113 |
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
|
114 |
|
21 | 115 |
# compute size of cols without expand |
116 |
for col in no_expand_cols: |
|
117 |
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
|
118 |
|
21 | 119 |
# compute size of cols with expand |
120 |
if no_expand_size > total_space + expand_num: |
|
121 |
for col in expand_cols: |
|
122 |
col.size = 1 |
|
123 |
else: |
|
124 |
total_req = sum([col.sizereq for col in expand_cols]) |
|
125 |
remaining_space = 0. |
|
126 |
for col in expand_cols: |
|
127 |
frac, intp = math.modf(expand_size * col.sizereq / total_req) |
|
128 |
col.size = int(intp) |
|
129 |
remaining_space += frac |
|
130 |
if remaining_space > 0.99: |
|
131 |
remaining_space -= 1. |
|
132 |
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
|
133 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
134 |
# compute indexes |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
135 |
idx = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
136 |
for col in self.columns: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
137 |
if not col.header: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
138 |
col.index = idx |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
139 |
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
|
140 |
|
21 | 141 |
def draw_head(self, screen, x, y): |
142 |
screen.pushcolor('strong') |
|
143 |
for col in self.columns: |
|
144 |
screen.puts(x, y, col.title[:col.size]) |
|
145 |
x += col.size + self.spacing |
|
146 |
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
|
147 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
148 |
def draw_row(self, screen, x, y, row, highlight): |
21 | 149 |
for col, data in zip(self.columns, row): |
150 |
if col.header: |
|
151 |
screen.pushcolor('strong') |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
152 |
elif col.index in highlight: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
153 |
screen.pushcolor('active') |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
154 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
155 |
screen.pushcolor('normal') |
21 | 156 |
screen.puts(x, y, data[:col.size]) |
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
157 |
screen.popcolor() |
21 | 158 |
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
|
159 |
|
21 | 160 |
def on_draw(self, 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 |
|
176 |
def on_keypress(self, keyname, char): |
|
177 |
if keyname: |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
178 |
if keyname == 'up': self.move_up() |
21 | 179 |
if keyname == 'down': self.move_down() |
180 |
if keyname == 'left': self.move_left() |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
181 |
if keyname == 'right': self.move_right() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
182 |
if keyname == 'pageup': self.move_pageup() |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
183 |
if keyname == 'pagedown': self.move_pagedown() |
21 | 184 |
self.redraw() |
185 |
||
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
186 |
def set_yofs(self, yofs): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
187 |
if yofs > self.rowcount - (self.height - self.headsize): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
188 |
yofs = self.rowcount - (self.height - self.headsize) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
189 |
if yofs < 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
190 |
yofs = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
191 |
self.offset.y = yofs |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
192 |
self.handle('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
|
193 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
194 |
def move_up(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
195 |
if self.acell.y > 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
196 |
self.acell.y -= 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
197 |
if self.acell.y < self.offset.y: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
198 |
self.set_yofs(self.acell.y) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
199 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
200 |
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
|
201 |
|
22
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
202 |
def move_down(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
203 |
log=logging.getLogger('tuikit') |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
204 |
log.debug('height %d', self.height) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
205 |
if self.acell.y < self.rowcount - 1: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
206 |
self.acell.y += 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
207 |
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
|
208 |
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
|
209 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
210 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
211 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
212 |
def move_pageup(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
213 |
if self.acell.y >= self.height - self.headsize - 1: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
214 |
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.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
|
216 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
217 |
self.acell.y = 0 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
218 |
self.set_yofs(0) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
219 |
|
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 |
def move_pagedown(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
222 |
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
|
223 |
self.acell.y += self.height - self.headsize - 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
224 |
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
|
225 |
else: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
226 |
self.acell.y = self.rowcount - 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
227 |
self.set_yofs(self.acell.y) |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
228 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
229 |
def move_left(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
230 |
if self.acell.x > 0: |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
231 |
self.acell.x -= 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
232 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
233 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
234 |
|
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
235 |
def move_right(self): |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
236 |
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
|
237 |
self.acell.x += 1 |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
238 |
return True |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
239 |
return False |
6ca8b2d221c3
Update TableView: cursor movement.
Radek Brich <radek.brich@devl.cz>
parents:
21
diff
changeset
|
240 |