source: tol/tolbase/lib/toltk/init_toltk.tcl @ 8d687fe

1941-docker-image-to-testdevel
Last change on this file since 8d687fe was ab6d232, checked in by Jorge Pérez <josp.jorge@…>, 15 years ago

#refs 1404, USE_TOLTCL_31 environment variable to load a specific toltcl shared lib, it is useful when debugging

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@4125 be4846ae-f051-483a-831f-b64e7d08527f

  • Property mode set to 100755
File size: 11.8 KB
Line 
1#!/bin/sh
2#-*-tcl-*-
3# the next line restarts using wish \
4exec wish "$0" -- ${1+"$@"}
5
6#/////////////////////////////////////////////////////////////////////////////
7# FILE    : init_toltk.tcl
8# PURPOSE : This file loads packages and libraries and initializes a project.
9#/////////////////////////////////////////////////////////////////////////////
10
11package require Tk
12
13set trace 0
14#/////////////////////////////////////////////////////////////////////////////
15  proc Tolcon_Trace { msg {tags ""} {args ""} } {
16#
17# PURPOSE: Writes a trace message in a toplevel window. It's used for
18#          debugging. If release versions uncomment the initial return.
19#
20# PARAMETERS:
21#   msg -> Message to trace
22#
23#/////////////////////////////////////////////////////////////////////////////
24  global trace
25  if {$trace eq 0} {
26    return
27  }
28 
29  set w .__debugwin
30  if { ![winfo exists $w] } {
31    toplevel $w
32    ScrolledWindow $w.sw
33    text $w.sw.t
34    $w.sw setwidget $w.sw.t
35    # tags of text widget
36    $w.sw.t tag configure bold -font {Tahoma 8 bold}
37    $w.sw.t tag configure big -font {Tahoma 10 bold}
38    $w.sw.t tag configure verybig -font {Tahoma 12 bold}
39    $w.sw.t tag configure normal -font {Tahoma 8}
40    $w.sw.t tag configure small -font {Tahoma 7}
41    $w.sw.t tag configure centered -justify center
42    $w.sw.t tag configure underline -underline on   
43    $w.sw.t tag configure red -foreground red
44    $w.sw.t tag configure green -foreground darkgreen
45    $w.sw.t tag configure blue -foreground darkblue
46    $w.sw.t tag configure grey -foreground darkgrey
47   
48    #::BayesText::MenuCreate $w.sw.t
49    pack $w.sw -fill both -expand yes
50  }
51  $w.sw.t insert end "$msg\n" $tags
52  $w.sw.t see end
53  update
54}
55
56proc TraceMainGeometry { msg } {
57  puts "== $msg == wm geometry . == [wm geometry .]"
58  puts "== $msg == winfo geometry . == [winfo geometry .]"
59}
60
61#/////////////////////////////////////////////////////////////////////////////
62  proc LoadPackages {} {
63#
64# PURPOSE: Load packages
65#
66#/////////////////////////////////////////////////////////////////////////////
67  package require snit
68  package require BWidget
69  package require msgcat
70  namespace import msgcat::*
71  package require Tktable
72  package require -exact BLT 2.4
73  package require autoscroll 1.1
74  package require tclodbc
75  if {[info exist ::env(USE_TOLTCL_31)]} {
76    puts "requested to load Toltcl from $::env(USE_TOLTCL_31)"
77    load $::env(USE_TOLTCL_31)
78  } else {
79    package require Toltcl 3.1
80  }
81  package require rmtps_client
82  package require byswidget
83  package require mkWidgets 1.3
84  #NOTE. Por precaución cargamos el paquete aqui
85  #En un futuro cambiar
86  package require bfunctions
87}
88
89#/////////////////////////////////////////////////////////////////////////////
90 proc OpenAssocFile {file {run 0} {inc 0}} {
91#/////////////////////////////////////////////////////////////////////////////
92  switch [string toupper [file extension $file]] {
93    ".SQL" {
94      #::Editor::Open $file
95    }
96    ".PRJ" {
97      if { $inc } {
98        ::tol::console eval "Set IncludePRJ(Text \"$file\")"
99      } else {
100        ::TolProject::Open $file $run
101      }
102    }
103    ".BDT" {
104      if { $inc } {
105        ::tol::console eval "Set IncludeBDT(Text \"$file\")"
106      } else {
107        ::EditTable::Open $file
108      }
109    }
110    ".BST" {
111      if { $inc } {
112        ::tol::console eval "Set IncludeBST(Text \"$file\")"
113      } else {
114        ::EditTable::Open $file
115      }
116    }
117    ".BMT" {
118      if { $inc } {
119        ::tol::console eval "Set IncludeBMT(Text \"$file\")"
120      } else {
121        ::EditTable::Open $file
122      }
123    }
124    ".TOL" {
125      if { $inc } {
126        ::tol::console eval "Set IncludeTOL(Text \"$file\")"
127      } else {
128        ::Editor::Open $file $run
129      }
130    }
131  }
132}
133
134
135#/////////////////////////////////////////////////////////////////////////////
136  proc loadInfoProjects { prjini } {
137#
138# PURPOSE: Loads in a list the name and paths of each project to load
139#
140# RETURN: the list with the data
141#
142#/////////////////////////////////////////////////////////////////////////////
143  global iniparse
144  global toltk_library
145  global toltk_script_path
146 
147  set values {}
148  # File exists ?
149  set ok 0
150  if { [ file isfile $prjini ] } {
151    if { [ file readable $prjini ] } {
152      set ok 1
153      set fileProject [ file normalize $prjini ]
154      # se intentara leer el iniproject.tol desde este sitio
155      lappend values Project,path,root [ file dir $fileProject ]
156    } else {
157      tk_messageBox -default ok -icon error \
158          -message [ mc "The project does not exist, file not found or not readable: %s" $prj ] \
159          -parent . -title "Error" -type ok
160      return ""
161    }
162  } else {
163    # comportamiento anterior, pudiera limpiarse
164    lappend values Project,path,root ""
165    set pathInitTol ""
166    set dir $prjini
167    set dirPrjIni "[file normalize $dir]/../../../"
168    set fileProject [file join $dirPrjIni "project.ini"]
169    if {[file exists $fileProject]} {
170      set ok [ file writable $fileProject ]
171    } else {
172      set fileProject [file join $dir "project.ini"]
173      if {[file exists $fileProject]} {
174        set ok [ file writable $fileProject ] 
175      }
176    }
177  }
178  # exists project.ini ?
179  if {$ok} {
180    set id [iniparse:openfile $fileProject]
181    catch { ::iniFile::Create $fileProject }
182    foreach prj $iniparse($id,sections) {
183      if { $prj eq "Project" } {
184        lappend values Project,title [::iniFile::Read Project title {}]
185        lappend values Project,splash [::iniFile::Read Project splash {}]
186        lappend values Project,names [lrange $iniparse($id,sections) 1 end]
187      } else {
188        set name [::iniFile::Read $prj name ""]
189        set path [::iniFile::Read $prj path ""]
190        if { [string length $path] } {
191          set _path [file join $toltk_library $path]
192          if { [file exists $_path] } {
193            set $path $_path
194          } else {
195            #si la ruta se da relativa y tolbase se ejecuta desde archivo asociado
196            set __path [file join $toltk_script_path $path]
197            if { [file exists $__path] } {
198              set $path $__path
199            }
200          }
201          set pathtcl [file join $path tcl]
202        } else {
203          set path [file join $toltk_library toltk]
204          set pathtcl $path
205        }
206        # check exists file ?
207        if {[string length $name] && [string length $path] &&
208            [file exists [file join $pathtcl ${name}.tcl]]} {
209          lappend values ${prj},name $name
210          lappend values ${prj},path $path
211          lappend values ${prj},path,tcl $pathtcl
212        } else {
213          # erase prj in list of project
214          array set arrtemp $values
215          set lstAux $arrtemp(Project,names)
216          set arrtemp(Project,names) [lreplace $arrtemp(Project,names) \
217            [lsearch -exac $arrtemp(Project,names) $prj] \
218            [lsearch -exac $arrtemp(Project,names) $prj]]
219          set values [array get arrtemp]
220          unset arrtemp
221          # show mwssage
222          if {[string length $name] && [string length $path]} {
223            tk_messageBox -default ok -icon error \
224              -message "The project does not exist: $prj ([file join $pathtcl ${name}.tcl])" \
225              -parent . -title "Error" -type ok
226          }
227        }
228      }
229    }
230    iniparse:closefile $id
231  }
232  return $values
233}
234
235if {[info exist ::env(DEBUG_TOLTCL)] && $::env(DEBUG_TOLTCL) eq "yes"} {
236  set tt_debug "d" 
237} else {
238  set tt_debug "" 
239}
240
241
242set info_script [info script]
243if {[file type $info_script] eq "link"} {
244  set info_script [file readlink $info_script]
245}
246set toltk_script_path [ file normalize [file dirname $info_script] ]
247# load tclIndex
248set dir $toltk_script_path
249source [file join $toltk_script_path "tclIndex"]
250unset dir
251
252set executable_path [ file normalize [file dirname [info nameofexecutable] ] ]
253array set GuiVersionInfo {major 1 minor 1 release 6 comment "cvs trunk"}
254
255# path user
256if { [string equal $tcl_platform(platform) "windows"] } {
257  set home_path $env(USERPROFILE) 
258} else {
259  set home_path $env(HOME) 
260}
261
262if { ![info exists toltk_library] } {
263  set toltk_library [file normalize [file join $toltk_script_path ..]]
264}
265
266if { ![info exists toltk_bin] } {
267  set toltk_bin [file normalize [file join $toltk_library ../bin]]
268}
269
270if {[lsearch $auto_path $toltk_library] == -1} {
271  set auto_path [linsert $auto_path 0 $toltk_library]
272}
273
274if { ![info exists blt_libPath] } {
275  set blt_libPath [file join $toltk_library blt]
276}
277
278if { ![info exists env(BLT_LIBRARY)] } {
279  set env(BLT_LIBRARY) [file join $toltk_library blt]
280}
281
282if { ![info exists tkTable_libPath] } {
283  set tkTable_libPath [file join $toltk_library Tktable]
284  set env(TK_TABLE_LIBRARY) [file join $toltk_library Tktable]
285}
286
287if { ![info exists byswidget_library] } {
288  set byswidget_library [file normalize [file join $toltk_script_path byswidget]]
289}
290# NOTE: necessary for TkCVS
291if { ![info exists tkcvs_library] } {
292  set tkcvs_library [file normalize [file join $toltk_script_path tkcvs]]
293}
294
295if {[lsearch $auto_path $toltk_library] == -1} {
296  set auto_path [linsert $auto_path end $byswidget_library]
297}
298
299# Load project
300namespace import project::*
301set project::data(iniproject) 1
302set state ""
303set project::data(-project) $toltk_script_path
304foreach option $argv {
305  if { $state eq "" } {
306    switch -- $option {
307      -b {
308        set project::data(oculto) 1
309      }
310      -np {
311        set project::data(iniproject) 0
312      }
313      -project {
314        set state "project"
315      }
316      default {
317        puts "unknown option $option"
318      }
319    }
320  } else {
321    switch $state {
322      project {
323        set project::data(-project) [ file normalize $option ]
324      }
325      default {
326        puts "unknown state $state"
327      }
328    }
329    set state ""
330  }
331}
332
333# Get info about project
334set infoProjects [ loadInfoProjects $project::data(-project) ]
335project::project $infoProjects
336
337# load iniFile
338::iniFile::Create [file join $home_path "tolcon.ini"]
339
340
341# load language files, stored in msgs subdirectory
342set lang [::iniFile::Read TolConsole language es]
343::msgcat::mclocale $lang
344
345# Load Packages
346LoadPackages
347
348Tolcon_Trace "toltk_script_path=$toltk_script_path"
349
350Tolcon_Trace "begin"
351if { [winfo exists .__debugwin] } {
352  wm geometry .__debugwin 1000x170+20+550
353}
354
355::msgcat::mcload [file join $toltk_script_path msgs]
356#option read [file join $::BWIDGET::LIBRARY "lang" "${lang}.rc"] startupFile
357
358# inicializo el kernel de tol con el lenguaje apropiado
359
360::tol::initkernel $lang vA
361
362# Evalute the client TOL code to expose rmtps_client functionality
363#
364::rmtps_client::define_TOLAPI
365
366
367#Cargo word.tcl (version modificada por Bayes)
368AutoLoadWord
369
370Tolcon_Trace "Librerias cargadas"
371
372::tol::language $lang
373Supertext::overrideTextCommand
374# force BWidget autoload
375Bitmap::use
376
377set toltk_images_path [file join ${toltk_script_path} images]
378if { [lsearch $Bitmap::path $toltk_images_path] == -1 } {
379  lappend Bitmap::path [file join $toltk_script_path images]
380}
381
382#Añado las opciones de un text a la ventana de debug
383if { [winfo exists .__debugwin] } {
384  ::BayesText::MenuCreate .__debugwin.sw.t
385}
386
387# cargo los hooks ya que no entran en el mecanismo de tclIndex
388source [file join $toltk_script_path tolmethods.tcl]
389
390catch {
391  project::init
392} msgerr
393Tolcon_Trace "$msgerr : $::errorInfo" "red bold"
394
395# Show Info GCFFile
396::TolConsole::GetGCFFile
397
398Tolcon_Trace "argv0= $::argv0, argc= $::argc, argv= $::argv"
399#puts "argv0= $::argv0, argc= $::argc, argv= $::argv"
400
401set loadandrun 0
402set include 0
403set salir 0
404foreach file $argv {
405  if { [string equal $file "-b"] } { set salir 1 }
406  if { [string equal $file "-r"] } {
407    set loadandrun 1
408    continue
409  }
410  if { [string equal $file "-i"] } {
411    set include 1
412    continue
413  }
414  OpenAssocFile $file $loadandrun $include
415  set loadandrun 0
416  set include 0
417}
418
419if { $salir } { exit }
420
421# Gives a name for the application
422#if {$project::data(name) eq ""} {
423#  set prj ""
424#} else  {
425#  set prj "- $project::data(name)"
426#}
427#wm title . "TOLBase $prj"
428# Show the dialog
429
430#::TolConsole::ODBCShow
Note: See TracBrowser for help on using the repository browser.