Simple text editor

This is defunct code and just an example of how one may handle dynamic change of UI-language. Feel free to use it if you want but please don't send me bugfixes or coding tips. Thanks! - VL.

Uses the iwidgets scrolledtext variant of the Tk text widget.


escargo 19 Dec 2003 - Where is the file chopmap.tcl?


 #====================================================================#
 #-- PROGRAM ------: mimers brunn translator tools
 #-- You can always find the latest version of theese files at:
 #-- http://mimersbrunn.sourceforge.net
 #-- FILENAME -----: mimersTV.tcl
 #-- VERSION ------: 1.0.0a
 #-- DESCRIPTION --: Simple GUI for viewing, editing and converting
 #-- plain text files in different encodings.
 #-- AUTHOR -------: Veronica Loell     #-- EMAIL -: [email protected]
 #-- FILE CREATED -: 2002-02-24 10:24
 #-- LAST CHANGED -: 2002-02-24 10:24
 #-- COPYRIGHT ----: Nakawe data SE7207250346
 #   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  
 #====================================================================#
 
 package require Iwidgets 3.0.1
 package require msgcat
 package require Tclx
 
 source chopmap.tcl
 
 variable Enc "identity"
 variable FileName ""
 variable UILang "en"
 variable Filter ""
 
 proc OpenFile {} {
         global Enc FileName Filter
         .txt delete 1.0 end
         set FileName [tk_getOpenFile]
    set FilePointer [open $FileName r]
    fconfigure $FilePointer -encoding $Enc
    # Put into the text area
          set TheText [read $FilePointer]
          close $FilePointer
          switch $Filter {
                 HEXsv {set theText [FilterHexUnknownSwedish $TheText]}
                 default {}
         }                        
          .txt insert end $TheText
          wm title . [::msgcat::mc "Mimers' Intelligent text editor - %s" [file tail $FileName]]
 }
 
 proc SaveFile {} {
         global Enc
         set FileName [tk_getSaveFile ]
    set FilePointer [open $FileName w]
    fconfigure $FilePointer -encoding $Enc
    # Get the entire text and write it to file
           set TheText [.txt get 1.0 end] 
         puts -nonewline $FilePointer $TheText
          close $FilePointer
          wm title . [::msgcat::mc "Mimers' \
          Intelligent text editor - %s" [file tail $FileName]]
 }
 
 proc ReloadFile {} {
         global Enc FileName Filter
         .txt delete 1.0 end
         set FilePointer [open $FileName r]
         fconfigure $FilePointer -encoding $Enc
         # Put onto the text area
          set TheText [read $FilePointer]
          close $FilePointer
          switch $Filter {
                 HEXsv {set TheText [FilterHexUnknownSwedish $TheText]}
                 default {}
         }                        
          .txt insert end $TheText
 }
 
 proc OpenCharInfo {} {
         toplevel .help
         wm title .help [::msgcat::mc "Find your encoding:"]
         text .help.txtHelp -wrap word
         pack .help.txtHelp
    set FilePointer [open [file join tcl_charset_iana] r]
    fconfigure $FilePointer -encoding utf-8
    # Put into the text area
          set TheText [read $FilePointer]
          close $FilePointer
         .help.txtHelp insert end $TheText
         set Encoding [.cbxEncoding getcurselection]
         .help.txtHelp see        [.help.txtHelp search $Encoding 1.1 end]
 }
         
 proc MimersTE {} {
         global Enc        Filter
         iwidgets::scrolledtext .txt -hscrollmode dynamic
         frame .frm
         button .btnOpen -command {OpenFile}
         button .btnReload -command {ReloadFile}
         button .btnSave -command {SaveFile}
         button .btnCharInfo -command {OpenCharInfo}
         iwidgets::combobox .cbxEncoding -selectioncommand {set Enc [.cbxEncoding getcurselection]}                
         set encodingList [lsort [encoding names]]
         for {set i 0} {$i < [llength $encodingList]} {incr i} {
                 .cbxEncoding insert list end [lindex $encodingList $i]
         }
         iwidgets::combobox .cbxFilter -selectioncommand {set Filter [.cbxFilter getcurselection]}
         .cbxFilter insert list end HEXsv
         iwidgets::combobox .cbxUILang -selectioncommand {setUILang [mapLang [.cbxUILang getcurselection]]}
 
         pack .frm -pady 5 -padx 5 -anchor nw
         pack .txt  -pady 10 -padx 10 -fill both
         grid .cbxEncoding -in .frm -column 0 -row 0 -padx 5 -pady 5 -sticky e
         grid .cbxFilter -in .frm -column 0 -row 1 -padx 5 -sticky e
         grid .btnCharInfo -in .frm -column 1 -row 0 -padx 5 -pady 5
         grid .btnOpen -in .frm -column 2 -row 0 -padx 5 -pady 5 -sticky we
         grid .btnReload -in .frm -column 2 -row 1 -padx 5 -pady 5 -sticky we
         grid .btnSave -in .frm -column 3 -row 0 -padx 5 -pady 5        
         grid .cbxUILang -in .frm -column 4 -row 1 -sticky e
         .cbxUILang insert list end Svenska English
 }
 
 proc setUILang {Lang} {
         ::msgcat::mclocale $Lang
         set fd [open [cconcat [file join msgs $Lang] ".msg"] r]
         fconfigure $fd -encoding utf-8
         set utfscript [read $fd]
         close $fd
         eval $utfscript
         .btnOpen configure -text [::msgcat::mc "Open file"] 
         .btnReload configure -text [::msgcat::mc "Reload file"]
         .btnSave configure -text [::msgcat::mc "Save file"]
         .btnCharInfo configure  -text [::msgcat::mc "??"]
         .cbxEncoding configure -labeltext [::msgcat::mc "Choose encoding:"]
         .cbxFilter configure -labeltext [::msgcat::mc "Choose filter:"]
         .cbxUILang configure -labeltext [::msgcat::mc "Choose language:"]
         wm title . [::msgcat::mc         "Mimers' Intelligent text editor - Version 1.0.0a"]
 }
 
 proc mapLang {LangName} {
         if {$LangName == "English"} {
                 return en
         } else {
                 return sv
         }
 }
 MimersTE
 #setUILang {en}
----
 ## Swedish messages for Mimers brunn STE.
 ## Copyright (C) 2002 Free Software Foundation, Inc.
 ## Veronica Loell <[email protected]>, 2002.
 ##
 #msgid ""
 #msgstr ""
 #"Project-Id-Version: mimersSTE 1.0.0a"
 #"POT-Creation-Date: 2002-02-24 16:51"
 #"PO-Revision-Date: 2002-02-27 21:58+0100\n"
 #"Last-Translator: Veronica Loell <[email protected]>\n"
 #"Language-Team: Swedish <[email protected]>\n"
 #"MIME-Version: 1.0\n"
 #"Content-Type: text/plain; charset=iso-8859-1\n"
 #"Content-Transfer-Encoding: 8bit\n"
 
 #. widget: window title
 #: E:/mimersbrunn/STE/mimersTE.tcl:51
 ::msgcat::mcset sv\
 "Mimers' Intelligent text editor - %s"\
  \
 "Mimers Intelligenta texteditor - %s"\
 
 #. widget: window title
 #: E:/mimersbrunn/STE/mimersTE.tcl:63
 ::msgcat::mcset sv\
 "Mimers' Intelligent text editor - %s"\
  \
 "Mimers Intelligenta texteditor - %s"\
 
 #. widget: none
 #: E:/mimersbrunn/STE/mimersTE.tcl:84
 ::msgcat::mcset sv\
 "Find your encoding:"\
  \
 "Hitta din teckenkodning"\
 
 #. widget: button
 #: E:/mimersbrunn/STE/mimersTE.tcl:132
 ::msgcat::mcset sv\
 "Open file"\
  \
 "Öppna fil"\
 
 #. widget: button
 #: E:/mimersbrunn/STE/mimersTE.tcl:133
 ::msgcat::mcset sv\
 "Reload file"\
  \
 "Hämta om fil"\
 
 #. widget: button
 #: E:/mimersbrunn/STE/mimersTE.tcl:134
 ::msgcat::mcset sv\
 "Save file"\
  \
 "Spara fil"\
 
 #. widget: button
 #: E:/mimersbrunn/STE/mimersTE.tcl:135
 ::msgcat::mcset sv\
 "??"\
  \
 "??"\
 
 #. widget: iwidgets::combo box
 #: E:/mimersbrunn/STE/mimersTE.tcl:136
 ::msgcat::mcset sv\
 "Choose encoding:"\
  \
 "Välj teckenkodning:"\
 
 #. widget: iwidgets::combo box
 #: E:/mimersbrunn/STE/mimersTE.tcl:137
 ::msgcat::mcset sv\
 "Choose filter:"\
  \
 "Välj filter:"\
 
 #. widget: iwidgets::combo box
 #: E:/mimersbrunn/STE/mimersTE.tcl:138
 ::msgcat::mcset sv\
 "Choose language:"\
  \
 "Välj språk:"\
 
 #. widget: window title
 #: E:/mimersbrunn/STE/mimersTE.tcl:140
 ::msgcat::mcset sv\
 "Mimers' Intelligent text editor - Version 1.0.0a"\
  \
 "Mimers Intelligenta texteditor - Version 1.0.0a"\