Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tk print from 8.7 for 8.6

99 views
Skip to first unread message

greg

unread,
Sep 10, 2023, 2:43:13 PM9/10/23
to
Two files print-8.6erw.tcl and print-test.tcl.
tried to see if it also works with 8.6


#print-8.6erw.tcl
package require gdi
package require printer
#Tcl Extensions by Michael Schwarz
#http://wiki.tcl-lang.org/page/TkPrint
package require struct::list

namespace eval ::tk::print {
proc _opendoc {} {
printer job start
}

proc _openpage {} {
printer page start
}

proc _closedoc {} {
printer job end
}

proc _closepage {} {
printer page end
}

proc _gdi {args} {
gdi {*}$args
#tailcall gdi {*}$args
}

proc _selectprinter {} {
# variable printargs
variable printer_name
variable paper_width
variable paper_height
variable dpi_x
variable dpi_y
variable copies
set hDc [printer dialog select]
set attr [struct::list flatten [printer attr -hDc $hDc]]
# set printer_name [dict get $attr device]
# set printargs(printer_name) [dict get $attr device]
set printer_name [lindex $hDc 0]
set paper_width [lindex [dict get $attr "page dimensions"] 0]
set paper_height [lindex [dict get $attr "page dimensions"] 1]
set dpi_x [lindex [dict get $attr "pixels per inch"] 0]
set dpi_y [lindex [dict get $attr "pixels per inch"] 1]
set copies [dict get $attr copies]
}

#print-test.tcl
package require Tk
#tk 8.7
#https://core.tcl-lang.org/tips/doc/trunk/tip/604.md
#https://core.tcl-lang.org/tk/file?name=library/print.tcl&ci=tip

source print.tcl
source print-8.6erw.tcl

text .t
button .btn -text print -command {tk print .t}
.t insert end "hello World"
pack .t .btn

greg

unread,
Sep 11, 2023, 12:49:24 AM9/11/23
to
#print-8.6erw.tcl
#0.2
if {[tk windowingsystem] eq "win32"} {
if {[info tclversion] eq "8.6"} {
package require gdi
package require printer
#Tcl Extensions by Michael Schwarz
#http://wiki.tcl-lang.org/page/TkPrint
package require struct::list

namespace eval ::tk::print {

proc _openprinter {args} {
printer open args
}

proc _closeprinter {} {
printer close
}

proc _opendoc {} {
printer job start
}

Kevin Walzer

unread,
Sep 12, 2023, 10:28:12 PM9/12/23
to
On 9/11/23 12:49 AM, greg wrote:
> #print-8.6erw.tcl
> #0.2
> if {[tk windowingsystem] eq "win32"} {
> if {[info tclversion] eq "8.6"} {
> package require gdi
> package require printer
> #Tcl Extensions by Michael Schwarz
> #http://wiki.tcl-lang.org/page/TkPrint
> package require struct::list

Yes, the "tk print" code for Windows was based on these libraries by
Michael Schwartz, so the original libraries should work just fine on 8.6.

--Kevin

greg

unread,
Sep 13, 2023, 2:29:15 PM9/13/23
to
tk print for tk 8.7 is a great thing.
Also helped me understand printer/gdi better.
I really like the solution in print.tcl for linux print.
Searched for something like this for a long time.
0 new messages