klnx_a.tcl



# INTERFACES GRAFICAS DE KAREL
###############################################################################
###############################################################################
#		INTERFACES GRAFICAS DE KAREL
#
#		Autor: Ing. CUAUHTEMOC RIVERA LOAIZA
#
#		Universidad Michoacana de San Nicolas de Hidalgo
#
#		Seccion de Graduados de la Facultad de Ingenieria 
#		Electrica
#
#		Maestria en Sistemas Computacionales
#
#		Noviembre 1997 	crivera@scfie.eie.umich.mx
###############################################################################
###############################################################################
catch {destroy .karel}
catch {destroy .programa}

#########		CIUDAD DE KAREL
toplevel .karel
wm title .karel "El Mundo de Karel"
canvas .karel.ambiente -width 556 -height 535 -bg white
	.karel.ambiente create text 280 10 -text "A    V    E    N    I   D    A    S" -fill blue 
	.karel.ambiente create text 10 225 -text "C" -fill blue
	.karel.ambiente create text 10 245 -text "A" -fill blue
	.karel.ambiente create text 10 265 -text "L" -fill blue
	.karel.ambiente create text 10 285 -text "L" -fill blue 
	.karel.ambiente create text 10 305 -text "E" -fill blue 
	.karel.ambiente create text 10 325 -text "S" -fill blue 

########   EJE X
	set linea 0
	for { set i 20} { $i <= 520 } { set i [expr $i +20] } {
		if { fmod($linea,2) == 0} {set color gray80} {set color gray60}
		.karel.ambiente create line 40 $i 520 $i -fill $color
		incr linea
	}

#########  EJE Y	
	set linea 0
	for { set i 40} { $i <= 520 } { set i [expr $i +20] } {
		if { fmod($linea,2) == 0} {set color gray80} {set color gray60}
		.karel.ambiente create line $i 20 $i 520 -fill $color
		incr linea
	}
	 
# Numeracion de las calles 
	set j 21
	for { set i 25} { $i >0 } { incr i -1 } {
		set j [expr $j + 20]
		if { fmod( $j , 2) != 0} {
		.karel.ambiente create text 30 $j -text "$i"}
	}

# Numeracion de las avenidas
	set j 21
	for { set i 1 } { $i < 26 } { incr i } {
		set j [expr $j +20]
		if { fmod( $j , 2) != 0} {
		.karel.ambiente create text $j 530 -text "$i" }
	}

#PUNTOS CARDINALES
	.karel.ambiente create line 540 220 540 340 -width 3 -arrow both
	.karel.ambiente create line 530 280 550 280 -width 3 -arrow both
	.karel.ambiente create text 540 215 -text "N"
	.karel.ambiente create text 540 345 -text "S"
	#.karel.ambiente create text 265 490 -text "E"
	#.karel.ambiente create text 195 490 -text "O"

pack .karel.ambiente -side top

############################################################################
####	INTERFAZ PARA EL PROGRAMA FUENTE, HECHA CON EL "Visual Tcl v1.10 Project"
####   http://www.neuron.com
############################################################################
#############################################################################
proc Window {args} {
global vTcl
    set cmd [lindex $args 0]
    set name [lindex $args 1]
    set newname [lindex $args 2]
    set rest [lrange $args 3 end]
    if {$name == "" || $cmd == ""} {return}
    if {$newname == ""} {
        set newname $name
    }
    set exists [winfo exists $newname]
    switch $cmd {
        show {
            if {$exists == "1" && $name != "."} {wm deiconify $name; return}
            if {[info procs vTclWindow(pre)$name] != ""} {
                eval "vTclWindow(pre)$name $newname $rest"
            }
            if {[info procs vTclWindow$name] != ""} {
                eval "vTclWindow$name $newname $rest"
            }
            if {[info procs vTclWindow(post)$name] != ""} {
                eval "vTclWindow(post)$name $newname $rest"
            }
        }
        hide    { if $exists {wm withdraw $newname; return} }
        iconify { if $exists {wm iconify $newname; return} }
        destroy { if $exists {destroy $newname; return} }
    }
}

###############################################
# PROCEDIMIENTOS GENERADOS POR EL VISUAL TCL
#

proc vTclWindow. {base} {
    if {$base == ""} {
        set base .
    }
    ############################
    #CREACION DE LOS WIDGETS
    ############################
    wm focusmodel $base passive
    wm geometry $base 200x200+0+0
    wm maxsize $base 1028 749
    wm minsize $base 132 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm withdraw $base
    wm title $base "vt"
    #####################################
    # POSICIONAMIENTO DE LOS WIDGETS
    #####################################
}

proc vTclWindow.programa {base} {
    if {$base == ""} {
        set base .programa
    }
    if {[winfo exists $base]} {
        wm deiconify $base; return
    }
    ############################
    #CREACION DE LOS WIDGETS
    ############################
    toplevel $base -class Toplevel \
        -background #0080ff 
    wm focusmodel $base passive
    wm geometry $base 360x508+403+21
    wm maxsize $base 1028 749
    wm minsize $base 132 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm deiconify $base
   wm title $base "Karel para Linux"
    frame $base.cpd19 \
        -borderwidth 1 -height 30 -relief raised -width 30 
    scrollbar $base.cpd19.01 \
        -borderwidth 1 -command {.programa.cpd19.03 xview} -orient horiz \
        -width 10 
    scrollbar $base.cpd19.02 \
        -borderwidth 1 -command {.programa.cpd19.03 yview} -orient vert \
        -width 17 
    text $base.cpd19.03 \
        -background #ffffff \
        -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -height 1 \
        -width 8 -xscrollcommand {.programa.cpd19.01 set} \
        -yscrollcommand {.programa.cpd19.02 set} 
    frame $base.cpd21 \
        -background #c0c0c0 -borderwidth 1 -height 30 -relief sunken \
        -width 30 
    menubutton $base.cpd21.01 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.01.02 -padx 4 \
        -pady 3 -text Archivo -width 6 
    menu $base.cpd21.01.02 \
        -cursor {} -tearoff 0 
    $base.cpd21.01.02 add command \
        -label Nuevo  \
       -command { set alto 1 
		destroy .karel.ambiente
		set boton Avance
		source klnx_ambiente.tcl
		.programa.cpd19.03 delete 1.0 end }
    $base.cpd21.01.02 add command \
        -label Abrir -command { carga_archivo .programa.cpd19.03 archivo_x 1
        set avance 0} 
    $base.cpd21.01.02 add separator
    $base.cpd21.01.02 add command \
        -command {destroy .karel
destroy .programa} -label Salir 
    menubutton $base.cpd21.03 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.03.04 -padx 4 \
        -pady 3 -text Edicion 
    menu $base.cpd21.03.04 \
        -cursor {} -tearoff 0 

    $base.cpd21.03.04 add command \
        -label Cortar -command CORTAR_AL_PORTAPAPELES
    $base.cpd21.03.04 add command \
        -label Copiar -command COPIAR_AL_PORTAPAPELES
    $base.cpd21.03.04 add command \
        -label Pegar -command { PEGAR_DEL_PORTAPAPELES .programa.cpd19.03 }
    menubutton $base.cpd21.05 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.05.06 -padx 4 \
        -pady 3 -text Ayuda 
    menu $base.cpd21.05.06 \
        -tearoff 0 
   $base.cpd21.05.06 add command \
        -label "Acerca de ..." -command {source klnx_acerca.tcl }
    menubutton $base.cpd21.men23 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.men23.01 \
        -padx 4 -pady 3 -text Opciones -width 6 
    menu $base.cpd21.men23.01  \
        -tearoff 0 
    $base.cpd21.men23.01 add command \
    -label "Ver Archivo *.kar" -command muestra_fuente 
    menubutton $base.cpd21.men24 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.men24.01 \
        -padx 4 -pady 3 -text Compila -width 6     
    menu $base.cpd21.men24.01 \
        -tearoff 0 
    $base.cpd21.men24.01 add command \
        -label Compilar 
    menubutton $base.cpd21.men25 \
        -activebackground #c0c0c0 -anchor w -menu .programa.cpd21.men25.01 \
        -padx 4 -pady 3 -text Ejecuta -width 6 
    menu $base.cpd21.men25.01 \
        -tearoff 0 
    $base.cpd21.men25.01 add command \
    $base.cpd21.men25.01 add command \
0 ] }
    $base.cpd21.men25.01 add command \
 ] }
    button $base.but17 \
        -background green -padx 11 -pady 4 -textvariable boton \
        -command { avanza_instruccion $memoria($avance) $avance 
	.programa.but17 configure -bg green -fg black
	set boton Avance
	set alto 1
	incr avance }
    entry $base.etiqueta -textvariable archivo\
	-width 30 -bg white
    bind $base.etiqueta <Key-Return> {
	carga_archivo .programa.cpd19.03 $archivo 0
	set avance 0} 

    entry $base.nada \
        -background #0080ff -relief raised -textvariable continua -width 0 
    pack $base.nada \
        -in .programa -anchor ne -expand 0 -fill none -side top
    #####################################
    # POSICIONAMIENTO DE LOS WIDGETS
    #####################################
    place $base.cpd19 \
        -x 10 -y 80 -width 343 -height 416 -anchor nw 
    grid columnconf $base.cpd19 0 -weight 1
    grid rowconf $base.cpd19 0 -weight 1
    grid $base.cpd19.01 \
        -in .programa.cpd19 -column 0 -row 1 -columnspan 1 -rowspan 1 -sticky ew 
    grid $base.cpd19.02 \
        -in .programa.cpd19 -column 1 -row 0 -columnspan 1 -rowspan 1 -sticky ns 
    grid $base.cpd19.03 \
        -in .programa.cpd19 -column 0 -row 0 -columnspan 1 -rowspan 1 \
        -sticky nesw 
    place $base.cpd21 \
        -x 5 -y 10 -width 325 -height 25 -anchor nw 
    pack $base.cpd21.01 \
        -in .programa.cpd21 -anchor center -expand 0 -fill none -side left 
    pack $base.cpd21.03 \
        -in .programa.cpd21 -anchor center -expand 0 -fill none -side left 
    pack $base.cpd21.05 \
        -in .programa.cpd21 -anchor center -expand 0 -fill none -side right 
    place $base.cpd21.men23 \
        -x 105 -y 0 -width 63 -height 23 -anchor nw 
    place $base.cpd21.men24 \
        -x 170 -y 5 -width 59 -height 15 -anchor nw 
    place $base.cpd21.men25 \
        -x 225 -y 5 -width 54 -height 15 -anchor nw 
    place $base.but17 \
        -x 10 -y 45 -anchor nw -bordermode ignore
    place $base.etiqueta -x 100 -y 45 
}


############################################################################
####	INTERFAZ PARA LA PILA DE KAREL
############################################################################
proc vTclWindow.programa.pila {base} {
    if {$base == ""} {
        set base .programa.pila
    }
    if {[winfo exists $base]} {
        wm deiconify $base; return
    }


    toplevel $base -class Toplevel \
        -background #0080ff 
    wm focusmodel $base passive
    wm geometry $base 246x232+554+198
    wm maxsize $base 1028 749
    wm minsize $base 132 1
    wm overrideredirect $base 0
    wm resizable $base 1 1
    wm deiconify $base
    wm title $base "Pila"
    frame $base.frame \
        -borderwidth 1 -height 30 -relief raised -width 30 
    scrollbar $base.frame.scrollx \
        -borderwidth 1 -command {.programa.pila.frame.text xview} -orient horiz \
        -width 10 
    scrollbar $base.frame.scrolly \
        -borderwidth 1 -command {.programa.pila.frame.text yview} -orient vert \
        -width 10 
    text $base.frame.text \
        -background #ffffff \
        -font -Adobe-Helvetica-Medium-R-Normal-*-*-120-*-*-*-*-*-* -height 1 \
        -width 8 -xscrollcommand {.programa.pila.frame.scrollx set} \
        -yscrollcommand {.programa.pila.frame.scrolly set} 
    place $base.frame \
        -x 5 -y 5 -width 238 -height 221 -anchor nw 
    grid columnconf $base.frame 0 -weight 1
    grid rowconf $base.frame 0 -weight 1
    grid $base.frame.scrollx \
        -in .programa.pila.frame -column 0 -row 1 -columnspan 1 -rowspan 1 -sticky ew 
    grid $base.frame.scrolly \
        -in .programa.pila.frame -column 1 -row 0 -columnspan 1 -rowspan 1 -sticky ns 
    grid $base.frame.text \
        -in .programa.pila.frame -column 0 -row 0 -columnspan 1 -rowspan 1 \
        -sticky nesw 
}

Window show .
Window show .programa
Window show .programa.pila