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
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
})
})

View File

@ -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)