source: tol/tolbase/lib/toltk/init_toltk.tcl @ 817b775

1941-docker-image-to-testdevel
Last change on this file since 817b775 was df1ac43, checked in by Jorge Pérez <josp.jorge@…>, 18 years ago

set trace 0

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

  • Property mode set to 100755
File size: 10.3 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
56#/////////////////////////////////////////////////////////////////////////////
57  proc LoadPackages {} {
58#
59# PURPOSE: Load packages
60#
61#/////////////////////////////////////////////////////////////////////////////
62  package require snit
63  package require BWidget
64  package require msgcat
65  namespace import msgcat::*
66  package require Tktable
67  package require -exact BLT 2.4
68  package require tclodbc
69  if {[info exist ::env(USE_TOLTCL)]} {
70    puts "requested to load Toltcl from $::env(USE_TOLTCL)"
71    load $::env(USE_TOLTCL)
72  } else {
73    package require -exact Toltcl 1.1.7
74  }
75  package require rmtps_client
76  package require byswidget
77  package require mkWidgets 1.3
78  #NOTE. Por precaución cargamos el paquete aqui
79  #En un futuro cambiar
80  package require bfunctions
81}
82
83#/////////////////////////////////////////////////////////////////////////////
84 proc OpenAssocFile {file {run 0} {inc 0}} {
85#/////////////////////////////////////////////////////////////////////////////
86  switch [string toupper [file extension $file]] {
87    ".SQL" {
88      #::Editor::Open $file
89    }
90    ".PRJ" {
91      if { $inc } {
92        ::tol::console eval "Set IncludePRJ(Text \"$file\")"
93      } else {
94        ::TolProject::Open $file $run
95      }
96    }
97    ".BDT" {
98      if { $inc } {
99        ::tol::console eval "Set IncludeBDT(Text \"$file\")"
100      } else {
101        ::EditTable::Open $file
102      }
103    }
104    ".BST" {
105      if { $inc } {
106        ::tol::console eval "Set IncludeBST(Text \"$file\")"
107      } else {
108        ::EditTable::Open $file
109      }
110    }
111    ".BMT" {
112      if { $inc } {
113        ::tol::console eval "Set IncludeBMT(Text \"$file\")"
114      } else {
115        ::EditTable::Open $file
116      }
117    }
118    ".TOL" {
119      if { $inc } {
120        ::tol::console eval "Set IncludeTOL(Text \"$file\")"
121      } else {
122        ::Editor::Open $file $run
123      }
124    }
125  }
126}
127
128
129#/////////////////////////////////////////////////////////////////////////////
130  proc loadInfoProjects { dir } {
131#
132# PURPOSE: Loads in a list the name and paths of each project to load
133#
134# RETURN: the list with the data
135#
136#/////////////////////////////////////////////////////////////////////////////
137  global iniparse
138  global toltk_library
139  global toltk_script_path
140 
141  # File exists ?
142  set ok 0
143  set dirPrjIni "[file normalize $dir]/../../../"
144  set fileProject [file join $dirPrjIni "project.ini"]
145  if {[file exists $fileProject]} {
146    set ok 1
147  } else {
148    set fileProject [file join $dir "project.ini"]
149    if {[file exists $fileProject]} {
150      set ok 1 
151    }
152  }
153  # exists project.ini ?
154  if {$ok} {
155    set id [iniparse:openfile $fileProject]
156    ::iniFile::Create $fileProject
157    set values {}
158    foreach prj $iniparse($id,sections) {
159      if { $prj eq "Project" } {
160        lappend values Project,title [::iniFile::Read Project title {}]
161        lappend values Project,splash [::iniFile::Read Project splash {}]
162        lappend values Project,names [lrange $iniparse($id,sections) 1 end]
163      } else {
164        set name [::iniFile::Read $prj name ""]
165        set path [::iniFile::Read $prj path ""]
166        if { [string length $path] } {
167          set _path [file join $toltk_library $path]
168          if { [file exists $_path] } {
169            set $path $_path
170          } else {
171            #si la ruta se da relativa y tolbase se ejecuta desde archivo asociado
172            set __path [file join $toltk_script_path $path]
173            if { [file exists $__path] } {
174              set $path $__path
175            }
176          }
177          set pathtcl [file join $path tcl]
178        } else {
179          set path [file join $toltk_library toltk]
180          set pathtcl $path
181        }
182        # check exists file ?
183        if {[string length $name] && [string length $path] &&
184            [file exists [file join $pathtcl ${name}.tcl]]} {
185          lappend values ${prj},name $name
186          lappend values ${prj},path $path
187          lappend values ${prj},path,tcl $pathtcl
188        } else {
189          # erase prj in list of project
190          array set arrtemp $values
191          set lstAux $arrtemp(Project,names)
192          set arrtemp(Project,names) [lreplace $arrtemp(Project,names) \
193            [lsearch -exac $arrtemp(Project,names) $prj] \
194            [lsearch -exac $arrtemp(Project,names) $prj]]
195          set values [array get arrtemp]
196          unset arrtemp
197          # show mwssage
198          if {[string length $name] && [string length $path]} {
199            tk_messageBox -default ok -icon error \
200              -message "The project does not exist: $prj ([file join $pathtcl ${name}.tcl])" \
201              -parent . -title "Error" -type ok
202          }
203        }
204      }
205    }
206    iniparse:closefile $id
207    return $values
208  }
209  return ""
210}
211
212if {[info exist ::env(DEBUG_TOLTCL)] && $::env(DEBUG_TOLTCL) eq "yes"} {
213  set tt_debug "d" 
214} else {
215  set tt_debug "" 
216}
217
218
219set info_script [info script]
220if {[file type $info_script] eq "link"} {
221  set info_script [file readlink $info_script]
222}
223set toltk_script_path [file dirname $info_script]
224# load tclIndex
225set dir $toltk_script_path
226source [file join $toltk_script_path "tclIndex"]
227unset dir
228
229set executable_path [file dirname [info nameofexecutable]]
230array set GuiVersionInfo {major 1 minor 1 release 6 comment "cvs trunk"}
231
232# path user
233if { [string equal $tcl_platform(platform) "windows"] } {
234  set home_path $env(USERPROFILE) 
235} else {
236  set home_path $env(HOME) 
237}
238
239if { ![info exists toltk_library] } {
240  set toltk_library [file normalize [file join $toltk_script_path ..]]
241}
242
243if { ![info exists toltk_bin] } {
244  set toltk_bin [file normalize [file join $toltk_library ../bin]]
245}
246
247if {[lsearch $auto_path $toltk_library] == -1} {
248  set auto_path [linsert $auto_path 0 $toltk_library]
249}
250
251if { ![info exists blt_libPath] } {
252  set blt_libPath [file join $toltk_library blt]
253}
254
255if { ![info exists env(BLT_LIBRARY)] } {
256  set env(BLT_LIBRARY) [file join $toltk_library blt]
257}
258
259if { ![info exists tkTable_libPath] } {
260  set tkTable_libPath [file join $toltk_library Tktable]
261  set env(TK_TABLE_LIBRARY) [file join $toltk_library Tktable]
262}
263
264if { ![info exists byswidget_library] } {
265  set byswidget_library [file normalize [file join $toltk_script_path byswidget]]
266}
267# NOTE: necessary for TkCVS
268if { ![info exists tkcvs_library] } {
269  set tkcvs_library [file normalize [file join $toltk_script_path tkcvs]]
270}
271
272if {[lsearch $auto_path $toltk_library] == -1} {
273  set auto_path [linsert $auto_path end $byswidget_library]
274}
275
276# Get info about project
277set infoProjects [loadInfoProjects $toltk_script_path]
278
279# load iniFile
280::iniFile::Create [file join $home_path "tolcon.ini"]
281
282
283# load language files, stored in msgs subdirectory
284set lang [::iniFile::Read TolConsole language es]
285::msgcat::mclocale $lang
286
287# Load Packages
288LoadPackages
289
290Tolcon_Trace "toltk_script_path=$toltk_script_path"
291# Load project
292namespace import project::*
293foreach option $argv {
294  if { [string equal $option "-b"] } {
295    set project::data(oculto) 1
296  }
297}
298project::project $infoProjects
299
300
301Tolcon_Trace "begin"
302if { [winfo exists .__debugwin] } {
303  wm geometry .__debugwin 1000x170+20+550
304}
305
306::msgcat::mcload [file join $toltk_script_path msgs]
307#option read [file join $::BWIDGET::LIBRARY "lang" "${lang}.rc"] startupFile
308
309# inicializo el kernel de tol con el lenguaje apropiado
310
311::tol::initkernel $lang vA
312
313# Evalute the client TOL code to expose rmtps_client functionality
314#
315::rmtps_client::define_TOLAPI
316
317
318#Cargo word.tcl (version modificada por Bayes)
319AutoLoadWord
320
321Tolcon_Trace "Librerias cargadas"
322
323::tol::language $lang
324Supertext::overrideTextCommand
325# force BWidget autoload
326Bitmap::use
327
328set toltk_images_path [file join ${toltk_script_path} images]
329if { [lsearch $Bitmap::path $toltk_images_path] == -1 } {
330  lappend Bitmap::path [file join $toltk_script_path images]
331}
332
333#Añado las opciones de un text a la ventana de debug
334if { [winfo exists .__debugwin] } {
335  ::BayesText::MenuCreate .__debugwin.sw.t
336}
337
338# cargo los hooks ya que no entran en el mecanismo de tclIndex
339source [file join $toltk_script_path tolmethods.tcl]
340
341catch {
342  project::init
343} msgerr
344Tolcon_Trace "$msgerr : $::errorInfo" "red bold"
345
346# Show Info GCFFile
347::TolConsole::GetGCFFile
348
349Tolcon_Trace "argv0= $::argv0, argc= $::argc, argv= $::argv"
350#puts "argv0= $::argv0, argc= $::argc, argv= $::argv"
351
352set loadandrun 0
353set include 0
354set salir 0
355foreach file $argv {
356  if { [string equal $file "-b"] } { set salir 1 }
357  if { [string equal $file "-r"] } {
358    set loadandrun 1
359    continue
360  }
361  if { [string equal $file "-i"] } {
362    set include 1
363    continue
364  }
365  OpenAssocFile $file $loadandrun $include
366  set loadandrun 0
367  set include 0
368}
369
370if { $salir } { exit }
371
372# Gives a name for the application
373#if {$project::data(name) eq ""} {
374#  set prj ""
375#} else  {
376#  set prj "- $project::data(name)"
377#}
378#wm title . "TOLBase $prj"
379# Show the dialog
380
381#::TolConsole::ODBCShow
Note: See TracBrowser for help on using the repository browser.