summaryrefslogtreecommitdiff
path: root/lib/pale/leddisplay.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pale/leddisplay.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/leddisplay.tcl133
1 files changed, 90 insertions, 43 deletions
diff --git a/lib/pale/leddisplay.tcl b/lib/pale/leddisplay.tcl
index 55b13a5..44cc7ad 100755..100644
--- a/lib/pale/leddisplay.tcl
+++ b/lib/pale/leddisplay.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 _LEDDISPLAY_TCL ] } {
+set _LEDDISPLAY_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
@@ -36,7 +41,11 @@ class LedDisplay {
inherit VirtualHWComponent
# Font: Font to be used in the panel -- bold
- common cb_font [font create -weight bold -size -10 -family {helvetica}]
+ common cb_font [font create \
+ -weight bold \
+ -size [expr {int(-10 * $::font_size_factor)}] \
+ -family {helvetica} \
+ ]
common COMPONENT_NAME "LED Display" ;# Name of this component
common CLASS_NAME "LedDisplay" ;# Name of this class
common COMPONENT_ICON {leddisplay} ;# Icon for this panel (16x16)
@@ -53,16 +62,17 @@ class LedDisplay {
{#5555AA #0000FF}
{#AA55AA #8800FF}
}
+ common DIMMED_COLOR {#BBBBBB}
# Configuration menu
common CONFMENU {
{cascade {Common electrode} 7 "diode" .ca false 1 {
{radiobutton "Common anode" {}
::LedDisplay::cfg_common_anode 1
- "common_electrode_chanded" 7 ""}
- {radiobutton "Common catode" {}
+ "common_electrode_changed" 7 ""}
+ {radiobutton "Common cathode" {}
::LedDisplay::cfg_common_anode 0
- "common_electrode_chanded" 7 ""}
+ "common_electrode_changed" 7 ""}
}}
{cascade {Color} 0 "colorize" .color false 1 {
{radiobutton "Red" {}
@@ -92,15 +102,20 @@ class LedDisplay {
"Save configuration into a file"}
{command {Load configuration} {} 0 "load_from" {fileopen}
"Load configuration from a file"}
+ {separator}
+ {checkbutton "Window always on top" {} {::LedDisplay::menu_keep_win_on_top}
+ 1 0 0 {keep_win_on_top_changed}
+ ""}
}
private variable conf_led_color {red} ;# Color: Selected color for LED's
+ private variable keep_win_on_top 0 ;# Bool: Toplevel window
private variable leds ;# Array of CanvasObject (polygon): leds(segment_num) --> LED polygon
private variable wires ;# Array of CanvasObject (line): Wire connection LED with uC
private variable connection_port ;# Array of Int: Index is key number, value is port number or {-}
private variable connection_pin ;# Array of Int: Index is key number, value is bit number or {-}
- private variable common_anode 1 ;# Bool: 1 == common anode; 0 == common catode
+ private variable common_anode 1 ;# Bool: 1 == common anode; 0 == common cathode
# ------------------------------------------------------------------
# INTERNAL APPLICATION LOGIC
@@ -148,7 +163,7 @@ class LedDisplay {
# @return void
private method create_gui {} {
# Create panel window and canvas widget
- set win [toplevel .leddisplay$count -class $component_name -bg {#EEEEEE}]
+ set win [toplevel .leddisplay$count -class $component_name -bg ${::COMMON_BG_COLOR}]
set canvas_widget [canvas $win.canvas \
-bg white -width 0 -height 0 \
-highlightthickness 0 \
@@ -231,7 +246,7 @@ class LedDisplay {
-text [mc "PORT"] \
-font $cb_font \
-anchor ne
- $canvas_widget create text 50 5 \
+ $canvas_widget create text 42 5 \
-text [mc "BIT"] \
-font $cb_font \
-anchor nw
@@ -239,18 +254,18 @@ class LedDisplay {
-text [mc "PORT"] \
-font $cb_font \
-anchor ne
- $canvas_widget create text 210 5\
+ $canvas_widget create text 202 5\
-text [mc "BIT"] \
-font $cb_font \
-anchor nw
- $canvas_widget create text 5 155\
- -text [mc "Note"] \
- -font $cb_font \
- -anchor w
- $canvas_widget create window 40 155 \
+ $canvas_widget create text 35 160 \
+ -text [mc "Note"] \
+ -font $cb_font \
+ -anchor e
+ $canvas_widget create window 40 160 \
-window [ttk::entry $canvas_widget.usr_note \
- -validate all \
+ -validate key \
-validatecommand "$this set_modified" \
] \
-width 180 -anchor w
@@ -261,14 +276,25 @@ class LedDisplay {
pack $canvas_widget -fill both -expand 1
# Set window parameters
- wm geometry $win =230x170
+ wm minsize $win 230 175
wm iconphoto $win ::ICONS::16::$component_icon
- wm title $win "[mc $component_name] - [string trim $project {:}] - MCU 8051 IDE"
+ wm title $win "[mc $component_name] - [$project cget -projectName] - MCU 8051 IDE"
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW "$this close_window"
bindtags $win [list $win Toplevel all .]
}
+ ## Value of configuration menu variable "keep_win_on_top" has been changed
+ # @return void
+ public method keep_win_on_top_changed {} {
+ set keep_win_on_top $LedDisplay::menu_keep_win_on_top
+ if {$keep_win_on_top} {
+ wm attributes $win -topmost 1 -alpha 0.8
+ } else {
+ wm attributes $win -topmost 0 -alpha 1.0
+ }
+ }
+
## Reconnect the specified LED to another port pin
# @parm Int i - LED number (0..7)
# @return void
@@ -282,20 +308,22 @@ class LedDisplay {
# Change state of the device
if {$drawing_on} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
# Set flag modified
set_modified
}
- ## LED's common electrode chanded
+ ## LED's common electrode changed
# @return void
- public method common_electrode_chanded {} {
+ public method common_electrode_changed {} {
set common_anode ${::LedDisplay::cfg_common_anode}
if {$drawing_on} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
set_modified
}
@@ -306,7 +334,8 @@ class LedDisplay {
set conf_led_color ${::LedDisplay::color}
if {$drawing_on} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
set_modified
}
@@ -404,8 +433,8 @@ class LedDisplay {
}
# Draw
- set leds($i) [$canvas_widget create polygon \
- $coordinates -width 0 -fill #888888 \
+ set leds($i) [$canvas_widget create polygon \
+ $coordinates -width 0 -fill $DIMMED_COLOR \
]
}
@@ -414,7 +443,7 @@ class LedDisplay {
set leds(7) [$canvas_widget create oval \
[expr {49 + $x}] [expr {77 + $y}] \
[expr {58 + $x}] [expr {86 + $y}] \
- -width 0 -fill #888888 \
+ -width 0 -fill $DIMMED_COLOR \
]
# Print segment labels
@@ -452,12 +481,12 @@ class LedDisplay {
# @return void
public method mcu_changed {} {
# Refresh lists of possible values in port selection ComboBoxes
- set avaliable_ports [concat - [$project pale_get_avaliable_ports]]
+ set available_ports [concat - [$project pale_get_available_ports]]
for {set i 0} {$i < 8} {incr i} {
- $canvas_widget.cb_p$i configure -values $avaliable_ports
+ $canvas_widget.cb_p$i configure -values $available_ports
- if {[lsearch -ascii -exact $avaliable_ports $connection_port($i)] == -1} {
+ if {[lsearch -ascii -exact $available_ports $connection_port($i)] == -1} {
$canvas_widget.cb_p$i current 0
set connection_port($i) {-}
}
@@ -472,11 +501,13 @@ class LedDisplay {
# '|' - High frequency
# 'X' - Access to external memory
# '?' - No volatge
- # '-' - Undeterminable value (some noise)
+ # '-' - Indeterminable value (some noise)
# '=' - High forced to low
# '0' - Logical 0
# '1' - Logical 1
- public method new_state {state} {
+ public method new_state {_state} {
+ upvar $_state state
+
# Determinate index of LED color in list COLORS
set color_idx [lsearch -ascii -exact \
{red orange yellow green blue purple} \
@@ -490,7 +521,7 @@ class LedDisplay {
# Not connected
if {[lindex $pp 0] == {-} || [lindex $pp 1] == {-}} {
- $canvas_widget itemconfigure $leds($i) -fill {#888888}
+ $canvas_widget itemconfigure $leds($i) -fill $DIMMED_COLOR
$canvas_widget itemconfigure $wires($i) -fill {#000000}
continue
}
@@ -500,7 +531,7 @@ class LedDisplay {
{0} { ;# Logical 0
if {$common_anode} {
set segment_color {2}
- } {
+ } else {
set segment_color {0}
}
set wire_color {#00FF00}
@@ -508,7 +539,7 @@ class LedDisplay {
{1} { ;# Logical 1
if {$common_anode} {
set segment_color {0}
- } {
+ } else {
set segment_color {2}
}
set wire_color {#FF0000}
@@ -533,8 +564,8 @@ class LedDisplay {
# Determinate segment color (true color, not just number)
if {!$segment_color} {
- set segment_color {#888888}
- } {
+ set segment_color $DIMMED_COLOR
+ } else {
incr segment_color -1
set segment_color [lindex $COLORS [list $color_idx $segment_color]]
}
@@ -563,6 +594,7 @@ class LedDisplay {
[$canvas_widget.usr_note get] \
$conf_led_color \
$common_anode \
+ $keep_win_on_top \
] \
]
}
@@ -578,7 +610,7 @@ class LedDisplay {
# Restore window geometry
if {[string length [lindex $state 2]]} {
- wm geometry $win [lindex $state 2]
+ wm geometry $win [regsub {^\=?\d+x\d+} [lindex $state 2] [join [wm minsize $win] {x}]]
}
# Load user note
@@ -592,6 +624,13 @@ class LedDisplay {
set common_anode 1
}
+ if {[lindex $state 6] != {}} {
+ set keep_win_on_top [lindex $state 6]
+ if {$keep_win_on_top} {
+ wm attributes $win -topmost 1 -alpha 0.8
+ }
+ }
+
# Restore state of ComboBoxes
for {set i 0} {$i < 8} {incr i} {
## PIN
@@ -620,12 +659,13 @@ class LedDisplay {
}
# Accept new state of ports
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
update
# Fail
}]} then {
- puts "Unable to load config for $class_name"
+ puts "Unable to load configuration for $class_name"
return 0
# Success
@@ -638,7 +678,8 @@ class LedDisplay {
## Simulated MCU has been reseted
# @return void
public method reset {} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
@@ -651,6 +692,7 @@ class LedDisplay {
public method config_menu_special {} {
set ::${class_name}::color $conf_led_color
set ::${class_name}::cfg_common_anode $common_anode
+ set ::${class_name}::menu_keep_win_on_top $keep_win_on_top
}
## This method is called after configuration menu has beed created
@@ -669,7 +711,7 @@ class LedDisplay {
#
# Note: There is defined text tag "tag_bold" in the text widget
public method show_help_special {text_widget} {
- $text_widget insert insert [mc "Virtual LED display with common anode (default) or catode. Each segment can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes on the bottom of the panel. Panel configuration can be saved to a file (with extension vhc). And can be loaded from that file later.\n\n"]
+ $text_widget insert insert [mc "Virtual LED display with common anode (default) or cathode. Each segment can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes on the bottom of the panel. Panel configuration can be saved to a file with extension vhc, and can be loaded from that file later.\n\n"]
set color_idx [lsearch -ascii -exact \
{red orange yellow green blue purple} \
@@ -679,7 +721,7 @@ class LedDisplay {
$text_widget insert insert [mc "LED states:"]
$text_widget tag add tag_bold {insert linestart} {insert lineend}
$text_widget insert insert [mc "\n "]
- $text_widget window create insert -pady 1 -create "frame $text_widget.f0 -bd 1 -width 14 -height 16 -bg #888888"
+ $text_widget window create insert -pady 1 -create "frame $text_widget.f0 -bd 1 -width 14 -height 16 -bg $DIMMED_COLOR"
$text_widget insert insert [mc " Off\n "]
$text_widget window create insert -pady 1 -create "frame $text_widget.f1 -bd 1 -width 14 -height 16 -bg [lindex $COLORS [list $color_idx 0]]"
$text_widget insert insert [mc " Fast blinking\n "]
@@ -700,8 +742,13 @@ class LedDisplay {
$canvas_widget itemconfigure $leds($i) -fill {#888888}
$canvas_widget itemconfigure $wires($i) -fill {#000000}
}
- } {
- new_state [$project pale_get_true_state]
+ } else {
+ set state [$project pale_get_true_state]
+ new_state state
}
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard