
Добавил:
deadpigeon
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:lab6 / lab6
.tcl package require Tk
set file_content ""
set subckt_names ""
proc open_file {} {
global file_content subckt_names
set filetypes {
{"SPICE Files" {.sp}}
{"All Files" *}
}
set filename [tk_getOpenFile -filetypes $filetypes]
if {$filename eq ""} {
return
}
set file_content [read_file $filename]
set file_content [remove_comments $file_content]
set subckt_names [extract_subckts $file_content]
.left_text delete 1.0 end
.left_text insert end $file_content
.right_text delete 1.0 end
.right_text insert end $subckt_names
}
proc read_file {filename} {
set f [open $filename r]
set content [read $f]
close $f
return $content
}
proc remove_comments {content} {
set lines [split $content "\n"]
set stripped_lines {}
foreach line $lines {
#set trimmed_line [string trim $line]
if {[string index $line 0] ne "*"} {
lappend stripped_lines $line
}
}
return [join $stripped_lines "\n"]
}
proc extract_subckts {content} {
set lines [split $content "\n"]
set subckts {}
foreach line $lines {
if {[string match "*subckt*" $line]} {
set subckt_name [lindex [split $line] 1]
lappend subckts $subckt_name
}
}
return [join $subckts "\n"]
}
proc about {} {
set about_text "Tcl/Tk program example"
tk_messageBox -title "About" -message $about_text -type ok -icon info
}
proc exit_app {} {
set answer [tk_messageBox -title "Exit" -message "Exit the program?" -type yesno -icon question]
if {$answer eq "yes"} {
exit
}
}
wm title . "Lab 6"
menu .menu
. configure -menu .menu
menu .menu.file -tearoff 0
.menu add cascade -label "File" -menu .menu.file
.menu.file add command -label "Open" -command open_file
.menu.file add separator
.menu.file add command -label "Exit" -command exit_app
menu .menu.help -tearoff 0
.menu add cascade -label "Help" -menu .menu.help
.menu.help add command -label "About" -command about
text .left_text -width 40 -height 20 -wrap none -bg green
text .right_text -width 20 -height 20 -wrap none -bg green
pack .left_text -side left -fill both -expand true
pack .right_text -side right -fill both -expand true
tkwait window .
set file_content ""
set subckt_names ""
proc open_file {} {
global file_content subckt_names
set filetypes {
{"SPICE Files" {.sp}}
{"All Files" *}
}
set filename [tk_getOpenFile -filetypes $filetypes]
if {$filename eq ""} {
return
}
set file_content [read_file $filename]
set file_content [remove_comments $file_content]
set subckt_names [extract_subckts $file_content]
.left_text delete 1.0 end
.left_text insert end $file_content
.right_text delete 1.0 end
.right_text insert end $subckt_names
}
proc read_file {filename} {
set f [open $filename r]
set content [read $f]
close $f
return $content
}
proc remove_comments {content} {
set lines [split $content "\n"]
set stripped_lines {}
foreach line $lines {
#set trimmed_line [string trim $line]
if {[string index $line 0] ne "*"} {
lappend stripped_lines $line
}
}
return [join $stripped_lines "\n"]
}
proc extract_subckts {content} {
set lines [split $content "\n"]
set subckts {}
foreach line $lines {
if {[string match "*subckt*" $line]} {
set subckt_name [lindex [split $line] 1]
lappend subckts $subckt_name
}
}
return [join $subckts "\n"]
}
proc about {} {
set about_text "Tcl/Tk program example"
tk_messageBox -title "About" -message $about_text -type ok -icon info
}
proc exit_app {} {
set answer [tk_messageBox -title "Exit" -message "Exit the program?" -type yesno -icon question]
if {$answer eq "yes"} {
exit
}
}
wm title . "Lab 6"
menu .menu
. configure -menu .menu
menu .menu.file -tearoff 0
.menu add cascade -label "File" -menu .menu.file
.menu.file add command -label "Open" -command open_file
.menu.file add separator
.menu.file add command -label "Exit" -command exit_app
menu .menu.help -tearoff 0
.menu add cascade -label "Help" -menu .menu.help
.menu.help add command -label "About" -command about
text .left_text -width 40 -height 20 -wrap none -bg green
text .right_text -width 20 -height 20 -wrap none -bg green
pack .left_text -side left -fill both -expand true
pack .right_text -side right -fill both -expand true
tkwait window .