1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
#!/usr/bin/tclsh
# Part of MCU 8051 IDE ( http://https://sourceforge.net/projects/mcu8051ide/ )
############################################################################
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# Copyright (C) 2014 by Moravia Microsystems, s.r.o. #
# martin.osmera@gmail.com #
# #
# This program is free software; you can redistribute it and#or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
# >>> File inclusion guard
if { ! [ info exists _ERRORHANDLER_TCL ] } {
set _ERRORHANDLER_TCL _
# <<< File inclusion guard
# --------------------------------------------------------------------------
# DESCRIPTION
# Background error handler
# --------------------------------------------------------------------------
namespace eval ErrorHandler {
variable num_of_opened 0 ;# Int: Number of currently opened dialogues
variable count 0 ;# Int: Counter of ivokations
variable enabled 1 ;# Bool: Dialog window enabled
## Open dialog window
# @parm String message - Error message
# @return void
proc open_dialog {message} {
variable count ;# Int: Counter of ivokations
variable enabled ;# Bool: Dialog window enabled
variable num_of_opened ;# Int: Number of currently opened dialogues
if {$num_of_opened > 2} {
puts stderr "ERROR MESSAGE SUPPRESED (too many error dialogues opened at the time)"
return
}
incr num_of_opened
# Send error message to standard error output
puts stderr [string repeat # 64]
puts stderr "# PROGRAM ERROR #"
puts stderr [string repeat # 64]
puts stderr $::errorInfo
puts stderr [string repeat # 64]
# Save log file
if {![catch {set log_file [open [file join ${::X::defaultDirectory} mcu8051ide_errors.log] a]}]} {
puts $log_file [string repeat # 64]
puts $log_file "Program version:\t${::VERSION}"
puts $log_file "Tcl version:\t\t${::tcl_version}"
puts $log_file "Tk version:\t\t${::tk_version}"
puts $log_file [string repeat - 64]
puts $log_file $::errorInfo
close $log_file
}
# Create dialog window
if {!$enabled} {return}
incr count
set win [toplevel .error_dialog$count -bg {#EE0000} -class {Error message} -bg ${::COMMON_BG_COLOR}]
# Create window frames
set main_frame [frame $win.main_frame]
set top_frame [frame $main_frame.top_frame -bg {#EE0000}]
set middle_frame [frame $main_frame.middle_frame]
set bottom_frame [frame $main_frame.bottom_frame]
# Create window header
pack [label $top_frame.header_lbl \
-text [mc "PROGRAM 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 text tags
$middle_frame.text tag configure tag_bold \
-font [font create \
-family $::DEFAULT_FIXED_FONT \
-weight bold \
-size [expr {int(-12 * $::font_size_factor)}] \
]
$middle_frame.text tag configure tag_tt \
-font [font create \
-family $::DEFAULT_FIXED_FONT \
-size [expr {int(-12 * $::font_size_factor)}] \
]
$middle_frame.text tag configure tag_big_bold \
-font [font create \
-family {helvetica} \
-weight bold \
-size [expr {int(-17 * $::font_size_factor)}] \
]
# Write error message
$middle_frame.text insert end [mc "Program version: %s\n" "${::VERSION}"]
$middle_frame.text insert end [mc "Error log saved in: %s\n" "${::X::defaultDirectory}[file separator]mcu8051ide_errors.log"]
$middle_frame.text insert end [mc "Please send this file to %s\n\n\n" {<martin.osmera@gmail.com>}]
create_link_tag_in_text_widget $middle_frame.text
convert_all_https_to_links $middle_frame.text
$middle_frame.text tag add tag_big_bold 1.0 4.0
$middle_frame.text insert end [mc "ERROR DETAILS:\n--------------\n"]
$middle_frame.text tag add tag_bold 6.0 8.0
$middle_frame.text insert end $::errorInfo
$middle_frame.text tag add tag_tt 8.0 end
$middle_frame.text configure -state disabled
# Create button frame
pack [ttk::button $bottom_frame.skip \
-text [mc "Skip errors"] \
-compound left \
-command "
set ::ErrorHandler::enabled 0
::ErrorHandler::close_dialog $count
" \
] -side left
pack [ttk::button $bottom_frame.ok \
-text [mc "Close"] \
-style GreenBg.TButton \
-command "::ErrorHandler::close_dialog $count" \
] -side right
focus -force $bottom_frame.ok
# Pack window frames
pack $top_frame -fill x -anchor n
pack $middle_frame -fill both -expand 1
pack $bottom_frame -fill x
pack $main_frame -fill both -expand 1 -padx 5 -pady 5
# Configure dialog window
set x [expr {[winfo screenwidth $win] / 2 - 225}]
set y [expr {[winfo screenheight $win] / 2 - 125}]
wm iconphoto $win ::ICONS::16::bug
wm title $win [mc "PROGRAM ERROR - MCU 8051 IDE"]
wm minsize $win 450 250
wm geometry $win =550x250+$x+$y
wm protocol $win WM_DELETE_WINDOW "::ErrorHandler::close_dialog $count"
update
raise $win
catch {grab $win}
}
## Close dialog window
# @parm Int number - Dialog unique number
# @return void
proc close_dialog {number} {
variable num_of_opened ;# Int: Number of currently opened dialogues
incr num_of_opened -1
destroy .error_dialog$number
}
}
# Register error handler
proc bgerror {message} {
::ErrorHandler::open_dialog $message
}
# >>> File inclusion guard
}
# <<< File inclusion guard
|