Skip to content

Commit 189e9a4

Browse files
committed
Bugfixes, improved validation
1 parent 34045da commit 189e9a4

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

Averager.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
__copyright__ = '(c) 2024-2025 Ilya Razmanov'
4141
__credits__ = 'Ilya Razmanov'
4242
__license__ = 'unlicense'
43-
__version__ = '3.23.1.1'
43+
__version__ = '3.23.7.9'
4444
__maintainer__ = 'Ilya Razmanov'
4545
__email__ = 'ilyarazmanov@gmail.com'
4646
__status__ = 'Production'
@@ -159,11 +159,11 @@ def GetSource(event=None) -> None:
159159
│ GLOBALS! They are used during saving! │
160160
└────────────────────────────────────────┘ """
161161

162-
if Path(sourcefilename).suffix == '.png':
162+
if Path(sourcefilename).suffix.lower() == '.png':
163163
# ↓ Reading PNG image as list
164164
X, Y, Z, maxcolors, source_image3D, info = png2list(sourcefilename)
165165

166-
elif Path(sourcefilename).suffix in ('.ppm', '.pgm', '.pbm', '.pnm'):
166+
elif Path(sourcefilename).suffix.lower() in ('.ppm', '.pgm', '.pbm', '.pnm'):
167167
# ↓ Reading PNM image as list
168168
X, Y, Z, maxcolors, source_image3D = pnm2list(sourcefilename)
169169
# ↓ Creating dummy info required to correctly Save As PNG later.
@@ -405,10 +405,10 @@ def Save(event=None) -> None:
405405
resultfilename = sourcefilename
406406
UIBusy()
407407
# ↓ Save format choice
408-
if Path(resultfilename).suffix == '.png':
408+
if Path(resultfilename).suffix.lower() == '.png':
409409
info['compression'] = 9 # Explicitly setting compression
410410
list2png(resultfilename, image3D, info) # Writing file
411-
elif Path(resultfilename).suffix in ('.ppm', '.pgm', '.pnm'):
411+
elif Path(resultfilename).suffix.lower() in ('.ppm', '.pgm', '.pnm'):
412412
list2pnm(resultfilename, image3D, maxcolors) # Writing file
413413
# ↓ Flagging image as saved, not filtered
414414
is_saved = True # to block future repetitive saving
@@ -426,7 +426,7 @@ def SaveAs(event=None) -> None:
426426

427427
# ↓ Adjusting "Save as" formats to be displayed
428428
# according to bitdepth and source extension
429-
src_extension = Path(sourcefilename).suffix
429+
src_extension = Path(sourcefilename).suffix.lower()
430430
if Z == 1:
431431
if src_extension in ('.pgm', '.pnm'):
432432
format_list = [('Portable grey map', '.pgm'), ('Portable network graphics', '.png')]
@@ -460,10 +460,10 @@ def SaveAs(event=None) -> None:
460460
return None
461461
UIBusy()
462462
# ↓ Save format choice
463-
if Path(resultfilename).suffix == '.png':
463+
if Path(resultfilename).suffix.lower() == '.png':
464464
info['compression'] = 9 # Explicitly setting compression
465465
list2png(resultfilename, image3D, info) # Writing file
466-
elif Path(resultfilename).suffix in ('.ppm', '.pgm'):
466+
elif Path(resultfilename).suffix.lower() in ('.ppm', '.pgm'):
467467
list2pnm(resultfilename, image3D, maxcolors) # Writing file
468468
else:
469469
raise ValueError('Extension not recognized')
@@ -476,9 +476,18 @@ def SaveAs(event=None) -> None:
476476

477477

478478
def valiDig(new_value):
479-
"""Validate Spinbox input and reject non-numerical."""
480-
481-
return True if new_value.isdigit() else False
479+
"""Validate Spinbox input and reject non-integer."""
480+
481+
if new_value.strip() == '':
482+
return True
483+
try:
484+
_ = int(new_value)
485+
if _ >= 0 and _ < 256:
486+
return True
487+
else:
488+
return False
489+
except ValueError:
490+
return False
482491

483492

484493
def incWheel(event) -> None:

POVRayThread.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
__copyright__ = '(c) 2024-2025 Ilya Razmanov'
4040
__credits__ = 'Ilya Razmanov'
4141
__license__ = 'unlicense'
42-
__version__ = '1.23.1.1'
42+
__version__ = '1.23.7.9'
4343
__maintainer__ = 'Ilya Razmanov'
4444
__email__ = 'ilyarazmanov@gmail.com'
4545
__status__ = 'Production'
@@ -159,11 +159,11 @@ def GetSource(event=None) -> None:
159159
│ NOTE: maxcolors, image3D are GLOBALS! │
160160
└────────────────────────────────────────┘ """
161161

162-
if Path(sourcefilename).suffix == '.png':
162+
if Path(sourcefilename).suffix.lower() == '.png':
163163
# ↓ Reading PNG image as list
164164
X, Y, Z, maxcolors, image3D, info = png2list(sourcefilename)
165165

166-
elif Path(sourcefilename).suffix in ('.ppm', '.pgm', '.pbm', '.pnm'):
166+
elif Path(sourcefilename).suffix.lower() in ('.ppm', '.pgm', '.pbm', '.pnm'):
167167
# ↓ Reading PNM image as list
168168
X, Y, Z, maxcolors, image3D = pnm2list(sourcefilename)
169169

@@ -393,9 +393,18 @@ def SaveAsStitch() -> None:
393393

394394

395395
def valiDig(new_value):
396-
"""Validate Spinbox input and reject non-numerical."""
397-
398-
return True if new_value.isdigit() else False
396+
"""Validate Spinbox input and reject non-integer."""
397+
398+
if new_value.strip() == '':
399+
return True
400+
try:
401+
_ = int(new_value)
402+
if _ >= 0 and _ < 256:
403+
return True
404+
else:
405+
return False
406+
except ValueError:
407+
return False
399408

400409

401410
def incWheel(event) -> None:

0 commit comments

Comments
 (0)