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

Поисковые слова: п п р п р п р п р п р п р п р п р п
#MODULE PRD_input_Selection_menu
#
#***********************************************************************
"""

**PURPOSE** --
Creates a menu for selecting PRD files from a given
input directory.



**DEVELOPER** --
K. Clark

**MODIFICATION HISTORY** --

o Initial implementation 8/14/02
o Added browse button 1/26/04 KWC.
o Modified 5/13/04 KWC - Allow Browse_dir to be a list.
o Modified 5/18/04 KWC - Added Update_Browse_list method.
"""
#***********************************************************************
import Tix
from Tkconstants import *

from Tkinter import *
import Pmw
import os

import PRD_input_Checklist_widget

__version__ = " 5/18/04"

class PRD_input_Selection_menu:

def __init__ (self, aframe, Browse_dir, comment1, comment2,
file_type=None):
"""
Constructor.
"""

# Create storage for the browse directory.
self.val = StringVar()

# Create a new frame for the File Selection Menu.
self.frame = Frame (aframe)

# Create an entry widget for specifying the directory name.
Dir_entry = self.Dir_entry_menu(self.frame, Browse_dir, comment1)
Dir_entry.pack()

# Create the Tix Checklist widget to select the files to be used.
self.file_Checklist = PRD_input_Checklist_widget.PRD_input_Checklist_widget(
self.frame, comment2, file_type)
self.file_Checklist.pack (expand=1, fill='both', padx=4, pady=4)

# Initial population of the file Checklist menu.
self.file_Checklist.Update(self.val.get())

def Dir_entry_menu (self, aframe, Browse_dir, comment):
"""
Input directory widget.
"""
bframe = Frame(aframe)

# Define the directory to be searched.
self.val.set(Browse_dir)

self.Dir_entry = Tix.ComboBox(bframe, history=1, editable=1,
label=comment)
self.Dir_entry.label.pack(side='top')
self.Dir_entry.entry.configure(width=80)

# Erase the entry widget when Control-u entered.
self.Dir_entry.entry.bind ('', self.Clear_Dir_entry_menu)

self.Dir_entry.configure(variable=self.val)

# Populate the widget with a single or multiple entries.
self.Update_Browse_list(Browse_dir)

# Update the file Checklist menu when entered.
self.Dir_entry.configure (command=self.Update_Checklist)

self.Dir_entry.pack(side='left')

# Create a browse box to find the directory.
self.Dir_browse = self.Dir_browse_box(bframe)
self.Dir_browse.pack(side='right')

return bframe

def Dir_browse_box(self, aframe):
""" Creates a directory browse dialog box for searching directories.
"""
# Create a directory browse dialog box.
Dir_browse = spss_dir_dialog('')
Dir_browse.dirbox.config(value=self.val.get())
Dir_browse.config(command=self.Update_Dir_entry)

Browse_btn = Button(aframe, text='Browse ...',
command=Dir_browse.popup)
return Browse_btn

def Update_Browse_list (self, Browse_list):
"""
Handles a list of browse directories.
"""
if (type(Browse_list) == type([])):
for dir in Browse_list:
self.Update_Dir_entry(dir)
else:
self.Update_Dir_entry(Browse_list)

def Update_Dir_entry (self, path):
"""
Update the file Dir_entry widget with a new directory name.
"""
# Define the directory to be searched.
self.val.set(os.path.abspath(os.path.expanduser(path)))

self.Dir_entry.append_history(path)

def Clear_Dir_entry_menu (self, event):
"""
Clear the input directory widget.
"""
event.widget.delete(0,'end')

def Update_Checklist (self, event=None):
"""
Update the file Checklist menu with a list of files from the
specified directory.
"""
self.file_Checklist.Update (self.val.get())

def get_Checklist_dict (self):
"""
Returns a list of file(s) that have been selected for use on the
Checklist menu.
"""
return self.file_Checklist.val

def set_Checklist_dict(self, dict):
self.file_Checklist.val.set_selections(dict)

class spss_dir_dialog(Tix.DirSelectDialog):
"""Add focus grabbing capability to the Tix.DirSelectDialog widget.
"""
def __init__(self, master, cnf={}, **kw):
"""Constructor.
"""
Tix.DirSelectDialog.__init__(self, master, cnf, **kw)
# ok and cancel do the same thing
self.ok.config(command=self.popdownok)
self.cancel.config(command=self.popdowncanc)
self.popped_up = 0

def popup(self):
"""Call this when the directory selection widget is
brought up.
"""
Tix.DirSelectDialog.popup(self)
Pmw.pushgrab(self, 0, None)
self.popped_up = 1

def popdownok(self):
"""Call this when you want to get rid of the directory
selection widget.
"""
if self.popped_up:
Tix.DirSelectDialog.popdown(self)
# Have to call parent widget update to get selection.
self.tk.call(self.dirbox.dircbx, 'invoke')
Pmw.popgrab(self)
self.popped_up = 0

def popdowncanc(self):
"""Call this when you want to get rid of the directory
selection widget.
"""
if self.popped_up:
Tix.DirSelectDialog.popdown(self)
Pmw.popgrab(self)
self.popped_up = 0