summaryrefslogtreecommitdiff
path: root/lib/pale/virtual_hw_component.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pale/virtual_hw_component.tcl')
-rw-r--r--[-rwxr-xr-x]lib/pale/virtual_hw_component.tcl142
1 files changed, 79 insertions, 63 deletions
diff --git a/lib/pale/virtual_hw_component.tcl b/lib/pale/virtual_hw_component.tcl
index e0fb00b..c7a637d 100755..100644
--- a/lib/pale/virtual_hw_component.tcl
+++ b/lib/pale/virtual_hw_component.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 _VIRTUAL_HW_COMPONENT_TCL ] } {
+set _VIRTUAL_HW_COMPONENT_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
@@ -32,13 +37,15 @@ class VirtualHWComponent {
common hlp_dlg_count 0 ;# Int: Counter of help dialog instances
# Create fonts used in the text
- common hlp_normal_font [font create \
- -family {helvetica} \
- -size -14 -weight {normal} \
+ common hlp_normal_font [font create \
+ -family {helvetica} \
+ -size [expr {int(-14 * $::font_size_factor)}] \
+ -weight {normal} \
]
- common hlp_bold_font [font create \
- -family {helvetica} \
- -size -14 -weight {bold} \
+ common hlp_bold_font [font create \
+ -family {helvetica} \
+ -size [expr {int(-14 * $::font_size_factor)}] \
+ -weight {bold} \
]
protected variable config_menu_created 0 ;# Bool: COnfiguration menu created
@@ -47,9 +54,9 @@ class VirtualHWComponent {
protected variable modified 0 ;# Bool: Flag modified
protected variable project ;# Object: Project object
- protected variable win ;# Widget: Dialog window
+ protected variable win {} ;# Widget: Dialog window
protected variable drawing_on 1 ;# Bool: Flag panel enabled
- protected variable canvas_widget ;# Widget: Canvas widget - crucial part of the window
+ protected variable canvas_widget {} ;# Widget: Canvas widget - crucial part of the window
protected variable start_stop_button ;# Widget: Button "ON/OFF"
protected variable conf_button ;# Widget: Button to invoke configuration menu
@@ -78,7 +85,7 @@ class VirtualHWComponent {
-icon question \
-parent $win \
-title [mc "Component modified"] \
- -message [mc "Do you want to save configuration of this panel before closing ?"] \
+ -message [mc "Do you want to save the configuration of this panel before closing?"] \
] {
{yes} {
save_as
@@ -105,6 +112,10 @@ class VirtualHWComponent {
set modified 1
$project pale_set_modified
+ if {[winfo exists $win]} {
+ wm title $win "\[modified\] [regsub {^\[modified\] } [wm title $win] {}]"
+ }
+
return 1
}
@@ -112,6 +123,10 @@ class VirtualHWComponent {
# @return void
public method clear_modified {} {
set modified 0
+
+ if {[winfo exists $win]} {
+ wm title $win [regsub {^\[modified\] } [wm title $win] {}]
+ }
}
## Invoke configuration menu
@@ -136,9 +151,9 @@ class VirtualHWComponent {
# @return void
protected method create_config_menu {} {
set config_menu_created 1
- set conf_menu $canvas_widget.conf_menu
- menuFactory [subst "\${${class_name}::CONFMENU}"] \
- $conf_menu 0 "$this " 0 {}
+ set conf_menu $win.conf_menu
+ menuFactory [subst -nocommands "\${${class_name}::CONFMENU}"] \
+ $conf_menu 0 "$this " 0 {} [$this info class]
$this create_config_menu_special
}
@@ -149,14 +164,14 @@ class VirtualHWComponent {
# Create file selection dialog
catch {delete object ::fsd}
KIFSD::FSD ::fsd \
- -title "[mc {Save configuration}] - [mc $component_name] - [string trim $project {:}] - MCU 8051 IDE" \
+ -title "[mc {Save configuration}] - [mc $component_name] - [$project cget -projectName] - MCU 8051 IDE" \
-master $win \
-directory [$project cget -projectPath] \
-initialfile [file tail $current_filename] \
- -defaultmask 0 -multiple 0 -filetypes {
- {{VH component} {*.vhc} }
- {{All files} {*} }
- }
+ -defaultmask 0 -multiple 0 -filetypes [list \
+ [list [mc "VH component"] {*.vhc} ] \
+ [list [mc "All files"] {*} ] \
+ ]
# Open file after press of OK button
::fsd setokcmd "$this save_config_to_file \[::fsd get\]"
@@ -171,14 +186,14 @@ class VirtualHWComponent {
# Create file selection dialog
catch {delete object ::fsd}
KIFSD::FSD ::fsd \
- -title "[mc {Load configuration}] - [mc $component_name] - [string trim $project {:}] - MCU 8051 IDE" \
+ -title "[mc {Load configuration}] - [mc $component_name] - [$project cget -projectName] - MCU 8051 IDE" \
-master $win \
-directory [$project cget -projectPath] \
-initialfile [file tail $current_filename] \
- -defaultmask 0 -multiple 0 -filetypes {
- {{VH component} {*.vhc} }
- {{All files} {*} }
- }
+ -defaultmask 0 -multiple 0 -filetypes [list \
+ [list [mc "VH component"] {*.vhc} ] \
+ [list [mc "All files"] {*} ] \
+ ]
# Open file after press of OK button
::fsd setokcmd "$this load_config_from_file \[::fsd get\]"
@@ -208,9 +223,9 @@ class VirtualHWComponent {
-icon question \
-parent $win \
-title [mc "Overwrite file"] \
- -message [mc "A file with name '%s' already exists. Do you want to overwrite it ?" [file tail $filename]]
+ -message [mc "A file with name '%s' already exists. Do you want to overwrite it?" [file tail $filename]]
] != {yes}
- } {
+ } then {
return 0
}
}
@@ -224,7 +239,7 @@ class VirtualHWComponent {
# Try to open the file
if {[catch {
- set file [open $filename {w} 420]
+ set file [open $filename {w} 0640]
}]} then {
tk_messageBox \
-type ok \
@@ -241,15 +256,14 @@ class VirtualHWComponent {
# Save configuration to the file
puts $file "# MCU 8051 IDE: Virtual HW component configuration file"
- puts $file "# Date: [clock format [clock seconds] -format {%D}]"
- puts $file "# Project: [string trim $project {:}]"
+ puts $file "# Project: [$project cget -projectName]"
puts $file "# Component: $component_name\n"
puts $file $config
# Finalize
set current_filename $filename
close $file
- set modified 0
+ clear_modified
return 1
}
@@ -310,18 +324,19 @@ class VirtualHWComponent {
# Finalize ...
set current_filename $filename
close $file
- set modified 0
+ clear_modified
return 1
}
## Show help dialog
+ # @parm Bool leave_empty=0 - Do not write implicitly anything into the help window
# @return void
- public method show_help {} {
+ public method show_help {{leave_empty 0}} {
# Increment counter of help dialog instances
incr hlp_dlg_count
# Create toplevel window
- set dialog [toplevel .help_dialog_${class_name}_${hlp_dlg_count} -class {Help} -bg {#EEEEEE}]
+ set dialog [toplevel .help_dialog_${class_name}_${hlp_dlg_count} -class {Help} -bg ${::COMMON_BG_COLOR}]
## Create top frame (header and icon)
set top_frame [frame $dialog.top_frame]
@@ -332,7 +347,7 @@ class VirtualHWComponent {
# Header text
pack [label $top_frame.header_label \
-anchor w -justify left \
- -text $component_name \
+ -text [namespace eval ::$class_name "mc {$component_name}"] \
] -side left
pack $top_frame -anchor n -pady 2
@@ -351,20 +366,15 @@ class VirtualHWComponent {
-command "$text_widget yview" \
] -side right -fill y
# Finalize ...
- pack $main_frame -fill both -expand 1
+ pack $main_frame -fill both -expand 1 -padx 2
- ## Create bottom frame (button close)
- # Separator
- pack [ttk::separator $dialog.sep \
- -orient horizontal \
- ] -fill x
# Button "Close"
pack [ttk::button $dialog.close_button \
-text [mc "Close"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command "destroy $dialog" \
- ] -ipady 0
+ ] -ipady 0 -pady 2
# Create text tags in the text widget
@@ -373,30 +383,32 @@ class VirtualHWComponent {
# Fill in the text widget with the help message
$this show_help_special $text_widget
- ## Display section "Wire colors"
- $text_widget insert insert "\n\n"
- $text_widget insert insert [mc "Wire colors:"]
- $text_widget tag add tag_bold {insert linestart} {insert lineend}
- $text_widget insert insert "\n"
- # Create canvas widget
- set cw [canvas $text_widget.canvas\
- -bg {#FFFFFF} \
- -takefocus 0 \
- -cursor left_ptr \
- -bd 0 -relief flat \
- -width 170 -height 110 \
- ]
- bind $cw <Button-5> "$text_widget yview scroll +5 units; break"
- bind $cw <Button-4> "$text_widget yview scroll -5 units; break"
- # Fill in the canvas widget
- $project Graph_create_legend $cw 1
- # Show the canvas widget
- $text_widget window create insert -window $cw
+ if {!$leave_empty} {
+ ## Display section "Wire colors"
+ $text_widget insert insert "\n\n"
+ $text_widget insert insert [mc "Wire colors:"]
+ $text_widget tag add tag_bold {insert linestart} {insert lineend}
+ $text_widget insert insert "\n"
+ # Create canvas widget
+ set cw [canvas $text_widget.canvas\
+ -bg {#FFFFFF} \
+ -takefocus 0 \
+ -cursor left_ptr \
+ -bd 0 -relief flat \
+ -width 170 -height 110 \
+ ]
+ bind $cw <Button-5> "$text_widget yview scroll +5 units; break"
+ bind $cw <Button-4> "$text_widget yview scroll -5 units; break"
+ # Fill in the canvas widget
+ $project Graph_create_legend $cw 1
+ # Show the canvas widget
+ $text_widget window create insert -window $cw
+ }
# Finalize ...
$text_widget configure -state disabled
- wm minsize $dialog 300 300
- wm title $dialog $component_name
+ wm minsize $dialog [expr {int(300 * $::font_size_factor)}] [expr {int(300 * $::font_size_factor)}]
+ wm title $dialog [namespace eval ::$class_name "mc {$component_name}"]
wm iconphoto $dialog ::ICONS::16::help
focus -force $dialog.close_button
}
@@ -411,13 +423,17 @@ class VirtualHWComponent {
## Adjust apparence of "ON/OFF" button
# Turn ON
if {$state} {
- $start_stop_button configure -style GreenBg.TButton -text "ON"
+ $start_stop_button configure -style GreenBg.TButton -text [mc "ON"]
# Turn OFF
} else {
- $start_stop_button configure -style RedBg.TButton -text "OFF"
+ $start_stop_button configure -style RedBg.TButton -text [mc "OFF"]
}
# Call component specific procedure
$this on_off_special
}
}
+
+# >>> File inclusion guard
+}
+# <<< File inclusion guard