00001 # Copyright (C) 1997-2004 The CDG Team <cdg@nats.informatik.uni-hamburg.de> 00002 # 00003 # This file is free software; as a special exception the author gives 00004 # unlimited permission to copy and/or distribute it, with or without 00005 # modifications, as long as this notice is preserved. 00006 # 00007 # This program is distributed in the hope that it will be useful, but 00008 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 00009 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00010 00011 ## ---------------------------------------------------------------------------- 00012 ## YadaLog - a text output widget. 00013 ## This class defines a scrollable text window used to display the informations, 00014 ## warnings and errors that occure during YADA. 00015 ## 00016 ## \author Michael Daum 00017 ## 00018 ## $Id: YadaLog.tcl,v 1.9 2004/02/25 14:42:09 micha Exp $ 00019 ## ---------------------------------------------------------------------------- 00020 class YadaLog { 00021 inherit iwidgets::Scrolledtext 00022 00023 # variables ---------------------------------------------------------------- 00024 00025 ## list of highlightened patterns in the text. 00026 private variable _tagging {} 00027 00028 ## flag used in print(). 00029 private variable _needsLineFeed 0 00030 00031 ## flag indicating whether new text should be focused or not. 00032 public variable followData 1 00033 00034 # methods ------------------------------------------------------------------ 00035 public method autotag {pattern args}; ## \type TclString, TclList 00036 public method print {message}; ## \type TclString 00037 public method clear {} 00038 00039 constructor {args} {}; ## \type TclList 00040 }; 00041 00042 ## ---------------------------------------------------------------------------- 00043 ## constructor 00044 ## ---------------------------------------------------------------------------- 00045 body YadaLog::constructor {args} { 00046 eval itk_initialize $args 00047 } 00048 00049 ## ---------------------------------------------------------------------------- 00050 ## print a message on the widget. 00051 ## The text is added to the end of the already printed text and highlightened 00052 ## according to the configured autotags. \see autotag(). After inserting the 00053 ## text tcltk is given an update loop to refresh its widges. 00054 ## \param message the text to be displayed. 00055 ## ---------------------------------------------------------------------------- 00056 body YadaLog::print {message} { 00057 00058 # remember first position 00059 ::scan [index end] %d logFirst 00060 incr logFirst -1 00061 00062 # split string by formfeeds if available 00063 00064 set splitMessages [split "$message" "\r"] 00065 set lastMessage [lindex $splitMessages end] 00066 set splitMessages [lreplace $splitMessages end end] 00067 00068 foreach splitMessage $splitMessages { 00069 if {$_needsLineFeed} { 00070 mark set insert end 00071 delete "insert linestart" "insert lineend" 00072 } 00073 insert end "$splitMessage" 00074 } 00075 00076 if {$lastMessage == ""} { 00077 set _needsLineFeed 1 00078 } else { 00079 if {$_needsLineFeed} { 00080 mark set insert end 00081 delete "insert linestart" "insert lineend" 00082 } 00083 insert end "$lastMessage" 00084 set _needsLineFeed 0 00085 } 00086 00087 # remember last position 00088 ::scan [index end] %d logLast 00089 00090 # apply autotagging 00091 foreach pattern $_tagging { 00092 for {set i $logFirst} {$i < $logLast} {incr i} { 00093 mark set last $i.0 00094 while {[regexp -indices $pattern [get last "last lineend"] indices]} { 00095 00096 mark set first "last + [lindex $indices 0] chars" 00097 mark set last "last + 1 chars + [lindex $indices 1] chars" 00098 tag add $pattern first last 00099 } 00100 } 00101 } 00102 00103 if {$followData} { 00104 see end 00105 } 00106 update 00107 } 00108 00109 ## ---------------------------------------------------------------------------- 00110 ## clear the text. 00111 ## This simply deletes all previousply printed text. 00112 ## ---------------------------------------------------------------------------- 00113 body YadaLog::clear {} { 00114 delete 1.0 end 00115 } 00116 00117 ## ---------------------------------------------------------------------------- 00118 ## configure syntax highlightning. 00119 ## This method lets you define a pattern as a regular expression and associate 00120 ## tag configurations (see tk::text). 00121 ## \param pattern a regular expression matching a part of printed text. 00122 ## \param args list of tag configurations in the text widget 00123 ## ---------------------------------------------------------------------------- 00124 body YadaLog::autotag {pattern args} { 00125 lappend _tagging $pattern 00126 eval tag configure $pattern $args 00127 } 00128