source: trunk/SRC/buildinit.pro @ 269

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

replace some print by some report in some .pro (continuation) + improvements/corrections of some *.pro headers

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