Now you edit the original icon and not the edited previously

master
kirbylife 2021-05-20 21:06:32 -05:00
parent 01ba24b8e1
commit a2821886f1
2 changed files with 6 additions and 4 deletions

View File

@ -47,7 +47,7 @@ Page {
activated = !activated activated = !activated
iconEditor.corners[idCell] = activated iconEditor.corners[idCell] = activated
py.importModule("main", function(){ 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 icon.source = result
}) })
}) })
@ -68,6 +68,7 @@ Page {
anchors.topMargin: 10 anchors.topMargin: 10
text: "Save" text: "Save"
onClicked: { onClicked: {
iconEditor.attrs.old_icon = iconEditor.attrs.Icon.toString()
iconEditor.attrs.Icon = icon.source.toString() iconEditor.attrs.Icon = icon.source.toString()
py.importModule("main", function(){ py.importModule("main", function(){
py.call("main.save_icon", [iconEditor.attrs], function(result){ py.call("main.save_icon", [iconEditor.attrs], function(result){
@ -86,7 +87,7 @@ Page {
Component.onCompleted: { Component.onCompleted: {
py.addImportPath(Qt.resolvedUrl("../src")); py.addImportPath(Qt.resolvedUrl("../src"));
py.importModule("main", function(){ 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 icon.source = result
}) })
}) })

View File

@ -22,7 +22,6 @@ def avg_colors(img):
pixel = img.getpixel((x, y)) pixel = img.getpixel((x, y))
if pixel[-1] > 0: # Doesn't count the transparent pixels if pixel[-1] > 0: # Doesn't count the transparent pixels
counter[pixel] += 1 counter[pixel] += 1
print(counter.most_common(4))
return counter.most_common(1)[0][0] return counter.most_common(1)[0][0]
def add_background(img: Image, bg_tuple: tuple) -> Image: def add_background(img: Image, bg_tuple: tuple) -> Image:
@ -92,9 +91,11 @@ def sailify(raw_str, pattern):
output_base64 = base64.b64encode(output_data) output_base64 = base64.b64encode(output_data)
return "data:image/png;base64," + output_base64.decode() return "data:image/png;base64," + output_base64.decode()
def save_icon(app): def backup_icon(app):
if not os.path.exists(app["path"] + "backup"): if not os.path.exists(app["path"] + "backup"):
shutil.copyfile(app["path"], app["path"] + "_backup") shutil.copyfile(app["path"], app["path"] + "_backup")
def save_icon(app):
new_content = deparse_file(app) new_content = deparse_file(app)
with open(app["path"], "w") as f: with open(app["path"], "w") as f:
f.write(new_content) f.write(new_content)