Skip to content

Commit c8875f0

Browse files
Tunnels clear counter button introduced (#196)
* Introduced Tunnels clear counter button In order to avoid negative counting of animal into tunnels, a clear counter button has been in UI to allow user to force counter reset. * addressed PR comments
1 parent 25e1857 commit c8875f0

File tree

4 files changed

+155
-84
lines changed

4 files changed

+155
-84
lines changed

wadas/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
# Date: 2024-08-14
1818
# Description: module to keep track of WADAS version
1919

20-
__version__ = "v1.0.0.a3"
20+
__version__ = "v1.0.0.a4"
2121
__dbversion__ = __version__

wadas/ui/mainwindow.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@
3636
import keyring
3737

3838
from PySide6 import QtCore, QtGui
39-
from PySide6.QtCore import QThread, QTimer, QSettings
39+
from PySide6.QtCore import Qt, QThread, QTimer, QSettings
4040
from PySide6.QtGui import QBrush, QImage, QPixmap
4141
from PySide6.QtWidgets import (
4242
QComboBox,
4343
QFileDialog,
4444
QLabel,
45+
QListWidgetItem,
4546
QMainWindow,
4647
QMessageBox,
4748
)
@@ -136,6 +137,9 @@ def __init__(self):
136137
# Connect Actions
137138
self._connect_actions()
138139

140+
# Connect slots
141+
self.ui.pushButton_clean_tunnel_counter.clicked.connect(self.on_clear_tunnel_counter_clicked)
142+
139143
# Create required folders
140144
os.makedirs("log", exist_ok=True)
141145

@@ -523,6 +527,39 @@ def enabled_whatsapp_notifier_exists(self):
523527
Notifier.notifiers[notifier].type == Notifier.NotifierTypes.WHATSAPP and
524528
Notifier.notifiers[notifier].enabled) for notifier in Notifier.notifiers))
525529

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+
526563
def update_toolbar_status_on_run(self, running):
527564
"""Update toolbar status while running model."""
528565

@@ -550,11 +587,13 @@ def update_toolbar_status_on_run(self, running):
550587
def update_info_widget(self):
551588
"""Update information widget."""
552589

590+
show_tunnel_mode_widgets = False
553591
if OperationMode.cur_operation_mode_type:
554592
self.ui.label_op_mode.setText(OperationMode.cur_operation_mode_type.value)
555593
match OperationMode.cur_operation_mode_type:
556594
case OperationMode.OperationModeTypes.TunnelMode:
557595
classification_en_txt = "No"
596+
show_tunnel_mode_widgets = True
558597
case OperationMode.OperationModeTypes.AnimalDetectionMode:
559598
classification_en_txt = "No"
560599
case OperationMode.OperationModeTypes.CustomSpeciesClassificationMode:
@@ -583,13 +622,17 @@ def update_info_widget(self):
583622
if cur_notifier and cur_notifier.enabled) or "None"
584623
self.ui.label_notification_method.setText(notifier_lable_text)
585624

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:
590629
self.ui.listWidget_en_tunnels.clear()
591630
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)
593636

594637
def test_model_mode_input_dialog(self):
595638
"""Method to run dialog for insertion of a URL to fetch image from."""

wadas/ui/qt/mainwindow.ui

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,24 @@
2727
</property>
2828
<widget class="QWidget" name="centralwidget">
2929
<layout class="QGridLayout" name="gridLayout" rowstretch="300,0" columnstretch="300,0,0">
30-
<item row="0" column="1">
31-
<widget class="Line" name="line">
30+
<item row="1" column="0" colspan="3">
31+
<widget class="QPlainTextEdit" name="plainTextEdit_log">
3232
<property name="sizePolicy">
33-
<sizepolicy hsizetype="Fixed" vsizetype="MinimumExpanding">
33+
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
3434
<horstretch>0</horstretch>
3535
<verstretch>0</verstretch>
3636
</sizepolicy>
3737
</property>
38-
<property name="orientation">
39-
<enum>Qt::Orientation::Vertical</enum>
38+
<property name="minimumSize">
39+
<size>
40+
<width>400</width>
41+
<height>100</height>
42+
</size>
4043
</property>
4144
</widget>
4245
</item>
4346
<item row="0" column="2">
44-
<layout class="QVBoxLayout" name="verticalLayout">
47+
<layout class="QVBoxLayout" name="verticalLayout_right_info_pane">
4548
<item>
4649
<widget class="QLabel" name="label_op_mode_title">
4750
<property name="sizePolicy">
@@ -145,6 +148,22 @@
145148
<item>
146149
<widget class="QListWidget" name="listWidget_en_tunnels"/>
147150
</item>
151+
<item>
152+
<widget class="QPushButton" name="pushButton_clean_tunnel_counter">
153+
<property name="enabled">
154+
<bool>false</bool>
155+
</property>
156+
<property name="sizePolicy">
157+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
158+
<horstretch>0</horstretch>
159+
<verstretch>0</verstretch>
160+
</sizepolicy>
161+
</property>
162+
<property name="text">
163+
<string>Clean selected tunnel counter</string>
164+
</property>
165+
</widget>
166+
</item>
148167
<item>
149168
<widget class="QLabel" name="label">
150169
<property name="sizePolicy">
@@ -254,6 +273,19 @@
254273
</item>
255274
</layout>
256275
</item>
276+
<item row="0" column="1">
277+
<widget class="Line" name="line">
278+
<property name="sizePolicy">
279+
<sizepolicy hsizetype="Fixed" vsizetype="MinimumExpanding">
280+
<horstretch>0</horstretch>
281+
<verstretch>0</verstretch>
282+
</sizepolicy>
283+
</property>
284+
<property name="orientation">
285+
<enum>Qt::Orientation::Vertical</enum>
286+
</property>
287+
</widget>
288+
</item>
257289
<item row="0" column="0">
258290
<widget class="QLabel" name="label_image">
259291
<property name="enabled">
@@ -282,22 +314,6 @@
282314
</property>
283315
</widget>
284316
</item>
285-
<item row="1" column="0" colspan="3">
286-
<widget class="QPlainTextEdit" name="plainTextEdit_log">
287-
<property name="sizePolicy">
288-
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
289-
<horstretch>0</horstretch>
290-
<verstretch>0</verstretch>
291-
</sizepolicy>
292-
</property>
293-
<property name="minimumSize">
294-
<size>
295-
<width>400</width>
296-
<height>100</height>
297-
</size>
298-
</property>
299-
</widget>
300-
</item>
301317
</layout>
302318
</widget>
303319
<widget class="QMenuBar" name="menubar">

0 commit comments

Comments
 (0)