4
4
from osc import Tab
5
5
from queue import Queue
6
6
from threading import Event
7
- from utils .misc_utils import bg_color_highlight , bg_color_clear
8
-
7
+ from utils .misc_utils import bg_color_highlight , bg_color_clear , is_valid_int_input
9
8
10
9
class SettingsWidget :
11
10
def __init__ (
@@ -84,6 +83,7 @@ def __init__(
84
83
key = self .gui_osc_port ,
85
84
size = (0 , 10 ),
86
85
tooltip = f'{ lang ._instance .get_string ("general.portTooltip" )} .' ,
86
+ enable_events = True ,
87
87
),
88
88
],
89
89
[
@@ -110,6 +110,7 @@ def __init__(
110
110
key = self .gui_osc_receiver_port ,
111
111
size = (0 , 10 ),
112
112
tooltip = f'{ lang ._instance .get_string ("general.receiverPortTooltip" )} :' ,
113
+ enable_events = True ,
113
114
),
114
115
],
115
116
[
@@ -152,6 +153,7 @@ def __init__(
152
153
key = self .gui_cam_resolution_x ,
153
154
size = (0 , 20 ),
154
155
tooltip = f'{ lang ._instance .get_string ("general.xResolutionTooltip" )} ' ,
156
+ enable_events = True ,
155
157
),
156
158
# ],
157
159
# [
@@ -164,6 +166,7 @@ def __init__(
164
166
key = self .gui_cam_resolution_y ,
165
167
size = (0 , 10 ),
166
168
tooltip = f'{ lang ._instance .get_string ("general.yResolutionTooltip" )} ' ,
169
+ enable_events = True ,
167
170
),
168
171
# ],
169
172
# [
@@ -241,115 +244,96 @@ def render(self, window, event, values):
241
244
# If anything has changed in our configuration settings, change/update those.
242
245
changed = False
243
246
244
- try :
245
- if self .config .gui_osc_port != int (values [self .gui_osc_port ]):
246
- try :
247
- int (values [self .gui_osc_port ])
248
- if len (values [self .gui_osc_port ]) <= 5 :
249
- self .config .gui_osc_port = int (values [self .gui_osc_port ])
250
- changed = True
251
- else :
252
- print (
253
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscPort" )} \033 [0m'
254
- )
255
- except :
256
- print (
257
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscPort" )} \033 [0m'
258
- )
259
- except :
260
- print (
261
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscValue" )} \033 [0m'
262
- )
247
+ # Check if the OSC port is a valid integer and update if necessary
248
+ value = values [self .gui_osc_port ]
249
+ if value .isdigit () and len (value ) <= 5 :
250
+ if self .config .gui_osc_port != int (value ):
251
+ self .config .gui_osc_port = int (value )
252
+ changed = True
253
+ else :
254
+ if not is_valid_int_input (value ):
255
+ value = value [:- 1 ]
256
+ window [self .gui_osc_port ].update (value )
257
+ values [self .gui_osc_port ] = value
263
258
264
- try :
265
- if self .config .gui_osc_receiver_port != int (
266
- values [self .gui_osc_receiver_port ]
267
- ):
268
- try :
269
- int (values [self .gui_osc_receiver_port ])
270
- if len (values [self .gui_osc_receiver_port ]) <= 5 :
271
- self .config .gui_osc_receiver_port = int (
272
- values [self .gui_osc_receiver_port ]
273
- )
274
- changed = True
275
- else :
276
- print (
277
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscPort" )} \033 [0m'
278
- )
279
- except :
280
- print (
281
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscPort" )} \033 [0m'
282
- )
283
- except :
284
- print (
285
- f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("general.oscValue" )} \033 [0m'
286
- )
259
+ # Check if the OSC receiver port is a valid integer and update if necessary
260
+ value = values [self .gui_osc_receiver_port ]
261
+ if value .isdigit () and len (value ) <= 5 :
262
+ if self .config .gui_osc_receiver_port != int (value ):
263
+ self .config .gui_osc_receiver_port = int (value )
264
+ changed = True
265
+ else :
266
+ print (f'\033 [91m[{ lang ._instance .get_string ("log.error" )} ] { lang ._instance .get_string ("error.oscPort" )} \033 [0m' )
267
+ if not is_valid_int_input (value ):
268
+ value = value [:- 1 ]
269
+ window [self .gui_osc_receiver_port ].update (value )
270
+ values [self .gui_osc_receiver_port ] = value
287
271
272
+ # Update OSC address if it has changed
288
273
if self .config .gui_osc_address != values [self .gui_osc_address ]:
289
274
self .config .gui_osc_address = values [self .gui_osc_address ]
290
275
changed = True
291
276
292
- if (
293
- self .config .gui_osc_recalibrate_address
294
- != values [self .gui_osc_recalibrate_address ]
295
- ):
296
- self .config .gui_osc_recalibrate_address = values [
297
- self .gui_osc_recalibrate_address
298
- ]
277
+ # Update recalibrate address if it has changed
278
+ if self .config .gui_osc_recalibrate_address != values [self .gui_osc_recalibrate_address ]:
279
+ self .config .gui_osc_recalibrate_address = values [self .gui_osc_recalibrate_address ]
299
280
changed = True
300
281
282
+ # Update check option
301
283
if self .config .gui_update_check != values [self .gui_update_check ]:
302
284
self .config .gui_update_check = values [self .gui_update_check ]
303
285
changed = True
304
286
287
+ # Update ROSC option
305
288
if self .config .gui_ROSC != values [self .gui_ROSC ]:
306
289
self .config .gui_ROSC = values [self .gui_ROSC ]
307
290
changed = True
308
291
309
- if self .config .gui_osc_location != values [self .gui_osc_location ]:
310
- self .config .gui_osc_location = values [self .gui_osc_location ]
311
- changed = True
292
+ # Update camera resolution X if it's a valid integer and different
293
+ value = values [self .gui_cam_resolution_x ]
294
+ if value .isdigit ():
295
+ if str (self .config .gui_cam_resolution_x ) != value :
296
+ self .config .gui_cam_resolution_x = int (value )
297
+ changed = True
298
+ else :
299
+ value = value [:- 1 ]
300
+ window [self .gui_cam_resolution_x ].update (value )
301
+ values [self .gui_cam_resolution_x ] = value
312
302
313
- if values [self .gui_cam_resolution_x ] != "" :
314
- if (
315
- str (self .config .gui_cam_resolution_x )
316
- != values [self .gui_cam_resolution_x ]
317
- ):
318
- try :
319
- self .config .gui_cam_resolution_x = int (
320
- values [self .gui_cam_resolution_x ]
321
- )
322
- changed = True
323
- except :
324
- print (lang ._instance .get_string ("general.notAnInt" ))
325
- if values [self .gui_cam_resolution_y ] != "" :
326
- if (
327
- str (self .config .gui_cam_resolution_y )
328
- != values [self .gui_cam_resolution_y ]
329
- ):
330
- try :
331
- self .config .gui_cam_resolution_y = int (
332
- values [self .gui_cam_resolution_y ]
333
- )
334
- changed = True
335
- except :
336
- print (lang ._instance .get_string ("general.notAnInt" ))
337
- if values [self .gui_cam_framerate ] != "" :
338
- if str (self .config .gui_cam_framerate ) != values [self .gui_cam_framerate ]:
339
- try :
340
- self .config .gui_cam_framerate = int (values [self .gui_cam_framerate ])
341
- changed = True
342
- except :
343
- print (lang ._instance .get_string ("general.notAnInt" ))
303
+ # Update camera resolution Y if it's a valid integer and different
304
+ value = values [self .gui_cam_resolution_y ]
305
+ if value .isdigit ():
306
+ if str (self .config .gui_cam_resolution_y ) != value :
307
+ self .config .gui_cam_resolution_y = int (value )
308
+ changed = True
309
+ else :
310
+ value = value [:- 1 ]
311
+ window [self .gui_cam_resolution_y ].update (value )
312
+ values [self .gui_cam_resolution_y ] = value
344
313
314
+ # Update camera framerate if it's a valid integer and different
315
+ value = values [self .gui_cam_framerate ]
316
+ if value .isdigit ():
317
+ if str (self .config .gui_cam_framerate ) != value :
318
+ self .config .gui_cam_framerate = int (value )
319
+ changed = True
320
+ else :
321
+ value = value [:- 1 ]
322
+ window [self .gui_cam_framerate ].update (value )
323
+ values [self .gui_cam_framerate ] = value
324
+
325
+ # Update the use of the red channel
345
326
if self .config .gui_use_red_channel != bool (values [self .gui_use_red_channel ]):
346
327
self .config .gui_use_red_channel = bool (values [self .gui_use_red_channel ])
347
328
changed = True
348
329
330
+ # Update language if it has changed
349
331
if self .config .gui_language != values [self .gui_language ]:
350
332
self .config .gui_language = values [self .gui_language ]
351
333
changed = True
352
334
335
+ # Save the configuration if changes were made
353
336
if changed :
354
337
self .main_config .save ()
338
+
355
339
self .osc_queue .put ((Tab .SETTINGS ))
0 commit comments