summaryrefslogtreecommitdiff
path: root/lib/pale/simplekeypad.tcl
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
committerAndrej Shadura <andrewsh@debian.org>2018-05-08 15:59:31 +0200
commit47aa8b00b2b11df13a100489e0f904a4947177ef (patch)
treeb35c9acc778ea2f761f3c549f7bee2f4491b3144 /lib/pale/simplekeypad.tcl
parent5b8466f7fae0e071c0f4eda13051c93313910028 (diff)
Import Upstream version 1.4.7
Diffstat (limited to 'lib/pale/simplekeypad.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/simplekeypad.tcl108
1 files changed, 71 insertions, 37 deletions
diff --git a/lib/pale/simplekeypad.tcl b/lib/pale/simplekeypad.tcl
index d7baa83..0889106 100755..100644
--- a/lib/pale/simplekeypad.tcl
+++ b/lib/pale/simplekeypad.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 _SIMPLEKEYPAD_TCL ] } {
+set _SIMPLEKEYPAD_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
@@ -36,15 +41,15 @@ class SimpleKeyPad {
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 "Simple Keypad" ;# Name of this component
@@ -63,9 +68,14 @@ class SimpleKeyPad {
"Save configuration into a file"}
{command {Load configuration} {} 0 "load_from" {fileopen}
"Load configuration from a file"}
+ {separator}
+ {checkbutton "Window always on top" {} {::SimpleKeyPad::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 ;# Array of CanvasObject (line): Wires connected to MCU pins
private variable wire_o ;# Array of CanvasObject (oval): Wires connected to MCU pins
@@ -74,7 +84,7 @@ class SimpleKeyPad {
private variable text ;# Array of CanvasObject (text): Key descriptions
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 enaged ;# Array of Bool: enaged(port_num,bit_num) --> Is connected to this device ?
+ private variable enaged ;# Array of Bool: enaged(port_num,bit_num) --> Is connected to this device?
# ------------------------------------------------------------------
@@ -181,12 +191,12 @@ class SimpleKeyPad {
# @return void
private method create_gui {} {
# Create panel window and canvas widget
- set win [toplevel .simplekeypad$count -class $component_name -bg {#EEEEEE}]
+ set win [toplevel .simplekeypad$count -class $component_name -bg ${::COMMON_BG_COLOR}]
set canvas_widget [canvas $win.canvas -bg white -width 0 -height 0]
set cb_p_y 65
set cb_b_y 85
- set usr_n_y 105
+ set usr_n_y 110
set x 50
# Create labels
@@ -198,13 +208,13 @@ class SimpleKeyPad {
-text [mc "BIT"] \
-font $cb_font \
-anchor w
- $canvas_widget create text 5 $usr_n_y \
+ $canvas_widget create text 32 $usr_n_y \
-text [mc "Note"] \
-font $cb_font \
- -anchor w
+ -anchor e
$canvas_widget create window 37 $usr_n_y \
-window [ttk::entry $canvas_widget.usr_note \
- -validate all \
+ -validate key \
-validatecommand "$this set_modified" \
] \
-width 220 -anchor w
@@ -251,7 +261,7 @@ class SimpleKeyPad {
-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
@@ -261,16 +271,16 @@ class SimpleKeyPad {
-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 =260x120
+ wm minsize $win 265 125
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 .]
@@ -319,7 +329,7 @@ class SimpleKeyPad {
$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
@@ -333,7 +343,7 @@ class SimpleKeyPad {
public method key_leave {i} {
if {$keys($i)} {
set color {#333333}
- } {
+ } else {
set color {#CCCCCC}
}
$canvas_widget itemconfigure $rect($i) -outline $color
@@ -436,6 +446,17 @@ class SimpleKeyPad {
set radio_buttons $::SimpleKeyPad::menu_radio_buttons
}
+ ## 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 $SimpleKeyPad::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
+ }
+ }
+
# ------------------------------------------------------------------
# VIRTUAL HW COMMON INTERFACE -- CALLED FROM PALE ENGINE
# ------------------------------------------------------------------
@@ -444,12 +465,12 @@ class SimpleKeyPad {
# @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) {-}
}
@@ -465,11 +486,13 @@ class SimpleKeyPad {
# '|' - 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
+
# Iterate over keys
for {set i 0} {$i < 8} {incr i} {
# Determinate index in the list of port states
@@ -479,7 +502,7 @@ class SimpleKeyPad {
if {[lindex $pp 0] == {-} || [lindex $pp 1] == {-} || !$drawing_on} {
if {$keys($i)} {
set wire_color {#00DD00}
- } {
+ } else {
set wire_color {#000000}
}
@@ -522,9 +545,6 @@ class SimpleKeyPad {
$canvas_widget itemconfigure $lever($keys(${i})${i}) -fill $wire_color
$canvas_widget itemconfigure $wire_o($i) -outline $wire_color
}
-
- # Return new port states
- return $state
}
## Withdraw panel window from the screen
@@ -545,6 +565,7 @@ class SimpleKeyPad {
[$canvas_widget.usr_note get] \
[array get keys] \
$radio_buttons \
+ $keep_win_on_top \
] \
]
}
@@ -560,7 +581,7 @@ class SimpleKeyPad {
# 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
@@ -570,6 +591,12 @@ class SimpleKeyPad {
# Restore keys configuration and states
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
+ }
+ }
# Restore state of ComboBoxes
for {set i 0} {$i < 8} {incr i} {
@@ -608,7 +635,7 @@ class SimpleKeyPad {
# Fail
}]} then {
- puts "Unable to load config for $class_name"
+ puts "Unable to load configuration for $class_name"
return 0
# Success
@@ -621,7 +648,8 @@ class SimpleKeyPad {
## 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
}
# ------------------------------------------------------------------
@@ -631,7 +659,8 @@ class SimpleKeyPad {
## This method is called before configuration menu invocation
# @return void
public method config_menu_special {} {
- set ::SimpleKeyPad::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
@@ -645,7 +674,7 @@ class SimpleKeyPad {
#
# 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 8 switches. Each of them can connect any port pin of the simulated uC to the ground. 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. Wire colors are identical to colors used in graph representing IO ports.\n\n"]
+ $text_widget insert insert [mc "This tool consists of 8 switches. Each of them can connect any port pin of the simulated uC to ground. 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. 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 "]
@@ -654,7 +683,7 @@ class SimpleKeyPad {
$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
@@ -665,6 +694,11 @@ class SimpleKeyPad {
## 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