-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'guigoroupsfixed' into MailFromGroupInsertion
- Loading branch information
Showing
1 changed file
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
from types import TracebackType | ||
from traceback import print_tb | ||
from typing import Literal, Any, NoReturn | ||
from tkinter import Menu, simpledialog, ttk, Listbox, Tk, Text, Button, Frame, Label, Entry, Scrollbar, Toplevel, Misc, messagebox, Menubutton, RAISED | ||
from tkinter import Menu, simpledialog, ttk, Listbox, Tk, Text, Button, Frame, Label, Entry, Scrollbar, Toplevel, Misc, messagebox, Menubutton, RAISED, VERTICAL, Canvas | ||
from tkinter.ttk import Combobox | ||
from tkinter.constants import NORMAL, DISABLED, BOTH, RIDGE, END, LEFT, RIGHT, TOP, X, Y, INSERT, SEL, WORD | ||
from models import Contact, IModel, Template, Group | ||
|
@@ -376,7 +376,7 @@ def show_placeholder_menu(event): | |
start_index = end_index | ||
|
||
class GroupEditor(Toplevel): | ||
def __init__(self, parent: AppUI, edited: Group | None = None): | ||
def __init__(self, parent: AppUI, groupName: str | None = None, edited: Group | None = None): | ||
super().__init__(parent.root) | ||
self.parent = parent | ||
self.currentGroup = edited | ||
|
@@ -400,11 +400,123 @@ def prepareInterface(self): | |
self.name_entry.insert(INSERT, self.currentGroup.name) | ||
[self.add_contact(c) for c in self.currentGroup.contacts] | ||
|
||
btn_save = Button(self, text="Zapisz", bg="lightblue", fg="black", command=self.__save_group_clicked) | ||
btn_save.grid(row=2, column=0, columnspan=2, padx=5, pady=5, sticky="ew") | ||
btn_add_list_contact = Button(self, text="Dodaj z listy", bg="lightblue", fg="black", command=self.add_contact_from_list_window) | ||
btn_add_list_contact.grid(row=2, column=0, padx=5, pady=5, sticky="ew") | ||
|
||
btn_add_manual_contact = Button(self, text="Dodaj ręcznie", bg="lightblue", fg="black", command=self.add_manual_contact_window) | ||
btn_add_manual_contact.grid(row=2, column=1, padx=5, pady=5, sticky="ew") | ||
|
||
def add_contact(self, c: Contact): | ||
self.email_text.insert(INSERT, c) | ||
btn_save = Button(self, text="Zapisz", bg="lightblue", fg="black", command=self.__save_group_clicked) | ||
btn_save.grid(row=3, column=0, columnspan=2, padx=5, pady=5, sticky="ew") | ||
|
||
def add_contact(self, c: 'Contact'): | ||
self.email_text.insert(INSERT, str(c.email) + "\n") | ||
|
||
def add_contact_from_list_window(self): | ||
def search_contact(): | ||
search_criteria = search_entry.get().strip().lower() | ||
for widget in contact_inner_frame.winfo_children(): | ||
widget.destroy() | ||
for idx, (email, name, surname) in enumerate(fake_data): | ||
if search_criteria in name.lower() or search_criteria in surname.lower() or search_criteria in email.lower(): | ||
Label(contact_inner_frame, text=f"Mail {idx+1}:").grid(row=idx, column=0, padx=5, pady=5) | ||
Label(contact_inner_frame, text=f"{email} - {name} {surname}").grid(row=idx, column=1, padx=5, pady=5) | ||
Button(contact_inner_frame, text="Dodaj kontakt", bg="lightblue", fg="black", command=lambda email=email: add_contact_from_list(email)).grid(row=idx, column=2, padx=5, pady=5) | ||
|
||
contact_window = Toplevel(self) | ||
contact_window.title("Dodaj kontakt z listy") | ||
|
||
group_editor_geometry = self.winfo_geometry() | ||
|
||
contact_window.geometry(group_editor_geometry) | ||
|
||
contact_frame = Frame(contact_window) | ||
contact_frame.pack(fill=BOTH, expand=True) | ||
|
||
search_frame = Frame(contact_frame, bg="lightblue") | ||
search_frame.pack(fill=X, padx=5, pady=5) | ||
|
||
search_label = Label(search_frame, text="Wyszukaj:", bg="lightblue") | ||
search_label.pack(side=LEFT, padx=5, pady=5) | ||
|
||
search_entry = Entry(search_frame, bg="white", fg="black") | ||
search_entry.pack(side=LEFT, padx=5, pady=5, expand=True, fill=X) | ||
|
||
search_button = Button(search_frame, text="Szukaj", bg="lightblue", fg="black", command=search_contact) | ||
search_button.pack(side=LEFT, padx=5, pady=5) | ||
|
||
scrollbar = Scrollbar(contact_frame, orient=VERTICAL) | ||
scrollbar.pack(side=RIGHT, fill=Y) | ||
|
||
contact_canvas = Canvas(contact_frame, yscrollcommand=scrollbar.set) | ||
contact_canvas.pack(side=LEFT, fill=BOTH, expand=True) | ||
|
||
scrollbar.config(command=contact_canvas.yview) | ||
|
||
contact_inner_frame = Frame(contact_canvas) | ||
contact_canvas.create_window((0, 0), window=contact_inner_frame, anchor='nw') | ||
|
||
fake_data = [("[email protected]", "John", "Doe"), | ||
("[email protected]", "Jane", "Smith"), | ||
("[email protected]", "Michael", "Johnson"), | ||
("[email protected]", "Emily", "Brown"), | ||
("[email protected]", "William", "Jones"), | ||
("[email protected]", "Olivia", "Taylor"), | ||
("[email protected]", "David", "Anderson"), | ||
("[email protected]", "Sophia", "Thomas"), | ||
("[email protected]", "James", "Jackson"), | ||
("[email protected]", "Emma", "White"), | ||
("[email protected]", "Benjamin", "Harris"), | ||
("[email protected]", "Isabella", "Martin"), | ||
("[email protected]", "Daniel", "Thompson"), | ||
("[email protected]", "Ava", "Garcia"), | ||
("[email protected]", "Alexander", "Martinez"), | ||
("[email protected]", "TEST", "16"), | ||
("[email protected]", "TEST", "17")] | ||
|
||
def add_contact_from_list(email): | ||
self.email_text.insert(END, email + "\n") | ||
|
||
for idx, (email, name, surname) in enumerate(fake_data): | ||
Label(contact_inner_frame, text=f"Mail {idx+1}:").grid(row=idx, column=0, padx=5, pady=5) | ||
Label(contact_inner_frame, text=f"{email} - {name} {surname}").grid(row=idx, column=1, padx=5, pady=5) | ||
Button(contact_inner_frame, text="Dodaj kontakt", bg="lightblue", fg="black", command=lambda email=email: add_contact_from_list(email)).grid(row=idx, column=2, padx=5, pady=5) | ||
|
||
def on_frame_configure(event): | ||
contact_canvas.configure(scrollregion=contact_canvas.bbox("all")) | ||
|
||
contact_inner_frame.bind("<Configure>", on_frame_configure) | ||
|
||
def add_manual_contact_window(self): | ||
contact_window = Toplevel(self) | ||
contact_window.title("Dodaj kontakt ręcznie") | ||
|
||
email_label = Label(contact_window, text="Adres email:", bg="lightblue") | ||
email_label.grid(row=0, column=0, padx=5, pady=5) | ||
self.email_entry = Entry(contact_window, bg="white", fg="black") | ||
self.email_entry.grid(row=0, column=1, padx=5, pady=5) | ||
|
||
name_label = Label(contact_window, text="Imię:", bg="lightblue") | ||
name_label.grid(row=1, column=0, padx=5, pady=5) | ||
self.name_entry = Entry(contact_window, bg="white", fg="black") | ||
self.name_entry.grid(row=1, column=1, padx=5, pady=5) | ||
|
||
surname_label = Label(contact_window, text="Nazwisko:", bg="lightblue") | ||
surname_label.grid(row=2, column=0, padx=5, pady=5) | ||
self.surname_entry = Entry(contact_window, bg="white", fg="black") | ||
self.surname_entry.grid(row=2, column=1, padx=5, pady=5) | ||
|
||
btn_add_contact = Button(contact_window, text="Dodaj kontakt", bg="lightblue", fg="black", command=self.add_manual_contact) | ||
btn_add_contact.grid(row=3, column=0, columnspan=2, padx=5, pady=5, sticky="ew") | ||
|
||
def add_manual_contact(self): | ||
email = self.email_entry.get() | ||
name = self.name_entry.get() | ||
surname = self.surname_entry.get() | ||
if email: | ||
self.email_text.insert(END, f"{email}\n") | ||
else: | ||
messagebox.showerror("Błąd", "Podaj adres e-mail") | ||
|
||
def __save_group_clicked(self) -> None: | ||
if not self.currentGroup: | ||
|