Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(newb) How to paginate file contents

Status
Not open for further replies.

papageno

Technical User
Dec 25, 2004
24
ES
Hi, I am new to TCL. What I want to do is to get the contents of a text file, split it in pages and then display one page at a time on a text widget (with no scrollbar, just by clicking on a button).

Thanks in advance
 
When you define the text widget, you can specify how may lines to make it show:
text .<path>.<widgetname> -height <number of lines>

Then, what I would do is read in the whole file and split it into a list of lines:
set fid [open <filename> r]
set linelist [split [read $fid] \n]
close $fid


Now figure out how many pages you have:
set numlines [llength $linelist]
set numpages [expr {ceil($numlines/<number of lines>)}]


now loop through the number of pages when the button is pushed:
button .<path>.<button name> -text page -command {set pno [nxtpg pno]}
set pno 0
proc nxtpg {pno} {
global linelist <number of lines> numpages
if {$pno >= $numpages} {return $pno}
set ix1 [expr {1+$<number of lines>*$pno}]
set ix2 [expr {$ix1+$<number of lines>}]
for {set i $ix1} {$i<$ix2} {incr i} {
.<path>.<textwidgetname> insert end [lindex $linelist $i]\n
}
incr pno
return $pno
}



Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top