-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_dialog.py
More file actions
200 lines (172 loc) · 6.19 KB
/
delete_dialog.py
File metadata and controls
200 lines (172 loc) · 6.19 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
import sys
from PySide6.QtWidgets import (
QApplication, QDialog, QVBoxLayout, QHBoxLayout,
QLabel, QPushButton, QFrame
)
from PySide6.QtCore import Qt
from PySide6.QtGui import QFont
from mongodb import DBOps
db = DBOps()
class DeleteAgentDialog(QDialog):
"""Modal confirmation dialog for deleting an agent."""
def __init__(self, agent_name: str = "", parent=None):
super().__init__(parent)
self.agent_name = agent_name
self.setWindowTitle("Delete Agent")
self.setMinimumWidth(420)
self.setModal(True)
self._apply_style()
self._build_ui(agent_name)
# ------------------------------------------------------------------ #
# Theme #
# ------------------------------------------------------------------ #
def _apply_style(self):
self.setStyleSheet("""
QDialog {
background-color: #0f1117;
color: #e2e8f0;
font-family: 'Segoe UI', Arial, sans-serif;
}
QLabel#icon-label {
font-size: 40px;
}
QLabel#form-title {
font-size: 20px;
font-weight: 700;
color: #f1f5f9;
}
QLabel#form-subtitle {
font-size: 13px;
color: #94a3b8;
line-height: 1.5;
}
QLabel#agent-name-badge {
font-size: 13px;
font-weight: 700;
color: #fca5a5;
background-color: #7f1d1d33;
border: 1px solid #dc262644;
border-radius: 8px;
padding: 8px 16px;
}
QLabel#warning-note {
font-size: 11px;
color: #64748b;
}
QFrame#sep {
background-color: #1e293b;
max-height: 1px;
min-height: 1px;
}
QPushButton#btn-delete {
background-color: #dc2626;
color: #ffffff;
border: none;
border-radius: 20px;
font-size: 13px;
font-weight: 600;
padding: 10px 28px;
}
QPushButton#btn-delete:hover {
background-color: #ef4444;
}
QPushButton#btn-delete:pressed {
background-color: #b91c1c;
}
QPushButton#btn-cancel {
background-color: transparent;
color: #64748b;
border: 1px solid #1e293b;
border-radius: 20px;
font-size: 13px;
font-weight: 600;
padding: 10px 28px;
}
QPushButton#btn-cancel:hover {
background-color: #1e293b;
color: #e2e8f0;
}
QPushButton#btn-cancel:pressed {
background-color: #0f172a;
}
""")
# ------------------------------------------------------------------ #
# UI Construction #
# ------------------------------------------------------------------ #
def _build_ui(self, agent_name: str):
root = QVBoxLayout(self)
root.setContentsMargins(32, 28, 32, 28)
root.setSpacing(0)
# --- Warning icon ---
icon_label = QLabel("⚠️")
icon_label.setObjectName("icon-label")
icon_label.setAlignment(Qt.AlignCenter)
root.addWidget(icon_label)
root.addSpacing(14)
# --- Title ---
title = QLabel("Delete Agent")
title.setObjectName("form-title")
title.setAlignment(Qt.AlignCenter)
root.addWidget(title)
root.addSpacing(8)
# --- Subtitle ---
subtitle = QLabel("You are about to permanently delete the following agent:")
subtitle.setObjectName("form-subtitle")
subtitle.setAlignment(Qt.AlignCenter)
subtitle.setWordWrap(True)
root.addWidget(subtitle)
root.addSpacing(16)
# --- Agent name badge ---
name_badge = QLabel(agent_name)
name_badge.setObjectName("agent-name-badge")
name_badge.setAlignment(Qt.AlignCenter)
root.addWidget(name_badge)
root.addSpacing(14)
# --- Warning note ---
warning = QLabel("This action cannot be undone.")
warning.setObjectName("warning-note")
warning.setAlignment(Qt.AlignCenter)
root.addWidget(warning)
root.addSpacing(24)
# --- Separator ---
sep = QFrame()
sep.setObjectName("sep")
root.addWidget(sep)
root.addSpacing(24)
# --- Buttons ---
btn_row = QHBoxLayout()
btn_row.setSpacing(12)
btn_row.addStretch()
cancel_btn = QPushButton("Cancel")
cancel_btn.setObjectName("btn-cancel")
cancel_btn.setCursor(Qt.PointingHandCursor)
cancel_btn.setFixedHeight(40)
cancel_btn.clicked.connect(self.reject)
delete_btn = QPushButton("Delete Agent")
delete_btn.setObjectName("btn-delete")
delete_btn.setCursor(Qt.PointingHandCursor)
delete_btn.setFixedHeight(40)
delete_btn.clicked.connect(self.accept)
btn_row.addWidget(cancel_btn)
btn_row.addWidget(delete_btn)
root.addLayout(btn_row)
# ------------------------------------------------------------------ #
# Public helper #
# ------------------------------------------------------------------ #
def open_delete_dialog(agent_name: str) -> bool:
"""
Opens the delete confirmation dialog.
Returns True if the user confirmed deletion, False otherwise.
Deletion from DB is handled here.
"""
dialog = DeleteAgentDialog(agent_name=agent_name)
if dialog.exec() == QDialog.Accepted:
db.delete_document({"name": agent_name})
return True
return False
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setStyle("Fusion")
result = open_delete_dialog("TestAgent")
print("Deleted:" if result else "Cancelled.")
sys.exit(0)