PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/skein_engines/skeinforge-0006/skeinforge_tools/analyze.py

https://github.com/nmsl1993/ReplicatorG
Python | 87 lines | 69 code | 7 blank | 11 comment | 0 complexity | f14a4b10f97d9a40ba613808119dc7da MD5 | raw file
  1. """
  2. Analyze is a script to access the plugins which analyze a gcode file.
  3. An explanation of the gcodes is at:
  4. http://reprap.org/bin/view/Main/Arduino_GCode_Interpreter
  5. A gode example is at:
  6. http://forums.reprap.org/file.php?12,file=565
  7. """
  8. from __future__ import absolute_import
  9. #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.
  10. import __init__
  11. from skeinforge_tools.skeinforge_utilities import gcodec
  12. from skeinforge_tools.skeinforge_utilities import preferences
  13. from skeinforge_tools import polyfile
  14. import cStringIO
  15. import os
  16. import sys
  17. __author__ = "Enrique Perez (perez_enrique@yahoo.com)"
  18. __date__ = "$Date: 2008/21/04 $"
  19. __license__ = "GPL 3.0"
  20. def getAnalyzePluginFilenames():
  21. "Get analyze plugin fileNames."
  22. return gcodec.getPluginFilenames( 'analyze_plugins', __file__ )
  23. def writeOutput( fileName = '', gcodeText = '' ):
  24. "Analyze a gcode file. If no fileName is specified, comment the first gcode file in this folder that is not modified."
  25. if fileName == '':
  26. unmodified = gcodec.getUncommentedGcodeFiles()
  27. if len( unmodified ) == 0:
  28. print( "There is no gcode file in this folder that is not a comment file." )
  29. return
  30. fileName = unmodified[ 0 ]
  31. if gcodeText == '':
  32. gcodeText = gcodec.getFileText( fileName )
  33. analyzePluginFilenames = getAnalyzePluginFilenames()
  34. for analyzePluginFilename in analyzePluginFilenames:
  35. pluginModule = gcodec.getModule( analyzePluginFilename, 'analyze_plugins', __file__ )
  36. if pluginModule != None:
  37. pluginModule.writeOutput( fileName, gcodeText )
  38. class AnalyzePreferences:
  39. "A class to handle the analyze preferences."
  40. def __init__( self ):
  41. "Set the default preferences, execute title & preferences fileName."
  42. #Set the default preferences.
  43. self.archive = []
  44. self.analyzeLabel = preferences.LabelDisplay().getFromName( 'Open Preferences: ' )
  45. self.archive.append( self.analyzeLabel )
  46. analyzePluginFilenames = getAnalyzePluginFilenames()
  47. self.analyzePlugins = []
  48. for analyzePluginFilename in analyzePluginFilenames:
  49. analyzePlugin = preferences.DisplayToolButton().getFromFolderName( 'analyze_plugins', __file__, analyzePluginFilename )
  50. self.analyzePlugins.append( analyzePlugin )
  51. # self.analyzePlugins.sort( key = preferences.RadioCapitalized.getLowerName )
  52. self.archive += self.analyzePlugins
  53. self.fileNameInput = preferences.Filename().getFromFilename( [ ( 'Gcode text files', '*.gcode' ) ], 'Open File to be Analyzed', '' )
  54. self.archive.append( self.fileNameInput )
  55. #Create the archive, title of the execute button, title of the dialog & preferences fileName.
  56. self.executeTitle = 'Analyze'
  57. self.saveTitle = None
  58. preferences.setHelpPreferencesFileNameTitleWindowPosition( self, 'skeinforge_tools.analyze.html' )
  59. def execute( self ):
  60. "Analyze button has been clicked."
  61. fileNames = polyfile.getFileOrDirectoryTypesUnmodifiedGcode( self.fileNameInput.value, [], self.fileNameInput.wasCancelled )
  62. for fileName in fileNames:
  63. writeOutput( fileName )
  64. def main( hashtable = None ):
  65. "Display the analyze dialog."
  66. if len( sys.argv ) > 1:
  67. writeOutput( ' '.join( sys.argv[ 1 : ] ) )
  68. else:
  69. preferences.displayDialog( AnalyzePreferences() )
  70. if __name__ == "__main__":
  71. main()