/Program_Files/replicatorg-0025/skein_engines/skeinforge-0006/skeinforge_tools/analyze_plugins/analyze_utilities/preview.py

https://github.com/sialan/autonomous-sprayer
Python | 70 lines | 60 code | 8 blank | 2 comment | 9 complexity | 8793f69cd7fe1e1b779f6599f15c1d67 MD5 | raw file
  1. from __future__ import absolute_import
  2. import sys
  3. try:
  4. import Tkinter
  5. except:
  6. print( 'You do not have Tkinter, which is needed for the graphical interface.' )
  7. print( 'Information on how to download Tkinter is at:\nwww.tcl.tk/software/tcltk/' )
  8. try:
  9. from skeinforge_tools.analyze_plugins.analyze_utilities.layers import *
  10. from skeinforge_tools.analyze_plugins.analyze_utilities.gRead import *
  11. import ImageTk
  12. except:
  13. print( 'You do not have the Python Imaging Library, which is needed by preview and gifview to view the gcode.' )
  14. print( 'The Python Imaging Library can be downloaded from:\nwww.pythonware.com/products/pil/' )
  15. class Preview:
  16. def __init__(self, layers):
  17. self.images = make_images(layers)
  18. self.index = 0
  19. size = self.images[0].size
  20. self.root = Tkinter.Tk()
  21. self.root.title("Gifscene from HydraRaptor")
  22. frame = Tkinter.Frame(self.root)
  23. frame.pack()
  24. self.canvas = Tkinter.Canvas(frame, width = size[0], height = size[1])
  25. self.canvas.pack()
  26. self.canvas.config(scrollregion=self.canvas.bbox(Tkinter.ALL))
  27. self.exit_button = Tkinter.Button(frame, text = "Exit", fg = "red", command = frame.quit)
  28. self.exit_button.pack(side=Tkinter.RIGHT)
  29. self.down_button = Tkinter.Button(frame, text = "Down", command = self.down)
  30. self.down_button.pack(side=Tkinter.LEFT)
  31. self.up_button = Tkinter.Button(frame, text = "Up", command = self.up)
  32. self.up_button.pack(side=Tkinter.LEFT)
  33. self.update()
  34. self.root.mainloop()
  35. def update(self):
  36. # FIXME: Somehow this fails if this is launched using the Preferences,
  37. # but works from the command-line.
  38. self.image = ImageTk.PhotoImage(self.images[self.index])
  39. self.canvas.create_image(0,0, anchor= Tkinter.NW, image = self.image)
  40. if self.index < len(self.images) - 1:
  41. self.up_button.config(state = Tkinter.NORMAL)
  42. else:
  43. self.up_button.config(state = Tkinter.DISABLED)
  44. if self.index > 0:
  45. self.down_button.config(state = Tkinter.NORMAL)
  46. else:
  47. self.down_button.config(state = Tkinter.DISABLED)
  48. def up(self):
  49. self.index += 1
  50. self.update()
  51. def down(self):
  52. self.index -= 1
  53. self.update()
  54. def viewGif( fileName, gcodeText = '' ):
  55. layers = []
  56. try:
  57. gRead(fileName, layers, gcodeText)
  58. Preview(layers)
  59. except Exception, why:
  60. print( 'Preview failed: ' + str( why ) )
  61. if __name__ == "__main__":
  62. viewGif( ' '.join( sys.argv[ 1 : ] ) )