source: tol/tolbase/lib/toltk/init_toltk.tcl @ fa8b47d

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

refs #1347,

package require autoscroll 1.1

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

  • Property mode set to 100755
File size: 10.7 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)]} {
76    puts "requested to load Toltcl from $::env(USE_TOLTCL)"
77    load $::env(USE_TOLTCL)
78  } else {
79    package require Toltcl 2.0.2
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 { dir } {
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  # File exists ?
148  set ok 0
149  set dirPrjIni "[file normalize $dir]/../../../"
150  set fileProject [file join $dirPrjIni "project.ini"]
151  if {[file exists $fileProject]} {
152    set ok [ file writable $fileProject ]
153  } else {
154    set fileProject [file join $dir "project.ini"]
155    if {[file exists $fileProject]} {
156      set ok [ file writable $fileProject ] 
157    }
158  }
159  # exists project.ini ?
160  if {$ok} {
161    set id [iniparse:openfile $fileProject]
162    catch { ::iniFile::Create $fileProject }
163    set values {}
164    foreach prj $iniparse($id,sections) {
165      if { $prj eq "Project" } {
166        lappend values Project,title [::iniFile::Read Project title {}]
167        lappend values Project,splash [::iniFile::Read Project splash {}]
168        lappend values Project,names [lrange $iniparse($id,sections) 1 end]
169      } else {
170        set name [::iniFile::Read $prj name ""]
171        set path [::iniFile::Read $prj path ""]
172        if { [string length $path] } {
173          set _path [file join $toltk_library $path]
174          if { [file exists $_path] } {
175            set $path $_path
176          } else {
177            #si la ruta se da relativa y tolbase se ejecuta desde archivo asociado
178            set __path [file join $toltk_script_path $path]
179            if { [file exists $__path] } {
180              set $path $__path
181            }
182          }
183          set pathtcl [file join $path tcl]
184        } else {
185          set path [file join $toltk_library toltk]
186          set pathtcl $path
187        }
188        # check exists file ?
189        if {[string length $name] && [string length $path] &&
190            [file exists [file join $pathtcl ${name}.tcl]]} {
191          lappend values ${prj},name $name
192          lappend values ${prj},path $path
193          lappend values ${prj},path,tcl $pathtcl
194        } else {
195          # erase prj in list of project
196          array set arrtemp $values
197          set lstAux $arrtemp(Project,names)
198          set arrtemp(Project,names) [lreplace $arrtemp(Project,names) \
199            [lsearch -exac $arrtemp(Project,names) $prj] \
200            [lsearch -exac $arrtemp(Project,names) $prj]]
201          set values [array get arrtemp]
202          unset arrtemp
203          # show mwssage
204          if {[string length $name] && [string length $path]} {
205            tk_messageBox -default ok -icon error \
206              -message "The project does not exist: $prj ([file join $pathtcl ${name}.tcl])" \
207              -parent . -title "Error" -type ok
208          }
209        }
210      }
211    }
212    iniparse:closefile $id
213    return $values
214  }
215  return ""
216}
217
218if {[info exist ::env(DEBUG_TOLTCL)] && $::env(DEBUG_TOLTCL) eq "yes"} {
219  set tt_debug "d" 
220} else {
221  set tt_debug "" 
222}
223
224
225set info_script [info script]
226if {[file type $info_script] eq "link"} {
227  set info_script [file readlink $info_script]
228}
229set toltk_script_path [ file normalize [file dirname $info_script] ]
230# load tclIndex
231set dir $toltk_script_path
232source [file join $toltk_script_path "tclIndex"]
233unset dir
234
235set executable_path [ file normalize [file dirname [info nameofexecutable] ] ]
236array set GuiVersionInfo {major 1 minor 1 release 6 comment "cvs trunk"}
237
238# path user
239if { [string equal $tcl_platform(platform) "windows"] } {
240  set home_path $env(USERPROFILE) 
241} else {
242  set home_path $env(HOME) 
243}
244
245if { ![info exists toltk_library] } {
246  set toltk_library [file normalize [file join $toltk_script_path ..]]
247}
248
249if { ![info exists toltk_bin] } {
250  set toltk_bin [file normalize [file join $toltk_library ../bin]]
251}
252
253if {[lsearch $auto_path $toltk_library] == -1} {
254  set auto_path [linsert $auto_path 0 $toltk_library]
255}
256
257if { ![info exists blt_libPath] } {
258  set blt_libPath [file join $toltk_library blt]
259}
260
261if { ![info exists env(BLT_LIBRARY)] } {
262  set env(BLT_LIBRARY) [file join $toltk_library blt]
263}
264
265if { ![info exists tkTable_libPath] } {
266  set tkTable_libPath [file join $toltk_library Tktable]
267  set env(TK_TABLE_LIBRARY) [file join $toltk_library Tktable]
268}
269
270if { ![info exists byswidget_library] } {
271  set byswidget_library [file normalize [file join $toltk_script_path byswidget]]
272}
273# NOTE: necessary for TkCVS
274if { ![info exists tkcvs_library] } {
275  set tkcvs_library [file normalize [file join $toltk_script_path tkcvs]]
276}
277
278if {[lsearch $auto_path $toltk_library] == -1} {
279  set auto_path [linsert $auto_path end $byswidget_library]
280}
281
282# Get info about project
283set infoProjects [loadInfoProjects $toltk_script_path]
284
285# load iniFile
286::iniFile::Create [file join $home_path "tolcon.ini"]
287
288
289# load language files, stored in msgs subdirectory
290set lang [::iniFile::Read TolConsole language es]
291::msgcat::mclocale $lang
292
293# Load Packages
294LoadPackages
295
296Tolcon_Trace "toltk_script_path=$toltk_script_path"
297# Load project
298namespace import project::*
299set project::data(iniproject) 1
300foreach option $argv {
301  if { [string equal $option "-b"] } {
302    set project::data(oculto) 1
303  } elseif { $option eq "-np" } {
304    set project::data(iniproject) 0
305  }
306}
307project::project $infoProjects
308
309
310Tolcon_Trace "begin"
311if { [winfo exists .__debugwin] } {
312  wm geometry .__debugwin 1000x170+20+550
313}
314
315::msgcat::mcload [file join $toltk_script_path msgs]
316#option read [file join $::BWIDGET::LIBRARY "lang" "${lang}.rc"] startupFile
317
318# inicializo el kernel de tol con el lenguaje apropiado
319
320::tol::initkernel $lang vA
321
322# Evalute the client TOL code to expose rmtps_client functionality
323#
324::rmtps_client::define_TOLAPI
325
326
327#Cargo word.tcl (version modificada por Bayes)
328AutoLoadWord
329
330Tolcon_Trace "Librerias cargadas"
331
332::tol::language $lang
333Supertext::overrideTextCommand
334# force BWidget autoload
335Bitmap::use
336
337set toltk_images_path [file join ${toltk_script_path} images]
338if { [lsearch $Bitmap::path $toltk_images_path] == -1 } {
339  lappend Bitmap::path [file join $toltk_script_path images]
340}
341
342#Añado las opciones de un text a la ventana de debug
343if { [winfo exists .__debugwin] } {
344  ::BayesText::MenuCreate .__debugwin.sw.t
345}
346
347# cargo los hooks ya que no entran en el mecanismo de tclIndex
348source [file join $toltk_script_path tolmethods.tcl]
349
350catch {
351  project::init
352} msgerr
353Tolcon_Trace "$msgerr : $::errorInfo" "red bold"
354
355# Show Info GCFFile
356::TolConsole::GetGCFFile
357
358Tolcon_Trace "argv0= $::argv0, argc= $::argc, argv= $::argv"
359#puts "argv0= $::argv0, argc= $::argc, argv= $::argv"
360
361set loadandrun 0
362set include 0
363set salir 0
364foreach file $argv {
365  if { [string equal $file "-b"] } { set salir 1 }
366  if { [string equal $file "-r"] } {
367    set loadandrun 1
368    continue
369  }
370  if { [string equal $file "-i"] } {
371    set include 1
372    continue
373  }
374  OpenAssocFile $file $loadandrun $include
375  set loadandrun 0
376  set include 0
377}
378
379if { $salir } { exit }
380
381# Gives a name for the application
382#if {$project::data(name) eq ""} {
383#  set prj ""
384#} else  {
385#  set prj "- $project::data(name)"
386#}
387#wm title . "TOLBase $prj"
388# Show the dialog
389
390#::TolConsole::ODBCShow
Note: See TracBrowser for help on using the repository browser.