-
Notifications
You must be signed in to change notification settings - Fork 3
/
dcmcleanup.py
165 lines (141 loc) · 6.09 KB
/
dcmcleanup.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'dcmcleanup.ui'
#
# Created: Tue Feb 24 10:05:31 2015
# by: PyQt4 UI code generator 4.11
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
import os
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_CleanUpDialog(object):
dcmdirs = []
numcheckboxes = 0
def setupUi(self, Dialog, inputdir):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(400, 300)
self.verticalLayout_2 = QtGui.QVBoxLayout(Dialog)
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.label = QtGui.QLabel(Dialog)
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout.addWidget(self.label)
if not os.path.exists(inputdir):
inputdir = str(
os.path.dirname(os.path.realpath(os.path.abspath(__file__))))
files = os.listdir(inputdir)
print files
self.dcmdirs = [
f for f in files if f.endswith('.dcm') or f.endswith('.nii')]
print self.dcmdirs
indx = 0
if self.dcmdirs:
print "Creating check boxes"
for outdir in self.dcmdirs:
print "Creating check box ", outdir
# if os.path.exists(outdir):
# print "Creating check box ", outdir
try:
cmdline = "self.checkBox_" + \
str(indx) + " = QtGui.QCheckBox(Dialog);"
exec(cmdline) # , "<string>", "exec")
cmdline = "self.checkBox_" + \
str(indx) + ".setObjectName(_fromUtf8(\"checkbox\"));"
exec(cmdline) # , "<string>", "exec")
cmdline = "self.verticalLayout.addWidget(self.checkBox_" + str(
indx) + ")"
exec(cmdline) # , "<string>", "exec")
except SyntaxError:
print cmdline
print "Syntax Error in retranslateUi"
print cmdline
#compile(cmdline, "<string>", "exec")
indx = indx + 1
self.numcheckboxes = indx
# self.checkBox_2 = QtGui.QCheckBox(Dialog)
# self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
# self.verticalLayout.addWidget(self.checkBox_2)
spacerItem = QtGui.QSpacerItem(
20, 40, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
self.verticalLayout.addItem(spacerItem)
self.verticalLayout_2.addLayout(self.verticalLayout)
self.buttonBox = QtGui.QDialogButtonBox(Dialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(
QtGui.QDialogButtonBox.Cancel | QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Help)
self.buttonBox.setObjectName(_fromUtf8("buttonBox"))
self.verticalLayout_2.addWidget(self.buttonBox)
self.retranslateUi(Dialog)
QtCore.QObject.connect(
self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), Dialog.accept)
QtCore.QObject.connect(
self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
QtCore.QObject.connect(
self.buttonBox, QtCore.SIGNAL(_fromUtf8("helpRequested()")), Dialog.help)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(
_translate("Dialog", "Agilent2Dicom Clean up", None))
self.label.setText(
_translate("Dialog", "Delete existing DICOM folders", None))
indx = 0
for outdir in self.dcmdirs:
try:
if eval('self.checkBox_' + str(indx)):
cmdline = 'self.checkBox_' + \
str(indx) + \
'.setText(_translate("Dialog", str(outdir), None))'
print cmdline
exec(cmdline) # , "<string>", "exec")
else:
print "check box ", indx, "not valid"
except SyntaxError:
print "Syntax Error in retranslateUi"
indx = indx + 1
def getValues(self):
"""
"""
cindx = 0
checked_dcmdirs = []
for indx in xrange(0, self.numcheckboxes):
try:
if eval("self.checkBox_" + str(indx) + ".isChecked()"):
print "checkBox ", indx, self.dcmdirs[indx], " checked"
checked_dcmdirs.append(self.dcmdirs[indx])
cindx = cindx + 1
# exec(cmdline) #, "<string>", "exec")
except SyntaxError:
print "Syntax Error in getValues"
# if os.path.exists(outdir):
# exec("if self.checkBox_"+str(indx)+".isChecked(): checked_dcmdirs[cindx] = dcmdirs[indx]")
return checked_dcmdirs
def help(self):
'''Execute the command in response to the OK button.'''
for indx in xrange(0, self.numcheckboxes):
try:
if eval("self.checkBox_" + str(indx) + ".isChecked()"):
print "checkBox ", indx, self.dcmdirs[indx], " checked ", eval("self.checkBox_" + str(indx) + ".isChecked()")
# exec(cmdline) #, "<string>", "exec")
except SyntaxError:
print "Syntax Error in getValues"
self.close()
def accept(self):
'''Execute the command in response to the OK button.'''
self.close()
def reject(self):
'''Cancel.'''
self.close()
def close(self):
self.dcmdirs = []