Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/pass_default_menu.py
Дата изменения: Fri Feb 28 14:46:11 2014
Дата индексирования: Sat Mar 1 19:36:00 2014
Кодировка:

Поисковые слова: п п п п п п п п п
#MODULE pass_default_menu.py
#
#***********************************************************************
"""

**PURPOSE** --
This Generates the Default Settings menu.

**DEVELOPER** --
K. Clark and Don Chance

**MODIFICATION HISTORY** --
o Initial implementation 1/2/03
o filter on input run name. 11/11/03
o change cursor to a watch while waiting for the dialog box to
appear. dc 12/9/03
o add the comment box. dc 1/7/04
o disable editing of comment box. dc 2/24/04
o catch bad regular expressions. dc 4/1/04
o set disablebackground to white. dc 5/11/06
o set disablebackground to white only for TclVersion >= 8.4. dc 5/23/06
o specify default_pickle when input is a file. dc 2/28/07
o improve error handling for bad pickles. dc 7/17/08
"""
#***********************************************************************

__version__ = "7/17/08"

from Tkconstants import *
from Tkinter import *
import Tix
import tkMessageBox
import pickle_selection_menu
import spss_sys_util
import configure_util
import entry_box
import Pmw
import select_option_menu
import mscl_util
import abstract_pass_menu
import re
import os

class pass_default_menu(abstract_pass_menu.abstract_pass_menu):
def __init__(self, parent, pass_run=None, gui_clear=None, gui_save=None, verbose=0):
""" Constructor.
"""
abstract_pass_menu.abstract_pass_menu.__init__(self, parent, verbose)
self.parent = parent
if not pass_run:
self.pass_run = mscl_util.mscl_run()
else:
self.pass_run = pass_run

top_frame = Frame(self.frame)
top_frame.pack(side=TOP, fill='x')
button_frame = Frame(self.frame)
button_frame.pack(side=TOP, fill='x')

# Create an entry box for the pickle path
self.pickle_path_entry = entry_box.entry_box(top_frame, "Pickle path: ", pass_run.get_pickle_path())
self.pickle_path_entry.frame.pack(padx=10, pady=10, fill='x', side='top')

# Create a run comment box
self.comment_entry = entry_box.entry_box(top_frame, "Pickle description: ", pass_run.get_comment())
if TclVersion >= 8.4:
self.comment_entry.configure(state='disable', disabledbackground='white')
else:
self.comment_entry.configure(state='disable')
self.comment_entry.frame.pack(padx=10, pady=10, fill='x', side='top')

# Create dummy frame (for alignment purposes)
Frame(button_frame).pack(fill='both', expand=1)

# Create a button box
self.buttonbox = Pmw.ButtonBox(button_frame)
self.buttonbox.pack(padx = 10, pady = 10)

# Create a button to load an old run
self.buttonbox.add("Find previous run to load",
command=self.load_old_run)

# Create a clear button
self.buttonbox.add("Clear",
command=gui_clear)

# Create a save button
self.buttonbox.add("Save",
command=gui_save)

# Set the default button
self.buttonbox.setdefault("Find previous run to load")

# Create another dummy frame (for alignment purposes)
Frame(button_frame).pack(fill='both', expand=1)

# Create an empty frame at the bottom that expands to fill up excess space
Frame().pack(fill='both', expand=1, side='top')

# Bind return to the button push
self.pickle_path_entry.entry.bind('', self._processReturnKey_main)

def clear(self):
"""Clear out any previous run.
"""
self.pass_run = mscl_util.mscl_run()
self.pickle_path_entry.set_entry('')
self.comment_entry.set_entry('')

def load_old_run(self, dummy=None):
"""Create a dialog box containing a pickle selection menu for picking
the MSCL run to load.
"""
# Turn the cursor to a watch
old_cursor = self.parent.cget("cursor")
self.parent.configure(cursor="watch")

self.dialog = Pmw.Dialog('',
title="Choose a previous run",
buttons = ('OK', 'Cancel'),
defaultbutton = 'OK',
command = self.dialog_button_push)
# Make sure we have a valid regular expression
picklepath = self.pickle_path_entry.get_value()
if os.path.isfile(picklepath):
regex = os.path.splitext(os.path.basename(picklepath))[0]
default_pickle = self.pass_run
else:
regex = picklepath
default_pickle = None
try:
re.compile(regex)
except:
regex = ''

# Create a MSCL pickle file selection menu.
self.pass_run_sel_menu = pickle_selection_menu.pickle_selection_menu(self.dialog.interior(),
'mscl',
default_pickle=default_pickle,
regex=regex)
self.pass_run_sel_menu.frame.pack(padx=10, pady=10)

# Set the default button (the one executed when is hit).
self.dialog.bind('', self._processReturnKey_dialog)
self.dialog.focus_set()
# Turn the cursor back to whatever it was before
self.parent.configure(cursor=old_cursor)
self.dialog.activate()

def _processReturnKey_dialog(self, event):
self.dialog_button_push("OK")

def _processReturnKey_main(self, event):
self.buttonbox.invoke()

def dialog_button_push(self, button_name):
"""Executes when the OK or Cancel buttons on the 'load old run' dialog popup
are clicked.
"""
if button_name == 'OK':
self.pass_run = self.pass_run_sel_menu.get_configured_product()
if self.pass_run:
self.pickle_path_entry.set_entry(self.pass_run.get_pickle_path())
self.comment_entry.set_entry(self.pass_run.get_comment())
self.dialog.deactivate(button_name)

def get_entry(self):
"""Return the currently selected pass_run object.
"""
if not self.pass_run:
self.pass_run = mscl_util.mscl_run()
elif ((not self.pass_run.get_pickle_path()
and self.pickle_path_entry.get_entry()
and os.path.isfile(self.pickle_path_entry.get_entry())) or
(os.path.isfile(self.pickle_path_entry.get_entry())
and os.path.isfile(self.pass_run.get_pickle_path())
and not os.path.samefile(self.pickle_path_entry.get_entry(), self.pass_run.get_pickle_path()))):
try:
self.pass_run = configure_util.get_pickled_object(self.pickle_path_entry.get_entry())
except:
errortype, errorvalue, tb = sys.exc_info()
tkMessageBox.showerror("Error loading pickled object",
str(errorvalue))
self.pass_run = mscl_util.mscl_run()
return self.pass_run

def on_lower(self, run_obj):
"""This function runs when this tab is lowered.
"""
entry = self.get_entry()
if entry:
if self.verbose:
print "in pass_default_menu.on_lower, entry==true"
print "comment_entry=", self.comment_entry.get_entry()
print "self.pass_run.pickle_path =", self.pass_run.get_pickle_path()
entry.set_comment(self.comment_entry.get_entry())
return entry
else:
return run_obj

def on_raise(self, run_obj):
"""This function runs when this tab is raised.
"""
if self.verbose:
print "in pass_default_menu.on_raise"
print "pickle_path =", run_obj.get_pickle_path()
self.pass_run = run_obj
self.pickle_path_entry.set_entry(run_obj.get_pickle_path())
self.comment_entry.set_entry(run_obj.get_comment())

if __name__ == '__main__':
root = Tix.Tk()
m = mscl_util.mscl_run()

pass_default_menu(root, m).frame.pack()
root.mainloop()