Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
krwg authored Nov 21, 2024
1 parent ea68c5c commit 1d80145
Showing 1 changed file with 158 additions and 81 deletions.
239 changes: 158 additions & 81 deletions note.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import tkinter as tk
import customtkinter
import sqlite3
import json
from PIL import Image, ImageTk
import tkinter.messagebox as messagebox
import requests
Expand All @@ -10,8 +11,15 @@
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("blue")

CURRENT_VERSION = "1.1.0."

CURRENT_VERSION = "1.01"
conn = None
cur = None
settings_window = None

current_note_id = None

font_sizes = {"Заголовок": 30, "Подзаголовок": 24, "Обычный": 18}

def db_start():
global conn, cur
Expand All @@ -21,7 +29,9 @@ def db_start():
cur.execute("""
CREATE TABLE IF NOT EXISTS notes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
note TEXT
note TEXT,
pinned INTEGER DEFAULT 0,
formatted_text TEXT
)
""")
conn.commit()
Expand All @@ -30,56 +40,107 @@ def db_start():
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка подключения к базе данных.")

def save_note(event=None):
note = note_entry.get("1.0", tk.END).strip()
if note:
try:
cur.execute("INSERT INTO notes (note) VALUES (?)", (note,))
conn.commit()
update_notes_list()
note_entry.delete("1.0", tk.END)
except sqlite3.Error as e:
print(f"Ошибка сохранения заметки: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка сохранения заметки.")
global current_note_id
if current_note_id:
note = note_entry.get("1.0", tk.END).strip()
if note:
try:
font_size = selected_font_size.get()
formatted_data = {"text": note, "font_size": font_size}
formatted_text = json.dumps(formatted_data)
cur.execute("UPDATE notes SET note=?, formatted_text=? WHERE id=?", (note, formatted_text, current_note_id))
conn.commit()
update_notes_list()
note_entry.delete("1.0", tk.END)
selected_font_size.set("Обычный")
note_entry.configure(font=("Arial", font_sizes["Обычный"]))
current_note_id = None
except sqlite3.Error as e:
messagebox.showerror("Ошибка", f"Ошибка при сохранении заметки: {e}")
else:
messagebox.showwarning("Предупреждение", "Заметка пуста!")
else:
customtkinter.CTkMessageBox(title="Предупреждение", message="Заметка пуста!")
if event and event.state & 0x0004:
note_entry.insert(tk.END, "\n")
else:
note = note_entry.get("1.0", tk.END).strip()
if note:
try:
font_size = selected_font_size.get()
formatted_data = {"text": note, "font_size": font_size}
formatted_text = json.dumps(formatted_data)
cur.execute("INSERT INTO notes (note, formatted_text) VALUES (?, ?)", (note, formatted_text))
conn.commit()
update_notes_list()
note_entry.delete("1.0", tk.END)
selected_font_size.set("Обычный")
note_entry.configure(font=("Arial", font_sizes["Обычный"]))
except sqlite3.Error as e:
print(f"Ошибка сохранения заметки: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка сохранения заметки.")
else:
customtkinter.CTkMessageBox(title="Предупреждение", message="Заметка пуста!")


def update_notes_list():
notes_list.delete(0, tk.END)
for widget in note_container_frame.winfo_children():
widget.destroy()
global note_container_frame
note_container_frame = customtkinter.CTkFrame(left_frame, fg_color="#333333")
note_container_frame.grid(row=2, column=0, sticky="nsew", padx=10, pady=10)
note_container_frame.columnconfigure(0, weight=1)
for i in range(100):
note_container_frame.rowconfigure(i, weight=1)

try:
cur.execute("SELECT id, note FROM notes")
cur.execute("SELECT id, note, pinned, formatted_text FROM notes")
notes = cur.fetchall()
if notes:
notes_label.configure(text="")
instruction_label.grid_forget()
for i, (note_id, note_text) in enumerate(notes):
notes_list.insert(tk.END, note_text)
create_note_container(note_text, i, note_id)
for i, (note_id, note_text, pinned, formatted_text) in enumerate(notes):
create_note_container(json.loads(formatted_text), i, note_id, pinned)
else:
notes_label.configure(text="Здесь будут ваши заметки")
instruction_label.grid(row=1, column=0, sticky="w", padx=10, pady=5)
except sqlite3.Error as e:
print(f"Ошибка обновления списка заметок: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка обновления списка заметок.")
messagebox.showerror("Ошибка", f"Ошибка при обновлении списка заметок: {e}")
except Exception as e:
messagebox.showerror("Ошибка", f"Непредвиденная ошибка: {e}")

#dev.krwg

def create_note_container(formatted_data, row_index, note_id, pinned):
try:
container = customtkinter.CTkFrame(note_container_frame, fg_color="transparent", corner_radius=5, border_width=2, border_color="#555555")
container.grid(row=row_index, column=0, sticky="nsew", padx=10, pady=(5, 0))
container.columnconfigure(0, weight=1)

def create_note_container(note_text, row_index, note_id):
container = customtkinter.CTkFrame(note_container_frame, fg_color="transparent", corner_radius=5, border_width=2, border_color="#555555")
container.grid(row=row_index, column=0, sticky="nsew", padx=10, pady=(5, 0))
container.columnconfigure(0, weight=1)
try:
label = customtkinter.CTkLabel(container, text=formatted_data["text"], font=("Arial", font_sizes[formatted_data["font_size"]]), text_color="lightgray", anchor="w", justify="left", wraplength=300)
except (KeyError, TypeError):
label = customtkinter.CTkLabel(container, text=formatted_data["text"], font=("Arial", font_sizes["Обычный"]), text_color="lightgray", anchor="w", justify="left", wraplength=300)

label.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
container.rowconfigure(0, weight=1)

label = customtkinter.CTkLabel(container, text=note_text, font=("Arial", 12), text_color="lightgray", anchor="w", justify="left", wraplength=300)
label.grid(row=0, column=0, sticky="nsew", padx=10, pady=10)
container.rowconfigure(0, weight=1)
menu = tk.Menu(label, tearoff=0, bg="#333333", fg="lightgray")
menu.add_command(label="Удалить", command=lambda note_id=note_id: delete_note_by_id(note_id))
menu.add_command(label="Изменить", command=lambda note_id=note_id: edit_note(note_id))

menu = tk.Menu(container, tearoff=0)
menu.add_command(label="Удалить", command=lambda id=note_id: delete_note_by_id(id))
menu.add_command(label="Изменить", command=lambda id=note_id: edit_note(id))
if pinned:
menu.add_command(label="Открепить", command=lambda note_id=note_id: toggle_pinned(note_id, False))
else:
menu.add_command(label="Закрепить", command=lambda note_id=note_id: toggle_pinned(note_id, True))

label.bind("<Button-3>", lambda event, menu=menu: menu.post(event.x_root, event.y_root))
label.bind("<Button-1>", lambda event, text=note_text: copy_to_editor(text))
label.bind("<Button-3>", lambda event, menu=menu: menu.post(event.x_root, event.y_root))
label.bind("<Button-1>", lambda event, note_text=formatted_data["text"], note_id=note_id: copy_to_editor(note_text, note_id))

return container
if pinned:
container.configure(fg_color="#444444")

add_font_menu(label)
return container
except Exception as e:
messagebox.showerror("Ошибка", f"Ошибка создания контейнера заметки: {e}")

def delete_note_by_id(note_id):
try:
Expand All @@ -90,22 +151,21 @@ def delete_note_by_id(note_id):
print(f"Ошибка удаления заметки: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка удаления заметки.")

def copy_to_editor(note_text):
def copy_to_editor(note_text, note_id):
global current_note_id
note_entry.delete("1.0", tk.END)
note_entry.insert("1.0", note_text)
current_note_id = note_id

def toggle_fullscreen(event=None):
root.attributes('-fullscreen', not root.attributes('-fullscreen'))

settings_window = None
selected_section = None

def open_settings():
global settings_window, selected_section
if settings_window is None or not settings_window.winfo_exists():
settings_window = customtkinter.CTkToplevel(root)
settings_window.title("Настройки")
settings_window.geometry("600x300")
settings_window.geometry("800x600")
settings_window.resizable(False, False)

left_settings_column = customtkinter.CTkFrame(settings_window, fg_color="#333333")
Expand Down Expand Up @@ -135,6 +195,8 @@ def open_settings():

def close_settings():
global settings_window
if conn:
conn.close()
settings_window.destroy()
settings_window = None

Expand All @@ -153,8 +215,6 @@ def check_for_updates():
except Exception as e:
messagebox.showerror("Ошибка", f"Произошла непредвиденная ошибка: {e}")



def select_section(func, right_column):
global selected_section
selected_section = func
Expand All @@ -176,7 +236,7 @@ def display_about(right_column):
author_label = customtkinter.CTkLabel(right_column, text="krwg. 2024", font=("Arial", 10), text_color="lightgray")
author_label.pack(pady=5)

version_label = customtkinter.CTkLabel(right_column, text=f"Версия: 1.0 Moonstone", font=("Arial", 12))
version_label = customtkinter.CTkLabel(right_column, text=f"Версия: 1.1 Moonstone", font=("Arial", 12))
version_label.pack(pady=5)

check_updates_button = customtkinter.CTkButton(right_column, text="Проверить обновления", command=check_for_updates, fg_color=("gray70", "gray30"), hover_color=("gray80", "gray40"))
Expand All @@ -186,37 +246,39 @@ def display_main(right_column):
main_label = customtkinter.CTkLabel(right_column, text="В разработке, ожидайте в новой версии", font=("Arial", 12))
main_label.pack(pady=10)

def edit_note(note_id):
try:
cur.execute("SELECT note FROM notes WHERE id=?", (note_id,))
note_text = cur.fetchone()[0]
edit_window = customtkinter.CTkToplevel(root)
edit_window.title("Редактирование заметки")

edit_textbox = customtkinter.CTkTextbox(edit_window, font=("Arial", 12), fg_color="#444444", text_color="lightgray")
edit_textbox.insert("0.0", note_text)
edit_textbox.pack(pady=10, padx=10, fill="both", expand=True)
def add_font_menu(widget):
font_sizes = {"Заголовок": 30, "Подзаголовок": 24, "Обычный": 18}
selected_font_size = tk.StringVar(widget.master, "Обычный")

def save_edit():
edited_text = edit_textbox.get("1.0", tk.END).strip()
cur.execute("UPDATE notes SET note=? WHERE id=?", (edited_text, note_id))
conn.commit()
update_notes_list()
edit_window.destroy()
def change_font_size(size):
try:
widget.configure(font=("Arial", font_sizes[size]))
except KeyError:
customtkinter.CTkMessageBox(title="Ошибка", message="Неверный размер шрифта.")
except Exception as e:
customtkinter.CTkMessageBox(title="Ошибка", message=f"Ошибка изменения шрифта: {e}")

save_button = customtkinter.CTkButton(edit_window, text="Сохранить", command=save_edit)
save_button.pack(pady=10)
font_menu = tk.Menu(widget, tearoff=0, bg="#333333", fg="lightgray")
for size_name in font_sizes:
font_menu.add_command(label=size_name, command=lambda s=size_name: change_font_size(s))

except sqlite3.Error as e:
print(f"Ошибка редактирования заметки: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка редактирования заметки.")
widget.bind("<Button-3>", lambda event, menu=font_menu: menu.post(event.x_root, event.y_root))

def change_theme(is_dark):
if is_dark:
customtkinter.set_appearance_mode("dark")
else:
customtkinter.set_appearance_mode("light")

def toggle_pinned(note_id, pinned):
try:
cur.execute("UPDATE notes SET pinned=? WHERE id=?", (pinned, note_id))
conn.commit()
update_notes_list()
except sqlite3.Error as e:
print(f"Ошибка изменения статуса закрепления: {e}")
customtkinter.CTkMessageBox(title="Ошибка", message="Ошибка изменения статуса закрепления.")

root = customtkinter.CTk()
root.title("Just Keep")
root.geometry("800x600")
Expand All @@ -232,51 +294,66 @@ def change_theme(is_dark):
header_label = customtkinter.CTkLabel(header, text="JustKeep", font=("Arial", 24))
header_label.pack(pady=10, side=tk.LEFT, expand=True, fill="x")

#dev.krwg

try:
image = Image.open("settings_icon.png")
photo = ImageTk.PhotoImage(image)
settings_button = customtkinter.CTkButton(header, text="Настройки", image=photo, compound=tk.RIGHT, fg_color=("gray70", "gray30"), hover_color=("gray80", "gray40"), border_width=0)
settings_button = customtkinter.CTkButton(header, text="Настройки", image=photo, compound=tk.RIGHT, fg_color=("gray70", "gray30"), hover_color=("gray80", "gray40"), border_width=0, command=open_settings)
settings_button.image = photo
settings_button.pack(side=tk.RIGHT, padx=10, pady=10)
settings_button.configure(command=open_settings)
except FileNotFoundError:
print("Файл с иконкой не найден!")
settings_button = customtkinter.CTkButton(header, text="Настройки", command=open_settings, fg_color=("gray70", "gray30"), hover_color=("gray80", "gray40"), border_width=0)
settings_button.pack(side=tk.RIGHT, padx=10, pady=10)


left_frame = customtkinter.CTkFrame(root, fg_color="#333333")
left_frame.grid(row=1, column=0, sticky="nsew")

left_canvas = tk.Canvas(root, bg="#333333", highlightthickness=0)
left_canvas.grid(row=1, column=0, sticky="nsew")

notes_label = customtkinter.CTkLabel(left_canvas, text="Здесь будут ваши заметки", font=("Arial", 14), text_color="lightgray")
notes_label = customtkinter.CTkLabel(left_frame, text="Здесь будут ваши заметки", font=("Arial", 14), text_color="lightgray")
notes_label.grid(row=0, column=0, sticky="w", padx=10, pady=10)

instruction_label = customtkinter.CTkLabel(left_canvas, text="Для создания введите текст и Enter", font=("Arial", 10), text_color="#888888")
instruction_label = customtkinter.CTkLabel(left_frame, text="Для создания введите текст и Enter", font=("Arial", 10), text_color="#888888")
instruction_label.grid(row=1, column=0, sticky="w", padx=10, pady=5)

note_container_frame = customtkinter.CTkFrame(left_canvas, fg_color="#333333")
note_container_frame = customtkinter.CTkFrame(left_frame, fg_color="#333333")
note_container_frame.grid(row=2, column=0, sticky="nsew", padx=10, pady=10)
note_container_frame.columnconfigure(0, weight=1)

for i in range(100):
note_container_frame.rowconfigure(i, weight=1)

notes_list = tk.Listbox(left_canvas, width=0, height=0, font=("Arial", 12), bg="#333333", fg="lightgray", selectbackground="#666666", selectforeground="white", exportselection=False)


right_canvas = tk.Canvas(root, bg="#222222", highlightthickness=0)
right_canvas.grid(row=1, column=1, sticky="nsew")
right_frame = customtkinter.CTkFrame(root, fg_color="#222222")
right_frame.grid(row=1, column=1, sticky="nsew")

note_label = customtkinter.CTkLabel(right_canvas, text="Заметка:", font=("Arial", 12), text_color="lightgray")
note_entry = customtkinter.CTkTextbox(right_canvas, font=("Arial", 12), fg_color="#444444", text_color="lightgray")
note_label = customtkinter.CTkLabel(right_frame, text="Заметка:", font=("Arial", 12), text_color="lightgray")
note_entry = customtkinter.CTkTextbox(right_frame, font=("Arial", 12), fg_color="#444444", text_color="lightgray")
note_entry.bind("<Return>", save_note)
note_entry.bind("<Control-Return>", lambda event: note_entry.insert(tk.END, "\n"))

note_label.pack(pady=10, padx=10)
note_entry.pack(pady=10, padx=10, fill="both", expand=True)

selected_font_size = tk.StringVar(right_frame, "Обычный")

def change_note_font_size(size):
try:
note_entry.configure(font=("Arial", font_sizes[size]))
selected_font_size.set(size)
except KeyError:
customtkinter.CTkMessageBox(title="Ошибка", message="Неверный размер шрифта.")
except Exception as e:
customtkinter.CTkMessageBox(title="Ошибка", message=f"Ошибка изменения шрифта: {e}")

font_menu_main = tk.Menu(note_entry, tearoff=0, bg="#333333", fg="lightgray")
for size_name in font_sizes:
font_menu_main.add_command(label=size_name, command=lambda s=size_name: change_note_font_size(s))

note_entry.bind("<Button-3>", lambda event, menu=font_menu_main: menu.post(event.x_root, event.y_root))

#dev.krwg

root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=3)
Expand All @@ -289,6 +366,6 @@ def change_theme(is_dark):
db_start()
update_notes_list()

root.mainloop()
if conn:
conn.close()
root.protocol("WM_DELETE_WINDOW", lambda: [conn.close(), root.destroy()])

root.mainloop()

0 comments on commit 1d80145

Please sign in to comment.