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

📄 robot.tcl

📁 www工具包
💻 TCL
📖 第 1 页 / 共 2 页
字号:
#!bin/sh#the next line restarts using wish \exec /usr/local/bin/wish -f "$0" ${1+"$@"}# robot --# This script allows the user of the libwww web robot to issue # commands to the robot by checking options and clicking buttons.## MK, manoli@w3.org, Manolis Kamvysselis, 96/07/01#***********************************************************#Init = initialization and stuff that changes from platform#Init: initial values for variablesset url "http://www.w3.org/pub/WWW/"#init: id number for dialog boxesset id 0 #Init: Platform and computer dependent variablesproc InitPath {} {	global path webbot weblog webout webrules path source editor \			webbot-path weblog-path webout-path webrules-path	if [file exists webprefs] {		LoadPreferences	} else {		#prefs file does not exist: prompt user		Dialog "File webprefs not found. \n \			Would you like to create a new file \			in the current directory?" \			{create set cancel} \			{"Create File with Default Preferences" "Set Default Preferences" "Cancel"} \			{{SetDefaultPreferences; SavePreferences} SetDefaultPreferences ""}	}}#procedure to create a dialog box displaying a message,#defaults to ok and cancel, spelling Ok and Cancel and doing nothingproc Dialog {message {buttons {ok cancel}} {names {"ok" "cancel"}} {commands {"" ""}}} {	global id	set id [expr $id + 1]	if {"winfo exists .dialog$id" == 1} {		wm withdraw .dialog$id	}	toplevel .dialog$id	wm title .dialog$id "Dialog Box"	message .dialog$id.msg -aspect 1000 -text $message	pack .dialog$id.msg -side top	frame .dialog$id.buttons	foreach button $buttons {		set name [lindex $names [lsearch -exact $buttons $button]]		set command [lindex $commands [lsearch -exact $buttons $button]]		button .dialog$id.buttons.$button -text $name -command "wm withdraw .dialog$id; $command"		pack .dialog$id.buttons.$button -side left	}	pack .dialog$id.buttons -side bottom}#Window: name the window and set up bindingsproc SetWindow {} {	wm title . "W3C Web Robot user interface"			#key bindings equivalents to buttons	bind . <Return> Start	bind . <Control-x> exit	bind . <Control-q> exit		bind . <Control-p> AskPreferences}#***********************************************************#Menu: preferences for paths, and stuff all in a menuproc SetMenus {} {	global webbot source	#creates three menubuttons File, Edit, About	frame .menu	foreach which {file edit help} {		set Capitalized ""		append Capitalized [string toupper [string index $which 0]] \			[string range $which 1 end] 		menubutton .menu.$which -text $Capitalized -menu .menu.$which.menu		pack .menu.$which -side left	}	pack .menu -side top -fill x		#Menu: Robot: files to be used for output, log, and executable of the robot	set mfile [menu .menu.file.menu]	$mfile add command -label Run -command Start	$mfile add command -label "Edit Source" -command {exec $editor $source}	$mfile add separator	$mfile add command -label "Load Prefs..." -command {		Dialog "Load Preferences: This will discard the current Preferences" \		{ok set cancel} \		{"Go ahead" "View Current Preferences" "Abort the Mission"} \		{LoadPreferences AskPreferences ""}	}	$mfile add command -label "Save Prefs..." -command {			Dialog "Save Preferences: This will discard the Preferences Saved Previously" \		{ok set cancel} \		{"Go ahead" "View Current Preferences" "Abort the Mission"} \		{SavePreferences AskPreferences ""}	}	$mfile add separator	$mfile add command -label Preferences... -command AskPreferences	$mfile add separator	$mfile add command -label Quit -command exit		#Menu: edit copy paste and stuff	set medit [menu .menu.edit.menu]	$medit add command -label "Copy and Paste Url" -command CopyAndPasteUrl	$medit add command -label "Follow URL" -command FollowUrl		#Menu: about: version of the robot, and about the program	set mhelp [menu .menu.help.menu]	set blablahelp {"		To fetch links from a URL, enter the url and click webbot. 				To follow a URL returned, double click in the log, on the line of the 				URL that you want to follow. 				To simply copy a URL to the URL entry, so you can edit it afterwards, 				click the left then the right button on the corresponding line of the log. 		"}	$mhelp add command -label "Using" -command "Dialog $blablahelp ok Cool {}"			$mhelp add command -label "About the Robot" -command ShowVersion	set blablatext {"		Welcome to the W3C mini robot user interface. 				The selections that you make below, or in the preferences, are 				translated and passed on to the W3C mini robot, part of the 				w3c test library.				Have fun!!"}	$mhelp add command -label "About this Program" -command "Dialog $blablatext ok Thanx {}"}		#***********************************************************#Prefs: window to prompt for preferencesproc AskPreferences {} {	global editor source path webbot weblog webrules	toplevel .prefs	wm title .prefs "W3C WebRobot User Preferences"	#Editor: Which editor to use to edit the source	frame .prefs.editor	label .prefs.editor.l -text Editor:	entry .prefs.editor.path -textvariable editor	pack .prefs.editor.l -side left	pack .prefs.editor.path -side left -expand true -fill x	pack .prefs.editor -side top -fill x	#***********************************************************	#Edit: where to find the source of robot.tcl and editor to launch	frame .prefs.edit	label .prefs.edit.l -text Source:	entry .prefs.edit.source -textvariable source 	button .prefs.edit.edit -text Edit -command {exec $editor $source}	pack .prefs.edit.l -side left	pack .prefs.edit.source -side left -fill x -expand true	pack .prefs.edit.edit -side right	pack .prefs.edit -side top -fill x	#***********************************************************	#Path: Choose the common path of webbot weblog and webrules	frame .prefs.path		checkbutton .prefs.path.common -text Common -variable common \		-onvalue "Same" -offvalue "Different" -command {SetPath$common}	.prefs.path.common select	label .prefs.path.l -text Path:	entry .prefs.path.webbot -width 50 -relief sunken -textvariable path	bind .prefs.path.webbot <KeyRelease> {SetPath$common}	pack .prefs.path.common .prefs.path.l -side left	pack .prefs.path.webbot -side left -expand true	pack .prefs.path -side top -fill x	#***********************************************************	#SetPath*: procedures to set the path	proc SetPathSame {} {		global path		foreach what {bot log rules out} {			global web$what web$what-path			set web$what ""			append web$what $path [set web$what-path]		}	}	proc SetPathDifferent {} {		foreach what {bot log rules out} {			global web$what web$what-path			set web$what [set web$what-path]		}	}	#***********************************************************	#Log: choose the log file	array set Text {bot Webbot: log "Log File:" rules "Rules File:" \				out "Output File:"}	array set Value {bot webbot.exe log www-log rules www-rule out www-out}	foreach what {bot log rules out} {		global web$what web$what-path		frame .prefs.$what		set web$what-path $Value($what) 		label .prefs.$what.l -text $Text($what)		entry .prefs.$what.path -textvariable web$what-path		bind .prefs.$what.path <KeyRelease> {			global what			SetPath$common		}		label .prefs.$what.show -textvariable web$what -width 30		pack .prefs.$what.l -side left		pack .prefs.$what.path -side left -expand true -fill x		pack .prefs.$what.show -side right -expand true		pack .prefs.$what -side top -fill x	}		#***********************************************************	#Buttons: What to do once the preferences are set	frame .prefs.buttons	button .prefs.buttons.set -text "Set" -command ClosePrefsWindow	button .prefs.buttons.save -text "Save" -command "SavePreferences; ClosePrefsWindow"	button .prefs.buttons.load -text "Load" -command "LoadPreferences; ClosePrefsWindow"	button .prefs.buttons.edit -text "Edit" -command "$editor ${path}Webprefs"	foreach which {set save load edit} {		pack .prefs.buttons.$which -side left	}	pack .prefs.buttons -side top	proc ClosePrefsWindow {} {		wm withdraw .prefs	}}#prefs: initialize preferences, without saving them to a fileproc SetDefaultPreferences {} {	global path source editor webbot-path weblog-path webrules-path webout-path	set source ""	set path [pwd]\\	lappend source $path Robot.tcl	set editor "C:\\Program Files\\Accessories\\WordPad.exe"	set webbot-path webbot.exe	set weblog-path www-log	set webrules-path webrules	set webout-path www-out	foreach what {bot log out rules} {		global path web$what web$what-path		set web$what ""		append web$what $path [set web$what-path]	}}#prefs: Load preferences from webprefsproc LoadPreferences {} {	global editor source path webbot weblog webrules	Status Loading Preferences...	if [file exists webprefs] {		#the file webprefs exists: read the preferences		if [catch {open webprefs r} file] {			#file can't be read			Dialog "File Unreadable" ok "OK" ""		} else {			#file can be read			while {! [eof $file]} {				#still lines to read				gets $file line				if {[string compare # [string index $line 0]] == 0} {					#ignores commented lines				} else {					#assuming line of the form variable:value					set pair [split $line :]					set variable [lindex $pair 0]					set value [join [lrange $pair 1 [llength $pair]] :]					global $variable					set $variable $value					Log "setting $variable to $value"				} 
			}
			close $file
			TraceToButtons
		}

⌨️ 快捷键说明

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