|
36 | 36 | import keyring |
37 | 37 |
|
38 | 38 | from PySide6 import QtCore, QtGui |
39 | | -from PySide6.QtCore import QThread, QTimer, QSettings |
| 39 | +from PySide6.QtCore import Qt, QThread, QTimer, QSettings |
40 | 40 | from PySide6.QtGui import QBrush, QImage, QPixmap |
41 | 41 | from PySide6.QtWidgets import ( |
42 | 42 | QComboBox, |
43 | 43 | QFileDialog, |
44 | 44 | QLabel, |
| 45 | + QListWidgetItem, |
45 | 46 | QMainWindow, |
46 | 47 | QMessageBox, |
47 | 48 | ) |
@@ -136,6 +137,9 @@ def __init__(self): |
136 | 137 | # Connect Actions |
137 | 138 | self._connect_actions() |
138 | 139 |
|
| 140 | + # Connect slots |
| 141 | + self.ui.pushButton_clean_tunnel_counter.clicked.connect(self.on_clear_tunnel_counter_clicked) |
| 142 | + |
139 | 143 | # Create required folders |
140 | 144 | os.makedirs("log", exist_ok=True) |
141 | 145 |
|
@@ -523,6 +527,39 @@ def enabled_whatsapp_notifier_exists(self): |
523 | 527 | Notifier.notifiers[notifier].type == Notifier.NotifierTypes.WHATSAPP and |
524 | 528 | Notifier.notifiers[notifier].enabled) for notifier in Notifier.notifiers)) |
525 | 529 |
|
| 530 | + def on_tunnel_selected(self): |
| 531 | + """Method to update clear counter button on tunnel selection""" |
| 532 | + |
| 533 | + self.ui.pushButton_clean_tunnel_counter.setEnabled(True) |
| 534 | + |
| 535 | + def on_clear_tunnel_counter_clicked(self): |
| 536 | + """Method to clear counter for selected tunnel""" |
| 537 | + |
| 538 | + selected_item = self.ui.listWidget_en_tunnels.currentItem() |
| 539 | + if selected_item: |
| 540 | + selected_tunnel_id = selected_item.data(Qt.UserRole) |
| 541 | + tunnel = next((t for t in Tunnel.tunnels if t.id == selected_tunnel_id), None) |
| 542 | + |
| 543 | + if tunnel: |
| 544 | + reply = QMessageBox.question( |
| 545 | + self, |
| 546 | + f"Tunnel {selected_tunnel_id} counter reset", |
| 547 | + f"Are you sure you want to reset Tunnel {selected_tunnel_id} counter?", |
| 548 | + QMessageBox.Yes | QMessageBox.No, |
| 549 | + QMessageBox.No |
| 550 | + ) |
| 551 | + if reply == QMessageBox.Yes: |
| 552 | + tunnel.counter = 0 |
| 553 | + logger.info("Counter reset for tunnel %s", tunnel.id) |
| 554 | + self.ui.pushButton_clean_tunnel_counter.setEnabled(False) |
| 555 | + self.update_info_widget() |
| 556 | + else: |
| 557 | + logger.info("Tunnel %s counter reset aborted by user.", selected_tunnel_id) |
| 558 | + else: |
| 559 | + logger.error("No valid Tunnel ID provided while clearing counter.") |
| 560 | + else: |
| 561 | + logger.error("No selected tunnel, aborting counter reset.") |
| 562 | + |
526 | 563 | def update_toolbar_status_on_run(self, running): |
527 | 564 | """Update toolbar status while running model.""" |
528 | 565 |
|
@@ -550,11 +587,13 @@ def update_toolbar_status_on_run(self, running): |
550 | 587 | def update_info_widget(self): |
551 | 588 | """Update information widget.""" |
552 | 589 |
|
| 590 | + show_tunnel_mode_widgets = False |
553 | 591 | if OperationMode.cur_operation_mode_type: |
554 | 592 | self.ui.label_op_mode.setText(OperationMode.cur_operation_mode_type.value) |
555 | 593 | match OperationMode.cur_operation_mode_type: |
556 | 594 | case OperationMode.OperationModeTypes.TunnelMode: |
557 | 595 | classification_en_txt = "No" |
| 596 | + show_tunnel_mode_widgets = True |
558 | 597 | case OperationMode.OperationModeTypes.AnimalDetectionMode: |
559 | 598 | classification_en_txt = "No" |
560 | 599 | case OperationMode.OperationModeTypes.CustomSpeciesClassificationMode: |
@@ -583,13 +622,17 @@ def update_info_widget(self): |
583 | 622 | if cur_notifier and cur_notifier.enabled) or "None" |
584 | 623 | self.ui.label_notification_method.setText(notifier_lable_text) |
585 | 624 |
|
586 | | - tunnel_exist = bool(Tunnel.tunnels) |
587 | | - self.ui.label_enabled_tunnels.setVisible(tunnel_exist) |
588 | | - self.ui.listWidget_en_tunnels.setVisible(tunnel_exist) |
589 | | - if tunnel_exist: |
| 625 | + self.ui.label_enabled_tunnels.setVisible(show_tunnel_mode_widgets) |
| 626 | + self.ui.listWidget_en_tunnels.setVisible(show_tunnel_mode_widgets) |
| 627 | + self.ui.pushButton_clean_tunnel_counter.setVisible(show_tunnel_mode_widgets) |
| 628 | + if show_tunnel_mode_widgets: |
590 | 629 | self.ui.listWidget_en_tunnels.clear() |
591 | 630 | for tunnel in Tunnel.tunnels: |
592 | | - self.ui.listWidget_en_tunnels.addItem(f"{tunnel.id} ({tunnel.counter})") |
| 631 | + item = QListWidgetItem(f"{tunnel.id} ({tunnel.counter})") |
| 632 | + item.setData(Qt.UserRole, tunnel.id) |
| 633 | + self.ui.listWidget_en_tunnels.addItem(item) |
| 634 | + self.ui.listWidget_en_tunnels.currentItemChanged.connect(self.on_tunnel_selected) |
| 635 | + self.ui.pushButton_clean_tunnel_counter.setEnabled(False) |
593 | 636 |
|
594 | 637 | def test_model_mode_input_dialog(self): |
595 | 638 | """Method to run dialog for insertion of a URL to fetch image from.""" |
|
0 commit comments