source: trunk/SRC/buildinit.pro @ 223

Last change on this file since 223 was 223, checked in by pinsard, 17 years ago

improvements of some *.pro

  • Property svn:keywords set to Id
File size: 19.3 KB
Line 
1;+
2; @file_comments
3;
4;
5; @categories
6;
7;
8; @param PARENT {in}{required}
9; The ID of the parent widget.
10;
11; @keyword COLUMN
12; Buttons will be arranged in the number of columns specified by this keyword.
13;
14; @keyword ROW
15; Buttons will be arranged in the number of rows specified by this keyword.
16;
17; @keyword EVENT_FUNC
18; The name of an optional user-supplied event function for buttons.
19; This function is called with the return value structure whenever a
20; button is pressed, and follows the conventions for user-written event functions.
21;
22; @keyword FLOATING
23;
24;
25; @keyword INTEGER
26;
27;
28; @keyword LONG
29;
30;
31; @keyword STRING
32;
33;
34; @keyword FONT
35; The name of the font to be used for the button titles. If this keyword
36; is not specified, the default font is used.
37;
38; @keyword FRAME
39; Specifies the width of the frame to be drawn around the base.
40;
41; @keyword TITLE
42; The title of the window
43;
44; @keyword UVALUE
45; The user value to be associated with the widget.
46;
47; @keyword VALUE
48;
49;
50; @keyword RETURN_EVENTS
51;
52;
53; @keyword ALL_EVENTS
54;
55;
56; @keyword FIELDFONT
57;
58;
59; @keyword NOEDIT
60;
61;
62; @keyword TEXT_FRAME
63;
64;
65; @keyword XSIZE
66; The width of the base.
67;
68; @keyword YSIZE
69; The height of the base.
70;
71; @keyword UNAME
72; The user name to be associated with the widget.
73;
74; @returns
75;
76; @uses
77;
78; @restrictions
79;
80; @examples
81;
82;
83; @history
84;
85; @version
86; $Id$
87;-
88;
89;----------------------------------------------------------
90;----------------------------------------------------------
91;
92; slightly modified version of cw_field...
93FUNCTION cw_field2, Parent, COLUMN=Column, ROW=Row, $
94    EVENT_FUNC = efun, $
95    FLOATING=Float, INTEGER=Int, LONG=Long, STRING=String, $
96    FONT=LabelFont, FRAME=Frame, TITLE=Title, UVALUE=UValue, VALUE=TextValueIn, $
97    RETURN_EVENTS=ReturnEvents, ALL_EVENTS=AllUpdates, $
98    FIELDFONT=FieldFont, NOEDIT=NoEdit, TEXT_FRAME=Text_Frame, $
99    XSIZE=XSize, YSIZE=YSize, UNAME=uname
100;   FLOOR=vmin, CEILING=vmax
101;
102  compile_opt idl2, strictarrsubs
103;
104  resolve_routine, 'cw_field', /compile_full_file, /is_function
105    ;   Examine our keyword list and set default values
106    ;   for keywords that are not explicitly set.
107
108    Column      = KEYWORD_SET(Column)
109    Row         = 1 - Column
110    AllEvents       = 1 - KEYWORD_SET(NoEdit)
111
112    ; Enum Update { None, All, CRonly }
113    Update      = 0
114    IF KEYWORD_SET(AllUpdates) THEN Update  = 1
115    IF KEYWORD_SET(ReturnEvents) THEN Update    = 2
116
117    IF N_ELEMENTS(efun) LE 0 THEN efun = ''
118    IF N_ELEMENTS(Title) EQ 0 THEN Title='Input Field:'
119    TextValue = (N_ELEMENTS(TextValueIn) gt 0) ? TextValueIn : ''
120    ; Convert non-string values to strings.
121    if (SIZE(TextValue, /TNAME) ne 'STRING') then $
122        TextValue = STRTRIM(TextValue,2)
123    IF N_ELEMENTS(YSize) EQ 0 THEN YSize=1
124    IF N_ELEMENTS(uname) EQ 0 THEN uname='CW_FIELD_UNAME'
125
126    Type    = 0 ; string is default
127    IF KEYWORD_SET(Float) THEN  Type    = 1
128    IF KEYWORD_SET(Int) THEN    Type    = 2
129    IF KEYWORD_SET(Long) THEN   Type    = 3
130
131    ;   Don't allow multiline non string widgets
132    if (Type ne 0) then $
133        YSize=1
134    YSize = YSize > 1
135
136    ;   Build Widget
137
138    Base    = WIDGET_BASE(Parent, ROW=Row, COLUMN=Column, UVALUE=UValue, $
139            EVENT_FUNC='CW_FIELD_EVENT', $
140            PRO_SET_VALUE='CW_FIELD_SET', $
141            FUNC_GET_VALUE='CW_FIELD_GET', $
142            FRAME=Frame, UNAME=uname )
143    FOR i = 0, n_elements(title)-1 DO $
144      Label   = WIDGET_LABEL(Base, VALUE = Title[i], FONT = LabelFont, $
145                             UNAME = uname+'_LABEL', /align_left)
146    Text    = WIDGET_TEXT(Base, VALUE = TextValue, $
147            XSIZE=XSize, YSIZE=YSize, FONT=FieldFont, $
148            ALL_EVENTS=AllEvents, $
149            EDITABLE=(AllEvents AND TYPE EQ 0), $
150            FRAME=Text_Frame , $
151            UNAME=uname+'_TEXT')
152
153            ; NO_ECHO=(AllEvents AND (TYPE NE 0)))
154
155    ; Save our internal state in the first child widget
156    State   = {     $
157    efun: efun,         $
158    TextId:Text,        $
159    Title:Title,        $
160    Update:Update,      $
161    Type:Type       $
162    }
163    WIDGET_CONTROL, WIDGET_INFO(Base, /CHILD), SET_UVALUE=State, /NO_COPY
164    RETURN, Base
165  END
166;
167;----------------------------------------------------------
168;----------------------------------------------------------
169;
170;+
171; @file_comments
172;
173;
174; @categories
175;
176;
177; @param EVENT
178;
179;
180; @returns
181;
182;
183; @uses
184;
185;
186; @restrictions
187;
188;
189; @examples
190;
191;
192; @history
193;
194;
195; @version
196; $Id$
197;-
198PRO printerdef_event, event
199; get back the ids of the cw_field widgets
200;
201  compile_opt idl2, strictarrsubs
202;
203  widget_control, event.id, get_uvalue = cwids
204  IF size(cwids, /n_dimensions) EQ 1 THEN cwids = reform(cwids, 3, 1)
205help, cwids
206  dims = size(cwids, /dimensions)
207help,  dims
208print,  dims
209  results = strarr(dims)
210  FOR i = 0, dims[1]-1 DO BEGIN
211    widget_control, cwids[0, i], get_value = res & results[0, i] = res
212    widget_control, cwids[1, i], get_value = res & results[1, i] = res
213    widget_control, cwids[2, i], get_value = res & results[2, i] = res
214  ENDFOR
215  nothing = where(results EQ '', count)
216  IF count NE 0 THEN BEGIN
217    nothing = dialog_message('Some of the text box are still empty', dialog_parent = event.top, /information)
218    return
219  ENDIF
220; now we give the result to buildinit.pro by using the pointer uvalue
221   widget_control, event.top, get_uvalue = ptresult
222   *ptresult = temporary(results)
223; we destroy the widget
224   widget_control, event.top, /destroy
225  RETURN
226END
227;
228;----------------------------------------------------------
229;----------------------------------------------------------
230;
231;+
232; @file_comments
233;
234;
235; @categories
236;
237;
238; @param EVENT
239;
240;
241; @returns
242;
243;
244; @uses
245;
246;
247; @restrictions
248;
249;
250; @examples
251;
252;
253; @history
254;
255;
256; @version
257; $Id$
258;-
259PRO papsize_event, event
260; get back the ids of the cw_field widgets
261;
262  compile_opt idl2, strictarrsubs
263;
264  widget_control, event.id, get_uvalue = uvalue
265  IF uvalue[0] NE 'ok' THEN return
266  idist = widget_info(event.top, find_by_uname = 'list')
267  id = widget_info(idist, /list_select)
268  widget_control, idist, get_uvalue = selected
269  selected = selected[id]
270  selected = strsplit(selected, /extract)
271; now we give the result to buildinit.pro by using the pointer uvalue
272   widget_control, event.top, get_uvalue = ptresult
273   *ptresult = [float(selected[3]), float(selected[4])]
274; we destroy the widget
275   widget_control, event.top, /destroy
276  RETURN
277END
278;
279;----------------------------------------------------------
280;----------------------------------------------------------
281;
282;+
283; @file_comments
284;
285;
286; @categories
287;
288;
289; @param EVENT
290;
291;
292; @returns
293;
294;
295; @uses
296;
297;
298; @restrictions
299;
300;
301; @examples
302;
303;
304; @history
305;
306;
307; @version
308; $Id$
309;-
310PRO xask_event, event
311; now we give the answer to buildinit.pro by using the pointer uvalue
312;
313  compile_opt idl2, strictarrsubs
314;
315   widget_control, event.top, get_uvalue = ptranswer
316   *ptranswer = event.value
317; we destroy the widget
318   widget_control, event.top, /destroy
319  RETURN
320END
321;
322;----------------------------------------------------------
323;----------------------------------------------------------
324;
325;+
326; @file_comments
327;
328;
329; @categories
330;
331;
332; @keyword _EXTRA
333; Used to pass your keywords
334;
335; @returns
336;
337;
338; @uses
339;
340;
341; @restrictions
342;
343;
344; @examples
345;
346;
347; @history
348;
349;
350; @version
351; $Id$
352;-
353FUNCTION xask, _extra = ex
354;
355  compile_opt idl2, strictarrsubs
356;
357  base = widget_base()
358  field = cw_field2(base, /frame, /return_events, /column, _extra = ex)
359  ptranswer = ptr_new(/allocate_heap)
360; we realize the widget and wait for an answer
361  widget_control, base, /realize, set_uvalue = ptranswer
362  xmanager, 'xask', base
363; we get the answer
364  answer = *ptranswer
365; we freeing the pointer
366  ptr_free, ptranswer
367  RETURN, answer
368END
369;
370;----------------------------------------------------------
371;----------------------------------------------------------
372;
373;+
374; @file_comments
375;
376;
377; @categories
378;
379;
380; @keyword TITLE
381; The title of the window
382;
383; @keyword NOMARK
384;
385;
386; @keyword NOWRITE
387;
388;
389; @returns
390;
391;
392; @uses
393;
394;
395; @restrictions
396;
397;
398; @examples
399;
400;
401; @history
402;
403;
404; @version
405; $Id$
406;-
407FUNCTION getdir, title = title, nomark = nomark, nowrite = nowrite
408;
409  compile_opt idl2, strictarrsubs
410;
411 
412  REPEAT BEGIN
413    dir = dialog_pickfile(/directory, /must_exist, title = title)
414; make sure dir is ok, check read/write access and directory separator mark
415    dir = file_search(dir, /test_directory, /test_read $
416                      , test_write = 1 - keyword_set(nowrite) $
417                      , mark_directory = 1 - keyword_set(nomark))
418    dir = dir[0]
419  ENDREP UNTIL dir NE ''
420
421  RETURN, dir
422END
423;
424;----------------------------------------------------------
425;----------------------------------------------------------
426;
427;+
428; @file_comments
429;
430;
431; @categories
432;
433;
434; @returns
435;
436;
437; @uses
438;
439;
440; @restrictions
441;
442;
443; @examples
444;
445;
446; @history
447;
448;
449; @version
450; $Id$
451;-
452PRO buildinit
453;
454;
455  compile_opt idl2, strictarrsubs
456;
457  IF fix(strmid(!version.release, 0, 1)) LT 6 THEN BEGIN
458    print, '                   *** ***** ***'
459    print, '                   *** ERROR ***'
460    print, '                   *** ***** ***'
461    print, 'This version of SAXO needs at least IDL version 6.0'
462    print, '                   *** ***** ***'
463    print, '                   *** ERROR ***'
464    print, '                   *** ***** ***'
465    return
466  ENDIF
467  IF lmgr(/demo) EQ 1 THEN BEGIN
468    print, 'impossible to use buildinit in demo mode'
469    return
470  ENDIF
471;
472  init = [';' $
473          , '; This is the initialisation file.' $
474          , '; it defines the !path and the defaut values of some of the common variables' $
475          , ';' $
476          , '; this is supposed to speed-up IDL...' $
477          , ';' $
478          , '; a = fltarr(1000,1000,100)' $
479          , '; a = 0' $
480          , ';' $
481          , '; path definition' $
482          , ';']
483;
484; define "myIDL" directory
485  myIDL = getdir(title = 'Select the home directory (my IDL)', /nomark)
486; define "SAXO" directory
487  saxodir = getdir(title = 'Select SAXO directory', /nomark, /nowrite)
488; define the !path
489  init = [init, '!path = expand_path(''+'' + '''+myIDL+''') $' $
490          , '      + '':'' + expand_path(''+'' + '''+saxodir+''') $' $
491          , '      + '':'' + expand_path(''+'' + !dir)']
492;
493; should we keep the compatibility with the old version?
494;
495  yes = dialog_message(['shall we keep the compatibility' $
496                        , 'with the old version ?'], /question, /default_no)
497  yes = strlowcase(yes)
498 
499  init = [init $
500          , ';' $
501          , '; compatibility with the old version' $
502          , ';' $
503          , 'keep_compatibility, ' + strtrim(fix(yes EQ 'yes'), 2)]
504;
505; define all the commons
506;
507  init = [init $
508          , ';' $
509          , '; define all the commons' $
510          , ';' $
511          , '@all_cm']
512;
513; define default directories
514;
515  init = [init $
516          , ';' $
517          , '; define default directories' $
518          , ';' $
519          , 'homedir = isadirectory('''+myIDL+'/'', title = ''Select the default HOME directory'')']
520  iodir = getdir(title = 'Select the default IO directory')
521  init = [init $
522          , 'iodir = isadirectory('''+iodir+''', title = ''Select the default IO directory'')']
523  psdir = getdir(title = 'Select the default postscripts directory')
524  init = [init $
525          , 'psdir = isadirectory('''+psdir+''', title = ''Select the default postscripts directory'')']
526  imagedir = getdir(title = 'Select the default images directory')
527  init = [init $
528          , 'imagedir = isadirectory('''+imagedir+''', title = ''Select the default images directory'')']
529  animdir = getdir(title = 'Select the default animations directory')
530  init = [init $
531          , 'animdir = isadirectory('''+animdir+''', title = ''Select the default animations directory'')']
532;
533; number of printer
534;
535  ptnumb = xask(title = 'Number of accessible printers', value = 0, /long)
536;
537; define all the printer parameters
538;
539  init = [init $
540          , ';' $
541          , '; define printer parameters' $
542          , ';' ]
543;
544  IF ptnumb NE 0 THEN BEGIN
545    base = widget_base(/column, /frame)
546    cwids = lonarr(3, ptnumb)
547    FOR i = 0, ptnumb-1 DO BEGIN
548      subbase = widget_base(base, /row)
549      cwids[0, i] = cw_field(subbase, /string $
550                             , Title = 'printer_human_names['+strtrim(i, 2)+'] = ')
551      cwids[1, i] = cw_field(subbase, /string $
552                             , Title = 'printer_machine_names['+strtrim(i, 2)+'] = ')
553      cwids[2, i] = cw_field(subbase, /string, value = '\lpr -P' $
554                             , Title = 'print_command['+strtrim(i, 2)+'] = ')
555    ENDFOR
556    trash = widget_button(base, value = 'ok', uvalue = cwids)
557    ptresult = ptr_new(/allocate_heap)
558; we realize the widget and wait for an answer
559    widget_control, base, /realize, set_uvalue = ptresult
560    xmanager, 'printerdef', base
561;
562    init = [init $
563            , 'printer_human_names = strarr('+strtrim(ptnumb, 2)+')' $
564            , 'printer_machine_names = strarr('+strtrim(ptnumb, 2)+')' $
565            , 'print_command = strarr('+strtrim(ptnumb, 2)+')']
566    FOR i = 0, ptnumb-1 DO BEGIN
567      init = [init $
568              , 'printer_human_names['+strtrim(i, 2)+'] = ''' $
569              + (*ptresult)[0, i]+'''' $
570              , 'printer_machine_names['+strtrim(i, 2)+'] = ''' $
571              + (*ptresult)[1, i]+'''' $
572              , 'print_command['+strtrim(i, 2)+'] = ''' $
573              + (*ptresult)[2, i]+'''']
574    ENDFOR
575; we freeing the pointer
576    ptr_free, ptresult
577  ENDIF ELSE BEGIN
578    init = [init $
579            , 'printer_human_names = ''''' $
580            , 'printer_machine_names = ''''' $
581            , 'print_command = ''''']
582  ENDELSE
583;
584; Colors
585;
586  init = [init $
587          , ';' $
588          , '; colors ...' $
589          , ';' $
590          , 'device, decomposed = 0' $
591          , 'device, retain = 2']
592;
593; default color tables
594;
595  loadct, get_names = names
596
597  ntables = 40
598  title = ['               --------------------------------------               ' $
599           , '               --- Choose the default color table ---               ' $
600           , '               --------------------------------------               ', '']
601; the following lines come from loadct procedure...
602  nlines = (ntables + 2) / 3    ;# of lines to print
603  nend = nlines - ((nlines*3) - ntables)
604  for i = 0, nend-1 do $        ;Print each line
605    title = [title $
606             , string(format = "(i2,'- ',a17, 3x, i2,'- ',a17, 3x, i2,'- ',a17)" $
607                      , i, names[i], i+nlines, names[i+nlines] $
608                      , i+2*nlines < (ntables-1) $
609                      , names[i+2*nlines < (ntables-1)])]
610  if (nend lt nlines) then begin
611    for i = nend, nlines-1 do $
612      title = [title $
613               , string(format = "(i2,'- ',a17, 3x, i2,'- ',a17)", $
614                        i, names[i], i+nlines, names[i+nlines])]
615  ENDIF
616  title = [title, '']
617  ctnumb = 0 > xask(title = title, value = 39, /long) < 39
618;
619  init = [init $
620          , 'lct, '+strtrim(ctnumb, 2)]
621;
622; postscript position
623;
624  yes = dialog_message(['the default postscript position', 'is landscape?'], /question)
625  init = [init $
626          , ';' $
627          , '; postscript parameters ...' $
628          , ';' $
629          , 'key_portrait = '+strtrim(fix(strlowcase(yes) NE 'yes'), 2)]
630;
631; paper size
632;
633  list = ['a0           33.0556    46.7778    83.9611   118.816' $
634          , 'a1           23.3889    33.0556    59.4078   83.9611' $
635          , 'a2           16.5278    23.3889    41.9806   59.4078' $
636          , 'a3           11.6944    16.5278    29.7039   41.9806' $
637          , 'a4           8.26389    11.6944    20.9903   29.7039' $
638          , 'a5           5.84722    8.26389    14.8519   20.9903' $
639          , 'a6           4.125      5.84722    10.4775   14.8519' $
640          , 'a7           2.91667    4.125      7.40833   10.4775' $
641          , 'a8           2.05556    2.91667    5.22111   7.40833' $
642          , 'a9           1.45833    2.05556    3.70417   5.22111' $
643          , 'a10          1.02778    1.45833    2.61056   3.70417' $
644          , 'b0           39.3889    55.6667    100.048   141.393' $
645          , 'b1           27.8333    39.3889    70.6967   100.048' $
646          , 'b2           19.6944    27.8333    50.0239   70.6967' $
647          , 'b3           13.9167    19.6944    35.3483   50.0239' $
648          , 'b4           9.84722    13.9167    25.0119   35.3483' $
649          , 'b5           6.95833    9.84722    17.6742   25.0119' $
650          , 'archA        9          12         22.86     30.48' $
651          , 'archB        12         18         30.48     45.72' $
652          , 'archC        18         24         45.72     60.96' $
653          , 'archD        24         36         60.96     91.44' $
654          , 'archE        36         48         91.44     121.92' $
655          , 'flsa         8.5        13         21.59     33.02' $
656          , 'flse         8.5        13         21.59     33.02' $
657          , 'halfletter   5.5        8.5        13.97     21.59' $
658          , 'note         7.5        10         19.05     25.4' $
659          , 'letter       8.5        11         21.59     27.94' $
660          , 'legal        8.5        14         21.59     35.56' $
661          , '11x17        11         17         27.94     43.18' $
662          , 'ledger       17         11         43.18     27.94']
663  base = widget_base(/column)
664  trash = widget_label(base, value = '--- Select the paper size ---')
665  trash = widget_label(base, value = '')
666  trash = widget_label(base, value = 'PAPERSIZE    X inches   Y inches   X cm      Y cm', /align_left, uvalue = 'dummy')
667  listid = widget_list(base, value = list, uvalue = list, uname = 'list', ysize = n_elements(list) < 15)
668  widget_control, listid, set_list_select = 4
669  trash = widget_button(base, value = 'ok', uvalue = 'ok')
670  ptresult = ptr_new(/allocate_heap)
671; we realize the widget and wait for an answer
672  widget_control, base, /realize, set_uvalue = ptresult
673  xmanager, 'papsize', base
674;
675  papsize = *ptresult
676; we freeing the pointer
677  ptr_free, ptresult
678  init = [init $
679          , 'page_size = [' + strtrim(papsize[0], 2) $
680          + ', ' +strtrim(papsize[1], 2) + ']']
681;
682; window size
683;
684  title = ['         --- Size of the Window ---', '' $
685           , 'The size of window (in cm) is given by:' $
686           , 'windowsize_scale * page_size, with ' $
687           , 'page_size = [' + strtrim(papsize[0], 2)+ ', ' +strtrim(papsize[1], 2) + ']' $
688           , 'Please select a value for windowsize_scale ']
689  wsize_scale = xask(title = title, value = 1, /floating)
690  init = [init, 'windowsize_scale = ' + strtrim(wsize_scale, 2)]
691 
692;
693; postscript archiving...
694;
695  title = ['     --- Select the default postscript archiving method ---', ''$
696           , '0 : never archive the postscript' $
697           , '1 : always archive the postscript when printed' $
698           , '2 : ask if the postscript must be archived each time its printed', '']
699  archive_ps = 0 > xask(title = title, value = 0, /long) < 2
700  init = [init $
701          , 'archive_ps = '+strtrim(archive_ps, 2) $
702          , ';' $
703          , ';========================================================' $
704          , '; end of the part that should be modified by the users...' $
705          , ';========================================================' $
706          , ';' $
707          , '; if needed, keep compatibility with the old version' $
708          , ';' $
709          , '@updateold' $
710          , ';' ]
711
712  filename = xask(title = ['name of the init file', '(written in homedir: ' + myIDL + ')'], value = 'init.pro', /string)
713  journal, myIDL + '/' + filename
714  FOR i = 0, n_elements(init)-1 DO journal, init[i]
715  journal
716
717  RETURN
718END
Note: See TracBrowser for help on using the repository browser.