2
# "$Id: table.py 310 2007-02-22 11:12:22Z andreasheld $"
4
# Fl_Table test program for pyFLTK the Python bindings
5
# for the Fast Light Tool Kit (FLTK).
7
# FLTK copyright 1998-1999 by Bill Spitzak and others.
8
# Fl_Table copyright 2003 by G. Ercolano
9
# pyFLTK copyright 2003 by Andreas Held and others.
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 as published by the Free Software Foundation either
14
# version 2 of the License, or (at your option) any later version.
16
# This library is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
# Library General Public License for more details.
21
# You should have received a copy of the GNU Library General Public
22
# License along with this library if not, write to the Free Software
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
26
# Please report all bugs and problems to "pyfltk-user@lists.sourceforge.net".
33
def button_cb(w, data):
34
print "BUTTON: %s"%w.label()
36
class WidgetTable(Fl_Table_Row):
37
def __init__(self, x, y, w, h, l=""):
38
Fl_Table_Row.__init__(self, x, y, w, h, l)
41
self.col_header_height(25)
44
self.row_header_width(80)
47
def draw_cell(self, context, R, C, X, Y, W, H):
48
s="%d/%d"%(R,C) # text for each cell
50
if context==self.CONTEXT_STARTPAGE:
51
fl_font(FL_HELVETICA, 12) # font used by all headers
53
elif context==self.CONTEXT_RC_RESIZE:
55
for r in range(self.rows()):
56
for c in range(self.cols()):
57
if index >= self.children():
59
(status, X, Y, W, H) = self.find_cell(self.CONTEXT_TABLE, r, c, X, Y, W, H)
60
#(status, X, Y, W, H) = self.find_cell(self.CONTEXT_TABLE, r, c)
61
self.child(index).resize(X,Y,W,H)
65
elif context==self.CONTEXT_ROW_HEADER:
68
fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, self.row_header_color())
70
fl_draw(s1, X, Y, W, H, FL_ALIGN_CENTER)
73
elif context==self.CONTEXT_COL_HEADER:
75
fl_push_clip(X, Y, W, H)
76
fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, self.col_header_color())
78
fl_draw(s1, X, Y, W, H, FL_ALIGN_CENTER)
81
elif context==self.CONTEXT_CELL:
86
def SetSize(self, newrows, newcols):
91
for r in range(newrows):
92
for c in range(newcols):
97
(status, X, Y, W, H)=self.find_cell(self.CONTEXT_TABLE, r, c, X, Y, W, H)
101
inp = Fl_Input(X,Y,W,H)
105
butt = Fl_Light_Button(X,Y,W,H,s1)
106
self.s_list.append(s1)
107
butt.align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE)
108
butt.callback(button_cb, 0)
117
class DemoTable(Fl_Table_Row):
118
def __init__(self, x, y, w, h, l=""):
119
Fl_Table_Row.__init__(self, x, y, w, h, l)
121
def draw_cell(self, context, R, C, X, Y, W, H):
122
s="%d/%d"%(R,C) # text for each cell
124
if context==self.CONTEXT_STARTPAGE:
125
fl_font(FL_HELVETICA, 16)
127
elif context==self.CONTEXT_ROW_HEADER or context==self.CONTEXT_COL_HEADER:
128
fl_push_clip(X,Y,W,H)
129
fl_draw_box(FL_THIN_UP_BOX, X, Y, W, H, self.color())
131
fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER)
134
elif context==self.CONTEXT_CELL:
135
fl_push_clip(X,Y,W,H)
137
if self.row_selected(R):
138
fl_color(self.selection_color())
145
fl_draw(s, X, Y, W, H, FL_ALIGN_CENTER)
157
def table_cb(o, data):
159
print "%s callback: row=%d col=%d, context=%d, event=%d, clicks=%d"%(table.label(),table.callback_row(),table.callback_col(),table.callback_context(),Fl.event(), Fl.event_clicks())
161
if __name__=='__main__':
162
win1 = Fl_Window(940, 500, "widgettable")
163
table = WidgetTable(20, 20, win1.w()-40, win1.h()-40, "widgettable")
164
#table.SetSize(50, 50)
165
table.SetSize(20, 20)
167
win1.resizable(table)
181
win2 = Fl_Window(w, h, "testtablerow")
182
table1 = DemoTable(t1x, t1y, t1w, t1h, "Table 1")
183
table1.selection_color(FL_YELLOW)
184
table1.when(FL_WHEN_RELEASE) # handle table events on release
188
table1.col_header(1) # enable col header
189
table1.col_resize(4) # enable col resizing
190
table1.row_header(1) # enable row header
191
table1.row_resize(4) # enable row resizing
192
table1.callback(table_cb, table1)
193
table1.when(FL_WHEN_CHANGED|FL_WHEN_RELEASE)
196
table2 = DemoTable(t2x, t2y, t2w, t2h, "Table 2")
197
table2.selection_color(FL_YELLOW)
198
table2.when(FL_WHEN_RELEASE) # handle table events on release
202
table2.col_header(1) # enable col header
203
table2.col_resize(4) # enable col resizing
204
table2.row_header(1) # enable row header
205
table2.row_resize(4) # enable row resizing