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

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

english and nicer header (3a)

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