source: tol/tolbase/lib/toltk/sertable.tcl

devel
Last change on this file was e933fd6, checked in by Pedro Gea <pgea@…>, 10 years ago

Refs #1933
Se sustituyen los ::blt::tabset por NoteBook de BWidget. En total se sustituyeron 19 tabsets.
Se suspenden un par de widgets que parece que no se usan, y por tanto tampoco se les ha sustituido ::blt::tabset: bsersel, btab. bchilddetail tampoco parece usarse.
Se corrige un problem en InsertItem de tolinspe.

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

  • Property mode set to 100644
File size: 11.8 KB
Line 
1#/////////////////////////////////////////////////////////////////////////////
2# FILE    : sertable.tcl
3# PURPOSE : This file contains a namespace called SeriesTable with its
4#           functions. It's for managing series tables.
5#           It's a child of BayesTable so inherites all its functionalities.
6#/////////////////////////////////////////////////////////////////////////////
7
8
9#/////////////////////////////////////////////////////////////////////////////
10  namespace eval ::SeriesTable {
11#
12# PURPOSE: The purpose of this namespace is organize code and functions and
13#          provides functions to create and manage a series table.
14#          A special namespace is created for each instance of Series table.
15#
16# VARIABLES:
17#   tmpOpt  -> temporary array used to store the widgets and variables of the
18#              options dialog.
19#   formats ->
20#
21#/////////////////////////////////////////////////////////////////////////////
22}
23
24
25#/////////////////////////////////////////////////////////////////////////////
26  proc ::SeriesTable::Create {path sergrp} {
27#
28# PURPOSE: Creates a series table instance
29#
30# PARAMETERS:
31#   path   -> series table path (frame)
32#   sergrp -> tol series group to be tabulated
33#
34#/////////////////////////////////////////////////////////////////////////////
35  set this [::BayesTable::Create $path \
36      -fillproc "::SeriesTable::Fill $sergrp" -child SeriesTable\
37      -OnWriteIni "::SeriesTable::WriteIni" \
38      -OnOptionCreate "::SeriesTable::OptionsCreate" \
39      -OnOptionDestroy "::SeriesTable::OptionsDestroy" \
40      -OnOptionApply "::SeriesTable::OptionsApply"]
41  ::BayesTable::SetData $this sergrp $sergrp
42  ReadIni   $this
43  Configure $this
44}
45
46#/////////////////////////////////////////////////////////////////////////////
47  proc ::SeriesTable::Fill {sergrp this} {
48#
49# PURPOSE: Procedure to fill data elements of the table. Gets data from a
50#          group of series and sets them to the table.
51#
52# PARAMETERS:
53#   sergrp -> tol series group (created by toltcl ::tol::create command)
54#   this   -> Instance of BayesTable
55#
56#/////////////////////////////////////////////////////////////////////////////
57  # insert the series into the table
58  set numCols [$sergrp serie size]
59  set numRows [$sergrp dating size]
60  ::BayesTable::SetElement $this 0 0 [$sergrp dating name]
61  for {set i 0} {$i < $numRows} {incr i} {
62    ::BayesTable::SetElement $this [expr $i+1] 0 [GetTickLabel $sergrp $i]
63  }
64  for {set j 0} {$j < $numCols} {incr j} {
65    ::BayesTable::SetElement $this 0 [expr $j+1] [$sergrp serie $j name]
66    foreach vec_data [$sergrp serie $j data] {
67      set x [lindex $vec_data 0]
68      set y [lindex $vec_data 1]
69      for {set i 0} {$i < [llength $x]} {incr i} {
70        ::BayesTable::SetElement $this [expr round([lindex $x $i])+1]\
71                   [expr $j+1] [lindex $y $i]
72      }
73    }
74  }
75  ::BayesTable::SetMatrixInfo $this\
76                [list [expr $numRows+1] [expr $numCols+1]] ""
77}
78
79#/////////////////////////////////////////////////////////////////////////////
80  proc ::SeriesTable::GetTickLabel { group tick } {
81#
82# PURPOSE:
83#
84# PARAMETERS:
85#   group ->
86#   tick  ->
87#
88#/////////////////////////////////////////////////////////////////////////////
89  set str ""
90  catch {
91    set str [$group dating $tick]
92  }
93  return $str
94}
95
96
97#/////////////////////////////////////////////////////////////////////////////
98# OPTIONS
99#/////////////////////////////////////////////////////////////////////////////
100
101#/////////////////////////////////////////////////////////////////////////////
102  proc ::SeriesTable::OptionsDestroy {this} {
103#
104# PURPOSE: Called before options dialog is destroyed. This procedure is called
105#          by parent BayesTable. Actually doesn't do anything.
106#
107# PARAMETERS:
108#   this -> Instance of BayesTable
109#
110#/////////////////////////////////////////////////////////////////////////////
111
112}
113
114#/////////////////////////////////////////////////////////////////////////////
115  proc ::SeriesTable::OptionsCreate {this ts} {
116#
117# PURPOSE: Creates especific options of a series table. It's called by
118#          BayesTable when general table options are created.
119#
120# PARAMETERS:
121#   this -> Instance of BayesTable
122#   ts   -> tabset (=>NoteBook) in which options must be created
123#
124#/////////////////////////////////////////////////////////////////////////////
125  #insertar tabset   
126  set num_i 1
127  set lab_i Series
128  $ts insert $num_i $lab_i -text "  [mc $lab_i]  " -background \#d9d9d9
129  set tab_i [$ts getframe $lab_i]
130  $tab_i configure -borderwidth 2 -background \#d9d9d9 
131  set f [frame $tab_i.f]
132  pack $tab_i.f -fill both -expand yes
133   
134  set w_tabset [NoteBook $f.nb -tabbevelsize 8 -tabpady {2 6} -font {Arial 8}]
135  set num_i 0
136  set lab_i "Date Format"
137  $w_tabset insert $num_i $lab_i -text "  [mc $lab_i]  " -background \#d9d9d9
138  set tab_i [$w_tabset getframe $lab_i]
139  $tab_i configure -borderwidth 2 -background \#d9d9d9
140  set f1 [frame $tab_i.f]
141  pack $tab_i.f -fill both -expand yes 
142  $w_tabset raise [$w_tabset pages 0]   
143
144  OptionsGet $this
145  OptionsCreateDateFormat $this $f1
146  OptionsCheck $this
147  OptionsSet   $this
148
149  $w_tabset compute_size
150  grid $w_tabset -sticky news 
151  grid rowconfigure    $f 0 -weight 1
152  grid columnconfigure $f 0 -weight 1
153}
154
155
156#/////////////////////////////////////////////////////////////////////////////
157  proc ::SeriesTable::OptionsCreateDateFormat {this w} {
158#
159# PURPOSE: Creates a frame with date format options
160#
161# PARAMETERS:
162#   this -> Instance of BayesTable
163#   w    -> widget's path to allocate the frame
164#
165#/////////////////////////////////////////////////////////////////////////////
166  variable tmpOpt
167  variable formats
168
169  # X-Axis
170  TitleFrame $w.tf1 -text [mc "Format String"]
171  set f1 [$w.tf1 getframe]
172
173  set formats [list \
174     [mc "TOL Long Format"]   "%cy%Ym%md%d%uh%hi%is%s" \
175     [mc "TOL Short Format"]  "%cy%Ym%md%d" \
176     "Completo YYYY/MM/dd"    "%c%w %Y/%m/%d" \
177     "Completo dd/MM/YYYY"    "%c%w %d/%m/%Y" \
178     "Fecha larga"            "%c%W, %d de %N de %Y" \
179     "Completo dd/Month/YYYY" "%c%w %d/%n/%Y" \
180     [mc "User Defined"]]
181  foreach {cad for} $formats {
182    lappend lstCad $cad
183  }
184
185  label $f1.lFormat -text [mc Format]:
186  ComboBox $f1.cbFormat -width 30 -height 6 -editable false -values $lstCad\
187      -textvariable ::SeriesTable::tmpOpt(var,dateFormat)\
188      -modifycmd [list ::SeriesTable::OptionsCheckDateFormat $this]
189  label $f1.lString -text [mc String]:
190  set tmpOpt(widgets,dateString) [Entry $f1.eString -width 45 -state disabled\
191         -textvariable ::SeriesTable::tmpOpt(var,dateString)]
192  bind $f1.eString <KeyRelease> [list ::SeriesTable::OptionsCheckDateString $this]
193  label $f1.lView   -text [mc Sample]:
194  set tmpOpt(widgets,dateView) [Entry $f1.eView   -width 45 -state disabled\
195         -textvariable ::SeriesTable::tmpOpt(var,dateView)]
196  button $f1.bHelp  -text [mc "Format Specifiers"]\
197     -command [list ::SeriesGraph::ShowSpecifiers $w]
198  frame $f1.f -width 25
199  grid $f1.f $f1.lFormat $f1.cbFormat -sticky nw -padx 2 -pady 2
200  grid ^     $f1.lString $f1.eString  -sticky nw -padx 2 -pady 2
201  grid ^     $f1.lView   $f1.eView    -sticky nw -padx 2 -pady 2
202  grid ^     $f1.bHelp   -            -column 1    -sticky nw -pady 2
203  grid rowconfigure    $f1 3 -weight 1
204  grid columnconfigure $f1 2 -weight 1
205  grid $w.tf1 -sticky news -padx 2
206  grid rowconfigure    $w 0 -weight 1
207  grid columnconfigure $w 0 -weight 1
208}
209
210
211#/////////////////////////////////////////////////////////////////////////////
212  proc ::SeriesTable::OptionsGet {this} {
213#
214# PURPOSE: Initializes all options variables and stores them into the
215#          temporary 'tmpOpt' array.
216#
217# PARAMETERS:
218#   this   -> Instance of BayesTable
219#
220#/////////////////////////////////////////////////////////////////////////////
221  variable tmpOpt
222
223  set tmpOpt(var,dateString)   [::BayesTable::GetOption $this dateString]
224}
225
226
227#/////////////////////////////////////////////////////////////////////////////
228  proc ::SeriesTable::OptionsSet {this} {
229#
230# PURPOSE: Commits all options values from the temporary 'tmpOpt' array to
231#          other structure.
232#
233# PARAMETERS:
234#   this   -> Instance of BayesTable
235#
236#/////////////////////////////////////////////////////////////////////////////
237  variable tmpOpt
238
239  regsub -all var, [array names ::SeriesTable::tmpOpt var,*] "" optNames
240  foreach it $optNames {
241    ::BayesTable::SetOption $this dateString $tmpOpt(var,$it)
242  }
243}
244
245
246#/////////////////////////////////////////////////////////////////////////////
247  proc ::SeriesTable::OptionsApply {this} {
248#
249# PURPOSE: Applies options from the options dialog. It's called by BayesTable
250#          when general table options are applied.
251#
252# PARAMETERS:
253#   this  -> Instance of BayesTable
254#
255#/////////////////////////////////////////////////////////////////////////////
256  variable tmpOpt
257  OptionsApplyDateFormat $this $tmpOpt(var,dateString)
258  #Save options after apply
259  OptionsSet $this
260}
261
262
263proc ::SeriesTable::OptionsApplyDateFormat {this dateString} {
264  set sergrp [::BayesTable::GetData $this sergrp]
265  $sergrp format $dateString
266  ::SeriesTable::Fill $sergrp $this
267}
268
269
270proc ::SeriesTable::OptionsCheck {this} {
271  OptionsCheckDateString $this
272  #OptionsCheckDateFormat $this
273}
274
275proc ::SeriesTable::OptionsCheckDateFormat {this} {
276  variable tmpOpt
277  variable formats
278
279  if [string equal $tmpOpt(var,dateFormat) [mc "User Defined"]] {
280    $tmpOpt(widgets,dateString) configure -state normal
281    #set tmpOpt(var,dateString) ""
282  } else  {
283    $tmpOpt(widgets,dateString) configure -state disabled
284    set idx [lsearch -exact $formats $tmpOpt(var,dateFormat)]
285    set tmpOpt(var,dateString) [lindex $formats [expr $idx+1]]
286    #Coger la fecha del sistema, aplicarle el formato y mostrarla
287    set tmpOpt(var,dateView) [::tol::date now $tmpOpt(var,dateString)]
288  }
289}
290
291proc ::SeriesTable::OptionsCheckDateString {this} {
292  variable tmpOpt
293  variable formats
294
295  if {[set idx [lsearch -exact $formats $tmpOpt(var,dateString)]] != -1} {
296    set tmpOpt(var,dateFormat) [lindex $formats [expr $idx-1]]
297  } else  {
298    set tmpOpt(var,dateFormat) [lindex $formats end]
299    $tmpOpt(widgets,dateString) configure -state normal
300  }
301  set tmpOpt(var,dateView) [::tol::date now $tmpOpt(var,dateString)]
302}
303
304
305#/////////////////////////////////////////////////////////////////////////////
306# INIFILE
307#/////////////////////////////////////////////////////////////////////////////
308
309#/////////////////////////////////////////////////////////////////////////////
310  proc ::SeriesTable::ReadIni {this} {
311#
312# PURPOSE: Reads series table specific options from .ini file. First of all,
313#          reads options from BayesTable.
314#
315# PARAMETERS:
316#   this  -> Instance of BayesTable
317#
318#/////////////////////////////////////////////////////////////////////////////
319  # General options (parent)
320  ::BayesTable::ReadIni $this
321  # Specific options
322  set rini ::iniFile::Read
323  set sergrp [::BayesTable::GetData $this sergrp]
324  ::BayesTable::SetOption $this dateString \
325     [$rini SeriesTable dateString [$sergrp format]]
326}
327
328
329#/////////////////////////////////////////////////////////////////////////////
330  proc ::SeriesTable::WriteIni {this} {
331#
332# PURPOSE: Writes series table specific options to .ini file. This procedure
333#          is called by parent BayesTable.
334#
335# PARAMETERS:
336#   this  -> Instance of BayesTable
337#
338#/////////////////////////////////////////////////////////////////////////////
339  set wini ::iniFile::Write
340  $wini SeriesTable dateString  [::BayesTable::GetOption $this dateString]
341}
342
343
344#/////////////////////////////////////////////////////////////////////////////
345  proc ::SeriesTable::Configure {this} {
346#
347# PURPOSE: Configures some options of Series Table. First of all, configures
348#          options from BayesTable.
349#
350# PARAMETERS:
351#   this  -> Instance of BayesTable
352#
353#/////////////////////////////////////////////////////////////////////////////
354  # General options (parent)
355  ::BayesTable::Configure $this
356  # Specific options
357  OptionsApplyDateFormat $this [::BayesTable::GetOption $this dateString]
358}
Note: See TracBrowser for help on using the repository browser.