summaryrefslogtreecommitdiff
path: root/lib/rightpanel/hwmanager.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rightpanel/hwmanager.tcl')
-rw-r--r--[-rwxr-xr-x]lib/rightpanel/hwmanager.tcl340
1 files changed, 233 insertions, 107 deletions
diff --git a/lib/rightpanel/hwmanager.tcl b/lib/rightpanel/hwmanager.tcl
index 0e27941..133d821 100755..100644
--- a/lib/rightpanel/hwmanager.tcl
+++ b/lib/rightpanel/hwmanager.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 _HWMANAGER_TCL ] } {
+set _HWMANAGER_TCL _
+# <<< File inclusion guard
+
# --------------------------------------------------------------------------
# DESCRIPTION
# Provides panel for managing hardware plugins (e.g. Programmer, ICD, etc.)
@@ -29,24 +34,26 @@
class HwManager {
## COMMON
common PLUGIN_SEARCH_PATHS {
- ../hwplugins
/usr/share/mcu8051ide/hwplugins
/usr/local/share/mcu8051ide/hwplugins
}
+ if {$::MICROSOFT_WINDOWS} {
+ set PLUGIN_SEARCH_PATHS ${::INSTALLATION_DIR}/hwplugins
+ }
common inst_plg_count 0 ;# Int: Number of installed plugins
## PRIVATE
private variable parent ;# Widget: parent widget
- private variable gui_initialized 0 ;# Bool: GUI initialized
+ private variable hwman_gui_initialized 0 ;# Bool: GUI initialized
private variable main_frame ;# Widget: Main frame
private variable pagesmanager ;# Widget: Pages manager for plugins GUI
private variable plg_combobox ;# Widget: Plugin selection combobox
- private variable plg_refresh_but ;# Widget: Button "Refresh avaliable plugins"
+ private variable plg_refresh_but ;# Widget: Button "Refresh available plugins"
private variable ins_plugin_namespaces {} ;# List of Strings: Namespaces of installed (initialized) plugins
private variable ins_plugin_names {} ;# List of Strings: Names of installed (initialized) plugins
- private variable avl_plugin_files {} ;# List of Strings: Full filenames of avaliable plugins
- private variable avl_plugin_names {} ;# List of Strings: Names of avaliable plugins
+ private variable avl_plugin_files {} ;# List of Strings: Full filenames of available plugins
+ private variable avl_plugin_names {} ;# List of Strings: Names of available plugins
# List: Configuraion list of this panel (for session management)
private variable local_config [lindex $::CONFIG(HW_MANAGER_CONFIG) 0]
@@ -71,7 +78,7 @@ class HwManager {
if {[catch {
${ns}::dispose
- }]} {
+ }]} then {
plugin_error $name $ns
}
}
@@ -83,35 +90,35 @@ class HwManager {
# @return void
public method PrepareHwManager {_parent} {
set parent $_parent
- set gui_initialized 0
+ set hwman_gui_initialized 0
}
## Finalize initialization of this panel
# @return void
public method CreateHwManagerGUI {} {
- if {$gui_initialized} {return}
- set gui_initialized 1
+ if {$hwman_gui_initialized} {return}
+ set hwman_gui_initialized 1
# Create main GUI parts
set main_frame [frame $parent.main_frame]
set top_frame [frame $main_frame.top]
- set pagesmanager [PagesManager $main_frame.pagesmanager -background {#eeeeee}]
+ set pagesmanager [PagesManager $main_frame.pagesmanager -background ${::COMMON_BG_COLOR}]
## Create parts of top panel
# Label "HW"
pack [label $top_frame.plg_label \
-text [mc "HW:"] \
] -side left
- # Combobox of avaliable/installed plugins
+ # Combobox of available/installed plugins
set plg_combobox [ttk::combobox $top_frame.plg_cbbox \
-exportselection 1 \
-width 0 \
-state readonly \
]
- DynamicHelp::add $plg_combobox -text [mc "List avaliable or installed HW plugins"]
+ DynamicHelp::add $plg_combobox -text [mc "List available or installed HW plugins"]
bind $plg_combobox <<ComboboxSelected>> "$this hw_manager_plg_cbs"
pack $plg_combobox -fill x -expand 1 -side left
- setStatusTip -widget $plg_combobox -text [mc "Avaliable/installed plugins"]
+ setStatusTip -widget $plg_combobox -text [mc "available/installed plugins"]
# Button "Refresh"
set plg_refresh_but [ttk::button $top_frame.plg_refresh_but \
-image ::ICONS::16::reload \
@@ -119,7 +126,7 @@ class HwManager {
-style Flat.TButton \
]
DynamicHelp::add $top_frame.plg_refresh_but \
- -text [mc "Refresh list avaliable or installed HW plugins"]
+ -text [mc "Refresh list available or installed HW plugins"]
pack $plg_refresh_but -side left
setStatusTip -widget $plg_refresh_but -text [mc "Refresh"]
# Fill in the combobox
@@ -141,16 +148,16 @@ class HwManager {
pack $main_frame -fill both -expand 1
}
- ## Refresh list avaliable or installed HW plugins
+ ## Refresh list available or installed HW plugins
# @return void
public method hw_manager_refresh_plugins {} {
- if {!$gui_initialized} {CreateHwManagerGUI}
+ if {!$hwman_gui_initialized} {CreateHwManagerGUI}
if {${::CLI_OPTION(no-plugins)}} {return}
set avl_plugin_files [list]
set avl_plugin_names [list]
- # Search for avaliable plugins
+ # Search for available plugins
foreach dir $PLUGIN_SEARCH_PATHS {
set dir [file join ${::LIB_DIRNAME} $dir]
catch { ;# For Microsoft Windows it has to be enclosed by catch
@@ -158,6 +165,7 @@ class HwManager {
if {[lsearch -ascii -exact $avl_plugin_names [file tail [file rootname $file]]] != -1} {
continue
}
+
lappend avl_plugin_files $file
lappend avl_plugin_names [regsub -all {_} [file tail [file rootname $file]] { }]
}
@@ -172,12 +180,12 @@ class HwManager {
# @parm String plugin_name - Plugin to switch to
# @return void
public method hw_manager_switch_plugin {plugin_name} {
- if {!$gui_initialized} {CreateHwManagerGUI}
+ if {!$hwman_gui_initialized} {CreateHwManagerGUI}
if {${::CLI_OPTION(no-plugins)}} {return}
# Install the plugin if it wasn't installed yet
if {[lsearch -ascii -exact $ins_plugin_names $plugin_name] == -1} {
- # Check if the selected plugin is really avaliable
+ # Check if the selected plugin is really available
if {[lsearch -ascii -exact $avl_plugin_names $plugin_name] == -1} {
return
}
@@ -192,15 +200,15 @@ class HwManager {
]
}
- # Adjust the combobox of avaliable/installed plugins
- $pagesmanager raise [regsub -all {\s} $plugin_name {_}]
+ # Adjust the combobox of available/installed plugins
+ $pagesmanager raise [regsub -all {[\s\.]} $plugin_name {_}]
}
- ## "Change command" for the combobox of avaliable/installed plugins
+ ## "Change command" for the combobox of available/installed plugins
# Switches the selected plugin
# @return void
public method hw_manager_plg_cbs {} {
- if {!$gui_initialized} {CreateHwManagerGUI}
+ if {!$hwman_gui_initialized} {CreateHwManagerGUI}
hw_manager_switch_plugin [$plg_combobox get]
}
@@ -209,22 +217,24 @@ class HwManager {
# @parm String file_path - Full path to the plugin main file
# @return String - Plugin namespace
public method hw_manager_install_plugin {plugin_name file_path} {
- if {!$gui_initialized} {CreateHwManagerGUI}
+ if {!$hwman_gui_initialized} {CreateHwManagerGUI}
if {${::CLI_OPTION(no-plugins)}} {return}
set plg_ns {}
if {[catch {
- set frame [$pagesmanager add [regsub -all {\s} $plugin_name {_}]]
+ set frame [$pagesmanager add [regsub -all {[\s\.]} $plugin_name {_}]]
set plg_ns "::HwManager::plugin_ns::$inst_plg_count"
incr inst_plg_count
namespace eval $plg_ns "source {$file_path}"
- set min_ide_ver [subst "\$${plg_ns}::MIN_IDE_VER"]
+ set min_ide_ver [subst -nocommands "\$${plg_ns}::MIN_IDE_VER"]
if {[package vcompare $min_ide_ver $::VERSION] == 1} {
tk_messageBox \
+ -parent . \
-title [mc "Too old version"] \
- -type ok -icon warning \
+ -type ok \
+ -icon warning \
-message [mc "Plugin %s requires MCU 8051 IDE version %s and above, please upgrade your MCU 8051 IDE" $plugin_name $min_ide_ver]
}
@@ -234,7 +244,7 @@ class HwManager {
if {$idx != -1} {
${plg_ns}::restore_session [lindex $plugin_config_1 $idx]
}
- }]} {
+ }]} then {
plugin_error $plugin_name $plg_ns
}
@@ -252,9 +262,9 @@ class HwManager {
set plugin_author {not defined}
set authors_email {not defined}
set err_info $::errorInfo
- catch {set plugin_ver [subst "\$${plugin_ns}::P_VERSION"]}
- catch {set plugin_author [subst "\$${plugin_ns}::AUTHOR"]}
- catch {set authors_email [subst "\$${plugin_ns}::EMAIL"]}
+ catch {set plugin_ver [subst -nocommands "\$${plugin_ns}::P_VERSION"]}
+ catch {set plugin_author [subst -nocommands "\$${plugin_ns}::AUTHOR"]}
+ catch {set authors_email [subst -nocommands "\$${plugin_ns}::EMAIL"]}
# Print error message to stadrad error output
puts stderr "\n\n"
@@ -285,85 +295,87 @@ class HwManager {
close $log_file
}
- # Display GUI error message
- set dialog [toplevel .plugin_error -bg {#EEEEEE}]
-
- # Create window frames
- set main_dlg_frame [frame $dialog.main_frame]
- set top_frame [frame $main_dlg_frame.top_frame -bg {#EE0000}]
- set middle_frame [frame $main_dlg_frame.middle_frame]
- set bottom_frame [frame $main_dlg_frame.bottom_frame]
-
- # Create window header
- pack [label $top_frame.header_lbl \
- -text [mc "PLUGIN ERROR"] \
- -bg {#EE0000} -fg {#FFFFFF} \
- -font [font create \
- -family helvetica \
- -size -24 \
- -weight bold \
- ] \
- ] -side left -fill x -expand 1
-
- # Create error message text and scrollbar
- pack [text $middle_frame.text \
- -bg {white} -bd 0 \
- -yscrollcommand "$middle_frame.scrollbar set" \
- -width 0 -height 0 -relief flat -wrap word \
- ] -side left -fill both -expand 1 -padx 5 -pady 5
- bind $middle_frame.text <Button-1> {focus %W}
- pack [ttk::scrollbar $middle_frame.scrollbar \
- -orient vertical \
- -command "$middle_frame.text yview" \
- ] -fill y -side right
-
- # Create button "Close"
- pack [ttk::button $bottom_frame.ok \
- -text [mc "Close"] \
- -style GreenBg.TButton \
- -command "
+ # Display GUI error message (only if the main window is still visible)
+ if {[wm state .] != {withdrawn}} {
+ set dialog [toplevel .plugin_error -bg ${::COMMON_BG_COLOR}]
+
+ # Create window frames
+ set main_dlg_frame [frame $dialog.main_frame]
+ set top_frame [frame $main_dlg_frame.top_frame -bg {#EE0000}]
+ set middle_frame [frame $main_dlg_frame.middle_frame]
+ set bottom_frame [frame $main_dlg_frame.bottom_frame]
+
+ # Create window header
+ pack [label $top_frame.header_lbl \
+ -text [mc "PLUGIN ERROR"] \
+ -bg {#EE0000} -fg {#FFFFFF} \
+ -font [font create \
+ -family helvetica \
+ -size [expr {int(-24 * $::font_size_factor)}] \
+ -weight bold \
+ ] \
+ ] -side left -fill x -expand 1
+
+ # Create error message text and scrollbar
+ pack [text $middle_frame.text \
+ -bg {white} -bd 0 \
+ -yscrollcommand "$middle_frame.scrollbar set" \
+ -width 0 -height 0 -relief flat -wrap word \
+ ] -side left -fill both -expand 1 -padx 5 -pady 5
+ bind $middle_frame.text <Button-1> {focus %W}
+ pack [ttk::scrollbar $middle_frame.scrollbar \
+ -orient vertical \
+ -command "$middle_frame.text yview" \
+ ] -fill y -side right
+
+ # Create button "Close"
+ pack [ttk::button $bottom_frame.ok \
+ -text [mc "Close"] \
+ -style GreenBg.TButton \
+ -command "
+ grab release $dialog
+ destroy $dialog
+ " \
+ ] -side right
+ focus -force $bottom_frame.ok
+
+ # Display error message
+ $middle_frame.text insert insert [mc "Plugin name:\t%s\n" $plugin_name]
+ $middle_frame.text insert insert [mc "Plugin version:\t%s\n" $plugin_ver]
+ $middle_frame.text insert insert [mc "Author:\t\t%s <%s>\n" $plugin_author $authors_email]
+ $middle_frame.text insert insert "\n"
+ $middle_frame.text insert insert $err_info
+ $middle_frame.text insert insert "\n"
+ $middle_frame.text configure -state disabled
+
+ # Pack window frames
+ pack $top_frame -fill x -anchor n
+ pack $middle_frame -fill both -expand 1
+ pack $bottom_frame -fill x
+ pack $main_dlg_frame -fill both -expand 1 -padx 5 -pady 5
+
+ # Configure dialog window
+ set x [expr {[winfo screenwidth $dialog] / 2 - 225}]
+ set y [expr {[winfo screenheight $dialog] / 2 - 125}]
+ wm iconphoto $dialog ::ICONS::16::bug
+ wm title $dialog [mc "PLUGIN ERROR - MCU 8051 IDE"]
+ wm minsize $dialog 450 250
+ wm geometry $dialog =550x250+$x+$y
+ wm protocol $dialog WM_DELETE_WINDOW "
grab release $dialog
- destroy $dialog
- " \
- ] -side right
- focus -force $bottom_frame.ok
-
- # Display error message
- $middle_frame.text insert insert [mc "Plugin name:\t%s\n" $plugin_name]
- $middle_frame.text insert insert [mc "Plugin version:\t%s\n" $plugin_ver]
- $middle_frame.text insert insert [mc "Author:\t\t%s <%s>\n" $plugin_author $authors_email]
- $middle_frame.text insert insert "\n"
- $middle_frame.text insert insert $err_info
- $middle_frame.text insert insert "\n"
- $middle_frame.text configure -state disabled
-
- # Pack window frames
- pack $top_frame -fill x -anchor n
- pack $middle_frame -fill both -expand 1
- pack $bottom_frame -fill x
- pack $main_dlg_frame -fill both -expand 1 -padx 5 -pady 5
-
- # Configure dialog window
- set x [expr {[winfo screenwidth $dialog] / 2 - 225}]
- set y [expr {[winfo screenheight $dialog] / 2 - 125}]
- wm iconphoto $dialog ::ICONS::16::bug
- wm title $dialog [mc "PLUGIN ERROR - MCU 8051 IDE"]
- wm minsize $dialog 450 250
- wm geometry $dialog =550x250+$x+$y
- wm protocol $dialog WM_DELETE_WINDOW "
- grab release $dialog
- destroy $dialog"
- update
- raise $dialog
- grab $dialog
- wm transient $dialog .
- tkwait window $dialog
+ destroy $dialog"
+ update
+ raise $dialog
+ grab $dialog
+ wm transient $dialog .
+ tkwait window $dialog
+ }
}
## Ask all plugins wheather they are ready for exit
# @return Bool - 1 == Exit allowed; 0 == Exit DENIED
public method hw_manager_comfirm_exit {} {
- if {!$gui_initialized} {return 1}
+ if {!$hwman_gui_initialized} {return 1}
foreach plg_name $ins_plugin_names plg_ns $ins_plugin_namespaces {
set busy_flag 0
@@ -389,7 +401,7 @@ class HwManager {
## Get configuration list for this panel (intented for sessions management)
# @return void
public method hw_manager_get_cfg {} {
- if {!$gui_initialized} {
+ if {!$hwman_gui_initialized} {
return [list $local_config $plugin_config_0 $plugin_config_1]
}
@@ -409,11 +421,125 @@ class HwManager {
if {$idx == -1} {
lappend plugin_config_0 $plg_name
lappend plugin_config_1 $config
- } {
+ } else {
lset plugin_config_1 $idx $config
}
}
return [list $local_config $plugin_config_0 $plugin_config_1]
}
+
+ # ---------------------------------------------------------------------
+ # Functions mend to be accessed from HW control plug-ins
+ # ---------------------------------------------------------------------
+
+ ## Check whether there is some project opened in the IDE
+ # @return Bool - 1 == Yes, there is; 0 == No there is not
+ proc is_project_opened {} {
+ return [expr {!${::X::project_menu_locked}}]
+ }
+
+ ## Check whether MCU simulator is engaged
+ # @return Bool - 0 == 1 == Yes, it is; No it is not (or no project is opened)
+ proc is_simulator_engaged {} {
+ if {[lindex ${::X::simulator_enabled} ${::X::actualProjectIdx}] == 1} {
+ return 1
+ } else {
+ return 0
+ }
+ }
+
+ ## Get full name of file which is currently displayed in the source code editor
+ # @return String - Full file name including path or empty string in case there is no project opened
+ proc get_current_file {} {
+ if {![is_project_opened]} {
+ return {}
+ } else {
+ return [${::X::actualProject} editor_procedure {} getFileName {}]
+ }
+ }
+
+ ## Get full name of file which has been chosen as the project main file
+ # @return String - Full file name or empty string
+ proc get_project_main_file {} {
+ if {![is_project_opened]} {
+ return {}
+ } else {
+ return [${::X::actualProject} cget -P_option_main_file]
+ }
+ }
+
+ ## Get path the directory of currently active project
+ # @return String - Directory path or empty string in case there is no project opened
+ proc get_project_dir {} {
+ if {![is_project_opened]} {
+ return {}
+ } else {
+ return [${::X::actualProject} cget -projectPath]
+ }
+ }
+
+ ## Get name of the current project
+ # @return String - Name of the current project or empty string in case there is no project opened
+ proc get_project_name {} {
+ if {![is_project_opened]} {
+ return {}
+ } else {
+ return [${::X::actualProject} cget -projectName]
+ }
+ }
+
+ ## Initiate compilation if at least one of the source files was modified
+ # @parm String success_callback - Any command to execute after successful compilation
+ # @parm String failure_callback - Any command to execute after unsuccessful compilation
+ # @return Bool - 1 == Process successfully started; 0 == Unable to comply (no project is opened)
+ proc compile_if_nessesary_and_callback {success_callback failure_callback} {
+ if {![is_project_opened]} {
+ return 0
+ }
+
+ ::X::compile_if_nessesary_and_callback $success_callback $failure_callback
+ return 1
+ }
+
+ ## Open the specified Intel® 8 hex file in hexadecimal editor
+ # @parm String filename - Name of file to open (including path)
+ # @return Bool - 1 == Success; 0 == Failure
+ proc open_in_hexeditor {filename} {
+ return [[::X::__hexeditor] open_file $filename hex]
+ }
+
+ ## Start MCU simulator if possible
+ # @return Bool - 1 == Success; 0 == Unable to comply
+ proc start_simulator {} {
+ if {![is_project_opened]} {
+ return 0
+ }
+
+ if {[is_simulator_engaged]} {
+ return 0
+ }
+
+ ::X::__initiate_sim
+ return 1
+ }
+
+ ## Shutdown MCU simulator if possible
+ # @return Bool - 1 == Success; 0 == Unable to comply
+ proc shutdown_simulator {} {
+ if {![is_project_opened]} {
+ return 0
+ }
+
+ if {![is_simulator_engaged]} {
+ return 0
+ }
+
+ ::X::__initiate_sim
+ return 1
+ }
+}
+
+# >>> File inclusion guard
}
+# <<< File inclusion guard