OpenFiles_2.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. def uploadVHDFile(self):
  2. files = filedialog.askopenfilenames(
  3. initialdir=os.getcwd(),
  4. title="Choose VHD files",
  5. filetypes=(("VHD Files", "*.vhd"),)
  6. )
  7. try:
  8. for tf in files:
  9. if tf == "":
  10. self.tbUploadVar.set("")
  11. return
  12. tf = open(tf) # or tf = open(tf, 'r')
  13. filename = tf.name[tf.name.rfind("/") + 1:len(tf.name)]
  14. # copy file over to tcl locations
  15. if filename.endswith("true_testbench.vhd"):
  16. shutil.copy(tf.name, os.getcwd() + os.path.join("\\testbenches"))
  17. else:
  18. shutil.copy(tf.name, os.getcwd() + os.path.join(f'''\\testbenches\\{filename[0:len(filename)-4]}_true_testbench.vhd''' ))
  19. tf.close()
  20. except:
  21. self.tbUploadLabel.configure(style="Red.TLabel")
  22. self.tbUploadVar.set("An Error Occurred")
  23. return
  24. if len(files) == 1:
  25. # Generate an animation for the result
  26. self.tbUploadLabel.configure(style="Green.TLabel")
  27. self.tbUploadVar.set("Copied " + files[0][files[0].rfind("/") + 1:len(files[0])])
  28. elif len(files) > 1:
  29. self.tbUploadLabel.configure(style="Green.TLabel")
  30. self.tbUploadVar.set("Copied " + str(len(files)) + " Files")
  31. elif len(files) == 0:
  32. self.tbUploadLabel.configure(style="TLabel")
  33. self.tbUploadVar.set("")