-
Notifications
You must be signed in to change notification settings - Fork 1
/
Echo_Segmenter_UI_Full.py
120 lines (97 loc) · 3.73 KB
/
Echo_Segmenter_UI_Full.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# -*- coding: utf-8 -*-
"""
Created on 2/3/21
@author: MONTGM11
Echo_Segmenter_UI_Full.py
User interface for automated echocardiography tool. Combines b-mode and m-mode tools
"""
# Import libraries
import tkinter as tk
import tkinter.ttk as ttk
from tkinter import filedialog
from tkinter import messagebox as msg
import os
# Create GUI
window = tk.Tk()
window.title('Echocardiography Segmenter')
window.geometry('900x200')
# Title
appTitle = tk.Label(window,text='Echocardiography Segmenter',font=('calibri',20,'bold'),fg='forest green')
appTitle.grid(column=3,row=0)
# ----------------------- Formatting -----------------------
# Create offset at top and left
offsetBlank = tk.Label(text='',width = 4,height = 2)
offsetBlank.grid(column=0,row=0)
# Create space between rows
blankRow2 = tk.Label(text='',width = 1, height = 1)
blankRow2.grid(column=0,row=2)
blankRow2 = tk.Label(text='',width = 1, height = 1)
blankRow2.grid(column=0,row=4)
blankRow2 = tk.Label(text='',width = 1, height = 1)
blankRow2.grid(column=0,row=6)
blankRow2 = tk.Label(text='',width = 1, height = 1)
blankRow2.grid(column=0,row=8)
blankRow2 = tk.Label(text='',width = 1, height = 1)
blankRow2.grid(column=0,row=12)
# --------------------- Button to select study directory ---------------------
# Define callback
def button1clicked():
# Have user select input file
studyDir.set(filedialog.askdirectory())
studyDirNameDisp.configure(text=studyDir.get(),justify='left')
if len(studyDir.get()) > 0:
print(studyDir.get() + ' selected')
else:
print('No file found')
# Create button, label, and text displaying result
button1Label = tk.Label(window,text='Input Directory:',justify='right',width=20)
button1Label.grid(column=1,row=1)
studyDir = tk.StringVar()
studyDir.set('None Selected')
studyDirNameDisp = tk.Label(window,textvariable=studyDir,font=('arial',8),justify='center',bg='white',width=90)
studyDirNameDisp.grid(column=2,row=1,columnspan=3)
button1 = tk.Button(window,text='Select',command=button1clicked,justify='right',width=10)
button1.grid(column=5,row=1)
# ------------------------ Verbose Check Box ------------------------------
# M-Mode
verbose = tk.BooleanVar()
verbose.set(True)
chk1 = ttk.Checkbutton(window,text='Save QC Results',var=verbose)
chk1.grid(column=3,row=3)
# ----------------------- Run button ----------------------------
def runButtonClicked():
# This runs the main program
print('Running analysis...')
from preprocessing_modes import sort_modes, write_command
# Compose command string to feed into os system
comm1 = 'activate tf-latest'
# If verbose, add flag to commands
if verbose.get():
verboseString = '--verbose '
else:
verboseString = ''
# Parse input directory
runMode = sort_modes(studyDir.get())
# If no data in folder, alert user and exit
if runMode == 'None':
msg.showinfo(message='No Data Found')
return
# If M-Mode data present, add command to run M-Mode analysis.
comm2 = write_command(studyDir.get(),runMode,'M-Mode',verboseString)
# If B-Mode data present, add command to run B-Mode analysis.
comm3 = write_command(studyDir.get(),runMode,'B-Mode',verboseString)
# Combine into 1 command string
commandString = comm1 + comm2 + comm3
# Run the command to start the main program
a = os.system(commandString)
# Update user
if a==0:
cmpltMsg = 'Analysis Complete!'
else:
cmpltMsg = 'There was an issue with this run. CMD error code: ' + str(a)
print(cmpltMsg)
msg.showinfo(message=cmpltMsg)
runButton = tk.Button(window,text='Run',font=('Arial',18),command=runButtonClicked)
runButton.grid(column=3,row=5)
# Main
window.mainloop()