diff --git a/Interface/AppUI.py b/Interface/AppUI.py index 49014e7..61b017d 100644 --- a/Interface/AppUI.py +++ b/Interface/AppUI.py @@ -10,6 +10,7 @@ from .Settings import Settings from .TemplateEditor import TemplateEditor from MessagingService.senders import ISender +from sys import exit #import MessagingService.smtp_data #from MessagingService.ethereal_demo import send_email @@ -75,6 +76,7 @@ def run(self): def __exit_clicked(self) -> NoReturn | None: # Wait for saving objects to DB print("Exiting") + self.root.destroy() exit() def update_templates(self): diff --git a/Interface/GroupEditor.py b/Interface/GroupEditor.py index 7bfd152..e19923f 100644 --- a/Interface/GroupEditor.py +++ b/Interface/GroupEditor.py @@ -1,15 +1,15 @@ -from tkinter import Text, Button, Label, Entry, Tk, Toplevel +import pandas as pd +from tkinter import Text, Button, Label, Entry, Tk, Toplevel, filedialog from tkinter.constants import END, INSERT, WORD from group_controller import GroupController from models import Contact, Group from .ContactList import ContactList - class GroupEditor(Toplevel): def __init__(self, parent: Toplevel | Tk, edited: Group | None = None): super().__init__(parent.root) self.parent = parent - self.currentGroup = edited if edited != None else Group(_name="Nowa grupa" + str(len(Group.all_instances))) + self.currentGroup = Group() if edited is None else edited def prepareInterface(self): name_label = Label(self, text="Nazwa grupy:", bg="lightblue") @@ -18,27 +18,30 @@ def prepareInterface(self): self.email_text = Text(self, bg="lightblue", fg="black", wrap=WORD) btn_add_list_contact = Button(self, text="Dodaj z listy", bg="lightblue", fg="black", command=self.add_contact_from_list_window) btn_save = Button(self, text="Zapisz", bg="lightblue", fg="black", command=self.__save_group_clicked) + btn_import = Button(self, text="Importuj", bg="lightblue", fg="black", command=self.import_emails) + btn_export = Button(self, text="Eksportuj", bg="lightblue", fg="black", command=self.export_emails) name_label.grid(row=0, column=0, padx=5, pady=5, sticky="w") self.name_entry.grid(row=0, column=1, padx=5, pady=5, sticky="ew") email_label.grid(row=1, column=0, padx=5, pady=5, sticky="w") self.email_text.grid(row=1, column=1, padx=5, pady=5, sticky="nsew") btn_add_list_contact.grid(row=2, column=0, padx=5, pady=5, sticky="ew") - btn_save.grid(row=3, column=0, columnspan=2, padx=5, pady=5, sticky="ew") + btn_import.grid(row=2, column=1, padx=5, pady=5, sticky="ew") + btn_export.grid(row=3, column=0, padx=5, pady=5, sticky="ew") + btn_save.grid(row=3, column=1, padx=5, pady=5, sticky="ew") self.grid_columnconfigure(1, weight=1) self.grid_rowconfigure(1, weight=1) self.update() - def update(self): if self.currentGroup: self.title(f"Edytuj grupÄ™ {self.currentGroup.name}") self.name_entry.delete(0, END) self.name_entry.insert(0, self.currentGroup.name) self.currentGroup.contacts = GroupController.get_contacts(self.currentGroup) - self.email_text.delete('1.0', END) # Clear current content + self.email_text.delete('1.0', END) [self.add_contact(c) for c in self.currentGroup.contacts] else: self.title("Dodaj grupÄ™") @@ -58,3 +61,19 @@ def __save_group_clicked(self) -> None: self.currentGroup.name = self.name_entry.get() self.parent.update() self.destroy() + + def import_emails(self): + file_path = filedialog.askopenfilename(filetypes=[("Excel files", "*.xlsx")]) + if file_path: + df = pd.read_excel(file_path) + emails = df['email'].dropna().tolist() + for email in emails: + self.email_text.insert(INSERT, str(email) + "\n") + + def export_emails(self): + file_path = filedialog.asksaveasfilename(defaultextension=".xlsx", filetypes=[("Excel files", "*.xlsx")]) + if file_path: + txt = self.email_text.get(1.0, END).strip() + email_addresses = [address for address in txt.split("\n") if address.strip()] + df = pd.DataFrame(email_addresses, columns=["email"]) + df.to_excel(file_path, index=False) \ No newline at end of file diff --git a/main.py b/main.py index 4029aaa..c636e8b 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,14 @@ from MessagingService.senders import * from MessagingService.readers import * from UserInfo.LoginService import * -# from sys import platform +from sys import exit from group_controller import GroupController from models import DataImport, IModel, Template, Attachment, Contact, Message, Group, User from Triggers.triggers import ITrigger from Interface.AppUI import AppUI from DataSources.dataSources import DatabaseHandler, GapFillSource, IDataSource from additionalTableSetup import GroupContacts, MessageAttachment, SendAttempt +import tkinter as tk #from MessagingService.smtp_data import smtp_security, smtp_host, smtp_port #from globaldb import db @@ -23,18 +24,24 @@ dbURL = f"sqlite:///{dbname}" tables = [Template, DataImport, Attachment, Contact, User, ITrigger, Message, Group, MessageAttachment, SendAttempt, GroupContacts] - +def on_closing(): + print("Window closed by user.") + exit() + if __name__ == "__main__": db = DatabaseHandler(dbURL, tables) GroupController.setDbHandler(db) if db.checkIntegrity(): - print("Database intact, proceeding") + print("Database intact, proceeding.") + else: + print("Database integrity check failed. Exiting.") + exit() + db.LoadSavedState() ui = AppUI() ui.prepareInterface() - ui.setDb(db) _contact_fields = GapFillSource() @@ -48,13 +55,14 @@ sender = SMTPSender() except Exception as e: print(e) + exit() sender = SMTPSender() ui.setSender(sender) - # user = - # User(_email="russ.connelly30@ethereal.email", _password="QQcGx1RmfVkaEMjzqZ", _first_name="Russ", _last_name="Connelly", _selected=True) + # user = User(_email="russ.connelly30@ethereal.email", _password="QQcGx1RmfVkaEMjzqZ", _first_name="Russ", _last_name="Connelly", _selected=True) # ui.setUser(user) # ui.add_periodic_task(5000, pushQueuedInstances) + ui.run()