chiark / gitweb /
Add back the ultimaker platform, and made the platform mesh simpler.
[cura.git] / Cura / slice / 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
8 from fabmetheus_utilities import archive
9 from fabmetheus_utilities import settings
10 from skeinforge_application.skeinforge_utilities import skeinforge_profile
11
12
13 __author__ = 'Enrique Perez (perez_enrique@yahoo.com)'
14 __date__ = '$Date: 2008/21/04 $'
15 __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
16
17
18 def getFileOrDirectoryTypes( fileName, fileTypes, wasCancelled ):
19         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
20         if isEmptyOrCancelled( fileName, wasCancelled ):
21                 return []
22         if isDirectorySetting():
23                 return archive.getFilesWithFileTypesWithoutWords( fileTypes, [], fileName )
24         return [ fileName ]
25
26 def getFileOrDirectoryTypesUnmodifiedGcode(fileName, fileTypes, wasCancelled):
27         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
28         if isEmptyOrCancelled(fileName, wasCancelled):
29                 return []
30         if isDirectorySetting():
31                 return archive.getFilesWithFileTypesWithoutWords(fileTypes, [], fileName)
32         return [fileName]
33
34 def getFileOrGcodeDirectory( fileName, wasCancelled, words = [] ):
35         "Get the gcode files in the directory the file is in if directory setting is true.  Otherwise, return the file in a list."
36         if isEmptyOrCancelled( fileName, wasCancelled ):
37                 return []
38         if isDirectorySetting():
39                 dotIndex = fileName.rfind('.')
40                 if dotIndex < 0:
41                         print('The file name should have a suffix, like myfile.xml.')
42                         print('Since the file name does not have a suffix, nothing will be done')
43                 suffix = fileName[ dotIndex + 1 : ]
44                 return archive.getFilesWithFileTypeWithoutWords( suffix, words, fileName )
45         return [ fileName ]
46
47 def getNewRepository():
48         'Get new repository.'
49         return PolyfileRepository()
50
51 def isDirectorySetting():
52         "Determine if the directory setting is true."
53         return settings.getReadRepository( PolyfileRepository() ).directorySetting.value
54
55 def isEmptyOrCancelled( fileName, wasCancelled ):
56         "Determine if the fileName is empty or the dialog was cancelled."
57         return str(fileName) == '' or str(fileName) == '()' or wasCancelled
58
59
60 class PolyfileRepository(object):
61         "A class to handle the polyfile settings."
62         def __init__(self):
63                 "Set the default settings, execute title & settings fileName."
64                 skeinforge_profile.addListsToCraftTypeRepository('skeinforge_application.skeinforge_utilities.skeinforge_polyfile.html', self)
65                 self.directoryOrFileChoiceLabel = settings.LabelDisplay().getFromName('Directory or File Choice: ', self )
66                 directoryLatentStringVar = settings.LatentStringVar()
67                 self.directorySetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute All Unmodified Files in a Directory', self, False )
68                 self.fileSetting = settings.Radio().getFromRadio( directoryLatentStringVar, 'Execute File', self, True )