source: trunk/SRC/buildinit.pro @ 150

Last change on this file since 150 was 137, checked in by smasson, 18 years ago

review of Colors and Calendar routines

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