1 """ Main module for the PyRAF-version of the Epar parameter editor
2
3 $Id: epar.py 1463 2011-06-24 22:58:30Z stsci_embray $
4
5 M.D. De La Pena, 2000 February 04
6 """
7 from __future__ import division
8
9 from stsci.tools import capable
10 if capable.OF_GRAPHICS:
11 from Tkinter import *
12 from tkMessageBox import askokcancel, showwarning, showerror
13 import os, stat, sys, cStringIO
14 from stsci.tools import filedlg, listdlg, eparoption, editpar
15 import iraf, irafpar, irafhelp, wutil
16 from pyrafglobals import pyrafDir
17 else:
18 wutil = None
22 from stsci.tools.irafglobals import IrafError
23
24
25
26 eparHelpString = """\
27 The PyRAF Parameter Editor window is used to edit IRAF parameter sets. It
28 allows multiple parameter sets to be edited concurrently (e.g., to edit IRAF
29 Psets). It also allows the IRAF task help to be displayed in a separate window
30 that remains accessible while the parameters are being edited.
31
32
33 Editing Parameters
34 --------------------
35
36 Parameter values are modified using various GUI widgets that depend on the
37 parameter properties. It is possible to edit parameters using either the mouse
38 or the keyboard. Most parameters have a context-dependent menu accessible via
39 right-clicking that enables unlearning the parameter (restoring its value to
40 the task default), clearing the value, and activating a file browser that
41 allows a filename to be selected and entered in the parameter field. Some
42 items on the right-click pop-up menu may be disabled depending on the parameter
43 type (e.g., the file browser cannot be used for numeric parameters.)
44
45 The mouse-editing behavior should be familiar, so the notes below focus on
46 keyboard-editing. When the editor starts, the first parameter is selected. To
47 select another parameter, use the Tab key (Shift-Tab to go backwards) or Return
48 to move the focus from item to item. The Up and Down arrow keys also move
49 between fields. The toolbar buttons can also be selected with Tab. Use the
50 space bar to "push" buttons or activate menus.
51
52 Enumerated Parameters
53 Parameters that have a list of choices use a drop-down menu. The space
54 bar causes the menu to appear; once it is present, the up/down arrow
55 keys can be used to select different items. Items in the list have
56 accelerators (underlined, generally the first letter) that can be typed
57 to jump directly to that item. When editing is complete, hit Return or
58 Tab to accept the changes, or type Escape to close the menu without
59 changing the current parameter value.
60
61 Boolean Parameters
62 Boolean parameters appear as Yes/No radio buttons. Hitting the space
63 bar toggles the setting, while 'y' and 'n' can be typed to select the
64 desired value.
65
66 Parameter Sets
67 Parameter sets (Psets) appear as a button which, when clicked, brings
68 up a new editor window. Note that two (or more) parameter lists can be
69 edited concurrently. The Package and Task identification are shown
70 in the window and in the title bar.
71
72 Text Entry Fields
73 Strings, integers, floats, etc. appear as text-entry fields. Values
74 are verified to to be legal before being stored in the parameter. If an
75 an attempt is made to set a parameter to an illegal value, the program
76 beeps and a warning message appears in the status bar at the bottom of
77 the window.
78
79 To see the value of a string that is longer than the entry widget,
80 either use the left mouse button to do a slow "scroll" through the
81 entry or use the middle mouse button to "pull" the value in the entry
82 back and forth quickly. In either case, just click in the entry widget
83 with the mouse and then drag to the left or right. If there is a
84 selection highlighted, the middle mouse button may paste it in when
85 clicked. It may be necessary to click once with the left mouse
86 button to undo the selection before using the middle button.
87
88 You can also use the left and right arrow keys to scroll through the
89 selection. Control-A jumps to the beginning of the entry, and
90 Control-E jumps to the end of the entry.
91
92
93 The Menu Bar
94 --------------
95
96 File menu:
97 Execute
98 Save all the parameters, close the editor windows, and start the
99 IRAF task. This is disabled in the secondary windows used to edit
100 Psets.
101 Save & Quit
102 Save the parameters and close the editor window. The task is not
103 executed.
104 Save As...
105 Save the parameters to a user-specified file. The task is not
106 executed.
107 Unlearn/Defaults
108 Restore all parameters to the system default values for this
109 task. Note that individual parameters can be unlearned using the
110 menu shown by right-clicking on the parameter entry.
111 Cancel
112 Cancel editing session and exit the parameter editor. Changes
113 that were made to the parameters are not saved; the parameters
114 retain the values they had when the editor was started.
115
116 Open... menu:
117 Load parameters from any applicable user file found. Values are not
118 stored unless Execute or Save is then selected. If no such files are
119 found, this menu is not shown.
120
121 Options menu:
122 Display Task Help in a Window
123 Help on the IRAF task is available through the Help menu. If this
124 option is selected, the help text is displayed in a pop-up window.
125 This is the default behavior.
126 Display Task Help in a Browser
127 If this option is selected, instead of a pop-up window help is
128 displayed in the user's web browser. This requires access to
129 the internet and is a somewhat experimental feature. The HTML
130 version of help does have some nice features such as links to
131 other IRAF tasks.
132
133 Help menu:
134 Task Help
135 Display help on the IRAF task whose parameters are being edited.
136 By default the help pops up in a new window, but the help can also
137 be displayed in a web browser by modifying the Options.
138 EPAR Help
139 Display this help.
140
141
142 Toolbar Buttons
143 -----------------
144
145 The Toolbar contains a set of buttons that provide shortcuts for the most
146 common menu bar actions. Their names are the same as the menu items given
147 above: Execute, Save & Quit, Defaults, Cancel, and Task Help. The Execute
148 button is disabled in the secondary windows used to edit Psets.
149
150 Note that the toolbar buttons are accessible from the keyboard using the Tab
151 and Shift-Tab keys. They are located in sequence before the first parameter.
152 If the first parameter is selected, Shift-Tab backs up to the "Task Help"
153 button, and if the last parameter is selected then Tab wraps around and selects
154 the "Execute" button.
155 """
156
157
158 -def epar(theTask, parent=None, isChild=0):
171
172
174
175 - def __init__(self, theTask, parent=None, isChild=0,
176 title="PyRAF Parameter Editor", childList=None):
177
178
179 editpar.EditParDialog.__init__(self, theTask, parent, isChild,
180 title, childList, resourceDir=pyrafDir)
181
183 """ Overridden version, so as to use Iraf tasks and IrafParList """
184
185 if isinstance(theTask, irafpar.IrafParList):
186
187 self._taskParsObj = theTask
188 else:
189
190 self._taskParsObj = iraf.getTask(theTask)
191
193 """ Overridden version, so as to check for a special case. """
194
195
196
197 if isinstance(self._taskParsObj,irafpar.IrafParList) and \
198 not self._taskParsObj.getFilename():
199 return ''
200 else:
201 retval = ''
202 try:
203 retval = self._taskParsObj.saveParList(filename=filename,
204 comment=comment)
205 except IOError:
206 retval="Error saving to "+str(filename)+". Please check privileges."
207 showerror(message=retval, title='Error Saving File')
208 if set_ro:
209 privs = os.stat(filename).st_mode
210 try:
211 os.chmod(filename, privs ^ stat.S_IWUSR)
212 except OSError:
213 pass
214 return retval
215
221
223 """ Override this to tailor the GUI specifically for epar. """
224 self._useSimpleAutoClose = True
225
226 self._saveAndCloseOnExec = True
227 self._showSaveCloseOnExec = False
228
229 self._showExtraHelpButton = True
230
231 self._appName = "Epar"
232 self._appHelpString = eparHelpString
233 self._unpackagedTaskTitle = "Filename"
234 self._defaultsButtonTitle = "Unlearn"
235
236 if not wutil.WUTIL_USING_X:
237 x = "#ccccff"
238 self._frmeColor = x
239 self._taskColor = x
240 self._bboxColor = x
241 self._entsColor = x
242
243
245 """ Override to allow use of PsetEparOption.
246 Return None or a class which derives from EparOption. """
247 if paramTypeStr == "pset":
248 import pseteparoption
249 return pseteparoption.PsetEparOption
250 else:
251 return None
252
253
254
257
258
261
262
263
264 - def pfopen(self, event=None):
265 """ Load the parameter settings from a user-specified file. Any
266 changes here must be coordinated with the corresponding tpar pfopen
267 function. """
268
269 fname = self._openMenuChoice.get()
270 if fname == None: return
271
272 newParList = irafpar.IrafParList(self.taskName, fname)
273
274
275 self.setAllEntriesFromParList(newParList)
276 self.freshenFocus()
277 self.showStatus("Loaded parameter values from: "+fname, keep=2)
278
279
281 """ Return a string to be used as the filter arg to the save file
282 dialog during Save-As. """
283 filt = '*.par'
284 upx = iraf.envget("uparm_aux","")
285 if 'UPARM_AUX' in os.environ: upx = os.environ['UPARM_AUX']
286 if len(upx) > 0: filt = iraf.Expand(upx)+"/*.par"
287 return filt
288
289
291 """ Override to check for (and warn about) PSETs. """
292
293
294 pars = []
295 for par in self.paramList:
296 if par.type == "pset": pars.append(par.name)
297 if len(pars):
298 msg = "If you have made any changes to the PSET "+ \
299 "values for:\n\n"
300 for p in pars: msg += "\t\t"+p+"\n"
301 msg = msg+"\nthose changes will NOT be explicitly saved to:"+ \
302 '\n\n"'+fnameToBeUsed+'"'
303 showwarning(message=msg, title='PSET Save-As Not Yet Supported')
304
305
306 - def _saveAsPostSave_Hook(self, fnameToBeUsed):
307 """ Override this to notify irafpar. """
308
309 irafpar.newSpecialParFile(self.taskName, self.pkgName, fnameToBeUsed)
310
311
312 - def htmlHelp(self, helpString=None, title=None, istask=False, tag=None):
313 """ Overridden version, use irafhelp to invoke the HTML help """
314
315
316 if helpString and title:
317 editpar.EditParDialog.htmlHelp(self, helpString, title,
318 istask=istask, tag=tag)
319 else:
320
321 irafhelp.help(self.taskName, html=1)
322
323
324
326 """ Override this - in PyRAF we'll always use use iraf system help.
327 Do not query the task object. """
328 fh = cStringIO.StringIO()
329 iraf.system.help(taskname, page=0, Stdout=fh, Stderr=fh)
330 result = fh.getvalue()
331 fh.close()
332 return result
333