Compare commits

...

7 Commits

Author SHA1 Message Date
Arak
d070fdb346
Merge 92c5dbf4f2 into e6900c98aa 2024-06-09 17:59:52 +03:00
Hugo Posnic
e6900c98aa
Merge pull request #232 from ARAKHN1D/banner-button-update-subtitle
Properly update headerbar subtitle when changing mode with banner button
2024-06-09 10:41:31 +02:00
ARAKHNID
e45a18b01b Properly update headerbar subtitle on mode change 2024-06-07 10:10:54 -05:00
ARAKHNID
92c5dbf4f2 Remove io import
I forgot to remove this, I'd imported io in attempts to simplify the
code and forgot it was imported.
2024-05-16 16:33:13 -05:00
ARAKHNID
3e0944d778 Simplify overwrite mode revert code
This was done because the new code is cleaner and still produces the
desired result, at least from my testing.
2024-05-16 16:30:52 -05:00
ARAKHNID
e3149d39bd Add overwrite mode compatibility
This is done by creating a copy of the input file that is then used to
copy over onto the output file, effectively reverting it. This was the
best solution I could find.
2024-05-14 18:53:59 -05:00
ARAKHNID
1a3a6ec01e Revert file if larger
oxipng and jpegoptim already do this by default. cwebp doesn't have a
skip option, so manually reverting it is necessary.

Closes #172
2024-05-13 19:18:03 -05:00
2 changed files with 20 additions and 1 deletions

View File

@ -18,6 +18,7 @@
import threading
import subprocess
import logging
import shutil
from gi.repository import GLib, Gio
from pathlib import Path
@ -76,6 +77,12 @@ class Compressor():
GLib.idle_add(self.c_enable_compression, True)
def run_command(self, command, result_item):
if not self.do_new_file:
# Creates a copy of the input file
# This is done in case the output file is larger than the input file
temp_filename = result_item.filename + ".temp"
shutil.copy2(result_item.filename, temp_filename)
error = False
error_message = ''
try:
@ -97,6 +104,17 @@ class Compressor():
new_file_data = Path(result_item.new_filename)
if new_file_data.is_file():
result_item.new_size = new_file_data.stat().st_size
# This check is mainly for compressors that don't have a way
# to automatically detect and skip files
if result_item.new_size > result_item.size:
if self.do_new_file:
shutil.copy2(result_item.filename, result_item.new_filename)
else:
shutil.copy2(temp_filename, result_item.new_filename)
result_item.new_size = new_file_data.stat().st_size
Path(temp_filename).unlink(True)
else:
logging.error(str(output))
error_message = _("Can't find the compressed file")
@ -105,7 +123,7 @@ class Compressor():
GLib.idle_add(self.c_update_result_item, result_item, error, error_message)
def build_png_command(self, result_item):
pngquant = 'pngquant --quality=0-{} -f "{}" --output "{}"'
pngquant = 'pngquant --quality=0-{} -f "{}" --output "{}" --skip-if-larger'
oxipng = 'oxipng -o {} -i 1 "{}" --out "{}"'
if not self.metadata:

View File

@ -351,6 +351,7 @@ class CurtailWindow(Adw.ApplicationWindow):
def banner_change_mode(self, *args):
self._settings.set_boolean('new-file', True)
self.show_warning_banner()
self.set_saving_subtitle()
def on_preferences(self, *args):
if self.prefs_dialog is not None: