diff options
Diffstat (limited to 'lib/simulator/stopwatch.tcl')
-rw-r--r--[-rwxr-xr-x] | lib/simulator/stopwatch.tcl | 118 |
1 files changed, 62 insertions, 56 deletions
diff --git a/lib/simulator/stopwatch.tcl b/lib/simulator/stopwatch.tcl index 407cdd3..353ac41 100755..100644 --- a/lib/simulator/stopwatch.tcl +++ b/lib/simulator/stopwatch.tcl @@ -2,7 +2,7 @@ # Part of MCU 8051 IDE ( http://mcu8051ide.sf.net ) ############################################################################ -# Copyright (C) 2007-2009 by Martin Ošmera # +# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera # # martin.osmera@gmail.com # # # # This program is free software; you can redistribute it and#or modify # @@ -21,6 +21,11 @@ # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # ############################################################################ +# >>> File inclusion guard +if { ! [ info exists _STOPWATCH_TCL ] } { +set _STOPWATCH_TCL _ +# <<< File inclusion guard + # -------------------------------------------------------------------------- # DESCRIPTION # Stopwatch timer for MCU simulator @@ -28,7 +33,7 @@ class Stopwatch { ## Class variables - common count 0 ;# Int: Counter of class instances + common stopw_count 0 ;# Int: Counter of class instances # List: Short names of stopwatch entries common stats_keys { US CC IC @@ -43,16 +48,6 @@ class Stopwatch { {Subprogram calls} {RET} {RETI} {Breakpoints} } - # Normal font (for entry boxes) - common normal_font [font create \ - -family Helvetica \ - -size -12 -weight normal\ - ] - # Bold font (for entry boxes) - common bold_font [font create \ - -family Helvetica \ - -size -12 -weight bold \ - ] ## Private varibales private variable win ;# Widget: Dialog window @@ -68,15 +63,16 @@ class Stopwatch { constructor {} { # Configure ttk styles - if {!$count} { + if {!$stopw_count} { ttk::style configure Stopwatch.TEntry -fieldreadonlybackground {#F8F8F8} ttk::style configure Stopwatch_Focused_D.TEntry -fieldbackground {#AAAAFF} -fieldreadonlybackground {#AAAAFF} + ttk::style configure Stopwatch_Focused_D_Invalid.TEntry -fieldbackground {#AAAAFF} -foreground {#FF0000} ttk::style configure Stopwatch_Focused_I.TEntry -fieldbackground {#DDDDFF} -fieldreadonlybackground {#DDDDFF} } # Increment counter of object instances - set obj_idx $count - incr count + set obj_idx $stopw_count + incr stopw_count # Restore configuration from the previous session set i 0 @@ -116,7 +112,7 @@ class Stopwatch { # @return void public method stopwatch_invoke_dialog {} { if {$dialog_opened} {return} - set win [toplevel .stopwatch$obj_idx -class {Stopwatch} -bg {#EEEEEE}] + set win [toplevel .stopwatch$obj_idx -class {Stopwatch} -bg ${::COMMON_BG_COLOR}] set dialog_opened 1 set stopwatch_on 1 @@ -126,11 +122,15 @@ class Stopwatch { bind $win <Control-Key-q> "destroy $win; break" bindtags $win [list $win Toplevel all .] - wm title $win "[mc {Stopwatch}] - [string trim $this {:}] - MCU 8051 IDE" + wm title $win "[mc {Stopwatch}] - [$this cget -projectName] - MCU 8051 IDE" wm iconphoto $win ::ICONS::22::history wm protocol $win WM_DELETE_WINDOW "$this stopwatch_close" + wm resizable $win 0 0 + update catch { - wm geometry $win $window_geometry + wm geometry $win [regsub {^\=?\d+x\d+} $window_geometry \ + [regsub {\+\d+\+\d+$} [wm geometry $win] {}] \ + ] } } @@ -146,18 +146,18 @@ class Stopwatch { set stop_a 0 foreach key $stats_keys { # Overall - set org_O [subst "\$::Stopwatch::text_vars${obj_idx}($key,O)"] + set org_O [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,O)"] set ::Stopwatch::text_vars${obj_idx}($key,O) $run_statistics($i) # Current if {$stopwatch_on} { incr ::Stopwatch::text_vars${obj_idx}($key,C) [expr {$run_statistics($i) - $org_O}] - set stop_a [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + set stop_a [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] # Conditional stop - if {$stop_a && $stop_a <= [subst "\$::Stopwatch::text_vars${obj_idx}($key,C)"]} { + if {$stop_a && $stop_a <= [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,C)"]} { stopwatch_start_stop - if {[subst "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"]} { + if {[subst -nocommands "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"]} { if {[$this sim_run_in_progress]} { $this sim_run } elseif {[$this sim_anim_in_progress]} { @@ -232,7 +232,9 @@ class Stopwatch { # - Label "STOPPED" set label_stopped_lbl [label $top_frame.label_stopped_lbl \ -font [font create \ - -family {Helvetica} -size -21 -weight bold \ + -family {Helvetica} \ + -size -21 \ + -weight bold \ ] -text {STOPPED} -fg {#FF0000} -pady 0 \ ] @@ -299,6 +301,8 @@ class Stopwatch { bind $entrybox <Key-Down> "$this stopwatch_entry_key $key $tp down; break" bind $entrybox <Key-Left> "$this stopwatch_entry_key $key $tp left; break" bind $entrybox <Key-Right> "$this stopwatch_entry_key $key $tp right; break" + bind $entrybox <Shift-Key-Left> "continue" + bind $entrybox <Shift-Key-Right> "continue" bind $entrybox <Key-Tab> "$this stopwatch_entry_key $key $tp tab; break" if {!$::MICROSOFT_WINDOWS} { bind $entrybox <Key-ISO_Left_Tab> "$this stopwatch_entry_key $key $tp stab; break" @@ -356,7 +360,7 @@ class Stopwatch { $entryboxes($key,C) configure -style Stopwatch_Focused_I.TEntry $entryboxes($key,S) configure -style Stopwatch_Focused_I.TEntry $entryboxes($key,$type) configure -style Stopwatch_Focused_D.TEntry - } { + } else { $entryboxes($key,$type) selection clear $entryboxes($key,C) configure -style TEntry $entryboxes($key,S) configure -style TEntry @@ -459,11 +463,11 @@ class Stopwatch { # Adjust foreground color for entrybox in column "Current" if {$type == {C} && $string != {}} { - set max [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] - if {$max && $string >= $max} { - $entryboxes($key,C) configure -fg {#FF0000} -font $bold_font - } { - $entryboxes($key,C) configure -fg {#000000} -font $normal_font + set max [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + if {$max != {} && $max != 0 && $string >= $max} { + $entryboxes($key,C) configure -style Stopwatch_Focused_D_Invalid.TEntry + } else { + $entryboxes($key,C) configure -style Stopwatch_Focused_D.TEntry } } @@ -471,7 +475,7 @@ class Stopwatch { if {$type == {C} || $type == {S}} { if {$string != {} && $string != 0} { $clearbuttons($key,$type) configure -state normal - } { + } else { $clearbuttons($key,$type) configure -state disabled } } @@ -500,13 +504,13 @@ class Stopwatch { # @parm Bool text__html - File type (1 == Plain text; 0 == XHTML) # @return void public method stopwatch_save {text__html} { - # Determinate list of avaliable file extensions + # Determinate list of available file extensions if {$text__html} { set filetypes [list \ [list [::mc "Text files"] {*.txt}] \ [list [::mc "All files"] {*}] \ ] - } { + } else { set filetypes [list \ [list [::mc "HTML files"] {*.html}] \ [list [::mc "All files"] {*}] \ @@ -519,7 +523,7 @@ class Stopwatch { -directory [$this cget -projectPath] \ -master $win -filetypes [mc $filetypes] \ -defaultmask 0 -multiple 0 \ - -initialfile [string trim $this {:}] + -initialfile [$this cget -projectName] # Open file after press of OK button ::fsd setokcmd " @@ -544,7 +548,7 @@ class Stopwatch { if {![string length [file extension $filename]]} { if {$text__html} { append filename {.txt} - } { + } else { append filename {.html} } } @@ -559,7 +563,7 @@ class Stopwatch { -title [mc "Overwrite file"] \ -message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $filename]] ] != {yes} - } { + } then { return } # Create a backup file @@ -570,8 +574,8 @@ class Stopwatch { # Open the specified file if {[catch { - set file [open $filename w 420] - }]} { + set file [open $filename w 0640] + }]} then { tk_messageBox \ -parent . \ -type ok \ @@ -584,34 +588,33 @@ class Stopwatch { # Save as plain text if {$text__html} { set text {} - append text [string repeat { } 33] "Current" \ - [string repeat { } 10] "Stop after" \ - [string repeat { } 13] "Overall" + append text [string repeat { } 37] [mc "Current"] \ + [string repeat { } 10] [mc "Stop after"] \ + [string repeat { } 13] [mc "Overall"] puts $file $text foreach text $stats_names key $stats_keys { set text [mc $text] - append text [string repeat { } [expr {20 - [string length $text]}]] + append text [string repeat { } [expr {24 - [string length $text]}]] foreach subkey {C S O} { - set val [subst "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] + set val [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] append text [string repeat { } [expr {20 - [string length $val]}]] $val } puts $file $text } - puts $file "\nProject: [string trim $this {:}]" - puts $file "Date: [clock format [clock seconds] -format {%D}]" - puts $file "Generated by ${::APPNAME} ( http://mcu8051ide.sf.net )" + puts $file "\n[mc {Project:}] [$this cget -projectName]" + puts $file [mc "Generated by %s" "${::APPNAME} ( http://mcu8051ide.sf.net )"] # Save as XHTML - } { + } else { puts $file "<?xml version='1.0' encoding='utf-8' standalone='no'?>" puts $file "<!DOCTYPE html PUBLIC" puts $file "\t'-//W3C//DTD XHTML 1.1//EN'" puts $file "\t'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>" puts $file "<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>" - puts $file "<!--\n\tCreator: ${::APPNAME}\n\tDate: [clock format [clock seconds] -format {%D}]\n-->" + puts $file "<!-- Creator: ${::APPNAME} -->" puts $file "\t<head>" - puts $file "\t\t<title>[string trim $this {:}] stopwatch state [clock format [clock seconds] -format {%D}]</title>" + puts $file "\t\t<title>[$this cget -projectName] stopwatch state [clock format [clock seconds] -format {%D}]</title>" puts $file "\t\t<meta http-equiv=\"Content-Type\" content=\"application/xhtml+xml; charset=UTF-8\" />" puts $file "\t\t<meta name=\"Generator\" content=\"${::APPNAME}\" />" puts $file "\t\t<style type=\"text/css\">" @@ -639,7 +642,7 @@ class Stopwatch { puts $file "\t\t<table style=\"border-width: 1px\">" puts $file "\t\t\t<col /><col /><col /><col />" puts $file "\t\t\t<thead>" - puts $file "\t\t\t\t<tr class=\"sw_header\"><th> </th><th>Current</th><th>Stop after</th><th>Overall</th></tr>" + puts $file "\t\t\t\t<tr class=\"sw_header\"><th> </th><th>[mc {Current}]</th><th>[mc {Stop after}]</th><th>[mc {Overall}]</th></tr>" puts $file "\t\t\t</thead>" puts $file "\t\t\t<tbody>" foreach text $stats_names key $stats_keys { @@ -647,7 +650,7 @@ class Stopwatch { puts $file "\t\t\t\t\t<td class=\"sw_header\">[mc $text]</td>" foreach subkey {C S O} { puts -nonewline $file "\t\t\t\t\t<td class=\"sw_$subkey\">" - puts -nonewline $file [subst "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] + puts -nonewline $file [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,$subkey)"] puts $file "</td>" } puts $file "\t\t\t\t</tr>" @@ -656,9 +659,8 @@ class Stopwatch { puts $file "\t\t</table>" puts $file "\t\t<p>" - puts $file "\t\t\tProject: <b>[string trim $this {:}]</b><br />" - puts $file "\t\t\tDate: <b>[clock format [clock seconds] -format {%D}]</b><br />" - puts $file "\t\t\tGenerated by ${::APPNAME} ( <a href=\"http://mcu8051ide.sf.net\">http://mcu8051ide.sf.net</a> )" + puts $file "\t\t\t[mc {Project:}] <b>[$this cget -projectName]</b><br />" + puts $file "\t\t\t[mc {Generated by %s} "${::APPNAME} ( <a href=\"http://mcu8051ide.sf.net\">http://mcu8051ide.sf.net</a> )"]" puts $file "\t\t</p>" puts $file "\t</body>" @@ -680,7 +682,7 @@ class Stopwatch { local_status_tip $start_stop_button [mc "Stop"] pack forget $label_stopped_lbl # Stop - } { + } else { $start_stop_button configure -image ::ICONS::22::player_play local_status_tip $start_stop_button [mc "Start"] pack $label_stopped_lbl -side right -pady 0 -ipady 0 @@ -691,12 +693,16 @@ class Stopwatch { # @return void public method stopwatch_get_config {} { set result $window_geometry - lappend result [subst "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"] + lappend result [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}(stop_sim)"] foreach key $stats_keys { - lappend result [subst "\$::Stopwatch::text_vars${obj_idx}($key,S)"] + lappend result [subst -nocommands "\$::Stopwatch::text_vars${obj_idx}($key,S)"] } return $result } } + +# >>> File inclusion guard +} +# <<< File inclusion guard |