Skip to content

Commit

Permalink
better "try...finally" syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
thanoulis committed Feb 28, 2024
1 parent 8834287 commit 457aa01
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions tqemu
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,30 @@ proc tqemu::SelectImage {tree} {
if {$file ni [dict values $tqemu::filelist]} {
try {
tk busy hold .
set statelist [exec -- qemu-img snapshot -l $file]
exec -- qemu-img snapshot -l $file
} on error msg {
tk_messageBox -title "Error loading [file tail $file]" \
-icon error -type ok -parent . \
-message [lindex [split $msg ":"] 0] -detail $msg
return 1
} on ok statelist {
set node [$tree insert {} end -text [file tail $file]]
$tree tag add File $node
set statelist [lsearch -all -inline \
-regexp $statelist {vm-([[:digit:]]){14}\M}]
if {$statelist ne ""} {
foreach state $statelist {
set child [$tree insert $node end -text $state]
$tree tag add State $child
}
}
dict set tqemu::filelist $node $file
$tree see $node
$tree selection set $node
tqemu::Message "$file ready"
} finally {
tk busy forget .
}
set node [$tree insert {} end -text [file tail $file]]
$tree tag add File $node
set statelist [lsearch -all -inline \
-regexp $statelist {vm-([[:digit:]]){14}\M}]
if {$statelist ne ""} {
foreach state $statelist {
set child [$tree insert $node end -text $state]
$tree tag add State $child
}
}
dict set tqemu::filelist $node $file
$tree see $node
$tree selection set $node
tqemu::Message "$file ready"
} else {
foreach node [$tree children {}] {
set item [dict get $tqemu::filelist $node]
Expand Down Expand Up @@ -184,10 +185,11 @@ proc tqemu::CreateImage {} {
-icon error -type ok -parent . \
-message [lindex [split $msg ":"] 0] -detail $msg
return 1
} on ok msg {
tqemu::Message "$filename created Size:${imgsize}"
} finally {
tk busy forget .
}
tqemu::Message "$filename created Size:${imgsize}"
}

proc tqemu::Share {w} {
Expand Down Expand Up @@ -244,12 +246,13 @@ proc tqemu::DeleteState {node tree} {
-icon error -type ok -parent . \
-message [lindex [split $msg ":"] 0] -detail $msg
return 1
} on ok msg {
$tree tag remove State $node
$tree delete $node
tqemu::Message "$state deleted"
} finally {
tk busy forget .
}
$tree tag remove State $node
$tree delete $node
tqemu::Message "$state deleted"
}

proc tqemu::BuildCmd {{loadvm ""}} {
Expand Down

0 comments on commit 457aa01

Please sign in to comment.