mirror of
https://github.com/Project-Babble/ProjectBabble.git
synced 2026-11-24 02:51:16 -08:00
Add Input type blocking to Calibration Tab
This commit is contained in:
1 parent
3ca8112a37
commit
726209eaea
3 files changed
+25
-22
No files matched your search
@@ -4,7 +4,7 @@ from config import BabbleSettingsConfig
|
||||
from osc import Tab
|
||||
from queue import Queue
|
||||
from threading import Event
|
||||
import re
|
||||
from utils import misc_utils
|
||||
|
||||
|
||||
class AlgoSettingsWidget:
|
||||
@@ -135,19 +135,11 @@ class AlgoSettingsWidget:
|
||||
return
|
||||
self.cancellation_event.set()
|
||||
|
||||
def is_valid_float_input(self, value):
|
||||
# Allow empty string, negative sign, or a float number
|
||||
return bool(re.match(r'^-?\d*\.?\d*$', value))
|
||||
|
||||
def is_valid_int_input(self, value):
|
||||
# Allow empty string, negative sign, or an integer number
|
||||
return bool(re.match(r'^-?\d*$', value))
|
||||
|
||||
def render(self, window, event, values):
|
||||
# Input validation for the fields
|
||||
if event == self.gui_multiply:
|
||||
value = values[self.gui_multiply]
|
||||
if not self.is_valid_float_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
# Invalid input, remove last character
|
||||
value = value[:-1]
|
||||
window[self.gui_multiply].update(value)
|
||||
@@ -155,35 +147,35 @@ class AlgoSettingsWidget:
|
||||
|
||||
elif event == self.calib_deadzone:
|
||||
value = values[self.calib_deadzone]
|
||||
if not self.is_valid_float_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[self.calib_deadzone].update(value)
|
||||
values[self.calib_deadzone] = value
|
||||
|
||||
elif event == self.gui_inference_threads:
|
||||
value = values[self.gui_inference_threads]
|
||||
if not self.is_valid_int_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[self.gui_inference_threads].update(value)
|
||||
values[self.gui_inference_threads] = value
|
||||
|
||||
elif event == self.gui_gpu_index:
|
||||
value = values[self.gui_gpu_index]
|
||||
if not self.is_valid_int_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[self.gui_gpu_index].update(value)
|
||||
values[self.gui_gpu_index] = value
|
||||
|
||||
elif event == self.gui_min_cutoff:
|
||||
value = values[self.gui_min_cutoff]
|
||||
if not self.is_valid_float_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[self.gui_min_cutoff].update(value)
|
||||
values[self.gui_min_cutoff] = value
|
||||
|
||||
elif event == self.gui_speed_coefficient:
|
||||
value = values[self.gui_speed_coefficient]
|
||||
if not self.is_valid_float_input(value):
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[self.gui_speed_coefficient].update(value)
|
||||
values[self.gui_speed_coefficient] = value
|
||||
|
||||
@@ -6,6 +6,7 @@ from queue import Queue
|
||||
from threading import Event
|
||||
import numpy as np
|
||||
from calib_settings_values import set_shapes
|
||||
from utils import misc_utils
|
||||
|
||||
|
||||
class CalibSettingsWidget:
|
||||
@@ -194,12 +195,16 @@ class CalibSettingsWidget:
|
||||
|
||||
for count1, element1 in enumerate(self.shape):
|
||||
for count2, element2 in enumerate(element1):
|
||||
value = values[element2]
|
||||
if not misc_utils.is_valid_float_input(value):
|
||||
value = value[:-1]
|
||||
window[element2].update(value)
|
||||
values[element2] = value
|
||||
|
||||
if values[element2] != '':
|
||||
try:
|
||||
if float(self.array[count1][count2]) != float(values[element2]):
|
||||
self.array[count1][count2] = float(values[element2])
|
||||
changed = True
|
||||
except: print("Not a float")
|
||||
if float(self.array[count1][count2]) != float(value):
|
||||
self.array[count1][count2] = float(value)
|
||||
changed = True
|
||||
|
||||
if event == self.gui_reset_min:
|
||||
for count1, element1 in enumerate(self.shape):
|
||||
|
||||
@@ -6,6 +6,7 @@ import os
|
||||
import platform
|
||||
import cv2
|
||||
import subprocess
|
||||
import re
|
||||
from pygrabber.dshow_graph import FilterGraph
|
||||
|
||||
is_nt = True if sys.platform.startswith('win') else False
|
||||
@@ -157,8 +158,13 @@ def get_camera_index_by_name(name):
|
||||
|
||||
return None
|
||||
|
||||
#def get_serial_port(name):
|
||||
# for i, device in enumerate(cam_list):
|
||||
def is_valid_float_input(value):
|
||||
# Allow empty string, negative sign, or a float number
|
||||
return bool(re.match(r'^-?\d*\.?\d*$', value))
|
||||
|
||||
def is_valid_int_input(value):
|
||||
# Allow empty string, negative sign, or an integer number
|
||||
return bool(re.match(r'^-?\d*$', value))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user