source: trunk/SRC/buildinit.pro

Last change on this file was 495, checked in by pinsard, 10 years ago

fix thanks to coding rules; typo; dupe empty lines; trailing blanks

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