-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcellNamesGUI.py
More file actions
156 lines (127 loc) · 5.14 KB
/
Copy pathcellNamesGUI.py
File metadata and controls
156 lines (127 loc) · 5.14 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
from PyQt5.QtWidgets import QWidget, QListWidget, QPushButton, QHBoxLayout, QVBoxLayout, QMessageBox
from PyQt5.QtGui import QFont
class AssignNamesValuesWindow(QWidget):
"""
This function initializes an instance of the AssignValuesWindow class.
"""
def __init__(self, cell_line_list):
super().__init__()
self.result = None
self.resize(350, 400)
self.setWindowTitle("Cell Names")
font = QFont('sans-serif', 10)
# Save the default values for later use in reset
self.cell_names_list_default = cell_line_list
# Initialize the two list widgets
self.one_list = QListWidget()
# Populate the left list with all the values
self.one_list.addItems(cell_line_list)
# Set the font of each list
self.one_list.setFont(font)
# Create buttons to move items between the lists
self.delete_button = QPushButton("Delete")
self.reset_button = QPushButton("Reset")
self.apply_button = QPushButton("Apply")
# Connect the buttons to their corresponding functions
self.delete_button.clicked.connect(self.delete)
self.reset_button.clicked.connect(self.reset)
self.apply_button.clicked.connect(self.apply)
# Create horizontal and vertical layouts for the buttons and list widgets
button_layout = QVBoxLayout()
button_layout.addWidget(self.delete_button)
button_layout.addWidget(self.reset_button)
button_layout.addWidget(self.apply_button)
list_layout = QHBoxLayout()
list_layout.addWidget(self.one_list)
list_layout.addLayout(button_layout)
# Set the main layout for the window
self.setLayout(list_layout)
# Flag to indicate if Apply button was clicked
self.apply_clicked = False
# Set styles for the buttons
button_style = """
QPushButton {
border: 1px solid black;
color: black;
border-radius: 5px;
padding: 5px;
font-family: sans-serif
}
QPushButton:hover {
background-color: #2980b9;
cursor:pointer;
}
"""
delete_style = """
QPushButton {
border: 1px solid black;
color: black;
border-radius: 5px;
padding: 5px;
font-family: sans-serif
}
QPushButton:hover {
background-color: #e41b1b;
cursor:pointer;
}
"""
apply_style = """
QPushButton {
border: 1px solid black;
color: black;
border-radius: 5px;
padding: 5px;
font-family: sans-serif
}
QPushButton:hover {
background-color: #00ff80;
cursor:pointer;
}
"""
self.delete_button.setStyleSheet(delete_style)
self.reset_button.setStyleSheet(button_style)
self.apply_button.setStyleSheet(apply_style)
def delete(self):
"""
This method delete the selected item from the list.
"""
selected_items = self.one_list.selectedItems()
if not selected_items:
# If no items are selected, show an error message
QMessageBox.warning(self, "Error", "Please select an item to delete.")
return
for item in selected_items:
self.one_list.takeItem(self.one_list.row(item))
def reset(self):
"""
This method reset the values to the initial values of each list.
"""
self.one_list.clear()
self.one_list.addItems(self.cell_names_list_default)
def apply(self):
"""
This method set the result for the selected values.
"""
# Get the final state of the lists and return them as two separate lists
values = [self.one_list.item(i).text() for i in range(self.one_list.count())]
self.result = values
self.apply_clicked = True
self.close()
def closeEvent(self, event):
"""
This method handles the close event when the user clicks on the exit button.
Params:
event (QCloseEvent): The close event object.
Returns:
None
"""
if not self.apply_clicked:
reply = QMessageBox.question(self, 'Confirm Exit', 'Are you sure you want to exit?',
QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
if reply == QMessageBox.Yes:
# User confirmed exit, close the window
self.result = self.cell_names_list_default
event.accept()
else:
# User cancelled exit, ignore the close event
event.ignore()