#
#   Python GUI - File selection dialogs - Macintosh version
#

from EasyDialogs import AskFileForOpen, AskFileForSave
from Files import FileRef

def request_old_file(prompt = "Open File", default_dir = None):
    """Present a dialog requesting the name of an existing file.
    Returns a FileRef or None."""

    if prompt.endswith(":"):
        prompt = prompt[:-1]
    if default_dir:
        default_dir_path = default_dir.path
    else:
        default_dir_path = None
    result = AskFileForOpen(windowTitle = prompt,
        defaultLocation = default_dir_path, wanted = str)
    if result:
        return FileRef(path = result)
    else:
        return None

def request_new_file(prompt = "Save File", default_dir = None,
        default_name = ""):
    """Present a dialog requesting the name of
    an existing file. Returns a FileRef
    or None."""

    if prompt.endswith(":"):
        prompt = prompt[:-1]
    if default_dir:
        default_dir_path = default_dir.path
    else:
        default_dir_path = None
    result = AskFileForSave(message = prompt, savedFileName = default_name,
        windowTitle = prompt, defaultLocation = default_dir_path, wanted = str)
    if result:
        return FileRef(path = result)
    else:
        return None

#-----------------------------------------------------------------

#if __name__ == "__main__":
#	result = request_old_file_name()
#	print "Result:", result
