source: trunk/SRC/buildinit.pro @ 325

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

modification of some headers (+some corrections) to prepare usage of the new idldoc

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