| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
from fltk import * |
| 29 |
import random |
| 30 |
|
| 31 |
|
| 32 |
class WidgetTable(Fl_Table_Row): |
| 33 |
data = [] |
| 34 |
def __init__(self, x, y, w, h, l): |
| 35 |
Fl_Table_Row.__init__(self, x, y, w, h, l) |
| 36 |
self.end() |
| 37 |
|
| 38 |
|
| 39 |
def draw_cell(self, context, R, C, X, Y, W, H): |
| 40 |
if context==self.CONTEXT_STARTPAGE: |
| 41 |
fl_font(FL_HELVETICA, 12) |
| 42 |
return None |
| 43 |
elif context==self.CONTEXT_CELL: |
| 44 |
s = f"{self.data[R][C]}" |
| 45 |
fl_push_clip(X,Y,W,H) |
| 46 |
fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, self.row_header_color()) |
| 47 |
fl_color(FL_BLACK) |
| 48 |
fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER) |
| 49 |
fl_pop_clip() |
| 50 |
return None |
| 51 |
else: |
| 52 |
return None |
| 53 |
|
| 54 |
def SetSize(self, newrows, newcols): |
| 55 |
self.rows(newrows) |
| 56 |
self.cols(newcols) |
| 57 |
for r in range(newrows): |
| 58 |
l = [] |
| 59 |
for c in range(newcols): |
| 60 |
l.append(random.randint(0, 1000)) |
| 61 |
self.data.append(l) |
| 62 |
self.redraw() |
| 63 |
self.end() |
| 64 |
|
| 65 |
def getValue(self, row, col): |
| 66 |
return self.data[row][col] |
| 67 |
|
| 68 |
def setValue(self, row, col, value): |
| 69 |
self.data[row][col] = value |
| 70 |
self.redraw() |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
if __name__=='__main__': |
| 75 |
win1 = Fl_Window(842, 292, "widgettable") |
| 76 |
table = WidgetTable(20, 20, win1.w()-40, win1.h()-40, "widgettable") |
| 77 |
table.SetSize(10, 10) |
| 78 |
win1.end() |
| 79 |
win1.show() |
| 80 |
|
| 81 |
print("Some values: ") |
| 82 |
print(" 0:0:", table.getValue(0,0)) |
| 83 |
print(" 5:5:", table.getValue(5,5)) |
| 84 |
|
| 85 |
table.setValue(5,5,13) |
| 86 |
|
| 87 |
print(" 5:5:", table.getValue(5,5)) |
| 88 |
|
| 89 |
Fl.run() |