home *** CD-ROM | disk | FTP | other *** search
/ PC Extra 07 & 08 / pca1507.iso / Software / psp8 / Data1.cab / tkFileDialog.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-04-22  |  4.4 KB  |  89 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. from tkCommonDialog import Dialog
  5.  
  6. class _Dialog(Dialog):
  7.     
  8.     def _fixoptions(self):
  9.         
  10.         try:
  11.             self.options['filetypes'] = tuple(self.options['filetypes'])
  12.         except KeyError:
  13.             pass
  14.  
  15.  
  16.     
  17.     def _fixresult(self, widget, result):
  18.         if result:
  19.             import os
  20.             (path, file) = os.path.split(result)
  21.             self.options['initialdir'] = path
  22.             self.options['initialfile'] = file
  23.         
  24.         self.filename = result
  25.         return result
  26.  
  27.  
  28.  
  29. class Open(_Dialog):
  30.     '''Ask for a filename to open'''
  31.     command = 'tk_getOpenFile'
  32.  
  33.  
  34. class SaveAs(_Dialog):
  35.     '''Ask for a filename to save as'''
  36.     command = 'tk_getSaveFile'
  37.  
  38.  
  39. class Directory(Dialog):
  40.     '''Ask for a directory'''
  41.     command = 'tk_chooseDirectory'
  42.     
  43.     def _fixresult(self, widget, result):
  44.         if result:
  45.             self.options['initialdir'] = result
  46.         
  47.         self.directory = result
  48.         return result
  49.  
  50.  
  51.  
  52. def askopenfilename(**options):
  53.     '''Ask for a filename to open'''
  54.     return Open(**options).show()
  55.  
  56.  
  57. def asksaveasfilename(**options):
  58.     '''Ask for a filename to save as'''
  59.     return SaveAs(**options).show()
  60.  
  61.  
  62. def askopenfile(mode = 'r', **options):
  63.     '''Ask for a filename to open, and returned the opened file'''
  64.     filename = Open(**options).show()
  65.     if filename:
  66.         return open(filename, mode)
  67.     
  68.     return None
  69.  
  70.  
  71. def asksaveasfile(mode = 'w', **options):
  72.     '''Ask for a filename to save as, and returned the opened file'''
  73.     filename = SaveAs(**options).show()
  74.     if filename:
  75.         return open(filename, mode)
  76.     
  77.     return None
  78.  
  79.  
  80. def askdirectory(**options):
  81.     '''Ask for a directory, and return the file name'''
  82.     return Directory(**options).show()
  83.  
  84. if __name__ == '__main__':
  85.     print 'open', askopenfilename(filetypes = [
  86.         ('all filez', '*')])
  87.     print 'saveas', asksaveasfilename()
  88.  
  89.