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

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

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