canvPsImg.tcl
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:3k
源码类别:

通讯编程

开发平台:

Visual C++

  1. # This file creates a screen to exercise Postscript generation
  2. # for images in canvases.  It is part of the Tk visual test suite,
  3. # which is invoked via the "visual" script.
  4. #
  5. # RCS: @(#) $Id: canvPsImg.tcl,v 1.2 2002/07/12 13:40:59 dgp Exp $
  6. # Build a test image in a canvas
  7. proc BuildTestImage {} {
  8.     global BitmapImage PhotoImage visual level
  9.     catch {destroy .t.f}
  10.     frame .t.f -visual $visual -colormap new
  11.     pack .t.f -side top -after .t.top
  12.     bind .t.f <Enter> {wm colormapwindows .t {.t.f .t}}
  13.     bind .t.f <Leave> {wm colormapwindows .t {.t .t.f}}
  14.     canvas .t.f.c -width 550 -height 350 -borderwidth 2 -relief raised
  15.     pack .t.f.c
  16.     .t.f.c create rectangle 25 25 525 325 -fill {} -outline black
  17.     .t.f.c create image 50 50 -anchor nw -image $BitmapImage
  18.     .t.f.c create image 250 50 -anchor nw -image $PhotoImage
  19. }
  20. # Put postscript in a file
  21. proc FilePostscript { canvas } {
  22.     global level
  23.     $canvas postscript -file /tmp/test.ps -colormode $level
  24. }
  25. # Send postscript output to printer
  26. proc PrintPostcript { canvas } {
  27.     global level
  28.     $canvas postscript -file tmp.ps -colormode $level
  29.     exec lpr tmp.ps
  30. }
  31. catch {destroy .t}
  32. toplevel .t
  33. wm title .t "Postscript Tests for Canvases: Images"
  34. wm iconname .t "Postscript"
  35. message .t.m -text {This screen exercises the Postscript-generation abilities of Tk canvas widgets for images.  Click the buttons below to select a Visual type for the canvas and colormode for the Postscript output.  Then click "Print" to send the results to the default printer, or "Print to file" to put the Postscript output in a file called "/tmp/test.ps".  You can also click on items in the canvas to delete them.  
  36. NOTE: Some Postscript printers may not be able to handle Postscript generated in color mode.} -width 6i
  37. pack .t.m -side top -fill both
  38. frame .t.top
  39. pack .t.top -side top
  40. frame .t.top.l -relief raised -borderwidth 2
  41. frame .t.top.r -relief raised -borderwidth 2
  42. pack .t.top.l .t.top.r -side left -fill both -expand 1
  43. label .t.visuals -text "Visuals"
  44. pack .t.visuals -in .t.top.l
  45. set visual [lindex [winfo visualsavailable .] 0]
  46. foreach v [winfo visualsavailable .] {
  47.     # The hack below is necessary for some systems, which have more than one
  48.     # visual of the same type...
  49.     if {![winfo exists .t.$v]} {
  50.         radiobutton .t.$v -text $v -variable visual -value $v 
  51. -command BuildTestImage
  52.         pack .t.$v -in .t.top.l -anchor w
  53.     }
  54. }
  55. label .t.levels -text "Color Levels"
  56. pack .t.levels -in .t.top.r
  57. set level monochrome
  58. foreach l { monochrome gray color } {
  59.     radiobutton .t.$l -text $l -variable level -value $l
  60.     pack .t.$l -in .t.top.r -anchor w
  61. }
  62. set BitmapImage [image create bitmap -file $tk_library/demos/images/face.bmp 
  63. -background white -foreground black]
  64. set PhotoImage [image create photo -file $tk_library/demos/images/teapot.ppm]
  65. BuildTestImage
  66. frame .t.bot
  67. pack .t.bot -side top -fill x -expand 1
  68. button .t.file -text "Print to File" -command { FilePostscript .t.f.c }
  69. button .t.print -text "Print" -command { PrintPostscript .t.f.c }
  70. button .t.quit -text "Quit" -command { destroy .t }
  71. pack .t.file .t.print .t.quit -in .t.bot -side left -fill x -expand 1