head	1.10;
access;
symbols;
locks; strict;
comment	@# @;


1.10
date	93.04.08.18.36.59;	author miley;	state Exp;
branches;
next	1.9;

1.9
date	93.04.08.18.07.42;	author miley;	state Exp;
branches;
next	1.8;

1.8
date	93.04.07.22.57.34;	author miley;	state Exp;
branches;
next	1.7;

1.7
date	93.04.07.22.42.52;	author miley;	state Exp;
branches;
next	1.6;

1.6
date	93.04.07.20.17.43;	author miley;	state Exp;
branches;
next	1.5;

1.5
date	93.04.07.12.36.10;	author terry;	state Exp;
branches;
next	1.4;

1.4
date	93.04.07.01.49.01;	author miley;	state Exp;
branches;
next	1.3;

1.3
date	93.04.06.17.43.35;	author terry;	state Exp;
branches;
next	1.2;

1.2
date	93.04.06.01.35.09;	author miley;	state Exp;
branches;
next	1.1;

1.1
date	93.04.06.00.20.52;	author miley;	state Exp;
branches;
next	;


desc
@@


1.10
log
@added pg_query.help
@
text
@:
awk '  BEGIN {
 line=1
}
{
	if (line==4){
		line=5
		for (i=2;i<=num_fields;i++)
			type_list[i-1]=$i
	}
	if (line==3){
		line=4
		num_fields=NF
		for (i=2;i<=num_fields;i++){
			mixed_name_list[i-1]=$i
			name_list[i-1]=sprintf("%s",tolower($i))
		}
	}
	if (line==2){
		fullname=sprintf("%s.%s",name,$2)
		schema_name=sprintf("%s",$2)
		line=3
	}
	if (line==1){
		name=sprintf("%s",$2)
		line=2
	}
}
END {
	print  "#!/local/bin/wish -f"
	print  "###############################################"
	print  "# assemble the widget"
	printf "# name %s \n",fullname
	print  "###############################################"
	print  "set auto_path \"$tk_library/demos $auto_path\""
	print  "source \"$env(PGSCRIPTS)/tkutils\""
	print  "button .look -text \"Look up ^l\" -command {look_up}"
	print  "button .enter -text \"Enter into Database ^e\" -command {enter_it}"
	print  "button .clear -text \"Clear Entries ^t\" -command {clear_it}"
	print  "button .delete -text \"Delete (Beware) ^b \" -command {help_delete_it}"
	print  "button .retrieveall -text \"Retrieve ALL\" -command {ret_all}"
	print  "scrollbar .xscr -orient horizontal -command { link_view }"
	print  ".xscr set 240  40 0 40"
	print  "frame .button_fr" 
	print  "menubutton .button_fr.file -text \"File\" -menu .button_fr.file.m "
	print  "menu .button_fr.file.m"
	print  ".button_fr.file.m add command -label \"Look Up\" -command {look_up}"
	print  ".button_fr.file.m add command -label \"Enter into Database\" -command {enter_it}"
	print  ".button_fr.file.m add command -label \"Clear Entries\" -command {clear_it}"
	print  ".button_fr.file.m add command -label \"Delete Instance(s)\" -command { help_delete_it }"
	print  ".button_fr.file.m add command -label \"Retrieve All Instances\" -command { ret_all }"
	print  ".button_fr.file.m add command -label \"Quit\" -command {destroy .}"
	print "source $env(PGSCRIPTS)/pg_query.help"
	print  "pack append .button_fr  .button_fr.file { padx 10 left } .look {left fill} .enter  {left fill} \\"
	print ".clear {left fill} .delete {left fill}  .retrieveall {left fill}  .button_fr.help {padx 10 right }"


	num_fields=num_fields-1
	for (i=1;i<=num_fields;i++){
		printf "frame .%s\n", name_list[i]
		printf "label .%s.lab -text \"%s (%s)\"\n", name_list[i], name_list[i],type_list[i]
		printf "entry .%s.ent -width 40 -relief sunken -scroll {.xscr set}\n", name_list[i]
		printf "pack append .%s .%s.lab {left fill} .%s.ent {right fill} \n",name_list[i],name_list[i],name_list[i]

	}
	print  "pack append .  .xscr {bottom fill} .button_fr {top fill} \\"
	for (i=1;i<=num_fields-1;i++){
		printf "\t.%s {top fill}\\\n", name_list[i]
	}
	printf "\t.%s {top fill}\n", name_list[i]
	print  "###############################################"
	print  "#Now define the routines"
	print  "###############################################"
	print  "proc help_delete_it { } { noticebox  \\"
	print  "\"Sorry, this feature is not implemented"
	print  "The delete feature is a little dangerous as it is possible to delete other users data on accident."
	print  "We are hoping to have a solution in version 2.0.\"}"
	print  "proc quit { } { exit}"
	print  "proc link_view { num } { "
		for (i=1;i<=num_fields;i++){
			printf "\t.%s.ent view $num \n", name_list[i]
		}
	print  "} "
	print  "proc clear_it { } { "
		for (i=1;i<=num_fields;i++){
			printf "\t.%s.ent delete 0 end\n", name_list[i]
		}
	print  "} "
	print  "###############################################"
	print  "#Now enter_it"
	print  "###############################################"

	print  "proc enter_it { } { "
		printf  "\tset load_query \"append %s ( \"\n",schema_name
		for (i=1;i<=num_fields;i++){
			printf "\tset %s [.%s.ent get ]\n", name_list[i], name_list[i]
		}
		print  "\tset prev 0 "
		for (i=1;i<=num_fields;i++){
			printf "\tif {($prev==1)&&($%s!=\"\")}\\\n", name_list[i]
			printf "\t\t{set load_query $load_query[echo \" , \" ] }\n"
			printf "\tif {($%s!=\"\")}\\\n", name_list[i]
			if (type_list[i]=="_text"||type_list[i]=="text"|| \
				type_list[i]=="char"|| type_list[i]=="_char"|| \
				type_list[i]=="char16"|| type_list[i]=="_char16") {
			printf "\t\t{set load_query $load_query[echo \"%s=\\\"\"]$%s[echo \"\\\"\"];set prev 1}\n", mixed_name_list[i], name_list[i]
			} else {
			printf "\t\t{set load_query $load_query[echo \"%s=\"]$%s;set prev 1}\n", mixed_name_list[i], name_list[i]
			}
		}
	printf  "\tset load_query $load_query[echo \" ) \\\\g\"]\n"
	print  "puts stdout $load_query "
	print  "\tif {($prev==1)} {" 
	printf  "\t\tset load_answer [echo $load_query | monitor %s]\n",name
	print  "\t\tdisplay_answer .out $load_answer"
	print  "\t} "
	print  "} "
	print  "###############################################"
	print  "#Now look_up"
	print  "###############################################"
	print  "proc look_up { } { "
		printf  "\tset look_query \"retrieve (q.all) from q in %s where \"\n",schema_name
		for (i=1;i<=num_fields;i++){
			printf "\tset %s [.%s.ent get ]\n", name_list[i], name_list[i]
		}
		print  "\tset prev 0 "
		for (i=1;i<=num_fields;i++){
			printf "\tif {($prev==1)&&($%s!=\"\")}\\\n", name_list[i]
			printf "\t\t{set look_query $look_query[echo \" and \" ] }\n"
			printf "\tif {($%s!=\"\")}\\\n", name_list[i]
			if (type_list[i]=="_text"||type_list[i]=="text"|| \
				type_list[i]=="char"|| type_list[i]=="_char"|| \
				type_list[i]=="char16"|| type_list[i]=="_char16") {
			printf "\t\t{set look_query $look_query[echo \"q.%s~\\\"\"]$%s[echo \"\\\"\"];set prev 1}\n", mixed_name_list[i], name_list[i]
			} else {
			printf "\t\t{set look_query $look_query[echo \"q.%s=\"]$%s;set prev 1}\n", mixed_name_list[i], name_list[i]
			}
		}
	printf  "\tset look_query $look_query[echo \"  \\\\g\"]\n"
	print  "puts stdout $look_query "
	print  "\tif {($prev==1)} {" 
	printf  "\t\tset look_answer [echo $look_query | monitor %s]\n",name
	print  "\t\tdisplay_answer .out $look_answer"
	print  "\t} "
	print  "} "
	print  "###############################################"
	print  "###############################################"
	print  "#Now delete_it"
	print  "###############################################"
	print  "proc delete_it { } { "
		print "help_delete_it"
		print "return"
		printf  "\tset look_query \"delete q from q in %s where \"\n",schema_name
		for (i=1;i<=num_fields;i++){
			printf "\tset %s [.%s.ent get ]\n", name_list[i], name_list[i]
		}
		print  "\tset prev 0 "
		for (i=1;i<=num_fields;i++){
			printf "\tif {($prev==1)&&($%s!=\"\")}\\\n", name_list[i], name_list[i]
			printf "\t\t{set look_query $look_query[echo \" and \" ] }\n"
			printf "\tif {($%s!=\"\")}\\\n", name_list[i], name_list[i]
			if (type_list[i]=="_text"||type_list[i]=="text"|| \
				type_list[i]=="char"|| type_list[i]=="_char"|| \
				type_list[i]=="char16"|| type_list[i]=="_char16") {
			printf "\t\t{set look_query $look_query[echo \"q.%s~\\\"\"]$%s[echo \"\\\"\"];set prev 1}\n", mixed_name_list[i], name_list[i]
			} else {
			printf "\t\t{set look_query $look_query[echo \"q.%s=\"]$%s;set prev 1}\n", mixed_name_list[i], name_list[i]
			}
		}
	printf  "\tset look_query $look_query[echo \"  \\\\g\"]\n"
	print  "puts stdout $look_query "
	print  "\tif {($prev==1)} {" 
	printf  "\t\tset look_answer [echo $look_query | monitor %s]\n",name 
	print  "\t\tdisplay_answer .out $look_answer"
	print  "\t}"
	print  "} "
    print  "###############################################"
    print  "#Now retrieve all"
    print  "###############################################"
    print  "proc ret_all { } { "
    printf  "\tset look_query \"retrieve (q.all) from q in %s \"\n",schema_name
    printf  "\tset look_query $look_query[echo \"  \\\\g\"]\n"
    print  "puts stdout $look_query  "
    printf  "\tset look_answer [echo $look_query | monitor %s]\n",name
    print  "\tdisplay_answer .out $look_answer"
    print  "} "
    print  "###############################################"
	print  "###############################################"
	print "proc display_answer {w input} {"
	print "catch {destroy $w}"
	print "toplevel $w"
	print "wm geometry $w +0+500"
	print "wm title $w \"Output of Query to Database\""
	print "wm iconname $w \"Query\""
	print "button $w.ok -text OK -command \"destroy $w\""
	print "listbox $w.t -yscrollcommand \"$w.y set\" -setgrid true\\"
	print " -xscrollcommand \"$w.x set\" -geometry 80x20"
	print "scrollbar $w.y -relief flat -command \"$w.t yview\""
	print "scrollbar $w.x -relief flat -command \"$w.t xview\" -orient \"horizontal\""
	print "pack append $w $w.ok {bottom fillx} $w.x {bottom fillx} $w.y {right filly} $w.t {expand fill}"
	print "set g [ split $input \\n ]"
	print "fillbox $w.t $g"
    print "bind $w.t <Double-Button-1> {user_defined .user_win [selection get]}"
	print "bind $w <Any-Enter> \"focus $w.t\""
	print "}"
#########################
# Terrys additions
#########################

    print  "proc user_defined  { w input } {"
    print  "catch {destroy $w}"
    print  "toplevel $w"
    print  "wm geometry $w -0+500"
    print  "wm title $w \"Select A field to perform a user defined function\""
    print  "wm iconname $w \"User\""
    print  "button $w.ok -text OK -command \"destroy $w\""
    print  "listbox $w.t -yscrollcommand \"$w.y set\" -setgrid true\\"
    print  " -xscrollcommand \"$w.x set\" -geometry 80x20"
    print  "scrollbar $w.y -relief flat -command \"$w.t yview\""
    print  "scrollbar $w.x -relief flat -command \"$w.t xview\" -orient horiz"
    print  "pack append $w $w.ok {bottom fillx} $w.x {bottom fillx} \\"
    print  "$w.y {right filly} $w.t {expand fill}"
    print  "set g [ split $input | ]"
    print  "fillbox $w.t $g"
    print  "bind $w <Any-Enter> \"focus $w.t\""
    print  "bind $w.t <Double-Button-1> {user_action [selection get]}"
    print  "}"
    print "#"
    print "# Edit function here to do user defined act otherwise it "
    print "# will echo input"
    print "proc user_action  { input } {"
    print "#if you wish to define your own action replace these lines"
    print "puts stdout [format \"user_action not defined for : %s\" $input ]"
    printf "puts stdout \"To define an action edit  the file /tmp/%s.wish\"\n", fullname
    print "puts stdout \"and search for the proc user_action\""
    print "puts stdout \"An action defined there include an IDL call.\""
    print "puts stdout \"This section is for a user to customize retrival actions\""
    print "#################################### "
    print "# The following is not fool proof yet as the pcat is not working correctly"
    print "# Idl script uncomment the following "
    printf "# exec \"/local/pkg/postgres/bin/pcat -D %s $input " ,name
    printf "> /tmp/idltmp.%s \"\n",name
    print "# set fp [ open {|idl} w+ ]"
    print "# puts $fp g=fltarr(695,415)"
    printf "# puts $fp openr,1,\"/tmp/idltmp.%s\"\n",name
    print "# puts $fp \"readu,1,g\""
    print "# puts $fp \"close,1\""
    print "# puts $fp \"tvscl,g\""
    print "# puts $fp \"loadct,13\""
    print "# puts $fp \"wait,60\""
    print "# flush $fp "
    print "# close $fp "
    printf "# rm /tmp/idltmp.%s \n", name
    print "# End of Idl script "
    print "#################################### "

    print "}"


	print "proc fillbox { box tofill } {"
print "foreach i $tofill { if { ( $i != \"\\}\" ) && ( $i != \"\\{\" ) } {$box insert end $i }}"

	print "}"



	print  "###############################################"
	print  "#Now do the key bindings"
	print  "###############################################"
	print "frame .out "
	print "wm geometry . +0+0  "
	printf "wm title . \"/tmp/%s.wish\"\n",fullname
	printf "focus .%s.ent  \n",name_list[1]
	print "bind all <ButtonRelease-2> { %W insert insert [selection get] }"
	print "bind Entry <Control-c> {destroy .}"
	print "bind Entry <Control-e> {enter_it }"
	print "bind Entry <Control-l> {look_up }"
	print "bind Entry <Control-t> {clear_it }"
	print "bind Entry <Control-b> {help_delete_it }"
		for (i=1;i<num_fields;i++){
			printf "bind .%s.ent <Tab> {focus .%s.ent }\n",name_list[i],name_list[i+1]
			printf "bind .%s.ent <Return> {focus .%s.ent }\n",name_list[i],name_list[i+1]
		}
		printf "bind .%s.ent <Tab> {focus .%s.ent }\n",name_list[num_fields],name_list[1]
		printf "bind .%s.ent <Return> {focus .%s.ent }\n",name_list[num_fields],name_list[1]

}'
@


1.9
log
@minor changes for sourceing tkutils
@
text
@d53 1
a53 3
	print  "menubutton .button_fr.help -text \"Help\" -menu .button_fr.help.m"
	print  "menu .button_fr.help.m"
	print ".button_fr.help.m add command -label \"About Query...\" -command { query_help } "
a176 4
    print  "proc query_help { } { helpbox \"This is Help for the Query Tool used inside pg_browse"
    print  "More help and features in version 2.0.  Version 2.0 will have"
    print  "hooks for sucking tabular data and large objects directly into"
    print  "existing software packages\"}"
@


1.8
log
@added HERE
@
text
@d36 1
a36 2
	print  "set HERE /home/src/base/local/tk/pg_browse"
	print  "source \"${HERE}/tkutils\""
d76 1
a76 1
	print  "proc help_delete_it { } { helpbox  not_implemented \\"
d179 1
a179 1
    print  "proc query_help { } { infobox Help \"This is Help for the Query Tool used inside pg_browse"
@


1.7
log
@misc addtions
@
text
@d36 2
a37 1
	print  "source \"/home/src/base/local/tk/pg_browse/tkutils\""
@


1.6
log
@got rid of extra lines of copy and paste.:
@
text
@d40 1
a40 1
	print  "button .delete -text \"Delete (Beware) ^b \" -command {delete_it}"
d50 1
a50 1
	print  ".button_fr.file.m add command -label \"Delete Instance(s)\" -command { delete_it }"
d76 4
d153 2
d179 4
a182 1
    print  "proc query_help { } { }"
d267 1
a267 1
print "foreach i $tofill { if { ( $i != \"\}\" ) && ( $i != \"\{\" ) } {$box insert end $i }}"
d285 1
a285 1
	print "bind Entry <Control-b> {delete_it }"
@


1.5
log
@Ok - I added the ability to double click on the listbox and
then it creates a new listbox of all the fields,
then when the end user wants to add a default function all hes has
to do is pcat the file and run his stuff locally.
@
text
@a205 2
    print "bind $w.t <Double-Button-1> {user_defined .user_win [selection get]}"
    print "}"
@


1.4
log
@added file and help options.  Got rid of quit at bottom.
@
text
@d56 2
a57 1
	print  "pack append .button_fr  .button_fr.file { padx 10 left } .look {left fill} .enter  {left fill} .clear {left fill} .delete {left fill}  .retrieveall {left fill}  .button_fr.help {padx 10 right }"
d200 1
d203 56
d260 2
a261 1
	print "foreach i $tofill { $box insert end $i }"
@


1.3
log
@done
@
text
@d36 1
a41 1
	print  "button .quit -text \"Quit ^c\" -width 40 -command {quit}"
a43 1

d45 12
a56 2
	print  "pack append .button_fr .look {left fill} .enter {left fill} \\" 
	print  ".clear {left fill} .delete {left fill}  .retrieveall {left fill}"
d67 1
a67 1
	print  "pack append . .quit {bottom fill} .xscr {bottom fill} .button_fr {top fill} \\" 
d172 1
@


1.2
log
@replaced nawk with gawk.
@
text
@d2 1
a2 1
gawk '  BEGIN {
d182 7
a188 5
	print "text $w.t -relief raised -bd 2 -yscrollcommand \"$w.s set\" -setgrid true"
	print "scrollbar $w.s -relief flat -command \"$w.t yview\""
	print "pack append $w $w.ok {bottom fillx} $w.s {right filly} $w.t {expand fill}"
	print "$w.t insert 0.0  $input"
	print "$w.t mark set insert 0.0"
d191 4
@


1.1
log
@Initial revision
@
text
@d2 1
a2 1
nawk '  BEGIN {
@
