summaryrefslogtreecommitdiff
path: root/lib/utilities/asciichart.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utilities/asciichart.tcl')
-rw-r--r--[-rwxr-xr-x]lib/utilities/asciichart.tcl89
1 files changed, 61 insertions, 28 deletions
diff --git a/lib/utilities/asciichart.tcl b/lib/utilities/asciichart.tcl
index 01ac86e..bc44f3e 100755..100644
--- a/lib/utilities/asciichart.tcl
+++ b/lib/utilities/asciichart.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,14 +21,19 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _ASCIICHART_TCL ] } {
+set _ASCIICHART_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Interactive ASCII chart
# --------------------------------------------------------------------------
class AsciiChart {
- common count 0 ;# Int: Counter of object instances
- common ASCII_TABLE ;# Array of List: ASCII table
+ common ascii_chr_count 0 ;# Int: Counter of object instances
+ common ASCII_TABLE ;# Array of List: ASCII table
array set ASCII_TABLE {
0 {NUL ^@ \\0 {Null character}}
1 {SOH ^A {} {Start of Header}}
@@ -110,25 +115,27 @@ class AsciiChart {
constructor {} {
# Configure local ttk styles
- ttk::style configure AsciiChart_BlueFg.TEntry -foreground {#0000DD}
- ttk::style configure AsciiChart_RedFg.TEntry -foreground {#DD0000}
+ ttk::style configure AsciiChart_BlueFg.TEntry -foreground {#0000DD}
+ ttk::style configure AsciiChart_RedFg.TEntry -foreground {#DD0000}
+ ttk::style configure AsciiChart_RedBg.TEntry -fieldbackground {#FFDDDD}
+ ttk::style configure AsciiChart_GreenBg.TEntry -fieldbackground {#DDFFDD}
# Create dialog window
set window_visible 1
- set win [toplevel .asciichart$count -class {ASCII chart} -bg {#EEEEEE}]
- set obj_idx $count
- incr count
+ set win [toplevel .asciichart${ascii_chr_count} -class {ASCII chart} -bg ${::COMMON_BG_COLOR}]
+ set obj_idx $ascii_chr_count
+ incr ascii_chr_count
# Create dialog GUI
create_gui
# Set window event bindings
- bind $win <Control-Key-q> "::itcl::delete object $this; break"
+ bind $win <Control-Key-q> "$this close_window; break"
bindtags $win [list $win Toplevel all .]
# Set window parameters
wm iconphoto $win ::ICONS::16::math_matrix
- wm title $win "ASCII chart - MCU 8051 IDE"
+ wm title $win "[mc {ASCII chart}] - MCU 8051 IDE"
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW "$this close_window"
}
@@ -173,7 +180,7 @@ class AsciiChart {
set status_bar_lbl [label $bottom_frame.status_bar_lbl -justify left -anchor w]
pack $status_bar_lbl -side left -fill x -in $bottom_frame
pack [ttk::button $bottom_frame.close_but \
- -text "Exit" \
+ -text [mc "Exit"] \
-command "$this close_window" \
-compound left \
-image ::ICONS::16::exit \
@@ -182,14 +189,14 @@ class AsciiChart {
## Create main frame
set main_frame [frame $win.main_frame -bg {#DDDDDD}]
# Create vertical header
- grid [frame $main_frame.top_right_lbl -bg {#EEEEEE}] -sticky wens -row 0 -column 0
+ grid [frame $main_frame.top_right_lbl -bg ${::COMMON_BG_COLOR}] -sticky wens -row 0 -column 0
set header [list {} \
{0x0_} {0x1_} {0x2_} {0x3_} \
{0x4_} {0x5_} {0x6_} {0x7_} \
]
for {set y 1} {$y < 9} {incr y} {
grid [label $main_frame.vh_lbl$y -text [lindex $header $y] -bg {#FFFFFF}] \
- -row $y -column 0 -pady [expr {$y % 2}] -sticky ns
+ -row $y -column 0 -pady [expr {$y % 2}] -sticky wens
set vh_cells([expr {$y - 1}]) $main_frame.vh_lbl$y
}
# Create horizontal header
@@ -201,7 +208,7 @@ class AsciiChart {
]
for {set x 1} {$x < 17} {incr x} {
grid [label $main_frame.hh_lbl$x -text [lindex $header $x] -bg {#FFFFFF}] \
- -row 0 -column $x -padx [expr {$x % 2}] -sticky we
+ -row 0 -column $x -padx [expr {$x % 2}] -sticky wens
set hh_cells([expr {$x - 1}]) $main_frame.hh_lbl$x
}
# Create ASCII chart matrix
@@ -225,7 +232,7 @@ class AsciiChart {
set val [lindex $ASCII_TABLE($address) 0]
if {[string length $val] > 1} {
set foreground {#DD0000}
- } {
+ } else {
set foreground {#0000DD}
}
@@ -239,23 +246,44 @@ class AsciiChart {
-bg white -pady 0 \
]
- grid $frame -row $y -column $x -padx [expr {$x % 2}] -pady [expr {$y % 2}] -sticky we
+ grid $frame -row $y -column $x -padx [expr {$x % 2}] -pady [expr {$y % 2}] -sticky wens
set cells($address) $frame
foreach wdg [list $frame $frame.val_lbl $frame.char_lbl] {
bind $wdg <Enter> "$this cell_enter $address"
bind $wdg <Leave> "$this cell_leave $address"
bind $wdg <Button-1> "$this cell_click $address"
}
+
+ if {$address < 127} {
+ bind $frame <Key-Right> [list $this cell_click [expr {$address + 1}]]
+ }
+ if {$address > 0} {
+ bind $frame <Key-Left> [list $this cell_click [expr {$address - 1}]]
+ }
+ if {$address > 16} {
+ bind $frame <Key-Up> [list $this cell_click [expr {$address - 16}]]
+ }
+ if {$address < 112} {
+ bind $frame <Key-Down> [list $this cell_click [expr {$address + 16}]]
+ }
+
incr address
}
}
+ # Ensure than all cells have the same width and heigh
+ for {set i 0} {$i < 17} {incr i} {
+ grid columnconfigure $main_frame $i -uniform ascii
+ }
+ for {set i 1} {$i < 9} {incr i} {
+ grid rowconfigure $main_frame $i -uniform ascii
+ }
# Show ASCII chart
pack $main_frame -pady 5 -side top
## Create details frame (character details)
# Create labelframe
set details_frame_header_frm [frame $win.details_frame_header_frm]
- pack [label $details_frame_header_frm.lbl -text "Character: "] -side left
+ pack [label $details_frame_header_frm.lbl -text [mc "Character: "]] -side left
set char_ent [ttk::entry $details_frame_header_frm.ent \
-validatecommand "$this char_ent_validator %P" \
-width 4 \
@@ -407,6 +435,7 @@ class AsciiChart {
set selected_cell -1
return
}
+ focus $cells($address)
select_cell $address
if {$selected_cell != -1} {
fill_entryboxes $address {}
@@ -459,7 +488,7 @@ class AsciiChart {
# Set new background color
if {$keep_current} {
sel_bg_color $selected_cell {#DDFFDD}
- } {
+ } else {
sel_bg_color $selected_cell {#FFFFFF}
}
@@ -526,7 +555,7 @@ class AsciiChart {
$char_ent insert insert $value
if {[string length $value] > 1} {
$char_ent configure -style AsciiChart_RedFg.TEntry
- } {
+ } else {
$char_ent configure -style AsciiChart_BlueFg.TEntry
}
}
@@ -569,7 +598,7 @@ class AsciiChart {
## Validator for entrybox "Character"
# @parm String string - New entrybox contents
- # @return Bool - Allways 1
+ # @return Bool - Always 1
public method char_ent_validator {string} {
if {!$validation_ena} {return 1}
set validation_ena 0
@@ -599,7 +628,7 @@ class AsciiChart {
if {$length > 1} {
$char_ent configure -style AsciiChart_RedFg.TEntry
- } {
+ } else {
$char_ent configure -style AsciiChart_BlueFg.TEntry
}
@@ -638,7 +667,7 @@ class AsciiChart {
# Empty input string
set length [string length $string]
if {!$length} {
- $widget configure -bg {#FFFFFF}
+ $widget configure -style TEntry
clear_entryboxes $type
unselect_current_cell 0 0
set validation_ena 1
@@ -684,7 +713,7 @@ class AsciiChart {
if {$string > 127 || $string < 0} {
clear_entryboxes $type
unselect_current_cell 0 0
- $widget configure -bg {#FFDDDD}
+ $widget configure -style AsciiChart_RedBg.TEntry
set validation_ena 1
return 1
}
@@ -692,7 +721,7 @@ class AsciiChart {
# Adjust GUI (ACII chart and details frame)
select_cell $string
fill_entryboxes $string $type
- $widget configure -bg {#DDFFDD}
+ $widget configure -style AsciiChart_GreenBg.TEntry
return 1
}
@@ -710,14 +739,14 @@ class AsciiChart {
if {$type == {C}} {
set widget $caret_not_ent
set index 1
- } {
+ } else {
set widget $escape_seq_ent
set index 2
}
# Empty input string
if {![string length $string]} {
- $widget configure -bg {#FFFFFF}
+ $widget configure -style TEntry
clear_entryboxes $type
unselect_current_cell 0 0
set validation_ena 1
@@ -736,7 +765,7 @@ class AsciiChart {
select_cell $i
fill_entryboxes $i $type
- $widget configure -bg {#DDFFDD}
+ $widget configure -style AsciiChart_GreenBg.TEntry
set validation_ena 1
return 1
}
@@ -745,8 +774,12 @@ class AsciiChart {
# String not found
clear_entryboxes $type
unselect_current_cell 0 0
- $widget configure -bg {#FFDDDD}
+ $widget configure -style AsciiChart_RedBg.TEntry
set validation_ena 1
return 1
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard