chiark / gitweb /
Move SF into its own directory, to seperate SF and Cura. Rename newui to gui.
[cura.git] / Cura / cura_sf / skeinforge_application / skeinforge_utilities / skeinforge_polyfile.py
1 """
2 Polyfile is a script to choose whether the skeinforge toolchain will operate on one file or all the files in a directory.
3
4 """
5
6 from __future__ import absolute_import
7 #Init has to be imported first because it has code to workaround the python bug where relative imports don't work if the module is imported as a main module.
8 import __init__
9
10 from fabmetheus_utilities import archive
11 from fabmetheus_utilities import settings
12 from skeinforge_application.skeinforge_utilities import skeinforge_profile
13
14
15 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
16 __date__ = '$Date: 2008/21/04 $'
17 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
18
19
20 def getFileOrDirectoryTypes( fileName, fileTypes, wasCancelled ):
21         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
22         if isEmptyOrCancelled( fileName, wasCancelled ):
23                 return []
24         if isDirectorySetting():
25                 return archive.getFilesWithFileTypesWithoutWords( fileTypes, [], fileName )
26         return [ fileName ]
27
28 def getFileOrDirectoryTypesUnmodifiedGcode(fileName, fileTypes, wasCancelled):
29         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
30         if isEmptyOrCancelled(fileName, wasCancelled):
31                 return []
32         if isDirectorySetting():
33                 return archive.getFilesWithFileTypesWithoutWords(fileTypes, [], fileName)
34         return [fileName]
35
36 def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
37         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
38         if isEmptyOrCancelled( fileName, wasCancelled ):
39                 return []
40         if isDirectorySetting():
41                 dotIndex = fileName.rfind('.')
42                 if dotIndex < 0:
43                         print('The file name should have a suffix, like myfile.xml.')
44                         print('Since the file name does not have a suffix, nothing will be done')
45                 suffix = fileName[ dotIndex + 1 : ]
46                 return archive.getFilesWithFileTypeWithoutWords( suffix, words, fileName )
47         return [ fileName ]
48
49 def getNewRepository():
50         'Get new repository.'
51         return PolyfileRepository()
52
53 def isDirectorySetting():
54         "Determine if the directory setting is true."
55         return settings.getReadRepository( PolyfileRepository() ).directorySetting.value
56
57 def isEmptyOrCancelled( fileName, wasCancelled ):
58         "Determine if the fileName is empty or the dialog was cancelled."
59         return str(fileName) == '' or str(fileName) == '()' or wasCancelled
60
61
62 class PolyfileRepository:
63         "A class to handle the polyfile settings."
64         def __init__(self):
65                 "Set the default settings, execute title & settings fileName."
66                 skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_utilities.skeinforge_polyfile.html', self)
67                 self.directoryOrFileChoiceLabel = settings.LabelDisplay().getFromName('Directory or File Choice: ', self )
68                 directoryLatentStringVar = settings.LatentStringVar()
69                 self.directorySetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute All Unmodified Files in a Directory', self, False )
70                 self.fileSetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute File', self, True )