Skip to content

Commit 4087ee4

Browse files
committed
Better handling of Filter/Save sequences
1 parent 4c2c117 commit 4087ee4

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

Averager.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
__copyright__ = '(c) 2024-2025 Ilya Razmanov'
3939
__credits__ = 'Ilya Razmanov'
4040
__license__ = 'unlicense'
41-
__version__ = '3.22.08.20'
41+
__version__ = '3.22.11.11'
4242
__maintainer__ = 'Ilya Razmanov'
4343
__email__ = 'ilyarazmanov@gmail.com'
4444
__status__ = 'Production'
@@ -337,11 +337,36 @@ def SwitchView(event=None) -> None:
337337
ShowPreview(preview_filtered, 'Result')
338338

339339

340+
def onSave() -> None:
341+
global sourcefilename, resultfilename, is_saved
342+
global source_image3D, image3D, X, Y, Z, maxcolors
343+
global preview_data, preview_filtered, preview_src, info_normal
344+
345+
sourcefilename = resultfilename # Now saved file becomes new source file
346+
source_image3D = deepcopy(image3D)
347+
preview_data = list2bin(image3D, maxcolors, show_chessboard=True)
348+
preview_filtered = PhotoImage(data=preview_data)
349+
preview_src = preview_filtered
350+
351+
# ↓ disabling save
352+
menu02.entryconfig('Save', state='disabled')
353+
sortir.unbind_all('<Control-s>')
354+
# ↓ binding switch on preview click
355+
zanyato.unbind('<Button-1>') # left click
356+
zanyato.unbind('<space>') # # "Space" key. May be worth binding whole sortir?
357+
# ↓ preview source
358+
ShowPreview(preview_src, 'Source')
359+
# ↓ Adding filename, mode and status to window title a-la Photoshop
360+
sortir.title(f'Averager: {Path(sourcefilename).name}{color_mode_str}{"*" if is_filtered else ""}')
361+
info_normal = {'txt': f'{Path(sourcefilename).name}{"*" if is_filtered else ""} X={X} Y={Y} Z={Z} maxcolors={maxcolors}', 'fg': 'grey', 'bg': 'grey90'}
362+
UINormal()
363+
364+
340365
def Save(event=None) -> None:
341366
"""Once pressed on Save."""
342367

343368
global is_filtered, is_saved, info_normal, color_mode_str
344-
global source_image3D
369+
global source_image3D, sourcefilename, resultfilename
345370

346371
if is_saved: # block repetitive saving
347372
return
@@ -355,23 +380,19 @@ def Save(event=None) -> None:
355380
list2png(resultfilename, image3D, info) # Writing file
356381
elif Path(resultfilename).suffix in ('.ppm', '.pgm', '.pnm'):
357382
list2pnm(resultfilename, image3D, maxcolors) # Writing file
358-
# ↓ Now saved file becomes new source file
359-
source_image3D = image3D
360383
# ↓ Flagging image as saved, not filtered
361384
is_saved = True # to block future repetitive saving
362385
is_filtered = False
363-
menu02.entryconfig('Save', state='disabled')
364-
# ↓ Adding filename, mode and status to window title a-la Photoshop
365-
sortir.title(f'Averager: {Path(sourcefilename).name}{color_mode_str}{"*" if is_filtered else ""}')
366-
info_normal = {'txt': f'{Path(sourcefilename).name}{"*" if is_filtered else ""} X={X} Y={Y} Z={Z} maxcolors={maxcolors}', 'fg': 'grey', 'bg': 'grey90'}
386+
# ↓ Now saved file becomes new source file
387+
onSave()
367388
UINormal()
368389

369390

370391
def SaveAs(event=None) -> None:
371392
"""Once pressed on Save as..."""
372393

373-
global sourcefilename, is_saved, is_filtered, info_normal, color_mode_str
374-
global source_image3D
394+
global is_saved, is_filtered, info_normal, color_mode_str
395+
global source_image3D, sourcefilename, resultfilename
375396

376397
# ↓ Adjusting "Save as" formats to be displayed
377398
# according to bitdepth and source extension
@@ -416,16 +437,11 @@ def SaveAs(event=None) -> None:
416437
list2pnm(resultfilename, image3D, maxcolors) # Writing file
417438
else:
418439
raise ValueError('Extension not recognized')
419-
# ↓ Now saved file becomes new source file
420-
sourcefilename = resultfilename
421-
source_image3D = image3D
422440
# ↓ Flagging image as saved, not filtered, and disabling "Save"
423441
is_saved = True # to block future repetitive saving
424442
is_filtered = False
425-
menu02.entryconfig('Save', state='disabled')
426-
# ↓ Adding filename, mode and status to window title a-la Photoshop
427-
sortir.title(f'Averager: {Path(sourcefilename).name}{color_mode_str}{"*" if is_filtered else ""}')
428-
info_normal = {'txt': f'{Path(sourcefilename).name}{"*" if is_filtered else ""} X={X} Y={Y} Z={Z} maxcolors={maxcolors}', 'fg': 'grey', 'bg': 'grey90'}
443+
# ↓ Now saved file becomes new source file
444+
onSave()
429445
UINormal()
430446

431447

0 commit comments

Comments
 (0)