which_my_toast/en.py
2024-05-12 21:47:43 +09:00

161 lines
No EOL
7.4 KiB
Python

import customtkinter
import os
from PIL import Image
from winotify import Notification, audio
from plyer import notification
version = "0.1"
builddate = "2023/4/27"
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("which_my_toast")
self.geometry("786x380")
self.resizable(height=False, width=False)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1)
image_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "lib")
self.logo = customtkinter.CTkImage(Image.open(os.path.join(image_path, "logo.png")), size=(59, 54))
self.title_font = customtkinter.CTkFont(family="meiryo", size=20, weight="bold")
self.info_font = customtkinter.CTkFont(family="meiryo", size=14)
self.frame = customtkinter.CTkFrame(self, corner_radius=0)
self.frame.grid(row=0, column=0, sticky="nsew")
self.frame.grid_columnconfigure(4, weight=1)
self.frame_label = customtkinter.CTkLabel(self.frame, text=" which_my_toast", image=self.logo, compound="left", font=customtkinter.CTkFont(size=15, weight="bold"))
self.frame_label.grid(row=0, column=0, padx=20, pady=20)
self.library_text = customtkinter.CTkLabel(self.frame, text="Library", compound="left")
self.library_text.grid(row=1, column=0, sticky="ew")
self.winotify_button = customtkinter.CTkButton(self.frame, height=40, border_spacing=10, text="Winotify", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.frame_select_winotify)
self.winotify_button.grid(row=2, column=0, sticky="ew")
self.plyer_button = customtkinter.CTkButton(self.frame, height=40, border_spacing=10, text="Plyer", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.frame_select_plyer)
self.plyer_button.grid(row=3, column=0, sticky="ew")
self.info_button = customtkinter.CTkButton(self.frame,height=40, border_spacing=10, text="About this app", fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"), anchor="w", command=self.which_info)
self.info_button.grid(row=4, column=0, sticky="ew")
#winotify欄
self.winotify_frame = customtkinter.CTkFrame(self, fg_color="transparent")
self.winotify_frame.grid_columnconfigure(0, weight=1)
self.wn_title_label = customtkinter.CTkLabel(self.winotify_frame, text="Winotify", font=self.title_font)
self.wn_title_label.grid(row=1, column=0, padx=2, pady=5)
self.wn_info1_label = customtkinter.CTkLabel(self.winotify_frame, text="Recommended method for Windows 10 or later.", font=self.info_font)
self.wn_info1_label.grid(row=2, column=0, padx=5, pady=5)
self.wn_info2_label = customtkinter.CTkLabel(self.winotify_frame, text="※ App icons are not available.", font=self.info_font)
self.wn_info2_label.grid(row=3, column=0, padx=0, pady=0)
self.wn_app_textbox = customtkinter.CTkEntry(self.winotify_frame, placeholder_text="Application Title", width=520)
self.wn_app_textbox.grid(row=4, column=0, padx=20, pady=10)
self.wn_title_textbox = customtkinter.CTkEntry(self.winotify_frame, placeholder_text="Title", width=520)
self.wn_title_textbox.grid(row=5, column=0, padx=20, pady=10)
self.wn_msg_textbox = customtkinter.CTkEntry(self.winotify_frame, placeholder_text="Message", width=520)
self.wn_msg_textbox.grid(row=6, column=0, padx=20, pady=10)
self.wn_icon_textbox = customtkinter.CTkEntry(self.winotify_frame, placeholder_text="Message Icon Path", width=520)
self.wn_icon_textbox.grid(row=7, column=0, padx=20, pady=10)
self.wn_send_button = customtkinter.CTkButton(self.winotify_frame, text="Send",compound="right", command=self.winotify_send)
self.wn_send_button.grid(row=8, column=0, padx=40, pady=20)
#Plyer欄
self.plyer_frame = customtkinter.CTkFrame(self, fg_color="transparent")
self.plyer_frame.grid_columnconfigure(0, weight=1)
self.plyer_title_label = customtkinter.CTkLabel(self.plyer_frame, text="Plyer", font=self.title_font)
self.plyer_title_label.grid(row=1, column=0, padx=2, pady=5)
self.plyer_info1_label = customtkinter.CTkLabel(self.plyer_frame, text="Recommended method for legacy operating systems such as Windows 7", font=self.info_font)
self.plyer_info1_label.grid(row=2, column=0, padx=5, pady=5)
#self.plyer_info2_label = customtkinter.CTkLabel(self.plyer_frame, text="※アプリアイコンはicoファイルを指定してください。", font=self.info_font)
#self.plyer_info2_label.grid(row=3, column=0, padx=0, pady=0)
self.plyer_title_textbox = customtkinter.CTkEntry(self.plyer_frame, placeholder_text="Title", width=520)
self.plyer_title_textbox.grid(row=4, column=0, padx=20, pady=10)
self.plyer_msg_textbox = customtkinter.CTkEntry(self.plyer_frame, placeholder_text="Message", width=520)
self.plyer_msg_textbox.grid(row=5, column=0, padx=20, pady=10)
self.plyer_icon_textbox = customtkinter.CTkEntry(self.plyer_frame, placeholder_text="Application Icon Path (only ico image)", width=520)
self.plyer_icon_textbox.grid(row=6, column=0, padx=20, pady=10)
self.plyer_send_button = customtkinter.CTkButton(self.plyer_frame, text="Send", command=self.plyer_send)
self.plyer_send_button.grid(row=7, column=0, padx=40, pady=10)
self.select_frame_name("winotify_frame")
def select_frame_name(self, name):
self.winotify_button.configure(fg_color=("gray75", "gray25") if name == "winotify_frame" else "transparent")
self.plyer_button.configure(fg_color=("gray75", "gray25") if name == "plyer_frame" else "transparent")
if name == "winotify_frame":
self.winotify_frame.grid(row=0, column=1, sticky="nsew")
else:
self.winotify_frame.grid_forget()
if name == "plyer_frame":
self.plyer_frame.grid(row=0, column=1, sticky="nsew")
else:
self.plyer_frame.grid_forget()
def frame_select_winotify(self):
self.select_frame_name("winotify_frame")
def frame_select_plyer(self):
self.select_frame_name("plyer_frame")
#通知送信部
def winotify_send(self):
winotify_notification = Notification(
app_id = self.wn_app_textbox.get(),
title = self.wn_title_textbox.get(),
msg = self.wn_msg_textbox.get(),
icon = self.wn_icon_textbox.get()
)
winotify_notification.set_audio(audio.Default, loop=False)
winotify_notification.show()
def plyer_send(self):
notification.notify(
title = self.plyer_title_textbox.get(),
message = self.plyer_msg_textbox.get(),
app_icon = self.plyer_icon_textbox.get()
)
def which_info(self):
print(version)
which_info_msg_base = "which_my_toast Version {} \nBuild Date {}"
notification.notify(
title = "About this app",
message = which_info_msg_base.format(version,builddate),
app_icon = r"lib\logo.ico"
)
if __name__ == "__main__":
app = App()
app.mainloop()