summaryrefslogtreecommitdiff
path: root/lib/pale/matrixkeypad.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pale/matrixkeypad.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/matrixkeypad.tcl110
1 files changed, 72 insertions, 38 deletions
diff --git a/lib/pale/matrixkeypad.tcl b/lib/pale/matrixkeypad.tcl
index 186ead0..9400741 100755..100644
--- a/lib/pale/matrixkeypad.tcl
+++ b/lib/pale/matrixkeypad.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 _MATRIXKEYPAD_TCL ] } {
+set _MATRIXKEYPAD_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
@@ -36,15 +41,15 @@ class MatrixKeyPad {
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} \
]
# Font: Font to be used in the panel -- normal weight
- common cb_font_n [font create \
- -size -10 \
- -family {helvetica} \
+ common cb_font_n [font create \
+ -size [expr {int(-10 * $::font_size_factor)}] \
+ -family {helvetica} \
]
common COMPONENT_NAME "Matrix Keypad" ;# Name of this component
@@ -64,9 +69,14 @@ class MatrixKeyPad {
"Save configuration into a file"}
{command {Load configuration} {} 0 "load_from" {fileopen}
"Load configuration from a file"}
+ {separator}
+ {checkbutton "Window always on top" {} {::MatrixKeyPad::menu_keep_win_on_top}
+ 1 0 0 {keep_win_on_top_changed}
+ ""}
}
- private variable radio_buttons ;# Bool: Disallow key combinations
+ private variable radio_buttons 0 ;# Bool: Disallow key combinations
+ private variable keep_win_on_top 0 ;# Bool: Toplevel window
private variable keys ;# Array of Bool: Indicates key press
private variable wire
private variable wire_o
@@ -138,6 +148,17 @@ class MatrixKeyPad {
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 $MatrixKeyPad::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
+ }
+ }
+
## Reevaluate array of MCU port pins engaged by this device
# @return void
private method evaluete_enaged_pins {} {
@@ -193,18 +214,18 @@ class MatrixKeyPad {
# @return void
private method create_gui {} {
# Create panel window and canvas widget
- set win [toplevel .matrixkeypad$count -class $component_name -bg {#EEEEEE}]
+ set win [toplevel .matrixkeypad$count -class $component_name -bg ${::COMMON_BG_COLOR}]
set canvas_widget [canvas $win.canvas \
-bg white -width 0 -height 0 \
-highlightthickness 0 \
]
# Create labels
- $canvas_widget create text 33 20 \
+ $canvas_widget create text 36 20 \
-text [mc "PORT"] \
-font $cb_font \
-anchor e
- $canvas_widget create text 35 20 \
+ $canvas_widget create text 38 20 \
-text [mc "BIT"] \
-font $cb_font \
-anchor w
@@ -218,13 +239,13 @@ class MatrixKeyPad {
-font $cb_font \
-anchor e
- $canvas_widget create text 5 220 \
+ $canvas_widget create text 35 220 \
-text [mc "Note"] \
-font $cb_font \
- -anchor w
- $canvas_widget create window 35 220 \
+ -anchor e
+ $canvas_widget create window 40 220 \
-window [ttk::entry $canvas_widget.usr_note \
- -validate all \
+ -validate key \
-validatecommand "$this set_modified" \
] \
-width 180 -anchor w
@@ -259,7 +280,7 @@ class MatrixKeyPad {
-state readonly \
]
bind $canvas_widget.cb_p$i <<ComboboxSelected>> "$this reconnect $i"
-
+
$canvas_widget create window $x $y -anchor w \
-window [ttk::combobox $canvas_widget.cb_b$i \
-width 1 \
@@ -289,7 +310,7 @@ class MatrixKeyPad {
-state readonly \
]
bind $canvas_widget.cb_p$i <<ComboboxSelected>> "$this reconnect $i"
-
+
$canvas_widget create window $x $cb_b_y -anchor center \
-window [ttk::combobox $canvas_widget.cb_b$i \
-width 1 \
@@ -334,9 +355,9 @@ class MatrixKeyPad {
pack $canvas_widget -fill both -expand 1
# Set window parameters
- wm geometry $win =225x235
+ wm minsize $win 225 240
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 .]
@@ -455,7 +476,7 @@ class MatrixKeyPad {
$canvas_widget itemconfigure $rect($i) -outline #333333 -width 2
# Key released
- } {
+ } else {
$canvas_widget itemconfigure $lever(0$i) -fill #000000
$canvas_widget itemconfigure $lever(1$i) -fill #FFFFFF
$canvas_widget itemconfigure $text($i) -font $cb_font_n
@@ -469,7 +490,7 @@ class MatrixKeyPad {
public method key_leave {i} {
if {$keys($i)} {
set color {#333333}
- } {
+ } else {
set color {#CCCCCC}
}
$canvas_widget itemconfigure $rect($i) -outline $color
@@ -606,12 +627,12 @@ class MatrixKeyPad {
# @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) {-}
}
@@ -627,11 +648,13 @@ class MatrixKeyPad {
# '|' - 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
+
# Local variables
set row_state [list {} {} {} {}] ;# State of rows
set col_state [list {} {} {} {}] ;# State of columns
@@ -650,7 +673,7 @@ class MatrixKeyPad {
if {$i < 4} {
lset row_state $i [lindex $state $pp]
# Columns
- } {
+ } else {
lset col_state [expr {$i - 4}] [lindex $state $pp]
}
}
@@ -718,7 +741,7 @@ class MatrixKeyPad {
if {$i < 4} {
lset state $pp [lindex $row_state $i]
# Columns
- } {
+ } else {
lset state $pp [lindex $col_state [expr {$i - 4}]]
}
}
@@ -738,9 +761,6 @@ class MatrixKeyPad {
$canvas_widget itemconfigure $item -fill $color
}
}
-
- # Return new port states
- return $state
}
## Withdraw panel window from the screen
@@ -761,6 +781,7 @@ class MatrixKeyPad {
[$canvas_widget.usr_note get] \
[array get keys] \
$radio_buttons \
+ $keep_win_on_top \
] \
]
}
@@ -776,7 +797,7 @@ class MatrixKeyPad {
# 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
@@ -787,6 +808,13 @@ class MatrixKeyPad {
array set keys [lindex $state 4]
set radio_buttons [lindex $state 5]
+ 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
@@ -826,7 +854,7 @@ class MatrixKeyPad {
# Fail
}]} then {
- puts "Unable to load config for $class_name"
+ puts "Unable to load configuration for $class_name"
return 0
# Success
@@ -850,7 +878,8 @@ class MatrixKeyPad {
## This method is called before configuration menu invocation
# @return void
public method config_menu_special {} {
- set ::MatrixKeyPad::menu_radio_buttons $radio_buttons
+ set ::${class_name}::menu_radio_buttons $radio_buttons
+ set ::${class_name}::menu_keep_win_on_top $keep_win_on_top
}
## This method is called after configuration menu has beed created
@@ -864,7 +893,7 @@ class MatrixKeyPad {
#
# 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 16 switches connected in matrix. 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. Wire colors are identical to colors used in graph representing IO ports.\n\n"]
+ $text_widget insert insert [mc "This tool consists of 16 switches connected in matrix. 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. Wire colors are identical to colors used in graph representing IO ports.\n\n"]
$text_widget insert insert [mc "Keypad can be configured in two ways:"]
$text_widget tag add tag_bold {insert linestart} {insert lineend}
$text_widget insert insert [mc "\n "]
@@ -873,7 +902,7 @@ class MatrixKeyPad {
$text_widget insert insert [mc " To allow key combinations\n Menu -> Check \"Radio buttons\"\n "]
$text_widget insert insert [mc "2)"]
$text_widget tag add tag_bold {insert linestart} {insert lineend}
- $text_widget insert insert [mc " To do not allow key combinations\n Menu -> Uncheck \"Radio buttons\""]
+ $text_widget insert insert [mc " To not allow key combinations\n Menu -> Uncheck \"Radio buttons\""]
}
## This method is called before panel window closure
@@ -884,6 +913,11 @@ class MatrixKeyPad {
## Commit new on/off state
# @return void
public method on_off_special {} {
- new_state [$project pale_get_true_state]
+ set state [$project pale_get_true_state]
+ new_state state
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard