source: trunk/WIDGET/AUTOUR_de_XXX/xxxmenubar.pro @ 2

Last change on this file since 2 was 2, checked in by opalod, 22 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.9 KB
Line 
1;------------------------------------------------
2PRO xxxmenubar_event, event
3@common
4
5
6   case event.value of
7      'Open' :begin
8         newfile = selectfile()
9         if size(newfile, /type) NE 8 then return
10         widget_control, event.top, /hourglass
11         widget_control, event.top, update = 0
12         widget_control, event.top, get_uvalue = top_uvalue
13; on s''occupe de filelist
14         filelist = extractatt(top_uvalue, 'filelist')
15         filelist = [filelist, newfile.fileparameters.filename]
16         currentfile = n_elements(filelist)-1
17; on update le widget
18         filelistid = widget_info(event.top, find_by_uname = 'filelist')
19         widget_control, filelistid, set_value = filelist
20         widget_control, filelistid, set_list_select = currentfile
21; on update les elements filelist et currentfile de la top_uvalue
22         *top_uvalue[1, findline(top_uvalue, 'filelist')] = filelist
23         oldfile = *top_uvalue[1, findline(top_uvalue, 'currentfile')]
24         *top_uvalue[1, findline(top_uvalue, 'currentfile')] = currentfile
25; on s''occupe du nom de la variable
26         champid = widget_info(event.top, find_by_uname = 'champ')
27; quel etait le champ selectionne ? on le reselectionne ?
28         oldlistvar = (*(extractatt(top_uvalue, 'fileparameters'))[oldfile]).listvar
29         fieldname = oldlistvar[widget_info(champid,/droplist_select)]
30         index = where(newfile.fileparameters.listvar EQ fieldname) & index = 0>index[0]
31         widget_control, champid, set_value = newfile.fileparameters.listvar
32         widget_control, champid, set_droplist_select = index
33; on s''occupe du calendrier
34         date1id = widget_info(event.top, find_by_uname = 'calendar1')
35         widget_control, date1id, get_value = date1
36         widget_control, date1id, /destroy
37         if (where(newfile.fileparameters.time_counter EQ date1))[0] EQ -1 $
38          then date1 = newfile.fileparameters.time_counter[0]
39         date2id = widget_info(event.top, find_by_uname = 'calendar2')
40         widget_control, date2id, get_value = date2
41         widget_control, date2id, /destroy
42         if (where(newfile.fileparameters.time_counter EQ date2))[0] EQ -1 then date2 = date1
43         base12 = widget_info(event.top, find_by_uname = 'base12')
44         rien = cw_calendar(base12,newfile.fileparameters.time_counter,date1, uname = 'calendar1' $
45                            , uvalue = {name:'calendar1'}, /frame)
46         rien = cw_calendar(base12,newfile.fileparameters.time_counter,date2, uname = 'calendar2' $
47                            , uvalue = {name:'calendar2'}, /frame)
48; update la grille???
49         change = changegrid(newfile.meshparameters)
50         if change then BEGIN
51            domainid = widget_info(event.top, find_by_uname = 'domain')
52            widget_control, domainid, set_value = -1
53         endif
54; on update les elements fileparameters, readparameters et meshparameters de la top_uvalue
55         newfileparameters = ptrarr(currentfile+1, /allocate_heap)
56         FOR i = 0, currentfile-1 DO $
57          *newfileparameters[i] = *(extractatt(top_uvalue, 'fileparameters'))[i]
58         *newfileparameters[currentfile] = newfile.fileparameters
59         ptr_free, extractatt(top_uvalue, 'fileparameters')
60         *top_uvalue[1, findline(top_uvalue, 'fileparameters')] = newfileparameters
61;
62         newreadparameters = ptrarr(currentfile+1, /allocate_heap)
63         FOR i = 0, currentfile-1 DO $
64          *newreadparameters[i] = *(extractatt(top_uvalue, 'readparameters'))[i]
65         *newreadparameters[currentfile] = newfile.readparameters
66         ptr_free, extractatt(top_uvalue, 'readparameters')
67         *top_uvalue[1, findline(top_uvalue, 'readparameters')] = newreadparameters
68;
69         newmeshparameters = ptrarr(currentfile+1, /allocate_heap)
70         FOR i = 0, currentfile-1 DO $
71          *newmeshparameters[i] = *(extractatt(top_uvalue, 'meshparameters'))[i]
72         *newmeshparameters[currentfile] = newfile.meshparameters
73         ptr_free, extractatt(top_uvalue, 'meshparameters')
74         *top_uvalue[1, findline(top_uvalue, 'meshparameters')] = newmeshparameters
75; on actualise le widget!
76         widget_control, event.top, update = 1
77      end
78      'New xxx' :BEGIN
79         widget_control, event.top, get_uvalue = top_uvalue
80         extra = extractatt(top_uvalue, 'extra')
81         xxx, CALLERWIDID = event.top, _extra = extra
82      end
83      'Quit':begin
84         widget_control, event.top, get_uvalue = top_uvalue
85         ptr_free, extractatt(top_uvalue, 'exextra')
86         ptr_free, extractatt(top_uvalue, 'fileparameters')
87         ptr_free, extractatt(top_uvalue, 'readparameters')
88         ptr_free, extractatt(top_uvalue, 'meshparameters')
89         ptr_free, top_uvalue
90         widget_control, event.top, /destroy ;on ferme le widget
91      end
92      'PS' :BEGIN
93; we find homedir
94         homedir = isadirectory(io = homedir, title = 'Bad definition of homedir')
95         widget_control,event.top, get_uvalue = top_uvalue
96; portrait ou landscape ???
97         options = extractatt(top_uvalue, 'options')   
98         optionsflag = extractatt(top_uvalue, 'optionsflag')
99         portrait = (optionsflag[where(options EQ 'Portrait/Landscape'), 0])[0]
100; on recupere la liste des instructions
101         globalcommand = extractatt(top_uvalue, 'globalcommand')
102; on complete par le premiere et les dernieres lignes du programme
103         globalcommand = ['pro xxx2ps, NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape, DATE1IN = date1in, DATE2IN = date2in, _extra = ex' $
104                          , globalcommand $
105                          , 'return',  'end']
106         putfile, homedir+'xxx2ps.pro', globalcommand ; on l''ecrit
107         resolve_routine, 'xxx2ps' ; on le compile
108         xxx2ps, /post, portrait = portrait ; on l''applique
109      END
110      'Anim' :begin
111         xcreateanim, event.top
112      end
113      'Gif' :BEGIN
114         widget_control,event.top, get_uvalue = top_uvalue
115         petitin = extractatt(top_uvalue, 'petitin')
116         numdessinin = petitin[2]-1
117         petitout = extractatt(top_uvalue, 'petitout')
118         numdessinout = petitout[2]-1
119         tracecadre, petitin, /erase
120         tracecadre, petitout, /erase
121         filename = xquestion('dans quelle fichier gif voulez vous sauver !C l''ecran de xxx?', 'xxx_image.gif')
122         if rstrpos(filename, '.gif') NE strlen(filename)-4 then filename = filename+'.gif'
123         filename = isafile(file = filename, io = imagedir, /new)
124         saveimage, filename, /quiet
125      end
126      'Script':BEGIN
127; on recupere le nom du fichier
128         filename = xquestion('dans quelle procedure IDL voulez vous sauver !C la realisation de ce graph?', 'xxx_figure.pro')
129; on le complete par un .pro
130         if rstrpos(filename, '.pro') NE strlen(filename)-4 then filename = filename+'.pro'
131         filename = isafile(file = filename, io = homedir, /new)
132         widget_control,event.top, get_uvalue = top_uvalue
133; portrait ou landscape ???
134         options = extractatt(top_uvalue, 'options')   
135         optionsflag = extractatt(top_uvalue, 'optionsflag')
136         portrait = (optionsflag[where(options EQ 'Portrait/Landscape'), 0])[0]
137; on lit les commandes pour faire un plot
138         globalcommand = extractatt(top_uvalue, 'globalcommand')
139; on complete par le premiere et les dernieres lignes du programme
140         thisOS = strupcase(strmid(!version.os_family, 0, 3))
141         CASE thisOS of
142            'MAC':sep = ':'
143            'WIN':sep = '\'
144            ELSE:sep = '/'
145         ENDCASE
146         poslastsep = rstrpos(filename, sep)
147         proname = strmid(filename, poslastsep+1, strlen(filename)-poslastsep-1-4)
148         globalcommand = ['pro '+proname+', NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape, DATE1IN = date1in, DATE2IN = date2in, _extra = ex' $
149                          , '@common' $
150                          , ' ' $
151                          , '   portrait = '+strtrim(portrait, 1) $
152                          , '   '+globalcommand $
153                          , ' ' $
154                          , 'return' $
155                          , 'end']
156; on les ecrit dans un programme
157         putfile, filename, globalcommand
158      END
159      'Widget':BEGIN
160; on recupere le nom du fichier
161         filename = xquestion('dans quel fichier bianire voulez vous sauver le widget ?', 'xxx_widget.dat')
162; on le complete par un .dat
163         if rstrpos(filename, '.dat') NE strlen(filename)-4 then filename = filename+'.dat'
164         filename = isafile(file = filename, io = homedir, /new)
165;
166         widget_control, event.top, get_uvalue = uvalue
167         widget_control, extractatt(uvalue, 'graphid'),get_value=win
168         wshow, win
169         wset, win
170         image = tvrd(/true)
171         save, uvalue, image, filename = filename
172      END
173      'Prompt':BEGIN
174         commande = getfile(isadirectory(io = homedir)+'xxx_oneplot.pro')
175         for i = 0,  n_elements(commande)-1 do print, commande[i]
176      end
177      'Ok button' :begin
178         widget_control, event.top, get_uvalue = top_uvalue
179         options = extractatt(top_uvalue, 'options')
180         index = where(options EQ 'Ok button') & index = index[0]
181         optionsflag = extractatt(top_uvalue, 'optionsflag')
182         flag = 1-optionsflag[index, 0]
183         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, *] = flag
184         widget_control, widget_info(event.top, find_by_uname = 'base ok button'), map = flag
185      end
186      'Portrait/Landscape' :begin
187         widget_control, event.top, get_uvalue = top_uvalue
188         options = extractatt(top_uvalue, 'options')
189         index = where(options EQ 'Portrait/Landscape') & index = index[0]
190         optionsflag = extractatt(top_uvalue, 'optionsflag')
191         key_portrait= 1-optionsflag[index, 0]
192         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, *] = key_portrait
193; fenetre separee ou fenetre collee au widget ?
194         if widget_info(event.top, find_by_uname = 'graph') EQ 0 then BEGIN
195; on tue la fenetre
196            graphid = extractatt(top_uvalue, 'graphid')
197            widget_control, widget_info(graphid, /parent), /destroy
198; on la recree
199            basegraph = widget_base(title = 'xxx window',  group_leader = event.top, uvalue = event.top,  uname = 'basegraph')
200            windsize = givewindowsize()
201            graphid = widget_draw(basegraph, uname = 'graph' $
202                                  , uvalue = {name:'graph', press:0, click:0, x:[0., 0.], y:[0., 0.]} $
203                                  , /button_events, retain = 2 $
204                                  , xsize = windsize[0],ysize = windsize[1])
205            widget_control,basegraph,/realize
206            xmanager,'xxx',basegraph, /no_block
207; on redessine ce qu''il y avait dedans
208; we find homedir
209            homedir = isadirectory(io = homedir, title = 'Bad definition of homedir')
210; on recupere la liste des instructions
211            globalcommand = extractatt(top_uvalue, 'globalcommand')
212; on complete par le premiere et les dernieres lignes du programme
213            globalcommand = ['pro xxx2ps, NOERASE = noerase, POSTSCRIPT = postscript, PORTRAIT = portrait, LANDSCAPE = landscape' $
214                             , globalcommand $
215                             , 'return',  'end']
216            putfile, homedir+'xxx2ps.pro', globalcommand ; on l''ecrit
217            resolve_routine, 'xxx2ps' ; on le compile
218            xxx2ps, /noerase, portrait = key_portrait ; on l''applique
219; on reattribue l''element graphid de la top_uvalue
220            *top_uvalue[1, findline(top_uvalue, 'graphid')] = graphid
221         ENDIF ELSE BEGIN
222            extra = extractatt(top_uvalue, 'extra')
223            xxx, CALLERWIDID = event.top, /redraw, _extra = extra
224            widget_control, event.top, /destroy ;on ferme le widget
225         ENDELSE
226      end
227      'Overlay' :begin
228         widget_control, event.top, get_uvalue = top_uvalue
229         numdessinin = (extractatt(top_uvalue, 'petitin'))[2]-1
230         options = extractatt(top_uvalue, 'options')   
231         flags = extractatt(top_uvalue, 'optionsflag')
232         index = where(options EQ 'Overlay')
233; on change le flag sur Longitude / x index
234         flag = 1-flags[index, numdessinin] & flag = flag[0]
235; on le reeatribue
236         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
237      end
238      'Vecteur':BEGIN
239         widget_control, event.top, get_uvalue = top_uvalue
240         numdessinin = (extractatt(top_uvalue, 'petitin'))[2]-1
241         options = extractatt(top_uvalue, 'options')   
242         flags = extractatt(top_uvalue, 'optionsflag')
243         index = where(options EQ 'Vecteur')
244; on change le flag sur Longitude / x index
245         flag = 1-flags[index, numdessinin] & flag = flag[0]
246; on le reeatribue
247         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
248      end
249      'Longitude / x index':BEGIN
250         widget_control, event.top, get_uvalue = top_uvalue
251         numdessinin = (extractatt(top_uvalue, 'petitin'))[2]-1
252         options = extractatt(top_uvalue, 'options')   
253         flags = extractatt(top_uvalue, 'optionsflag')
254         index = where(options EQ 'Longitude / x index')
255; on change le flag sur Longitude / x index
256         flag = 1-flags[index, numdessinin] & flag = flag[0]
257; on le reeatribue
258         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
259; maintenant on va changer les sliders definissant la boite
260         domainid = widget_info(event.top, find_by_uname = 'domain')
261         boite = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
262; on veut retrouver le type de grille qui est utilisee
263         currentfile = extractatt(top_uvalue, 'currentfile')
264         listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
265         indexvar = widget_info(widget_info(event.top, find_by_uname = 'champ'), /droplist_select)
266         vargrid = strupcase(listgrid[indexvar])
267         if flag EQ 0 then BEGIN ; longitudes
268; on fait un domdef pour retrouver le lon1 lon2 correspondant a la
269; boite definie sur le widget...
270            domdef, boite, grille = vargrid, /xindex $
271             , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
272            widget_control, domainid, set_value = [lon1, lon2, boite[2:3]]
273         ENDIF ELSE BEGIN       ; xindex
274; maintenant ion veut retrouver premierx, dernierx correspondant a la
275; boite definie sur le widget...
276            domdef, boite, grille = vargrid $
277             , yindex = (flags[where(options EQ 'Latitude / y index'), numdessinin])[0]
278            grille, mask,glam,gphi,gdep,nx,ny,nz,premierx,premiery,premierz,dernierx,derniery,dernierz
279            widget_control, domainid, set_value = [premierx, dernierx, boite[2:3]]
280         ENDELSE
281; on met a jour la top_uvalue
282         widget_control, domainid, get_value = boite
283         (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boite
284      end
285      'Latitude / y index':begin
286         widget_control, event.top, get_uvalue = top_uvalue
287         numdessinin = (extractatt(top_uvalue, 'petitin'))[2]-1
288         options = extractatt(top_uvalue, 'options')   
289         flags = extractatt(top_uvalue, 'optionsflag')
290         index = where(options EQ 'Latitude / y index')
291; on change le flag sur Latitude / y index
292         flag = 1-flags[index, numdessinin] & flag = flag[0]
293; on le reeatribue
294         (*top_uvalue[1, findline(top_uvalue, 'optionsflag')])[index, numdessinin] = flag
295; maintenant on va changer les sliders definissant la boite
296         domainid = widget_info(event.top, find_by_uname = 'domain')
297         boite = (extractatt(top_uvalue, 'domaines'))[*, numdessinin]
298; on veut retrouver le type de grille qui est utilisee
299         currentfile = extractatt(top_uvalue, 'currentfile')
300         listgrid = (*(extractatt(top_uvalue, 'fileparameters'))[currentfile]).listgrid
301         indexvar = widget_info(widget_info(event.top, find_by_uname = 'champ'), /droplist_select)
302         vargrid = strupcase(listgrid[indexvar])
303         if flag EQ 0 then BEGIN ; latitudes
304; on fait un domdef pour retrouver le lat1 lat2 correspondant a la
305; boite definie sur le widget...
306            domdef, boite, grille = vargrid, /yindex $
307             , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
308            widget_control, domainid, set_value = [boite[0:1], lat1, lat2]
309         ENDIF ELSE BEGIN       ; yindex
310; maintenant ion veut retrouver premiery, derniery correspondant a la
311; boite definie sur le widget...
312            domdef, boite, grille = vargrid $
313             , xindex = (flags[where(options EQ 'Longitude / x index'), numdessinin])[0]
314            grille, mask,glam,gphi,gdep,nx,ny,nz,premierx,premiery,premierz,dernierx,derniery,dernierz
315            widget_control, domainid, set_value = [boite[0:1], premiery, derniery]
316         ENDELSE
317; on met a jour la top_uvalue
318         widget_control, domainid, get_value = boite
319         (*top_uvalue[1, findline(top_uvalue, 'domaines')])[*, numdessinin] = boite
320      end
321   endcase
322   return
323end
324;------------------------------------------------
325PRO xxxmenubar, parent, OPTIONS =options, _EXTRA = ex
326;       desc = [ '1\Colors' , $
327;    '0\Red' , $
328;    '0\Green' , $
329;    '1\Blue' , $
330;    '0\Light' , $
331;    '0\Medium' , $
332;    '0\Dark' , $
333;    '0\Navy' , $
334;    '2\Royal' , $
335;    '0\Cyan' , $
336;    '2\Magenta' , $
337;    '2\Quit' ]
338   desc = [ '1\File' , $
339            '0\Open' , $
340            '0\New xxx' , $
341            '2\Quit', $
342            '1\Save as' , $
343            '0\PS' , $
344            '0\Anim' , $
345            '0\Gif' , $
346            '0\Script', $
347            '0\Widget', $
348            '2\Prompt', $
349            '1\Flag options']
350   descsuite = options
351   if n_elements(descsuite) GE 2 then $
352    descsuite[0:n_elements(descsuite)-2] = '0\'+descsuite[0:n_elements(descsuite)-2]
353   descsuite[n_elements(descsuite)-1] = '2\'+descsuite[n_elements(descsuite)-1]
354   desc = [desc, descsuite]
355           
356   menu = CW_PDMENU(parent, desc, /RETURN_NAME, /mbar, uname = 'menubar', uvalue = {name:'menubar'}, _EXTRA = ex)
357
358
359;------------------------------------------------
360   return
361end
Note: See TracBrowser for help on using the repository browser.