Papermind

gcode viewer

Apr 28th, 2019
1,404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.47 KB | None | 0 0
  1.  
  2. import Tkinter, tkFileDialog, tkSimpleDialog, time, serial, turtle
  3.  
  4. from ScrolledText import ScrolledText
  5.  
  6. from tkFileDialog import askopenfilename
  7.  
  8. from tkSimpleDialog import*
  9.  
  10. from Tkinter import*
  11.  
  12.  
  13. root = Tk()
  14.  
  15. myFrame = Frame(root) #Frame(root, width = 800, height = 500)
  16.  
  17. myFrame.master.title("G-code Viewer")
  18.  
  19. myFrame.pack()
  20.  
  21.  
  22. def openfile():
  23.  
  24. filename = askopenfilename(filetypes=[("all files", "*")])
  25.  
  26. myFile = open(filename)
  27.  
  28. teks=ScrolledText(root)
  29.  
  30. Filereadlines = myFile.readlines()
  31.  
  32. turtle.title("Visual G-code Viewer")
  33.  
  34. for x in range(0,len(Filereadlines)):
  35.  
  36. data = Filereadlines[x]
  37.  
  38. splitspc = data.split(' ')
  39.  
  40. lensplit = len(splitspc)
  41.  
  42. if lensplit > 3:
  43.  
  44. splitX = splitspc[1].split('X')
  45.  
  46. splitY = splitspc[2].split('Y')
  47.  
  48. if splitspc[0] == 'M03':
  49.  
  50. turtle.down()
  51.  
  52. elif splitspc[0] == 'M04':
  53.  
  54. turtle.up()
  55.  
  56. elif splitspc[0] == 'M18':
  57.  
  58. turtle.up()
  59.  
  60. print "Done"
  61.  
  62.  
  63. if splitspc[0] == 'G1':
  64.  
  65. try:
  66.  
  67. print "grab"
  68.  
  69. print float(splitX[1])
  70.  
  71. print float(splitY[1])
  72.  
  73. turtle.goto(float(splitX[1]), float(splitY[1]))
  74.  
  75. except IndexError as e:
  76.  
  77. print "print gagal karena", e
  78.  
  79. else:
  80.  
  81. print "????"
  82.  
  83. time.sleep(0.1)
  84.  
  85. myFile.close()
  86.  
  87. teks.pack(expand = YES, fill = X)#(side=LEFT, expand = YES, fill = Y)
  88.  
  89.  
  90. Button(root, text="Quit", command=root.destroy).pack(side = BOTTOM, expand = YES, fill = X)
  91.  
  92. Button(root, text='Browse file', command=openfile).pack(side = BOTTOM, expand = YES, fill = X)
  93.  
  94. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment