summaryrefslogtreecommitdiff
path: root/lib/pale/ledmatrix.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pale/ledmatrix.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/ledmatrix.tcl132
1 files changed, 89 insertions, 43 deletions
diff --git a/lib/pale/ledmatrix.tcl b/lib/pale/ledmatrix.tcl
index b739f53..1be1718 100755..100644
--- a/lib/pale/ledmatrix.tcl
+++ b/lib/pale/ledmatrix.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 _LEDMATRIX_TCL ] } {
+set _LEDMATRIX_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
@@ -36,8 +41,12 @@ class LedMatrix {
inherit VirtualHWComponent
# Font: Font to be used in the panel -- bold
- common cb_font [font create -weight bold -size -10 -family {helvetica}]
- common COMPONENT_NAME "LED matrix" ;# Name of this component
+ common cb_font [font create \
+ -weight bold \
+ -size [expr {int(-10 * $::font_size_factor)}] \
+ -family {helvetica} \
+ ]
+ common COMPONENT_NAME "LED Matrix" ;# Name of this component
common CLASS_NAME "LedMatrix" ;# Name of this class
common COMPONENT_ICON {ledmatrix} ;# Icon for this panel (16x16)
@@ -135,7 +144,7 @@ class LedMatrix {
}}
{separator}
{command {All fade out} {} 0 "dim_all" {ledgray}
- "Dim all leds"}
+ "Dim all LEDs"}
{command {Show help} {} 5 "show_help" {help}
"Show brief help"}
{separator}
@@ -143,14 +152,19 @@ class LedMatrix {
"Save configuration into a file"}
{command {Load configuration} {} 0 "load_from" {fileopen}
"Load configuration from a file"}
+ {separator}
+ {checkbutton "Window always on top" {} {::LedMatrix::menu_keep_win_on_top}
+ 1 0 0 {keep_win_on_top_changed}
+ ""}
}
private variable conf_dim_interval 50 ;# Int: Interval to dim LED's in instruction cycles
private variable conf_matrix_mapping 0 ;# Int: Type of matrix mapping: 0 == Random; 1 == Row; 2 == Column
private variable conf_led_color {red} ;# Color: Selected color for LED's
+ private variable keep_win_on_top 0 ;# Bool: Toplevel window
## List of Bool: LED light up condition
- # Index 0 - Row must be in: 1 == log. 1; 0 = log. 0
- # Index 1 - Column must be in: 1 == log. 1; 0 = log. 0
+ # Index 0 - Row must be in: 1 == log. 1; 0 == log. 0
+ # Index 1 - Column must be in: 1 == log. 1; 0 == log. 0
private variable conf_led_cond {0 0}
private variable leds ;# Array of CanvasObject (image): LED's, leds(row,column)
private variable col ;# Array of CanvasObject (line): Column wires
@@ -216,6 +230,17 @@ class LedMatrix {
destroy $win
}
+ ## 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 $LedMatrix::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 wire to another port pin
# @parm Char col_or_row - 'C' => Column; 'R' => Row
# @parm Int i - Wire number (0..7)
@@ -229,7 +254,7 @@ class LedMatrix {
set connection_pin(R$i) [expr {7 - $connection_pin(R$i)}]
}
# Column
- } {
+ } else {
set connection_port(C$i) [$canvas_widget.cb_c_p$i get]
set connection_pin(C$i) [$canvas_widget.cb_c_b$i get]
if {$connection_pin(C$i) != {-}} {
@@ -239,7 +264,8 @@ class LedMatrix {
# Change state of the device
if {$drawing_on} {
- new_state [$project pale_get_true_state] 1
+ set state [$project pale_get_true_state]
+ new_state state 1
}
# Set flag modified
@@ -272,7 +298,8 @@ class LedMatrix {
# Change state of the device
if {$drawing_on} {
- new_state [$project pale_get_true_state] 1
+ set state [$project pale_get_true_state]
+ new_state state 1
}
# Set flag modified
@@ -285,12 +312,13 @@ class LedMatrix {
set conf_led_cond ${::LedMatrix::cond}
if {$drawing_on} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
set_modified
}
- ## Dim all LED's and reset their prevoius states
+ ## Dim all LED's and reset their previous states
# @return void
public method dim_all {} {
for {set i 0} {$i < 8} {incr i} {
@@ -308,7 +336,7 @@ class LedMatrix {
# @return void
private method create_gui {} {
# Create panel window and canvas widget
- set win [toplevel .ledmatrix$count -class $component_name -bg {#EEEEEE}]
+ set win [toplevel .ledmatrix$count -class $component_name -bg ${::COMMON_BG_COLOR}]
set canvas_widget [canvas $win.canvas \
-bg white -width 0 -height 0 \
-highlightthickness 0 \
@@ -318,7 +346,7 @@ class LedMatrix {
set led_sep 15
set sep 25
set y_0 100
- set x_0 85
+ set x_0 90
set y_1 [expr {$y_0 + 10}]
set x_1 [expr {$x_0 + 35}]
@@ -466,13 +494,13 @@ class LedMatrix {
-font $cb_font \
-anchor nw
- $canvas_widget create text 5 273 \
+ $canvas_widget create text 35 278 \
-text [mc "Note"] \
-font $cb_font \
- -anchor w
- $canvas_widget create window 40 273 \
+ -anchor e
+ $canvas_widget create window 40 278 \
-window [ttk::entry $canvas_widget.usr_note \
- -validate all \
+ -validate key \
-validatecommand "$this set_modified" \
] \
-width 230 -anchor w
@@ -490,7 +518,7 @@ class LedMatrix {
-text [mc "Turn HW simulation on/off"]
setStatusTip -widget $start_stop_button -text [mc "Turn HW simulation on/off"]
bind $start_stop_button <Button-3> "$this on_off_button_press; break"
- $canvas_widget create window 2 20 -window $start_stop_button -anchor sw
+ $canvas_widget create window 2 22 -window $start_stop_button -anchor sw
bindtags $start_stop_button [list $start_stop_button TButton all .]
# Create configuration menu button
@@ -500,16 +528,16 @@ class LedMatrix {
-command "$this config_menu" \
]
setStatusTip -widget $conf_button -text [mc "Configure"]
- $canvas_widget create window 2 20 -window $conf_button -anchor nw
+ $canvas_widget create window 2 22 -window $conf_button -anchor nw
bindtags $conf_button [list $conf_button TButton all .]
# Pack canvas
pack $canvas_widget -fill both -expand 1
# Set window parameters
- wm geometry $win =275x285
+ wm minsize $win 280 295
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 .]
@@ -538,17 +566,17 @@ class LedMatrix {
# @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_r_p$i configure -values $avaliable_ports
- $canvas_widget.cb_c_p$i configure -values $avaliable_ports
+ $canvas_widget.cb_r_p$i configure -values $available_ports
+ $canvas_widget.cb_c_p$i configure -values $available_ports
- if {[lsearch -ascii -exact $avaliable_ports $connection_port(R$i)] == -1} {
+ if {[lsearch -ascii -exact $available_ports $connection_port(R$i)] == -1} {
$canvas_widget.cb_r_p$i current 0
set connection_port(R$i) {-}
}
- if {[lsearch -ascii -exact $avaliable_ports $connection_port(C$i)] == -1} {
+ if {[lsearch -ascii -exact $available_ports $connection_port(C$i)] == -1} {
$canvas_widget.cb_c_p$i current 0
set connection_port(C$i) {-}
}
@@ -557,18 +585,20 @@ class LedMatrix {
## Accept new state of ports
# @parm List state - Port states ( 5 x {8 x bit} -- {bit0 bit1 bit2 ... bit7} )
- # @parm Bool preserve_prvious_state = 0 - Preserve previous state of component
+ # @parm Bool preserve_prvious_state=0 - Preserve previous state of component
# @return void
#
# Possible bit values:
# '|' - 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 {preserve_prvious_state 0}} {
+ public method new_state {_state {preserve_prvious_state 0}} {
+ upvar $_state state
+
# Change column wire colors
for {set i 0} {$i < 8} {incr i} {
# Determinate index in the list of port states
@@ -668,22 +698,22 @@ class LedMatrix {
}
# Determinate row state in this way:
- #+ row_state = 0 => Dim
- #+ row_state = 1 => Half dim
- #+ row_state = 2 => Brighten
+ #+ row_state == 0 => Dim
+ #+ row_state == 1 => Half dim
+ #+ row_state == 2 => Brighten
set row_state [lindex $state $pp]
switch -- $row_state {
{0} { ;# Logical 0
if {[lindex $conf_led_cond 0]} {
set row_state 0
- } {
+ } else {
set row_state 2
}
}
{1} { ;# Logical 1
if {[lindex $conf_led_cond 0]} {
set row_state 2
- } {
+ } else {
set row_state 0
}
}
@@ -717,14 +747,14 @@ class LedMatrix {
{0} { ;# Logical 0
if {[lindex $conf_led_cond 1]} {
set image 0 ;# ledgray
- } {
+ } else {
set image 1 ;# shining LED
}
}
{1} { ;# Logical 1
if {[lindex $conf_led_cond 1]} {
set image 1 ;# shining LED
- } {
+ } else {
set image 0 ;# ledgray
}
}
@@ -831,6 +861,7 @@ class LedMatrix {
$conf_dim_interval \
$conf_led_cond \
$conf_matrix_mapping \
+ $keep_win_on_top \
] \
]
}
@@ -846,7 +877,7 @@ class LedMatrix {
# 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
@@ -863,6 +894,13 @@ class LedMatrix {
set conf_matrix_mapping 0
}
+ if {[lindex $state 8] != {}} {
+ set keep_win_on_top [lindex $state 8]
+ if {$keep_win_on_top} {
+ wm attributes $win -topmost 1 -alpha 0.8
+ }
+ }
+
# Restore state of ComboBoxes
foreach foo {R C} bar {r c} {
for {set i 0} {$i < 8} {incr i} {
@@ -893,12 +931,13 @@ class LedMatrix {
}
# 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
@@ -912,7 +951,8 @@ class LedMatrix {
# @return void
public method reset {} {
dim_all
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
@@ -927,6 +967,7 @@ class LedMatrix {
set ::${class_name}::matrix_mapping $conf_matrix_mapping
set ::${class_name}::color $conf_led_color
set ::${class_name}::cond $conf_led_cond
+ set ::${class_name}::menu_keep_win_on_top $keep_win_on_top
}
## This method is called after configuration menu has beed created
@@ -945,7 +986,7 @@ class LedMatrix {
#
# Note: There is defined text tag "tag_bold" in the text widget
public method show_help_special {text_widget} {
- $text_widget insert insert [mc "This tool consists of 64 LED's. Each of them can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes. Panel configuration can be saved to a file (with extension vhc). And can be loaded from that file later. Condition on which a LED lights up and LED colors are configurable. Also fade out interval is configurable.\n\n"]
+ $text_widget insert insert [mc "This tool consists of 64 LED's. Each of them can be connected to any port pin of the simulated uC. Connections with the uC are made with ComboBoxes. Panel configuration can be saved to a file with extension vhc, and can be loaded from that file later. Condition on which a LED lights up and LED colors are configurable. Also fade out interval is configurable.\n\n"]
$text_widget insert insert [mc "LED states:"]
$text_widget tag add tag_bold {insert linestart} {insert lineend}
@@ -975,8 +1016,13 @@ class LedMatrix {
-image ::ICONS::16::ledgray
}
}
- } {
- new_state [$project pale_get_true_state] 1
+ } else {
+ set state [$project pale_get_true_state]
+ new_state state 1
}
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard