Debian Codegraph @

fltk/test/simple_table.py

raw symbols SCIP
1 #
2 # "$Id: simple_table.py 107 2005-08-17 10:25:30Z andreasheld $"
3 #
4 # Simple Fl_Table test program for pyFLTK the Python bindings
5 # for the Fast Light Tool Kit (FLTK).
6 #
7 # FLTK copyright 1998-1999 by Bill Spitzak and others.
8 # Fl_Table copyright 2003 by G. Ercolano
9 # pyFLTK copyright 2003-2006 by Andreas Held and others.
10 #
11 # This library is free software you can redistribute it and/or
12 # modify it under the terms of the GNU Library General Public
13 # License, version 2.0 as published by the Free Software Foundation.
14 #
15 # This library is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 # Library General Public License for more details.
19 #
20 # You should have received a copy of the GNU Library General Public
21 # License along with this library if not, write to the Free Software
22 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 # USA.
24 #
25 # Please report all bugs and problems to "[email protected]".
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) # font used by all headers
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()