⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 canvasprintbox.itk

📁 这是一个Linux下的集成开发环境
💻 ITK
📖 第 1 页 / 共 3 页
字号:
	itk_component add filerb {		radiobutton $cs.filerb \			-text File \			-justify left \			-anchor w \			-variable [scope _globVar($this,output)] \			-value file \			-command [code $this _update_attr]	} { 		usual		rename -font -labelfont labelFont Font	}	itk_component add fileef {		iwidgets::entryfield $cs.fileef \			-labeltext "filename:" \			-state disabled \			-labelpos w \			-textvariable [scope _globVar($this,fileef)]	}	itk_component add propsframe {		iwidgets::Labeledframe $itk_interior.propsframe \			-labelpos nw \			-labeltext "Properties"	}	set cs [$itk_component(propsframe) childsite]	itk_component add paperom {		iwidgets::optionmenu $cs.paperom \			-labelpos w -cyclicon 1 \			-labeltext "Paper size:" \			-command [code $this refresh]	} { 		usual		rename -font -labelfont labelFont Font	}	eval $itk_component(paperom) insert end [ezPaperInfo types]	$itk_component(paperom) select A4	itk_component add orientom {		iwidgets::radiobox $itk_interior.orientom \			-labeltext "Orientation" -command [code $this refresh]	}	$itk_component(orientom) add landscape -text Landscape	$itk_component(orientom) add portrait -text Portrait	$itk_component(orientom) select 0	itk_component add stretchcb {		checkbutton $cs.stretchcb \			-relief flat \			-text {Stretch to fit} \			-justify left \			-anchor w \			-variable [scope _globVar($this,stretchcb)] \			-command [code $this refresh]	} { 		usual		rename -font -labelfont labelFont Font	}	itk_component add postercb {		checkbutton $cs.postercb \			-relief flat \			-text Posterize \			-justify left \			-anchor w \			-variable [scope _globVar($this,postercb)] \			-command [code $this refresh]	} { 		usual		rename -font -labelfont labelFont Font	}	itk_component add hpcnt {		iwidgets::entryfield $cs.hpcnt \			-labeltext on \			-textvariable [scope _globVar($this,hpc)] \			-validate integer -width 3 \			-command [code $this refresh]	}	itk_component add vpcnt {		iwidgets::entryfield $cs.vpcnt \			-labeltext by \			-textvariable [scope _globVar($this,vpc)] \			-validate integer -width 3 \			-command [code $this refresh]	}	itk_component add pages {		label $cs.pages -text pages.	} { 		usual		rename -font -labelfont labelFont Font	}		set init_opts $args		grid $itk_component(canvasframe) -row 0 -column 0 -rowspan 4 -sticky nsew	grid $itk_component(propsframe)  -row 0 -column 1 -sticky nsew	grid $itk_component(outputom)    -row 1 -column 1 -sticky nsew	grid $itk_component(orientom)    -row 2 -column 1 -sticky nsew	grid columnconfigure $itk_interior 0 -weight 1	grid rowconfigure    $itk_interior 3 -weight 1	grid $itk_component(printerrb) -row 0 -column 0 -sticky nsw	grid $itk_component(printeref) -row 0 -column 1 -sticky nsw	grid $itk_component(filerb)    -row 1 -column 0 -sticky nsw	grid $itk_component(fileef)    -row 1 -column 1 -sticky nsw	iwidgets::Labeledwidget::alignlabels $itk_component(printeref) $itk_component(fileef)	grid columnconfigure $itk_component(outputom) 1 -weight 1	grid $itk_component(paperom)   -row 0 -column 0 -columnspan 2 -sticky nsw	grid $itk_component(stretchcb) -row 1 -column 0 -sticky nsw	grid $itk_component(postercb)  -row 2 -column 0 -sticky nsw	grid $itk_component(hpcnt)     -row 2 -column 1 -sticky nsw	grid $itk_component(vpcnt)     -row 2 -column 2 -sticky nsw	grid $itk_component(pages)     -row 2 -column 3 -sticky nsw	grid columnconfigure $itk_component(propsframe) 3 -weight 1	eval itk_initialize $args	bind $itk_component(pages) <Map> +[code $this _mapEventHandler]	bind $itk_component(canvas) <Configure> +[code $this refresh]}# ---------------------------------------------------------------# PUBLIC METHODS#----------------------------------------------------------------#<# This is used to set the canvas that has to be printed.# A stamp-sized copy will automatically be drawn to show how the# output would look with the current settings.## In:	canv - The canvas to be printed# Out:	canvas (attrib) - Holds the canvas to be printed#>	body iwidgets::Canvasprintbox::setcanvas {canv} {	set canvas $canv	_update_canvas}#<# Returns the value of the -printercmd or -filename option# depending on the current setting of -output.## In:	itk_option (attrib)# Out:	The value of -printercmd or -filename#>body iwidgets::Canvasprintbox::getoutput {} {	switch $_globVar($this,output) {	  "file" {		return $_globVar($this,fileef)	  }	  "printer" {	  	return $_globVar($this,printeref)	  }	}	return ""}#<# Perfrom the actual printing of the canvas using the current settings of# all the attributes.## In:	itk_option, rotate (attrib)# Out:	A boolean indicating wether printing was successful#>body iwidgets::Canvasprintbox::print {} {	global env tcl_platform	stop	if {$itk_option(-output) == "file"} {		set nm $itk_option(-filename)		if {[string range $nm 0 1] == "~/"} {			set nm "$env(HOME)/[string range $nm 2 end]"		}	} else {		set nm "/tmp/xge[winfo id $canvas]"	}	set pr [_calc_print_region]	set x1 [lindex $pr 0]	set y1 [lindex $pr 1]	set x2 [lindex $pr 2]	set y2 [lindex $pr 3]	set cx [expr int(($x2 + $x1) / 2)]	set cy [expr int(($y2 + $y1) / 2)]	if {!$itk_option(-stretch)} {		set ps [_calc_poster_size]		set pshw [expr int([lindex $ps 0] / 2)]		set pshh [expr int([lindex $ps 1] / 2)]		set x [expr $cx - $pshw]		set y [expr $cy - $pshh]		set w [ezPaperInfo $itk_option(-pagesize) pwidth $itk_option(-orient) $win]		set h [ezPaperInfo $itk_option(-pagesize) pheight $itk_option(-orient) $win]	} else {		set x $x1		set y $y1		set w [expr ($x2-$x1) / $_globVar($this,hpc)]		set h [expr ($y2-$y1) / $_globVar($this,vpc)]	}	set i 0	set px $x	while {$i < $_globVar($this,hpc)} {		set j 0		set py $y		while {$j < $_globVar($this,vpc)} {			set nm2 [expr {$_globVar($this,hpc) > 1 || $_globVar($this,vpc) > 1 ? "$nm$i.$j" : $nm}]			if {$itk_option(-stretch)} {				$canvas postscript \				  -file $nm2 \				  -rotate $rotate \				  -x $px -y $py \				  -width $w \				  -height $h \				  -pagex [ezPaperInfo $itk_option(-pagesize) centerx] \				  -pagey [ezPaperInfo $itk_option(-pagesize) centery] \				  -pagewidth [ezPaperInfo $itk_option(-pagesize) pwidth $itk_option(-orient)] \				  -pageheight [ezPaperInfo $itk_option(-pagesize) pheight $itk_option(-orient)]			} else {				$canvas postscript \				  -file $nm2 \				  -rotate $rotate \				  -x $px -y $py \				  -width $w \				  -height $h \				  -pagex [ezPaperInfo $itk_option(-pagesize) centerx] \				  -pagey [ezPaperInfo $itk_option(-pagesize) centery]			}			if {$itk_option(-output) == "printer"} {				set cmd "$itk_option(-printcmd) < $nm2"				if {[catch {eval exec $cmd &}]} {					return 0				}			}			set py [expr $py + $h]			incr j		}		set px [expr $px + $w]		incr i	}	return 1}#<# Retrieves the current value for all edit fields and updates# the stamp accordingly. Is useful for Apply-buttons.#>body iwidgets::Canvasprintbox::refresh {} {	stop	_update_canvas        return}#<# Stops the drawing of the "stamp". I'm currently unable to detect# when a Canvasprintbox gets withdrawn. It's therefore advised# that you perform a stop before you do something like that.#>body iwidgets::Canvasprintbox::stop {} {	if {$_reposition != ""} {		after cancel $_reposition		set _reposition ""	}	if {$_update_attr_id != ""} {		after cancel $_update_attr_id		set _update_attr_id ""	}        return}# ---------------------------------------------------------------# PROTECTED METHODS#----------------------------------------------------------------## Calculate the total size the output would be with the current# settings for "pagesize" and "posterize" (and "hpagecnt" and# "vpagecnt"). This size will be the size of the printable area,# some space has been substracted to take into account that a# page should have borders because most printers can't print on# the very edge of the paper.## In:	posterize, hpagecnt, vpagecnt, pagesize, orient (attrib)# Out:	A list of two numbers indicating the width and the height#	of the total paper area which will be used for printing#	in pixels.#body iwidgets::Canvasprintbox::_calc_poster_size {} {	set tpw [expr [ezPaperInfo $itk_option(-pagesize) \		pwidth $itk_option(-orient) $win]*$_globVar($this,hpc)]	set tph [expr [ezPaperInfo $itk_option(-pagesize) \		pheight $itk_option(-orient) $win]*$_globVar($this,vpc)]	return "$tpw $tph"}## Determine which area of the "source" canvas will be printed.# If "printregion" was set by the "user" this will be used and# converted to pixel-coordinates. If the user didn't set it# the bounding box that contains all canvas-items will be used# instead.## In:	printregion, canvas (attrib)# Out:	Four floats specifying the region to be printed in#	pixel-coordinates (topleft & bottomright).#body iwidgets::Canvasprintbox::_calc_print_region {} {	set printreg [expr {$itk_option(-printregion) != "" 		? $itk_option(-printregion) : [$canvas bbox all]}]	if {$printreg != ""} {		set prx1 [winfo fpixels $canvas [lindex $printreg 0]]		set pry1 [winfo fpixels $canvas [lindex $printreg 1]]		set prx2 [winfo fpixels $canvas [lindex $printreg 2]]		set pry2 [winfo fpixels $canvas [lindex $printreg 3]]		set res "$prx1 $pry1 $prx2 $pry2"	} else {		set res "0 0 0 0"	}		return $res}## Calculate the scaling factor needed if the output was# to be stretched to fit exactly on the page (or pages).# If stretching is turned off this will always return 1.0.## In:	stretch (attrib)# Out:	A float specifying the scaling factor.#body iwidgets::Canvasprintbox::_calc_print_scale {} {	if {$itk_option(-stretch)} {		set pr [_calc_print_region]		set prw [expr [lindex $pr 2] - [lindex $pr 0]]		set prh [expr [lindex $pr 3] - [lindex $pr 1]]		set ps [_calc_poster_size]		set psw [lindex $ps 0]		set psh [lindex $ps 1]		set sfx [expr $psw / $prw]		set sfy [expr $psh / $prh]		set sf [expr {$sfx < $sfy ? $sfx : $sfy}]		return $sf	} else {		return 1.0	}}## Schedule the thread that makes a copy of the "source"# canvas to the "stamp".## In:	win, canvas (attrib)# Out:	-#

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -