Skip to content

Commit 46e0936

Browse files
committed
Make script to generate icons
1 parent 2375d4b commit 46e0936

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

Magic_AI_Storybook/make_shortcut.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
3+
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
4+
#
5+
# SPDX-License-Identifier: MIT
6+
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
7+
8+
import os
9+
10+
def create_folders(file_path):
11+
path = os.path.dirname(file_path)
12+
if not os.path.exists(path):
13+
os.makedirs(path)
14+
15+
def write_file(path, contents):
16+
create_folders(path)
17+
with open(path, "w") as f:
18+
f.write(contents)
19+
20+
print(f"Shortcut created at {path}")
21+
22+
def main():
23+
APP_TITLE = "Magic Storybook"
24+
RUN_IN_TERMINAL = True
25+
APP_PATH = "~/Magic_AI_Storybook/story.py"
26+
APP_ICON = "~/Magic_AI_Storybook/images/magic_book_icon.png"
27+
FILENAME = "storybook.desktop"
28+
AUTO_START = True
29+
30+
if os.geteuid() == 0:
31+
username = os.environ["SUDO_USER"]
32+
else:
33+
username = os.getlogin()
34+
user_homedir = os.path.expanduser(f"~{username}")
35+
36+
print("Username is ", username)
37+
print("User home directory is ", user_homedir)
38+
39+
APP_PATH = APP_PATH.replace("~", user_homedir)
40+
APP_ICON = APP_ICON.replace("~", user_homedir)
41+
42+
shortcut_template = f"""[Desktop Entry]
43+
Comment=Run {APP_TITLE}
44+
Terminal={"true" if RUN_IN_TERMINAL else "false"}
45+
Name={APP_TITLE}
46+
Exec=sudo python {APP_PATH}
47+
Type=Application
48+
Icon={APP_ICON}
49+
"""
50+
51+
write_file(f"{user_homedir}/Desktop/{FILENAME}", shortcut_template)
52+
if AUTO_START:
53+
write_file(f"{user_homedir}/.config/autostart/{FILENAME}", shortcut_template)
54+
55+
if __name__ == "__main__":
56+
main()

Magic_AI_Storybook/story.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# SPDX-FileCopyrightText: 2023 Melissa LeBlanc-Williams for Adafruit Industries
22
#
33
# SPDX-License-Identifier: MIT
4-
# Desktop Icon from <a href="https://www.flaticon.com/free-icons/book" title="book icons">Book icons created by Freepik - Flaticon</a>
54

65
import threading
76
import sys
@@ -747,7 +746,3 @@ def main(args):
747746

748747
if __name__ == "__main__":
749748
main(parse_args())
750-
751-
# TODO:
752-
# * Figure out how to get the script to start on boot
753-
# * Play with chatgpt prompt parameters

Magic_AI_Storybook/storybook.desktop

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)