Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.stsci.edu/spst/UnixTransition/doc/abstract_check.py
Дата изменения: Fri Apr 8 12:46:10 2016
Дата индексирования: Mon Apr 11 02:10:46 2016
Кодировка:
#
#MODULE abstract_check
#
#***********************************************************************
"""

**PURPOSE** --
This module contains the abstract check class. Methods and
attributes common all checklist checks go here.

**DEVELOPER** --
Don Chance

**MODIFICATION HISTORY** --

o Initial implementation 9/21/00
o Filter out null characters from self.outfile. Must be done
until null characters are removed from the esm file. drc 2/5/02
o Remove previous fix. drc 11/07/02
o Modified for python 2.2 compatibility. drc 5/23/03
o fix button coloring problem. drc 12/7/15
"""
#***********************************************************************
from checklist_init import UNKNOWN, PASS, FAIL
import os
import spss_tk_util
if spss_tk_util.GUI_AVAILABLE:
from Tkinter import Checkbutton, IntVar, Label, Button, W, E, NORMAL, DISABLED
from Tkinter import TOP, X, RIGHT, LEFT, Toplevel, Frame, YES, Y, BOTH, RAISED
from Tkinter import BOTTOM, Scrollbar, Text


class abstract_check:
"""An abstract class for calendar/SMS checks.
"""
def __init__(self, my_checklist):
self.pf_status = UNKNOWN
self.my_checklist = my_checklist
self.outfile = os.path.join(self.my_checklist.outdir,
(self.my_checklist.calendar.get_name().lower()
+ "_" + self.__class__.__name__ + ".out"))
self.has_been_run = 0

def __getstate__(self):
"""Special method used when pickling this object.

Copies __dict__, but excludes all unpicklable values.
"""
state_dict = {}
for key in self.__dict__.keys():
# Exclude all Tkinter objects as they cannot be pickled
if key not in ['gui_pf_status',
'buttonReview',
'buttonRunCheck',
'review_window',
'checkbuttonPassItem',
'checkbuttonFailItem']:
state_dict[key] = self.__dict__[key]
return state_dict

def __str__(self):
return self.__doc__.rstrip()

def __setattr__(self, name, value):
# Keep pf_status and gui_pf_status in sync
if name == 'pf_status' and 'gui_pf_status' in self.__dict__:
self.__dict__['gui_pf_status'].set(value)
self.__dict__[name] = value

def run(self):
"""The code that actually runs the check.

Must return either PASS, FAIL, or UNKNOWN
"""
self.has_been_run = True
return UNKNOWN

def pack(self, my_frame, check_no):
if not spss_tk_util.GUI_AVAILABLE:
return
# Pass/fail buttons
self.gui_pf_status = IntVar()
self.gui_pf_status.set(self.pf_status)
self.checkbuttonPassItem = Checkbutton(my_frame,
variable=self.gui_pf_status,
onvalue=PASS,
offvalue=UNKNOWN,
command=self.gui_set_pf_status)
self.checkbuttonFailItem = Checkbutton(my_frame,
variable=self.gui_pf_status,
onvalue=FAIL,
offvalue=UNKNOWN,
command=self.gui_set_pf_status)

# Check name and number
labelCalCheck = Label(my_frame,
anchor=W,
text="%2i. %s" % (check_no, str(self)))

# Run and review buttons
self.buttonRunCheck = Button(my_frame,
anchor=E,
width=13,
state=NORMAL,
disabledforeground='gray',
text="Run check %i" % check_no,
command=self.gui_run)
if self.has_been_run:
review_button_state = NORMAL
else:
review_button_state = DISABLED
self.buttonReview = Button(my_frame,
anchor=E,
width=7,
disabledforeground='gray',
state=review_button_state,
text="Review",
command=self.review_check_gui)

# Pack the labels and buttons. The -padx is used on the check button PassItem
# to line up the check buttons with the "Pass Fail" label in the header.
my_frame.pack(side=TOP, anchor=W, fill=X)
self.checkbuttonPassItem.pack(side=LEFT, padx=2)
self.checkbuttonFailItem.pack(side=LEFT)
labelCalCheck.pack(side=LEFT)
self.buttonReview.pack(side=RIGHT)
self.buttonRunCheck.pack(side=RIGHT)

def gui_run(self):
self.buttonReview["state"] = DISABLED
self.buttonRunCheck["state"] = DISABLED
self.my_checklist.root.update()
self.run()
self.buttonReview["state"] = NORMAL
self.buttonRunCheck["state"] = NORMAL

def gui_set_pf_status(self):
# Note that a regular Python variable cannot be linked to a
# tkinter button. So, I need a special tkinter.IntVar variable,
# gui_pf_status, to link with the Pass/Fail buttons, but I want
# it synced up with the normal variable, pf_status. That syncing
# up is what I'm doing below.
#self.__dict__['pf_status'] = self.gui_pf_status.get()
self.pf_status = self.gui_pf_status.get()
if self.pf_status == PASS:
self.checkbuttonPassItem.config(selectcolor='green')
self.checkbuttonFailItem.config(selectcolor='white')
elif self.pf_status == FAIL:
self.checkbuttonFailItem.config(selectcolor='red')
self.checkbuttonPassItem.config(selectcolor='white')
else:
self.checkbuttonPassItem.config(selectcolor='white')
self.checkbuttonFailItem.config(selectcolor='white')

def review_check_gui(self):
self.buttonReview["state"] = DISABLED
self.buttonRunCheck["state"] = DISABLED

self.review_window = Toplevel()

bottom = Frame(self.review_window, borderwidth=10)
top = Frame(self.review_window)
b1 = Button(bottom, text="Exit", command=self.kill_result_box_gui)
bpass = Checkbutton(bottom,
text="Pass",
variable=self.gui_pf_status,
onvalue=PASS,
offvalue=UNKNOWN,
command=self.gui_set_pf_status)
bfail = Checkbutton(bottom,
text="Fail",
variable=self.gui_pf_status,
onvalue=FAIL,
offvalue=UNKNOWN,
command=self.gui_set_pf_status)
# Create textbox and scrollbar
scroll = Scrollbar(top)
msg = Text(top,
bd=2,
relief=RAISED,
yscrollcommand=scroll.set,
setgrid=YES)
scroll['command'] = msg.yview

bottom.pack(side=BOTTOM)
top.pack(side=TOP, expand=YES, fill=BOTH)
bpass.pack(side=LEFT)
bfail.pack(side=LEFT)
b1.pack(side=LEFT)
scroll.pack(side=RIGHT, fill=Y)
msg.pack(side=LEFT, expand=YES, fill=BOTH)

# Insert the output file into the review textbox
msg.insert("1.0", open(self.outfile).read())

self.review_window.title("Output file " + self.outfile)

def kill_result_box_gui(self):
self.review_window.destroy()
self.buttonReview["state"] = NORMAL
self.buttonRunCheck["state"] = NORMAL