home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.tcl
- Path: sparky!uunet!newsgate.watson.ibm.com!yktnews!admin!ghostwind!shmdgljd
- From: shmdgljd@rchland.vnet.ibm.com (Jay Schmidgall)
- Subject: tkfonts, a font browser in tk
- Sender: news@rchland.ibm.com
- Message-ID: <1992Nov19.150554.25365@rchland.ibm.com>
- Date: Thu, 19 Nov 1992 15:05:54 GMT
- Reply-To: jay@vnet.ibm.com
- Disclaimer: This posting represents the poster's views, not necessarily those of IBM
- Nntp-Posting-Host: ghostwind.rchland.ibm.com
- Organization: IBM Rochester, MN
- Lines: 82
-
- Uses xlsfonts to get a list of available fonts. Kludgy, but it works.
- Took a while to figure out how to insert the list of fonts into a listbox
- all at once rather than iterating over the list (which took a long time).
- Simple once I figured it out.
-
- Only shows characters I could easily type in the selected font.
- --------- Cut ---------------------------------------------------------
- #!/usr/contrib/bin/wish -f
-
- proc showfont { t args } {
- global text
- set w ".d$t"
- toplevel $w
- wm title $w $args
- set pos [expr [winfo x .]+[winfo width .]]+[winfo y .]
- wm geometry $w 400x200+$pos
- wm maxsize $w 1024 1024
- button $w.close -text Close -command "destroy $w"
-
- scrollbar $w.yscroll \
- -command "$w.t1 yview" \
- -relief raised
- text $w.t1 -font $args \
- -yscrollcommand "$w.yscroll set"
- $w.t1 insert end $text
-
- pack append $w \
- $w.close {top fillx} \
- $w.yscroll {left filly} \
- $w.t1 {top expand fill}
- }
-
- wm maxsize . 1024 1024
- wm geometry . 460x400
-
- button .quit -text Quit -command { destroy . }
-
- frame .frame
-
- scrollbar .frame.yscroll \
- -command ".frame.list yview" \
- -relief raised
-
- scrollbar .frame.xscroll \
- -command ".frame.list xview" \
- -relief raised \
- -orient horizontal
-
- listbox .frame.list \
- -yscrollcommand ".frame.yscroll set" \
- -xscrollcommand ".frame.xscroll set" \
- -font 7x13b \
- -relief flat
-
- tk_listboxSingleSelect .frame.list
- bind .frame.list <ButtonRelease-1> \
- { showfont %t [%W get [%W curselection]] }
-
- pack append .frame \
- .frame.yscroll {left filly} \
- .frame.xscroll {bottom fillx} \
- .frame.list {expand fill}
-
- set text \
- "~!@#\$%^&*()_+-={}|:\"<>?[]\\;',./`\n\
- 1234567890\n\
- abcdefghijklmnopqrstuvwxyz\n\
- ABCDEFGHIJKLMNOPQRSTUVWXYZ"
-
- pack append .\
- .quit {top fillx} \
- .frame {top expand fill}
-
- # Have to wrap {} around font names for cases
- # where the name contains spaces
- catch { exec xlsfonts | awk {{ print "{"$0"}" }} } fonts
- regsub -all \n $fonts " " fonts
- eval .frame.list insert end $fonts
- ------------- Cut -------------------------------------------------------
- --
- : jay jay@vnet.ibm.com My opinions and ideas, not my employer's.
- : shmdgljd@rchland.vnet.ibm.com (c) Copyright 1992. All rights reserved.
-