Funktion clear Checkboxes hinzugefügt

Soll um eine neue Suche zu starten alle ausgewählten Checkboxen abwählen.
This commit is contained in:
Domenik Rath 2023-12-06 15:37:59 +01:00
parent 200bf76d01
commit 2357f8d2be

View File

@ -753,7 +753,7 @@ class WebseitenSucheApp(QWidget):
self.category_webpages_mapping = {category: webpages for category, webpages in zip(categories, webpages)}
self.selected_webpages = {webpage: False for category_webpages in webpages for webpage in category_webpages}
self.checkbox_states = {webpage: False for category_webpages in webpages for webpage in category_webpages}
self.search_term = ""
self.driver = None
@ -775,7 +775,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the first column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -795,7 +795,7 @@ class WebseitenSucheApp(QWidget):
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -817,7 +817,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the second column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -839,7 +839,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the second column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -860,7 +860,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the second column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -882,7 +882,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the second column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -903,7 +903,7 @@ class WebseitenSucheApp(QWidget):
# Add corresponding webpages in the second column
for row, webpage in enumerate(self.category_webpages_mapping[category]):
checkbox = QCheckBox(webpage)
checkbox.setChecked(self.selected_webpages[webpage])
checkbox.setChecked(self.checkbox_states[webpage])
checkbox.stateChanged.connect(self.make_checkbox_callback(webpage))
checkbox.setStyleSheet("color: white; border: 1px solid white;")
@ -941,7 +941,7 @@ class WebseitenSucheApp(QWidget):
# Neues Suche-Button
new_search_button = QPushButton("Neue Suche starten", self)
new_search_button.clicked.connect(self.new_search)
new_search_button.clicked.connect(self.clear_checkboxes)
layout.addWidget(new_search_button)
new_search_button.setStyleSheet("color: white; border: 1px solid white;")
@ -954,19 +954,23 @@ class WebseitenSucheApp(QWidget):
def make_checkbox_callback(self, webpage):
def checkbox_callback(state):
self.update_webpage_state(webpage, state)
self.checkbox_states[webpage] = state == Qt.Checked
return checkbox_callback
def update_webpage_state(self, webpage, state):
self.selected_webpages[webpage] = state == 2 # 2 entspricht dem Zustand "ausgewählt"
self.checkbox_states[webpage] = state
def clear_checkboxes(self):
for webpage in self.checkbox_states:
self.update_webpage_state(webpage, False)
def update_search_term(self, text):
self.search_term = text
def start_search(self):
selected_webpages = [webpage for webpage, selected in self.selected_webpages.items() if selected]
checkbox_states = [webpage for webpage, selected in self.checkbox_states.items() if selected]
if not selected_webpages:
if not checkbox_states:
QMessageBox.warning(self, "Fehler", "Bitte wählen Sie mindestens eine Webseite aus.")
return
@ -975,7 +979,7 @@ class WebseitenSucheApp(QWidget):
return
# Starte den Such-Thread
self.search_thread = SearchThread(selected_webpages, self.search_term)
self.search_thread = SearchThread(checkbox_states, self.search_term)
self.search_thread.search_finished.connect(self.search_finished)
self.search_thread.start()
@ -986,12 +990,6 @@ class WebseitenSucheApp(QWidget):
QMessageBox.critical(None, "Fehler", self.search_thread.error_message)
def new_search(self):
self.close_driver()
print("Neue Suche starten")
if __name__ == '__main__':
app = QApplication(sys.argv)
window = WebseitenSucheApp()