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

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

header improvements : type of parameters and keywords, default values, spell checking + idldoc assistant (IDL online_help)

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