Make script to generate icons

This commit is contained in:
Melissa LeBlanc-Williams 2023-05-19 15:52:28 -07:00
parent 2375d4b9e1
commit 46e0936dcd
3 changed files with 56 additions and 12 deletions

View file

@ -0,0 +1,56 @@
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
import os
def create_folders(file_path):
path = os.path.dirname(file_path)
if not os.path.exists(path):
os.makedirs(path)
def write_file(path, contents):
create_folders(path)
with open(path, "w") as f:
f.write(contents)
print(f"Shortcut created at {path}")
def main():
APP_TITLE = "Magic Storybook"
RUN_IN_TERMINAL = True
APP_PATH = "~/Magic_AI_Storybook/story.py"
APP_ICON = "~/Magic_AI_Storybook/images/magic_book_icon.png"
FILENAME = "storybook.desktop"
AUTO_START = True
if os.geteuid() == 0:
username = os.environ["SUDO_USER"]
else:
username = os.getlogin()
user_homedir = os.path.expanduser(f"~{username}")
print("Username is ", username)
print("User home directory is ", user_homedir)
APP_PATH = APP_PATH.replace("~", user_homedir)
APP_ICON = APP_ICON.replace("~", user_homedir)
shortcut_template = f"""[Desktop Entry]
Comment=Run {APP_TITLE}
Terminal={"true" if RUN_IN_TERMINAL else "false"}
Name={APP_TITLE}
Exec=sudo python {APP_PATH}
Type=Application
Icon={APP_ICON}
"""
write_file(f"{user_homedir}/Desktop/{FILENAME}", shortcut_template)
if AUTO_START:
write_file(f"{user_homedir}/.config/autostart/{FILENAME}", shortcut_template)
if __name__ == "__main__":
main()

View file

@ -1,7 +1,6 @@
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
#
# SPDX-License-Identifier: MIT
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
import threading
import sys
@ -747,7 +746,3 @@ def main(args):
if __name__ == "__main__":
main(parse_args())
# TODO:
# * Figure out how to get the script to start on boot
# * Play with chatgpt prompt parameters

View file

@ -1,7 +0,0 @@
[Desktop Entry]
Comment=Run Magic Storybook
Terminal=true
Name=Magic Storybook
Exec=sudo python /home/pi/Magic_AI_Storybook/story.py
Type=Application
Icon=/home/pi/Magic_AI_Storybook/images/magic_book_icon.png