def edit_contact(self, *args): corresponding_contacts = DataManipulation.find_coresponding_contacts( self.contacts, input("Entrez un mot cle pour la recherche : ")) if len(corresponding_contacts) == 0: m = EasyMenu("La recherche ne donne pas de resultat (" + str(len(corresponding_contacts)) + "), voulez-vous recommencer ?") m.set_prompt("Votre choix : ") m.add_entry("Oui", self.edit_contact) m.add_entry("Non", self.make_menu) m.show_menu() self.execute(m.wait_for_choise()) else: def start_edit(*args): index = args[0][0] self.contacts[index].wizard() self.contacts = Contact.Contact.update_all(self.contacts) io_formats.get_format(self.DEFAULT_DB_FORMAT).export_data( self.contacts, self.file_path) self.make_menu() menu = EasyMenu("Veuillez choisir le contact a modifier") menu.set_prompt("Votre choix: ") for contact, i in corresponding_contacts: menu.add_entry(contact.get_string(), start_edit, i) menu.show_menu() self.execute(menu.wait_for_choise())
def select_format(self, *args): if len(self.contacts) == 0: print("Aucun contact...") self.make_menu() return temp_menu = EasyMenu("Selection du format d'exportation") temp_menu.set_prompt("Votre choix: ") for file_format in io_formats.get_formats(): temp_menu.add_entry(file_format, self.export, file_format) temp_menu.show_menu() self.execute(temp_menu.wait_for_choise())
def export(self, args): file_format = args[0] menu = EasyMenu("Que voulez vous exporter en " + file_format + " ?") menu.set_prompt("Votre choix : ") print(file_format) menu.add_entry("Tous les contacts", self.export_all, file_format) menu.add_entry("Un/plusieurs contact(s)", self.export_single, file_format) menu.show_menu() self.execute(menu.wait_for_choise())
def convert(self, *args): input_file = input("Entrez le fichier de départ : ") if os.path.exists(input_file): temp_menu = EasyMenu("Selection du format d'exportation") temp_menu.set_prompt("Votre choix: ") for file_format in io_formats.get_formats(): if not input_file.endswith("." + file_format): temp_menu.add_entry(file_format, CliApp.convert_file, os.path.splitext(input_file)[1], file_format, input_file) temp_menu.show_menu() self.execute(temp_menu.wait_for_choise()) self.make_menu()
def delete_contact(self, *args): menu = EasyMenu("Veuillez choisir le/les contacts") menu.set_prompt("Votre choix (a,b,c,d): ") menu.set_multiple(True) for contact in self.contacts: menu.add_entry(contact.get_string(), None) menu.show_menu() chx = menu.wait_for_choise() contact_to_delete = DataManipulation.get_selected_from_index( self.contacts, chx) for i in contact_to_delete: self.contacts.remove(i) # io_formats.get_format(self.DEFAULT_DB_FORMAT).export_data(self.contacts, self.file_path) self.make_menu()
def export_single(self, file_format): file_format = file_format[0] menu = EasyMenu("Veuillez choisir le/les contacts") menu.set_prompt("Votre choix (a,b,c,d): ") menu.set_multiple(True) for contact in self.contacts: menu.add_entry(contact.get_string(), None) menu.show_menu() chx = menu.wait_for_choise() contact_to_write = DataManipulation.get_selected_from_index( self.contacts, chx) file_path = input("Entrez un chemin pour le fichier: ") io_formats.get_format(file_format).export_data(contact_to_write, file_path) self.make_menu()
def make_menu(self, empty=False): menu = EasyMenu("-" * 10 + "Contact Manager" + "-" * 10) menu.set_prompt("Entrez votre choix : ") if not self.loaded and not empty: menu.add_entry("Charger une base", self.load_base) menu.add_entry("Nouvelle base", self.create_base) else: self.loaded = True menu.add_entry("Visualiser la base", self.visualise) menu.add_entry("Exporter un/des contacts", self.select_format) menu.add_entry("Importer un/des contacts", self.import_menu) menu.add_entry("Ajouter un contact", self.add_contact) menu.add_entry("Editer un contact", self.edit_contact) menu.add_entry("Suprimer un contact", self.delete_contact) menu.add_entry("Convertir des données", self.convert) menu.add_entry("Quitter", self.quit) menu.show_menu() self.execute(menu.wait_for_choise())
def import_menu(self, *args): file_path = input("Entrez un chemin pour le fichier: ") menu = EasyMenu("Importation de fichiers") menu.set_prompt("Votre choix (a,b,c): ") menu.set_multiple(True) files_to_process = [] if os.path.exists(file_path): if os.path.isdir(file_path): filtered_files = DataManipulation.filter_file( DataManipulation.get_files(file_path), tuple(io_formats.get_ext())) for filtered in filtered_files: files_to_process.append(os.path.join(file_path, filtered)) menu.add_entry(filtered, None) menu.show_menu() chx = menu.wait_for_choise() sel = DataManipulation.get_selected_from_index( files_to_process, chx) for file in sel: ext = os.path.splitext(file)[1] print(ext) l = io_formats.get_format_from_ext(ext).import_data( file_path + '/' + file) self.contacts = self.contacts + l self.make_menu() return else: if file_path.endswith(tuple(io_formats.get_ext())): ext = os.path.splitext(file_path)[1] l = io_formats.get_format_from_ext(ext).import_data( file_path) self.contacts = self.contacts + l self.make_menu() return print("Le chemin/fichier n'est pas valide/dans un format reconu") self.import_menu()
def add_field(self): c = input( "Voulez vous ajouter de nouveaux champs ? (Ces champs peuvent ne pas être présent dans" + " certain format d'exportation)(O/N) : ") if c.lower().startswith("o"): menu = EasyMenu("Voici les types de champs") menu.set_prompt("Votre choix : ") menu.set_multiple(True) for types in field_types.get_fields(): menu.add_entry( "{} - {}".format( field_types.get_field(types).NAME, field_types.get_field(types).DESCRIPTION), None) menu.show_menu() ch = menu.wait_for_choise() value = input("Entrez le nom du champs") header = field_types.get_field_by_index(ch[0])(value) header.ask_value() self.available_headers.append(header) return self.add_field() return