Skip to content

Commit

Permalink
Add suffixes to image files to prevent overwriting
Browse files Browse the repository at this point in the history
  • Loading branch information
LolJohn11 committed Feb 26, 2024
1 parent 715634e commit ce3a3d3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Xbox:
## To-do:
- [X] Tooltips for text buttons
- [X] Character-specific buttons (stances, etc.)
- [ ] Add a suffix to generated images
- [X] Add a suffix to generated images
- [ ] Add number buttons
- [ ] UI Improvements
- [ ] Adding a colored background to the exported image
36 changes: 32 additions & 4 deletions app.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -408,9 +408,22 @@ class VirtualKeyboardApp:
combined_image.paste(img, (current_width, 0), mask=img.convert('RGBA').split()[3])
current_width += 80

# Export normal image
combined_image.save("notation.png")
messagebox.showinfo("Save Successful", "Image file(s) created successfully.")
# Define the base file name
base_filename = "notation.png"

# Check if the file already exists
if os.path.exists(base_filename):
# If it does, find a unique file name
suffix = 1
while os.path.exists(f"notation_{suffix}.png"):
suffix += 1

# Update the base file name with the unique suffix
base_filename = f"notation_{suffix}.png"

# Save the combined image
combined_image.save(base_filename)
messagebox.showinfo("Save Successful", f"Image file(s) created successfully.")

# Export dark image if checkbox is checked
if self.include_dark.get():
Expand All @@ -423,7 +436,22 @@ class VirtualKeyboardApp:
dark_image.paste(dark_img, (current_width, 0), mask=dark_img.convert('RGBA').split()[3])
current_width += 80

dark_image.save("notation_dark.png")
# Define the base file name for dark image
dark_base_filename = base_filename.replace(".png", "_dark.png")

# Check if the dark image file already exists
if os.path.exists(dark_base_filename):
# If it does, find a unique file name
suffix = 1
while os.path.exists(f"notation_{suffix}_dark.png"):
suffix += 1

# Update the base file name with the unique suffix
dark_base_filename = f"notation_{suffix}_dark.png"

# Save the dark image
dark_image.save(dark_base_filename)
# messagebox.showinfo("Save Successful", f"Dark image file '{dark_base_filename}' created successfully.")

if __name__ == "__main__":
root = tk.Tk()
Expand Down

0 comments on commit ce3a3d3

Please sign in to comment.