-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
201 lines (164 loc) · 7.42 KB
/
gui.py
File metadata and controls
201 lines (164 loc) · 7.42 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import sys
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QPushButton, QLabel, QFileDialog,
QMessageBox, QProgressBar, QTableWidget, QTableWidgetItem,
QHeaderView, QDialog, QScrollArea)
from PyQt6.QtCore import Qt, QSize
from PyQt6.QtGui import QPixmap, QIcon, QFont
import qdarkstyle
from pathlib import Path
import json
import requests
from datetime import datetime
class AnalysisDialog(QDialog):
def __init__(self, analysis_data, parent=None):
super().__init__(parent)
self.setWindowTitle("نتایج آنالیز")
self.setMinimumSize(800, 600)
layout = QVBoxLayout()
# Image display
image_label = QLabel()
pixmap = QPixmap(analysis_data['image_path'])
image_label.setPixmap(pixmap.scaled(400, 400, Qt.AspectRatioMode.KeepAspectRatio))
image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
# Results table
results_table = QTableWidget()
results_table.setColumnCount(2)
results_table.setHorizontalHeaderLabels(["یافته", "درصد اطمینان"])
results_table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
for result in analysis_data['results']:
row = results_table.rowCount()
results_table.insertRow(row)
results_table.setItem(row, 0, QTableWidgetItem(result['class']))
results_table.setItem(row, 1, QTableWidgetItem(f"{result['score']*100:.2f}%"))
# Layout organization
h_layout = QHBoxLayout()
h_layout.addWidget(image_label)
h_layout.addWidget(results_table)
layout.addLayout(h_layout)
self.setLayout(layout)
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("سیستم آنالیز تصاویر پزشکی")
self.setMinimumSize(1000, 600)
# Set dark theme
self.setStyleSheet(qdarkstyle.load_stylesheet())
# Main widget and layout
main_widget = QWidget()
self.setCentralWidget(main_widget)
layout = QVBoxLayout()
main_widget.setLayout(layout)
# Header
header = QLabel("سیستم آنالیز تصاویر پزشکی")
header.setFont(QFont("Vazirmatn", 24))
header.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(header)
# Upload section
upload_section = QWidget()
upload_layout = QVBoxLayout()
upload_section.setLayout(upload_layout)
upload_btn = QPushButton("آپلود تصویر DICOM")
upload_btn.setIcon(QIcon("icons/upload.png"))
upload_btn.setIconSize(QSize(24, 24))
upload_btn.setMinimumHeight(50)
upload_btn.clicked.connect(self.upload_file)
upload_layout.addWidget(upload_btn)
layout.addWidget(upload_section)
# Analysis history table
self.history_table = QTableWidget()
self.history_table.setColumnCount(5)
self.history_table.setHorizontalHeaderLabels([
"تاریخ", "نام فایل", "وضعیت", "نتایج", "عملیات"
])
self.history_table.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.Stretch)
layout.addWidget(self.history_table)
# Progress bar
self.progress_bar = QProgressBar()
self.progress_bar.setVisible(False)
layout.addWidget(self.progress_bar)
# Load existing analyses
self.load_analyses()
def upload_file(self):
file_path, _ = QFileDialog.getOpenFileName(
self,
"انتخاب فایل DICOM",
"",
"DICOM Files (*.dcm)"
)
if file_path:
self.progress_bar.setVisible(True)
self.progress_bar.setValue(0)
# Simulate upload and analysis
self.progress_bar.setValue(50)
# TODO: Implement actual file upload and analysis
analysis_data = {
'id': datetime.now().timestamp(),
'filename': Path(file_path).name,
'status': 'completed',
'image_path': 'path/to/processed/image.png',
'results': [
{'class': 'نرمال', 'score': 0.95},
{'class': 'تومور', 'score': 0.05}
]
}
self.progress_bar.setValue(100)
self.add_analysis_to_table(analysis_data)
self.progress_bar.setVisible(False)
def load_analyses(self):
# TODO: Load analyses from database
pass
def add_analysis_to_table(self, analysis_data):
row = self.history_table.rowCount()
self.history_table.insertRow(row)
# Date
self.history_table.setItem(row, 0, QTableWidgetItem(
datetime.fromtimestamp(analysis_data['id']).strftime('%Y-%m-%d %H:%M')
))
# Filename
self.history_table.setItem(row, 1, QTableWidgetItem(analysis_data['filename']))
# Status
status_item = QTableWidgetItem()
if analysis_data['status'] == 'completed':
status_item.setText("تکمیل شده")
status_item.setForeground(Qt.GlobalColor.green)
else:
status_item.setText("در حال پردازش")
status_item.setForeground(Qt.GlobalColor.yellow)
self.history_table.setItem(row, 2, status_item)
# Results button
results_btn = QPushButton("مشاهده نتایج")
results_btn.clicked.connect(lambda: self.show_results(analysis_data))
self.history_table.setCellWidget(row, 3, results_btn)
# Actions
actions_widget = QWidget()
actions_layout = QHBoxLayout()
actions_widget.setLayout(actions_layout)
download_btn = QPushButton("دانلود")
download_btn.clicked.connect(lambda: self.download_analysis(analysis_data))
delete_btn = QPushButton("حذف")
delete_btn.clicked.connect(lambda: self.delete_analysis(analysis_data))
actions_layout.addWidget(download_btn)
actions_layout.addWidget(delete_btn)
self.history_table.setCellWidget(row, 4, actions_widget)
def show_results(self, analysis_data):
dialog = AnalysisDialog(analysis_data, self)
dialog.exec()
def download_analysis(self, analysis_data):
# TODO: Implement download functionality
QMessageBox.information(self, "دانلود", "فایل با موفقیت دانلود شد.")
def delete_analysis(self, analysis_data):
reply = QMessageBox.question(
self,
"تایید حذف",
"آیا مطمئن هستید که میخواهید این آنالیز را حذف کنید؟",
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No
)
if reply == QMessageBox.StandardButton.Yes:
# TODO: Implement delete functionality
QMessageBox.information(self, "حذف", "آنالیز با موفقیت حذف شد.")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec())