Skip to content

Commit

Permalink
Merge pull request #170 from alanphys/filewrite
Browse files Browse the repository at this point in the history
fix pygui overwriting results
  • Loading branch information
jrkerns committed Mar 28, 2019
2 parents f5268d1 + 8148741 commit d3d9706
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions pylinac/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import subprocess
import struct
from typing import Union, Sequence
from datetime import datetime

import pydicom
import numpy as np
Expand Down Expand Up @@ -196,3 +197,12 @@ def open_path(path: str):
elif os.name == 'nt':
launcher = "explorer"
subprocess.call([launcher, path])


def file_exists(filename: str):
"""Check if the file exists and if it does add a timestamp"""
if osp.exists(filename):
filename, ext = osp.splitext(filename)
mytime = datetime.now().strftime("%Y%m%d%H%M%S")
filename = filename + mytime + ext
return filename
9 changes: 8 additions & 1 deletion pylinac/py_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def analyze_vmat():
v = vmat.DRMLC(image_paths=images)
v.analyze(tolerance=self.vmat_tol.get())
fname = osp.join(self.vmat_dmlcimg.get().replace('.dcm', '.pdf'))
fname = utilities.file_exists(fname)
v.publish_pdf(fname)
self.vmat_pdf.set(fname)
utilities.open_path(fname)
Expand Down Expand Up @@ -152,6 +153,7 @@ def analyze_pf():
num_pickets=pickets,
)
fname = osp.join(self.pf_file.get().replace('.dcm', '.pdf'))
fname = utilities.file_exists(fname)
pf.publish_pdf(fname)
self.pf_pdf.set(fname)
utilities.open_path(fname)
Expand Down Expand Up @@ -200,6 +202,7 @@ def analyze_cbct():
fname = self.ct_file.get().replace('.zip', '.pdf')
cat.analyze(hu_tolerance=self.ct_hu.get(), thickness_tolerance=self.ct_thickness.get(),
scaling_tolerance=self.ct_scaling.get())
fname = utilities.file_exists(fname)
cat.publish_pdf(fname)
self.ct_pdf.set(fname)
utilities.open_path(fname)
Expand Down Expand Up @@ -243,6 +246,7 @@ def analyze_log():
log = log_analyzer.load_log(self.log_file.get())
name, _ = osp.splitext(self.log_file.get())
fname = name + '.pdf'
fname = utilities.file_exists(fname)
log.publish_pdf(fname)
self.log_pdf.set(fname)
utilities.open_path(fname)
Expand Down Expand Up @@ -275,6 +279,7 @@ def analyze_star():
recursive=self.star_recursive.get())
name, _ = osp.splitext(self.star_file.get())
fname = name + '.pdf'
fname = utilities.file_exists(fname)
star.publish_pdf(fname)
self.star_pdf.set(fname)
utilities.open_path(fname)
Expand Down Expand Up @@ -319,7 +324,8 @@ def analyze_phan():
phantom.analyze()
name, _ = osp.splitext(self.phan_file.get())
fname = name + '.pdf'
phantom.publish_pdf(fname)
fname = utilities.file_exists(fname)
phantom.publish_pdf(utilities.file_exists(fname))
self.phan_pdf.set(fname)
utilities.open_path(fname)

Expand Down Expand Up @@ -366,6 +372,7 @@ def analyze_wl():
else:
wl = winston_lutz.WinstonLutz.from_zip(self.wl_file.get())
fname = self.wl_file.get().replace('.zip', '.pdf')
fname = utilities.file_exists(fname)
wl.publish_pdf(fname)
self.wl_pdf.set(fname)
utilities.open_path(fname)
Expand Down

0 comments on commit d3d9706

Please sign in to comment.