source: trunk/SRC/ToBeReviewed/WIDGET/xxx.pro @ 157

Last change on this file since 157 was 157, checked in by navarro, 18 years ago

header improvements + xxx doc

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 21.0 KB
Line 
1;+
2; @file_comments
3;
4;
5; @categories
6;
7;
8; @param EVENT
9;
10;
11; @returns
12;
13;
14; @uses
15;
16;
17; @restrictions
18;
19;
20; @examples
21;
22;
23; @history
24;
25;
26; @version
27; $Id$
28;-
29PRO xxx_event, event
30;------------------------------------------------------------
31;
32  compile_opt idl2, strictarrsubs
33;
34@common
35;------------------------------------------------------------
36;    = widget_info(event.top,find_by_uname = '')
37; What is the type of evenment ?
38;   if event.id EQ 622 then help,  event,  /struct
39   widget_control, event.id, get_uvalue=uval
40   if (tag_names(event, /structure_name))[0] EQ 'WIDGET_TRACKING' then uval = {name:'ActiverFenetre'}
41   if keyword_set(uval) EQ 0 then return
42;help,  event, /struct
43;help, uval , /struct
44; case on the type of evenment
45   widget_control, event.top, get_uvalue = top_uvalue
46; If we activate the keyword separate at the call of xxx
47   if size(top_uvalue, /type) EQ 3 then begin
48      event.top = top_uvalue
49      widget_control, event.top, get_uvalue = top_uvalue
50   endif
51; we delete the small widget created by notice.pro if it exists
52   noticebase = extractatt(top_uvalue, 'noticebase')
53   if noticebase NE 0 then BEGIN
54      widget_control, noticebase, /destroy
55      *top_uvalue[1, findline(top_uvalue, 'noticebase')] = 0l
56   endif
57;
58   options = extractatt(top_uvalue, 'options')
59   case uval.name OF
60      'menubar':xxxmenubar_event, event
61      'ok':nouveaudessin = 1
62      'specifie':
63      'action':
64      'calendar1':BEGIN
65         date2id = widget_info(event.top, find_by_uname = 'calendar2')
66         widget_control, date2id, get_value = date2
67         if event.value GT date2 then widget_control, date2id, set_value = event.value
68      END
69      'calendar2':BEGIN
70         date1id = widget_info(event.top, find_by_uname = 'calendar1')
71         widget_control, date1id, get_value = date1
72         if event.value LT date1 then widget_control, date1id, set_value = event.value
73      END
74      'domain':
75      'varlist':BEGIN
76         currentfile  = extractatt(top_uvalue, 'currentfile')
77         listvar = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listvar
78         name = listvar[event.index]
79         changefield, event.top, name
80      END
81      'txtcmd':
82      'filelist':BEGIN
83         changefile, event.top, event.index
84      END
85      'ActiverFenetre':BEGIN
86         if event.enter EQ 1 AND !d.name NE 'PS' then BEGIN
87;            graphid = widget_info(event.top,find_by_uname = 'graph')
88            graphid = extractatt(top_uvalue, 'graphid')
89            widget_control,graphid,get_value=win
90            wset, win
91            widget_control,event.top,get_uvalue=top_uvalue
92            numdessinin = (extractatt(top_uvalue, 'smallin'))[2]-1
93            !p = (extractatt(top_uvalue, 'penvs'))[numdessinin]
94            !x = (extractatt(top_uvalue, 'xenvs'))[numdessinin]
95            !y = (extractatt(top_uvalue, 'yenvs'))[numdessinin]
96         endif
97      END
98      'graph':BEGIN
99         quelclick = identifyclick(event)
100         case quelclick.type of
101            'inutile':return
102            'long':longclickaction, event
103            'single':singleclickaction, event
104            'double':doubleclickaction, event
105         endcase
106      END
107   endcase
108   if keyword_set(nouveaudessin) then letsdraw, event.top
109   return
110end
111;------------------------------------------------------------
112;------------------------------------------------------------
113;------------------------------------------------------------
114;------------------------------------------------------------
115;------------------------------------------------------------
116;------------------------------------------------------------
117;+
118;
119; @file_comments
120; A maximum of possibilities with a minimum of clics
121;
122; @categories
123; Widget
124;
125; @param DATAFILENAME
126;
127;
128; @param IDLFILE
129;
130;
131; @param ARGSPRO
132;
133;
134; @keyword SEPARATE
135; To separate the button part and the drawing part in 2 windows.
136; Useful for small screens, but be careful to do not saturate the
137; video memory of some antiquated Tx.
138;
139; @keyword RESTORE
140; 'toto.dat' or toto.dat is a file created at the time of a precedent
141; use of xxx thanks to the command "Widget" of the menu "save as".
142;
143; @keyword _EXTRA
144; Used to pass your keywords
145;
146; @uses
147; common.pro
148;
149; @history
150; Sebastien Masson (smasson\@lodyc.jussieu.fr)
151;
152; @version
153; $Id$
154;
155; @todo
156; seb: documenter le reste des keywords
157;
158;-
159;------------------------------------------------------------
160;------------------------------------------------------------
161;------------------------------------------------------------
162;------------------------------------------------------------
163;------------------------------------------------------------
164;------------------------------------------------------------
165PRO xxx, datafilename, idlfile, argspro, CALLERWIDID = CallerWidId $
166         , REDRAW = redraw, SEPARATE = separate, UVALUE = uvalue $
167         , RESTORE = restore, _EXTRA = ex
168;------------------------------------------------------------
169;
170  compile_opt idl2, strictarrsubs
171;
172@all_cm
173;------------------------------------------------------------
174; reinitialize the !p, !x, !y, !z variables
175;------------------------------------------------------------
176  reinitplt
177;------------------------------------------------------------
178; we get back the uvalue of the widget that called xxx to create a new widget
179  if keyword_set(restore) then BEGIN
180    restore = isafile(filename = restore, iodir = homedir, _extra = ex)
181    if size(restore, /type) NE 7 then restore = 0 ELSE BEGIN
182      restore, isafile(file = restore, iodir = homedir, _extra = ex)
183      newgrid = *(extractatt(uvalue, 'meshparameters'))[0]
184      change = changegrid(newgrid)
185    ENDELSE
186  endif
187  if n_elements(CallerWidId) NE 0 THEN $
188     widget_control, CallerWidId, get_uvalue = uvalue ELSE CallerWidId = 0
189;------------------------------------------------------------
190;------------------------------------------------------------
191; list of files we want to look at
192;
193  if keyword_set(uvalue) then BEGIN
194    currentfile = extractatt(uvalue, 'currentfile')
195    filelist = extractatt(uvalue, 'filelist')
196    fileparameters = extractatt(uvalue, 'fileparameters')
197    readparameters = extractatt(uvalue, 'readparameters')
198    meshparameters = extractatt(uvalue, 'meshparameters')
199  ENDIF ELSE BEGIN
200    newfile = selectfile(datafilename, idlfile, argspro, _extra = ex)
201    if size(newfile, /type) NE 8 then return
202    fileparameters = ptrarr(1, /allocate_heap)
203    *fileparameters[0] = newfile.fileparameters
204    readparameters = ptrarr(1, /allocate_heap)
205    *readparameters[0] = newfile.readparameters
206    meshparameters = ptrarr(1, /allocate_heap)
207    *meshparameters[0] = newfile.meshparameters
208    currentfile = 0
209    filelist = newfile.fileparameters.filename
210  ENDELSE
211;
212  if keyword_set(uvalue) THEN BEGIN
213    smallin = extractatt(uvalue, 'smallin')
214    smallout = extractatt(uvalue, 'smallout')
215  ENDIF ELSE BEGIN
216    smallin = [1, 1, 1]
217    smallout = [1, 1, 1]
218  ENDELSE
219  nbredessin = smallin[0]*smallin[1]
220  numdessinin = smallin[2]-1
221; warning flg definition must be consistent with cw_pdmenu argument
222; see also flag definition in cw_pagelayout
223  if keyword_set(uvalue) then BEGIN
224    flag = extractatt(uvalue, 'optionsflag')
225    key_portrait = flag[0, numdessinin]
226  ENDIF ELSE flag = [key_portrait, 0, 0, 0, 0]#replicate(1, nbredessin)
227
228;------------------------------------------------------------
229;------------------------------------------------------------
230; We start the widget definition
231;------------------------------------------------------------
232;------------------------------------------------------------
233;
234; widget and screen size
235  scrsize = get_screen_size()*0.95
236  windsize = givewindowsize()
237  xxxsize = [windsize[0] * (1-keyword_set(separate)) + 350, windsize[1]]
238;
239;------------------------------------------------------------
240; The top base
241;------------------------------------------------------------
242  IF xxxsize[0] LE scrsize[0] AND xxxsize[1] LE scrsize[1] THEN BEGIN
243    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
244                       , uname = 'base', space = 0)
245  ENDIF ELSE BEGIN
246    base = widget_base(title = 'xxx', GROUP_LEADER = group, /tracking_events $
247                       , uname = 'base', space = 0 $
248                       , xsize = xxxsize[0], ysize = xxxsize[1] $
249                       , x_scroll_size = (xxxsize[0] < scrsize[0]) $
250                       , y_scroll_size = (xxxsize[1] < scrsize[1]))
251  ENDELSE
252
253;------------------------------------------------------------
254; combobox for plots choice
255;------------------------------------------------------------
256  xoff = 0
257  yoff = 0
258  pltlst = ['plt', 'pltv' $
259            , 'pltz', 'pltz diag up', 'pltz diag dn' $
260            , 'pltt', 'pltt diag up', 'pltt diag dn' $
261            , 'xy', 'xz', 'yz', 'xt', 'yt', 'zt' $
262            , 'x', 'y', 'z', 't']
263  actid = widget_combobox(base, value = pltlst, uname = 'action', uvalue = {name:'action'} $
264                            , xoffset = xoff+5, yoffset = yoff+4, xsize = 90)
265  if keyword_set(uvalue) then BEGIN
266    selectact = (extractatt(uvalue, 'types'))[numdessinin]
267    selectact = (where(pltlst EQ selectact))[0]
268    widget_control, actid, set_combobox_select = 0 > selectact
269  ENDIF ELSE selectfile = 0
270
271;------------------------------------------------------------
272; menu/options
273;------------------------------------------------------------
274  xoff = xoff + 110
275  if keyword_set(uvalue) then begin
276    options = extractatt(uvalue, 'options')
277  ENDIF ELSE options = ['Portrait/Landscape', 'Overlay', 'Vecteur' $
278                        , 'Longitude / x index', 'Latitude / y index']
279
280   desc = [ '1\File', $
281            '0\Open' , $
282            '0\New xxx' , $
283            '2\Quit', $
284            '1\Save as' , $
285            '0\PostScript' , $
286            '0\Animated gif' , $
287            '0\Gif' , $
288            '0\IDL procedure', $
289            '0\RESTORE kwd of xxx', $
290            '2\Print to prompt', $
291            '1\Flag options']
292   descsuite = options
293   if n_elements(descsuite) GE 2 then $
294    descsuite[0:n_elements(descsuite)-2] = '0\'+descsuite[0:n_elements(descsuite)-2]
295   descsuite[n_elements(descsuite)-1] = '2\'+descsuite[n_elements(descsuite)-1]
296   desc = [desc, descsuite]
297;
298   menu = cw_pdmenu(base, desc, /RETURN_NAME, uname = 'menubar', uvalue = {name:'menubar'} $
299                    , xoffset = xoff, yoffset = yoff)
300
301;------------------------------------------------------------
302; Ok button
303;------------------------------------------------------------
304  yoff = yoff + 37
305  xoff = 5
306; boutton 'OK'
307  baseok = widget_button(base, value = ' OK ', uvalue = {name:'ok'}, uname = 'ok button' $
308                         , /frame, xoffset = xoff, yoffset = yoff)
309
310;------------------------------------------------------------
311; Page Layout
312;------------------------------------------------------------
313; page layout
314  xoff = xoff + 65
315  dummyid = cw_pagelayout(base, smallin, /row, /frame, xoffset = xoff, yoffset = yoff)
316;
317;------------------------------------------------------------
318; List of Variables
319;------------------------------------------------------------
320  xoff = xoff + 140
321  currentlistvar = (*fileparameters[currentfile]).listvar
322  vlstid = widget_combobox(base, value = currentlistvar, uvalue = {name:'varlist'} $
323                           , uname = 'varlist', xoffset = xoff, yoffset = yoff+1)
324  if keyword_set(uvalue) then BEGIN
325    selectvar = (extractatt(uvalue, 'varinfo'))[1, numdessinin]
326    selectvar = (where(currentlistvar EQ selectvar))[0]
327    widget_control, vlstid, set_combobox_select = 0 > selectvar
328  ENDIF ELSE selectvar = 0
329;------------------------------------------------------------
330; List of files
331;------------------------------------------------------------
332  yoff = yoff + 35
333  flstid = widget_combobox(base, value = file_basename(filelist), uname = 'filelist' $
334                           , xsize = 345, yoffset = yoff, uvalue = {name:'filelist'})
335  if keyword_set(uvalue) then BEGIN
336    selectfile = (extractatt(uvalue, 'varinfo'))[0, numdessinin]
337    selectfile = (where(file_basename(filelist) EQ selectfile))[0]
338    widget_control, flstid, set_combobox_select = 0 > selectfile
339  ENDIF ELSE selectfile = 0
340;------------------------------------------------------------
341; Text for computation
342;------------------------------------------------------------
343  yoff = yoff + 32
344; computation done on the files...
345  if keyword_set(uvalue) then txtvalue = (extractatt(uvalue, 'txtcmd'))[numdessinin] $
346  ELSE txtvalue = varexp
347  dummyid = widget_text(base, value = txtvalue, uvalue = {name:'txtcmd'}, uname = 'txtcmd' $
348                        , /editable, yoffset = yoff, xsize = 54, /frame)
349;------------------------------------------------------------
350; Calendar
351;------------------------------------------------------------
352  yoff = yoff + 40
353  currentcalendar = (*fileparameters[currentfile]).time_counter
354  key_caltype = (*fileparameters[currentfile]).caltype
355  fakecal = (*fileparameters[currentfile]).fakecal
356  if keyword_set(uvalue) then begin
357    dates = (extractatt(uvalue, 'dates'))[*, numdessinin]
358    date1 = date2jul(dates[0])
359    date2 = date2jul(dates[1])
360  ENDIF
361  basecalid = widget_base(base, column = 2, space = 0, yoffset = yoff, uname = 'basecal')
362  dummyid = cw_calendar(basecalid, currentcalendar, date1, FAKECAL = fakecal, uname = 'calendar1', uvalue = {name:'calendar1'}, /frame)
363  dummyid = cw_calendar(basecalid, currentcalendar, date2, FAKECAL = fakecal, uname = 'calendar2', uvalue = {name:'calendar2'}, /frame)
364;------------------------------------------------------------
365; Domain
366;------------------------------------------------------------
367  yoff = yoff + 60
368  vargrid = strupcase((*fileparameters[currentfile]).listgrid[selectvar])
369  IF vargrid EQ 'W' then zgrid = 'W' ELSE zgrid = 'T'
370  if keyword_set(uvalue) then boxzoom = (extractatt(uvalue, 'domaines'))[*, numdessinin]
371  dummyid = cw_domain(base, uname = 'domain', uvalue = {name:'domain'}, /unzoom, /frame $
372                      , boxzoom = boxzoom, yoffset = yoff, xoffset = 15)
373;------------------------------------------------------------
374; Plots specifications
375;------------------------------------------------------------
376  yoff = yoff + 230
377  speid = cw_specifie(base, uname = 'specifie', uvalue = {name:'specifie'}, /frame, /column $
378                      , /forxxx, yoffset = yoff)
379  if keyword_set(uvalue) then BEGIN
380    exextra = *((extractatt(uvalue, 'exextra'))[numdessinin])
381    IF n_elements(exextra) NE 0 THEN widget_control, speid, set_value = exextra
382  ENDIF
383;------------------------------------------------------------
384; drawing part
385;------------------------------------------------------------
386  if keyword_set(separate) then $
387     basegraph = widget_base(title = 'xxx window',  group_leader = base, uvalue = base) $
388  ELSE basegraph = base
389 
390  graphid = widget_draw(basegraph, uname = 'graph', /button_events, retain = 2 $
391                        , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
392                        , xoffset = 350*(1-keyword_set(separate)) $
393                        , xsize = windsize[0], ysize = windsize[1]); , tooltip = 'toto')
394;------------------------------------------------------------
395; realize the widget
396;------------------------------------------------------------
397  widget_control, base, /realize
398  if keyword_set(separate) then begin
399    widget_control, basegraph, /realize
400    xmanager, 'xxx', basegraph, /no_block
401  endif
402
403;------------------------------------------------------------
404  if keyword_set(uvalue) then BEGIN ;
405; We recopy the pointer uvalue in top_uvalue.
406; Beware, we have to redefine completely top_value from variables
407; pointed by uvalue. Otherwise, if we simply do top_value = uvalue,
408; when we delete by uvalue and variables on which it point, we
409; also delete variables on which point top_value.
410    case 1 of
411      keyword_set(redraw):BEGIN
412        top_uvalue = uvalue
413        widget_control, base, set_uvalue = top_uvalue
414; we find homedir
415        homedir = isadirectory(io = homedir, title = 'Bad definition of homedir')
416; We recuperae the list of instructions
417        globalcommand = extractatt(top_uvalue, 'globalcommand')
418; We complete by first and last lines of the program
419        createpro, globalcommand, filename = myuniquetmpdir + 'xxx2ps.pro' $
420                   , KWDLIST = ', NOERASE = noerase, POSTSCRIPT = postscript' $
421                   +', PORTRAIT = portrait, LANDSCAPE = landscape' $
422                   , /noerase
423      END
424      keyword_set(restore):begin
425        top_uvalue = uvalue
426        widget_control, base, set_uvalue = top_uvalue
427        widget_control, graphid, get_value = win
428        wshow, win
429        wset, win
430        tv, image, /true
431; widgets's state
432        updatewidget, base
433;
434      END
435      ELSE:BEGIN
436        top_uvalue = ptrarr(2, 29, /allocate_heap)
437        FOR i =  0, 28 do *top_uvalue[0, i] = *uvalue[0, i]
438        FOR i =  0, 14 do *top_uvalue[1, i] = *uvalue[1, i]
439        FOR i = 18, 27 do *top_uvalue[1, i] = *uvalue[1, i]
440        numfile = n_elements(extractatt(uvalue, 'filelist'))
441        *top_uvalue[1, 15] = ptrarr(numfile, /allocate_heap)
442        *top_uvalue[1, 16] = ptrarr(numfile, /allocate_heap)
443        *top_uvalue[1, 17] = ptrarr(numfile, /allocate_heap)
444        for i = 0, numfile-1 do begin
445          *(*top_uvalue[1, 15])[i] = *(*uvalue[1, 15])[i]
446          *(*top_uvalue[1, 16])[i] = *(*uvalue[1, 16])[i]
447          *(*top_uvalue[1, 17])[i] = *(*uvalue[1, 17])[i]
448        endfor
449        *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
450        for i = 0, nbredessin-1 do *(*top_uvalue[1, 28])[i] = *(*uvalue[1, 28])[i]
451        widget_control, base, set_uvalue = top_uvalue
452; Copy the screen of the widget of uvalue in top_value's one
453        if keyword_set(CallerWidId)  then begin
454          widget_control, extractatt(uvalue, 'graphid'), get_value = win
455          wshow, win
456          wset, win
457          image = tvrd(/true)
458          widget_control, graphid, get_value = win
459          wshow, win
460          wset, win
461          tv, image, /true
462        ENDIF
463      END
464    endcase
465    *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
466;
467ENDIF ELSE BEGIN
468; Otherwise we will define all elements we will hook at the widget
469; thanks to the top_value which is a pointer array with 2
470; columns: names and variables.
471; We initialize all these elements.
472; Variables concerning the widget in its generality.
473    if NOT keyword_set(ex)  then ex = {nothing:0}
474; variables se rapportant aux differents fichiers que l''on peut lire
475; variables specifiques a chaque dessin
476;     
477   
478; creation of the pointer we will hook at the widget.
479    top_uvalue = ptrarr(2, 29, /allocate_heap)
480; variables refering to the widget
481    *top_uvalue[0, 0] = 'options' & *top_uvalue[1, 0] = options
482    *top_uvalue[0, 1] = 'smallin' & *top_uvalue[1, 1] = smallin
483    *top_uvalue[0, 2] = 'smallout' & *top_uvalue[1, 2] = smallout
484    *top_uvalue[0, 3] = 'graphid' & *top_uvalue[1, 3] = graphid
485    *top_uvalue[0, 4] = 'alreadyvector' & *top_uvalue[1, 4] = -1
486    *top_uvalue[0, 5] = 'alreadyover' & *top_uvalue[1, 5] = -1
487    *top_uvalue[0, 6] = 'alreadyread' & *top_uvalue[1, 6] = -1
488    *top_uvalue[0, 7] = 'currentreadcmd' & *top_uvalue[1, 7] = ''
489    *top_uvalue[0, 8] = 'globalcommand' & *top_uvalue[1, 8] = ''
490    *top_uvalue[0, 9] = 'globaloldcommand' & *top_uvalue[1, 9] = ''
491    *top_uvalue[0, 10] = 'no more used' & *top_uvalue[1, 10] = 9999
492    *top_uvalue[0, 11] = 'noticebase' & *top_uvalue[1, 11] = 0l
493    *top_uvalue[0, 12] = 'extra' & *top_uvalue[1, 12] = ex
494; variables refering to different files we can read
495    *top_uvalue[0, 13] = 'currentfile' & *top_uvalue[1, 13] = currentfile
496    *top_uvalue[0, 14] = 'filelist' & *top_uvalue[1, 14] = filelist
497    *top_uvalue[0, 15] = 'fileparameters' & *top_uvalue[1, 15] = fileparameters
498    *top_uvalue[0, 16] = 'readparameters' & *top_uvalue[1, 16] = readparameters
499    *top_uvalue[0, 17] = 'meshparameters' & *top_uvalue[1, 17] = meshparameters
500; variables refering to different drawing we can do
501    *top_uvalue[0, 18] = 'penvs' & *top_uvalue[1, 18] = replicate(!p, nbredessin)
502    *top_uvalue[0, 19] = 'xenvs' & *top_uvalue[1, 19] = replicate(!x, nbredessin)
503    *top_uvalue[0, 20] = 'yenvs' & *top_uvalue[1, 20] = replicate(!y, nbredessin)
504    *top_uvalue[0, 21] = 'nameprocedures' & *top_uvalue[1, 21] = strarr(nbredessin)
505    *top_uvalue[0, 22] = 'types' & *top_uvalue[1, 22] = strarr(nbredessin)
506    *top_uvalue[0, 23] = 'varinfo' & *top_uvalue[1, 23] = strarr(2, nbredessin)   
507    *top_uvalue[0, 24] = 'domaines' & *top_uvalue[1, 24] = fltarr(6, nbredessin)
508    *top_uvalue[0, 25] = 'dates' & *top_uvalue[1, 25] = lonarr(2, nbredessin)
509    *top_uvalue[0, 26] = 'txtcmd' & *top_uvalue[1, 26] = strarr(nbredessin)
510    *top_uvalue[0, 27] = 'optionsflag' & *top_uvalue[1, 27] = flag
511    *top_uvalue[0, 28] = 'exextra' & *top_uvalue[1, 28] = ptrarr(nbredessin, /allocate_heap)
512;
513    widget_control, base, set_uvalue = top_uvalue
514    createhistory, base, smallin
515;
516  ENDELSE
517;------------------------------------------------------------
518  xmanager, 'xxx', base, /no_block
519;------------------------------------------------------------
520;------------------------------------------------------------
521  return
522end
Note: See TracBrowser for help on using the repository browser.