diff options
author | Kevin Walzer <kw@codebykevin.com> | 2021-05-23 14:45:43 (GMT) |
---|---|---|
committer | Kevin Walzer <kw@codebykevin.com> | 2021-05-23 14:45:43 (GMT) |
commit | 9c156a8ee53daeaa404076997c8d4fc1d2189608 (patch) | |
tree | 5ae8d67288b3eebb58bf05a89b9951d62e64f2c4 | |
parent | a327016f886dab6a6fc066ead899d25c4234ff3f (diff) | |
download | tk-9c156a8ee53daeaa404076997c8d4fc1d2189608.zip tk-9c156a8ee53daeaa404076997c8d4fc1d2189608.tar.gz tk-9c156a8ee53daeaa404076997c8d4fc1d2189608.tar.bz2 |
More work on widget demo
-rw-r--r-- | library/demos/widget | 77 | ||||
-rw-r--r-- | library/print.tcl | 10 |
2 files changed, 13 insertions, 74 deletions
diff --git a/library/demos/widget b/library/demos/widget index d2c8834..04d215b 100644 --- a/library/demos/widget +++ b/library/demos/widget @@ -644,82 +644,11 @@ proc showCode w { # file - Name of the original file (implicitly for title) proc printCode {w file} { - set code [$w get 1.0 end-1c] - - set dir "." - if {[info exists ::env(HOME)]} { - set dir "$::env(HOME)" - } - if {[info exists ::env(TMP)]} { - set dir $::env(TMP) - } - if {[info exists ::env(TEMP)]} { - set dir $::env(TEMP) - } - - set filename [file join $dir "tkdemo-$file"] - set outfile [open $filename "w"] - puts $outfile $code - close $outfile - - switch -- $::tcl_platform(platform) { - unix { - if {[catch {exec lp -c $filename} msg]} { - tk_messageBox -title "Print spooling failure" \ - -message "Print spooling probably failed: $msg" - } - } - windows { - if {[catch {PrintTextWin32 $filename} msg]} { - tk_messageBox -title "Print spooling failure" \ - -message "Print spooling probably failed: $msg" - } - } - default { - tk_messageBox -title "Operation not Implemented" \ - -message "Wow! Unknown platform: $::tcl_platform(platform)" - } - } - # - # Be careful to throw away the temporary file in a gentle manner ... - # - if {[file exists $filename]} { - catch {file delete $filename} - } -} - -# PrintTextWin32 -- -# Print a file under Windows using all the "intelligence" necessary -# -# Arguments: -# filename - Name of the file -# -# Note: -# Taken from the Wiki page by Keith Vetter, "Printing text files under -# Windows". -# Note: -# Do not execute the command in the background: that way we can dispose of the -# file smoothly. -# -proc PrintTextWin32 {filename} { - package require registry - set app [auto_execok notepad.exe] - set pcmd "$app /p %1" - catch { - set app [registry get {HKEY_CLASSES_ROOT\.txt} {}] - set pcmd [registry get \ - {HKEY_CLASSES_ROOT\\$app\\shell\\print\\command} {}] - } - - regsub -all {%1} $pcmd $filename pcmd - puts $pcmd - - regsub -all {\\} $pcmd {\\\\} pcmd - set command "[auto_execok start] /min $pcmd" - eval exec $command + tk print text $w + } - + # tkAboutDialog -- # # Pops up a message box with an "about" message diff --git a/library/print.tcl b/library/print.tcl index 1a049e2..bea590a 100644 --- a/library/print.tcl +++ b/library/print.tcl @@ -740,6 +740,11 @@ namespace eval ::tk::print { proc ::tk::print::canvas {w} { + if {[winfo class $w] ne "Canvas"} { + error "Tk only supports printing from canvas and text widgets." + return + } + if {[tk windowingsystem] eq "win32"} { ::tk::print::_print_widget $w 0 "Tk Print Output" } @@ -748,6 +753,11 @@ proc ::tk::print::canvas {w} { proc ::tk::print::text {w} { + if {[winfo class $w] ne "Text"} { + error "Tk only supports printing from canvas and text widgets." + return + } + if {[tk windowingsystem] eq "win32"} { set txt [$w get 1.0 end] set x [file join $::env(TEMP) tk_output.txt] |