diff --git a/qml/Icon.qml b/qml/Icon.qml index 91344b2..cadd08b 100644 --- a/qml/Icon.qml +++ b/qml/Icon.qml @@ -47,7 +47,7 @@ Page { activated = !activated iconEditor.corners[idCell] = activated py.importModule("main", function(){ - py.call("main.sailify", [iconEditor.attrs.Icon.toString().toString(), iconEditor.corners], function(result){ + py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), iconEditor.corners], function(result){ icon.source = result }) }) @@ -68,6 +68,7 @@ Page { anchors.topMargin: 10 text: "Save" onClicked: { + iconEditor.attrs.old_icon = iconEditor.attrs.Icon.toString() iconEditor.attrs.Icon = icon.source.toString() py.importModule("main", function(){ py.call("main.save_icon", [iconEditor.attrs], function(result){ @@ -86,7 +87,7 @@ Page { Component.onCompleted: { py.addImportPath(Qt.resolvedUrl("../src")); py.importModule("main", function(){ - py.call("main.sailify", [iconEditor.attrs.Icon.toString(), [1, 1, 1, 1]], function(result){ + py.call("main.sailify", [(iconEditor.attrs.old_icon || iconEditor.attrs.Icon).toString(), [1, 1, 1, 1]], function(result){ icon.source = result }) }) diff --git a/src/main.py b/src/main.py index 1217b1a..37b3a3d 100644 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,6 @@ def avg_colors(img): pixel = img.getpixel((x, y)) if pixel[-1] > 0: # Doesn't count the transparent pixels counter[pixel] += 1 - print(counter.most_common(4)) return counter.most_common(1)[0][0] def add_background(img: Image, bg_tuple: tuple) -> Image: @@ -92,9 +91,11 @@ def sailify(raw_str, pattern): output_base64 = base64.b64encode(output_data) return "data:image/png;base64," + output_base64.decode() -def save_icon(app): +def backup_icon(app): if not os.path.exists(app["path"] + "backup"): shutil.copyfile(app["path"], app["path"] + "_backup") + +def save_icon(app): new_content = deparse_file(app) with open(app["path"], "w") as f: f.write(new_content)