summaryrefslogtreecommitdiff
path: root/lib/utilities/eightsegment.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utilities/eightsegment.tcl')
-rw-r--r--[-rwxr-xr-x]lib/utilities/eightsegment.tcl64
1 files changed, 41 insertions, 23 deletions
diff --git a/lib/utilities/eightsegment.tcl b/lib/utilities/eightsegment.tcl
index de1903b..601d078 100755..100644
--- a/lib/utilities/eightsegment.tcl
+++ b/lib/utilities/eightsegment.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,13 +21,18 @@
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
+# >>> File inclusion guard
+if { ! [ info exists _EIGHTSEGMENT_TCL ] } {
+set _EIGHTSEGMENT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# 8 segment LED display configurator
# --------------------------------------------------------------------------
class EightSegment {
- common count 0 ;# Int: Counter of object instances
+ common ld_ed_count 0 ;# Int: Counter of object instances
private variable obj_idx ;# Int: Current object ID
private variable win ;# Widget: Dialog window
@@ -37,9 +42,9 @@ class EightSegment {
private variable canvas_objects ;# Array: LED segments in canvas widget
private variable validation_ena 1 ;# Bool: Entryboxs validation enabled
- private variable cc_hex_entry ;# Widget: Entrybox "Common catode - Hex"
- private variable cc_dec_entry ;# Widget: Entrybox "Common catode - Dec"
- private variable cc_bin_entry ;# Widget: Entrybox "Common catode - Bin"
+ private variable cc_hex_entry ;# Widget: Entrybox "Common cathode - Hex"
+ private variable cc_dec_entry ;# Widget: Entrybox "Common cathode - Dec"
+ private variable cc_bin_entry ;# Widget: Entrybox "Common cathode - Bin"
private variable ca_hex_entry ;# Widget: Entrybox "Common anode - Hex"
private variable ca_dec_entry ;# Widget: Entrybox "Common anode - Dec"
private variable ca_bin_entry ;# Widget: Entrybox "Common anode - Bin"
@@ -49,9 +54,9 @@ class EightSegment {
constructor {} {
# Create dialog window
- set win [toplevel .eightsegment$count -class {8 segment editor} -bg {#EEEEEE}]
- set obj_idx $count
- incr count
+ set win [toplevel .eightsegment${ld_ed_count} -class {8 segment editor} -bg ${::COMMON_BG_COLOR}]
+ set obj_idx $ld_ed_count
+ incr ld_ed_count
# Restore last session
for {set i 0} {$i < 8} {incr i} {
@@ -75,7 +80,7 @@ class EightSegment {
# Set window parameters
wm iconphoto $win ::ICONS::16::8seg
- wm title $win "8 segment editor"
+ wm title $win [mc "8 segment editor"]
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW "::itcl::delete object $this"
}
@@ -100,7 +105,7 @@ class EightSegment {
# Highlight ComboBoxes related to pins which are in confict
for {set segment 0} {$segment < 8} {incr segment} {
- set pin [subst "\$::EightSegment::con_${obj_idx}_$segment"]
+ set pin [subst -nocommands "\$::EightSegment::con_${obj_idx}_$segment"]
set seg2pin($segment) $pin
for {set i 0} {$i < 8} {incr i} {
@@ -133,9 +138,9 @@ class EightSegment {
ttk::style configure EightSegment_RedFg.TCombobox -foreground {#FF0000}
## Create entryboxes
- # - Common catode
+ # - Common cathode
set left_frame [frame $main_frame.left_frame]
- grid [label $left_frame.header_CC_lbl -text [mc "Common catode"]] \
+ grid [label $left_frame.header_CC_lbl -text [mc "Common cathode"]] \
-row 0 -column 0 -columnspan 4 -sticky w
grid [label $left_frame.sub_header_CC_hex_lbl -text [mc "Hex:"]] \
-row 1 -column 1 -sticky w
@@ -297,7 +302,7 @@ class EightSegment {
-text [mc "Close"] \
-command "::itcl::delete object $this" \
-image ::ICONS::16::exit \
- ] -side right -pady 5
+ ] -side right -pady 5 -padx 5
pack $status_bar -side left -fill x
# Pack window frames
@@ -315,11 +320,11 @@ class EightSegment {
}
## Copy contents of the specified exntrybox to clipboard
- # @parm Char common_electrode - C == Catode; A == Anode
+ # @parm Char common_electrode - C == Cathode; A == Anode
# @parm Char radix - H == Hexadecimal; D == Decimal; B == Binary
# @return void
public method copy_contents {common_electrode radix} {
- # Common catode
+ # Common cathode
if {$common_electrode == {C}} {
switch -- $radix {
{H} {set widget ${cc_hex_entry}}
@@ -327,7 +332,7 @@ class EightSegment {
{B} {set widget ${cc_bin_entry}}
}
# Common anode
- } {
+ } else {
switch -- $radix {
{H} {set widget ${ca_hex_entry}}
{D} {set widget ${ca_dec_entry}}
@@ -349,7 +354,7 @@ class EightSegment {
}
## Value entrybox validator
- # @parm Char common_electrode - C == Catode; A == Anode
+ # @parm Char common_electrode - C == Cathode; A == Anode
# @parm Char radix - H == Hexadecimal; D == Decimal; B == Binary
# @parm String value - String to validate
# @return Bool - always 1
@@ -387,10 +392,19 @@ class EightSegment {
}
# Convert value to decimal
- if {$radix == {H}} {
- set value [expr "0x$value"]
- } elseif {$radix == {B}} {
- set value [::NumSystem::bin2dec $value]
+ switch -- $radix {
+ {H} {
+ set value [expr "0x$value"]
+ }
+ {B} {
+ set value [::NumSystem::bin2dec $value]
+ }
+ {D} {
+ set value [string trimleft $value 0]
+ if {$value == {}} {
+ set value 0
+ }
+ }
}
# Adjust array $led() (LED states)
@@ -400,7 +414,7 @@ class EightSegment {
set leds($i) [expr {$value & $mask}]
set mask [expr {$mask * 2}]
}
- } {
+ } else {
set mask 1
for {set i 0} {$i < 8} {incr i} {
set leds($i) [expr {!($value & $mask)}]
@@ -422,7 +436,7 @@ class EightSegment {
for {set i 0} {$i < 8} {incr i} {
if {$leds($seg2pin($i))} {
$canvas_widget itemconfigure $canvas_objects($i) -fill #FF0000
- } {
+ } else {
$canvas_widget itemconfigure $canvas_objects($i) -fill #FFFFFF
}
}
@@ -507,3 +521,7 @@ class EightSegment {
}
}
set ::EightSegment::config $::CONFIG(EIGHT_SEG_EDITOR)
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard