/SFACT/fabmetheus_utilities/miscellaneous/nophead/preview.py

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