def __init__(self, parent, pydef_object, figure, init_subplot_nb): """ :param parent: parent window :param pydef_object: a Cell or Defect_Study object :param figure: a PyDEF Figure object :param init_subplot_nb: a Tkinter IntVar object""" tk.Toplevel.__init__(self, parent) self.title('Position of "%s" in figure "%s"' % (pydef_object.ID, figure.name)) self.resizable(False, False) self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.main_frame = ttk.Frame(self) self.main_frame.pack(expand=True, fill='both') self.main_frame.grid_columnconfigure(0, weight=1) # -------------------------------------------------- SUBPLOTS -------------------------------------------------- self.subplot_frame = ttk.Frame(self.main_frame) self.subplot_frame.grid(row=0, column=0, sticky='nswe') self.subplot_nb = tk.IntVar() self.subplot_nb.set(init_subplot_nb.get()) for f in range(1, figure.nb_rows + 1): for g in range(1, figure.nb_cols + 1): frame = ttk.LabelFrame(self.subplot_frame, width=100, height=100) frame.grid(row=f, column=g, padx=10) frame.grid_columnconfigure(0, weight=1) frame.grid_rowconfigure(0, weight=1) frame.grid_propagate(False) ttk.Radiobutton(frame, text=(f-1) * figure.nb_cols + g, variable=self.subplot_nb, value=(f-1) * figure.nb_cols + g).grid(sticky='ns') [self.subplot_frame.grid_columnconfigure(g, weight=1) for g in range(1, figure.nb_cols + 1)] # --------------------------------------------------- BUTTONS -------------------------------------------------- self.button_frame = ttk.Frame(self.main_frame) self.button_frame.grid(row=1, column=0, pady=10) def save_subplot_nb(): """Save the subplot number chosen to the init_subplot_nb variable """ init_subplot_nb.set(self.subplot_nb.get()) self.destroy() ttk.Button(self.button_frame, text='Cancel', command=self.destroy).grid(row=0, column=0, padx=5) ttk.Button(self.button_frame, text='OK', command=save_subplot_nb).grid(row=0, column=1, padx=5) self.bind('<Control-w>', lambda event: self.destroy()) ukf.centre_window(self)
def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title('Create a new figure') self.resizable(False, False) self.bind('<Control-w>', lambda event: self.destroy()) self.main_window = parent.main_window self.parent = parent self.project = parent.project self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.main_frame = ttk.Frame(self) # main ttk frame self.main_frame.pack(expand=True, fill='both') # Variables self.figure_name_var = tk.StringVar() self.nb_rows_var = tk.IntVar() self.nb_cols_var = tk.IntVar() self.figure_name_var.set('my figure') self.nb_rows_var.set(1) self.nb_cols_var.set(1) # ------------------------------------------------- FIGURE NAME ------------------------------------------------ self.figure_name_frame = ttk.Frame(self.main_frame) self.figure_name_frame.grid(row=0, padx=3, pady=3) ttk.Label(self.figure_name_frame, text='Figure name').pack(side='left', padx=3) ttk.Entry(self.figure_name_frame, textvariable=self.figure_name_var, width=30).pack(side='left', padx=3) # ---------------------------------------------- NB ROWS & COLUMNS --------------------------------------------- self.subplot_frame = ttk.Frame(self.main_frame) self.subplot_frame.grid(row=1, padx=3, pady=3) ttk.Label(self.subplot_frame, text='Number of rows').pack(side='left', padx=3) ttk.Entry(self.subplot_frame, textvariable=self.nb_rows_var, width=3).pack(side='left', padx=3) ttk.Label(self.subplot_frame, text='Number of columns').pack(side='left', padx=3) ttk.Entry(self.subplot_frame, textvariable=self.nb_cols_var, width=3).pack(side='left', padx=3) # --------------------------------------------------- BUTTONS -------------------------------------------------- self.button_frame = ttk.Frame(self.main_frame) self.button_frame.grid(row=2, padx=3, pady=3) ttk.Button(self.button_frame, text='OK', command=self.create_figure).pack(side='left', padx=5) ttk.Button(self.button_frame, text='Cancel', command=self.destroy).pack(side='left', padx=5) ukf.centre_window(self)
def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title('About') self.bind('<Control-w>', lambda event: self.destroy()) self.resizable(False, False) self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.main_frame = ttk.Frame(self) self.main_frame.pack(expand=True, fill='both') self.ribbon_image = tk.PhotoImage(data=pydef_images.ribbon) self.ribbon = tk.Label(self.main_frame, image=self.ribbon_image) self.ribbon.grid(row=0) ttk.Label(self.main_frame, text='Python for Defect Energy Formation 1.0.0\n', font="-size 20 -weight bold").grid(row=1) ttk.Label( self.main_frame, text= u'Original idea from: Dr. Stéphane Jobic, Dr. Camille Latouche & Emmanuel Péan' ).grid(row=2) ttk.Label(self.main_frame, text=u'Developer: Emmanuel Péan').grid(row=3) ttk.Label(self.main_frame, text='Logo design: Josselin Gesrel').grid(row=4) ttk.Label( self.main_frame, text='Testers: Dr. Julien Vidal & Dr. Camille Latouche\n').grid( row=5) ttk.Label(self.main_frame, text='Disclaimer', font='-weight bold').grid(row=6) ttk.Label( self.main_frame, text= 'This software is free of use and, although its development was made with care,\n' 'the authors can not guaranty the quality of its outputs\n ' 'and will not be liable for any damage caused by it.\n', justify=tk.CENTER).grid(row=7) ttk.Label(self.main_frame, text='A question, a recommendation, or anything else?\n' 'send us an e-mail at [email protected]', justify=tk.CENTER).grid(row=8) ukf.centre_window(self)
def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title('New project') self.grid_columnconfigure(0, weight=1) self.resizable(False, False) self.main_window = parent self.main_frame = ttk.Frame(self) # main ttk frame self.main_frame.pack(expand=True, fill='both') # ------------------------------------------------ PROJECT NAME ------------------------------------------------ self.project_name = tk.StringVar() ttk.Label(self.main_frame, text='Name').grid(row=0) ttk.Entry(self.main_frame, textvariable=self.project_name, width=40).grid(row=1, sticky='we') # --------------------------------------------------- BUTTONS -------------------------------------------------- def create_new_project(): """ Create a new Pydef_Project object and close the window """ project_name = self.project_name.get() if project_name == '': mb.showwarning('Error', 'The name of the project is blank', parent=self) else: new_project = pp.Pydef_Project( project_name) # create the new project with the given name parent.load_project(new_project) # load the new project self.destroy() # close the window self.button_frame = ttk.Frame(self.main_frame) self.button_frame.grid(row=2) ttk.Button(self.button_frame, text='OK', command=create_new_project).pack(side='left') ttk.Button(self.button_frame, text='Cancel', command=self.destroy).pack(side='left') ukf.centre_window(self)
def __init__(self): tk.Tk.__init__(self) tk.Tk.report_callback_exception = self.show_error # display errors in a window self.icon = tk.PhotoImage(data=pydef_images.icon) self.tk.call('wm', 'iconphoto', self._w, self.icon) self.resizable(False, False) # Styles s = ttk.Style() s.configure('my.TButton', font=('', 18), justify=tk.CENTER) self.columnconfigure(0, weight=1, uniform='uni') self.columnconfigure(1, weight=1, uniform='uni') self.columnconfigure(2, weight=1, uniform='uni') self.rowconfigure(0, weight=1, uniform='uni') self.rowconfigure(1, weight=1, uniform='uni') # New blank project self.load_project(pp.Pydef_Project('New project')) # -------------------------------------------------------------------------------------------------------------- # --------------------------------------------------- MENUBAR -------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.menubar = tk.Menu(self) # File menu self.file_menu = tk.Menu(self.menubar, tearoff=0) self.file_menu.add_command(label='New PyDEF project', command=self.create_new_project, accelerator='Ctrl+N') self.file_menu.add_command(label='Open PyDEF project', command=self.open_saved_project, accelerator='Ctrl+O') self.file_menu.add_command(label='Save PyDEF project', command=self.save_project, accelerator='Ctrl+S') self.menubar.add_cascade(label='File', menu=self.file_menu) # Help menu self.help_menu = tk.Menu(self.menubar, tearoff=0) self.help_menu.add_command(label='About', command=self.open_about_window, accelerator='Shift+Ctrl+A') self.help_menu.add_command(label='User Guide', command=self.open_user_guide, accelerator='Shift+Ctrl+D') self.help_menu.add_command(label='Parameters', command=self.open_parameters_window, accelerator='Shift+Ctrl+P') self.menubar.add_cascade(label='Help', menu=self.help_menu) self.config(menu=self.menubar) # -------------------------------------------------------------------------------------------------------------- # ---------------------------------------------- KEYBOARD SHORCUTS --------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.bind_all('<Control-q>', lambda event: self.quit_pydef()) self.protocol('WM_DELETE_WINDOW', self.quit_pydef) self.bind('<Control-n>', lambda event: self.create_new_project()) self.bind('<Control-o>', lambda event: self.open_saved_project()) self.bind('<Control-s>', lambda event: self.save_project()) self.bind_all('<Shift-Control-a>', lambda event: self.open_about_window()) self.bind_all('<Shift-Control-d>', lambda event: self.open_user_guide()) self.bind_all('<Shift-Control-p>', lambda event: self.open_parameters_window()) # -------------------------------------------------------------------------------------------------------------- # --------------------------------------------------- RIBBON --------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.ribbon_image = tk.PhotoImage(data=pydef_images.ribbon) self.ribbon = tk.Label(self, image=self.ribbon_image) self.ribbon.grid(row=0, column=0, columnspan=3) # -------------------------------------------------------------------------------------------------------------- # --------------------------------------------------- BUTTONS -------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # Images self.si_image = tk.PhotoImage(data=pydef_images.VASP_logo) self.defects_image = tk.PhotoImage(data=pydef_images.defects) self.defect_study_image = tk.PhotoImage( data=pydef_images.Substitution_cell) self.mat_study_image = tk.PhotoImage( data=pydef_images.Vacancy_Substitution_cell) self.diagram_image = tk.PhotoImage(data=pydef_images.chem_pot_diagram) self.defect_conc = tk.PhotoImage(data=pydef_images.defect_conc) # Buttons self.cell_button = ttk.Button(self, text='Import VASP\ncalculations', command=self.open_cells_window, style='my.TButton', image=self.si_image, padding=20, compound='bottom') self.defect_button = ttk.Button(self, text='Defect labels', command=self.open_defects_window, style='my.TButton', image=self.defects_image, compound='bottom') self.defect_study_button = ttk.Button( self, text='Defect Studies', command=self.open_defect_studies_window, style='my.TButton', image=self.defect_study_image, compound='bottom') self.mat_study_button = ttk.Button(self, text='Material studies', command=self.show_message, style='my.TButton', image=self.mat_study_image, padding=10, compound='bottom') self.chem_pot_button = ttk.Button( self, text='Chemical potential\ncalculation', command=self.show_message, style='my.TButton', image=self.diagram_image, padding=10, compound='bottom') self.defect_conc_button = ttk.Button( self, text='Defect concentration\ncalculation', command=self.show_message, style='my.TButton', padding=10, image=self.defect_conc, compound='bottom') self.cell_button.grid(row=1, column=0, padx=7, pady=7, sticky='nswe') self.defect_button.grid(row=1, column=1, padx=7, pady=7, sticky='nswe') self.defect_study_button.grid(row=1, column=2, padx=7, pady=7, sticky='nswe') self.mat_study_button.grid(row=2, column=0, padx=7, pady=7, sticky='nswe') self.chem_pot_button.grid(row=2, column=1, padx=7, pady=7, sticky='nswe') self.defect_conc_button.grid(row=2, column=2, padx=7, pady=7, sticky='nswe') self.mat_study_button.configure(state='disabled') self.chem_pot_button.configure(state='disabled') self.defect_conc_button.configure(state='disabled') ukf.centre_window(self)
def __init__(self, parent, items, items_on, output_var, label_on, label_off): """ :param parent: parent window :param items: list of all items :param items_on: list of items which are used :param output_var: Tkinter StringVar :param label_on: label for the list of used items :param label_off: label for the list of non used items """ tk.Toplevel.__init__(self, parent) self.title('Select items') self.resizable(False, False) self.bind('<Control-w>', lambda event: cancel()) self.parent = parent self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.main_frame = ttk.Frame(self) # Main ttk frame self.main_frame.pack(expand=True, fill='both') # DOS type choice from previous window items_off = list(set(items) - set(items_on)) # ------------------------------------------------- ITEMS ON --------------------------------------------------- self.on_frame = ttk.LabelFrame(self.main_frame, text=label_on) self.on_frame.grid(row=0, column=0) self.list_on = tk.Listbox(self.on_frame, width=20) self.yscrollbar_on = ttk.Scrollbar(self.on_frame, orient='vertical') self.list_on.pack(side='left', fill='both', expand=True) self.yscrollbar_on.pack(side='right', fill='y') self.list_on.config(yscrollcommand=self.yscrollbar_on.set) self.yscrollbar_on.config(command=self.list_on.yview) [self.list_on.insert('end', f) for f in items_on] # -------------------------------------------------- ITEMS OFF ------------------------------------------------- self.frame_off = ttk.LabelFrame(self.main_frame, text=label_off) self.frame_off.grid(row=0, column=2) self.list_off = tk.Listbox( self.frame_off, width=20) # list containing element non plotted self.yscrollbar_off = ttk.Scrollbar(self.frame_off, orient='vertical') self.list_off.pack(side='left', fill='both', expand=True) self.yscrollbar_off.pack(side='right', fill='y') self.list_off.config(yscrollcommand=self.yscrollbar_off.set) self.yscrollbar_off.config(command=self.list_off.yview) [self.list_off.insert('end', f) for f in items_off] # --------------------------------------------------- BUTTONS -------------------------------------------------- self.button_frame = ttk.Frame(self.main_frame) self.button_frame.grid(row=0, column=1, padx=5) def remove_selection(): """ Remove selected elements in the 'on' list and add them to the 'off' list """ selection = self.list_on.curselection() if len(selection) != 0: for selected in selection: items_ids = self.list_on.get(selected) self.list_off.insert(0, items_ids) self.list_on.delete(selected) def add_selection(): """ Add selected elements to the 'on' list and remove them from the 'off' list """ selection = self.list_off.curselection() if len(selection) != 0: for selected in selection: items_ids = self.list_off.get(selected) self.list_on.insert(0, items_ids) self.list_off.delete(selected) def add_all(): """ Add all items to the 'on' list and remove them from the 'off' list """ self.list_off.delete(0, 'end') self.list_on.delete(0, 'end') [self.list_on.insert(0, f) for f in items] def remove_all(): """ Remove all items from the 'on' list and add them to the 'off' list """ self.list_on.delete(0, 'end') self.list_off.delete(0, 'end') [self.list_off.insert(0, f) for f in items] ttk.Button(self.button_frame, text='>', command=remove_selection).pack(side='top') ttk.Button(self.button_frame, text='>>', command=remove_all).pack(side='top') ttk.Button(self.button_frame, text='<', command=add_selection).pack(side='top') ttk.Button(self.button_frame, text='<<', command=add_all).pack(side='top') def add_selected(event): """ Add the selected item to the 'on' list and remove it from the 'off' list when "event" happens """ widget = event.widget widget.curselection() add_selection() def remove_selected(event): """ Add the selected item to the 'off' list and remove it from the 'on' list when "event" happens """ widget = event.widget widget.curselection() remove_selection() self.list_on.bind( '<Double-Button-1>', remove_selected) # remove element when double-clicked self.list_off.bind('<Double-Button-1>', add_selected) # add item when double-clicked # ------------------------------------------------ MAIN BUTTONS ------------------------------------------------ self.main_button_frame = ttk.Frame(self.main_frame) self.main_button_frame.grid(row=1, column=0, columnspan=3) def save(): """ Save the choice and close the window """ choice = list(self.list_on.get(0, 'end')) if len(choice) == 0: mb.showerror('Error', 'Select at least one item', parent=self) return None else: output_var.set(','.join(choice)) print(output_var.get()) self.destroy() def cancel(): """ Save the initial items on and close the window """ output_var.set(','.join(items_on)) self.destroy() ttk.Button(self.main_button_frame, text='OK', command=save).pack(side='left') ttk.Button(self.main_button_frame, text='Cancel', command=cancel).pack(side='right') self.protocol('WM_DELETE_WINDOW', cancel) ukf.centre_window(self)
def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title('Parameters') self.bind('<Control-w>', lambda event: self.destroy()) self.project = parent.project self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(0, weight=1) self.main_frame = ttk.Frame(self) # Main ttk frame self.main_frame.pack(expand=True, fill='both') self.main_frame.grid_columnconfigure(0, weight=1, pad=20) self.main_frame.grid_rowconfigure(0, weight=1, pad=5) # --------------------------------------------- DEFAULT DIRECTORIES -------------------------------------------- self.dd_input_frame = ttk.Frame( self.main_frame) # Frame for default directories input self.dd_input_frame.grid(row=0, column=0, sticky='nswe') self.dd_input_frame.grid_columnconfigure(1, weight=1) def choose_vasp_dd(): """ Open a window to choose the default directory of the VASP data """ directory = fd.askdirectory(parent=self, initialdir=self.project.dd_vasp) if directory != '': self.dd_vasp_var.set(directory) def choose_pydef_dd(): """ Open a window to choose the default directory of the PyDEF data """ directory = fd.askdirectory(parent=self, initialdir=self.project.dd_pydef) if directory != '': self.dd_pydef_var.set(directory) # Labels ttk.Button(self.dd_input_frame, text='VASP data default directory', command=choose_vasp_dd).grid(row=0, column=0, padx=5, pady=3) ttk.Button(self.dd_input_frame, text='PyDEF data default directory', command=choose_pydef_dd).grid(row=1, column=0, padx=5, pady=3) # Variables self.dd_vasp_var = tk.StringVar() # default directory of the VASP data self.dd_pydef_var = tk.StringVar( ) # default directory of the PyDEF saves self.dd_vasp_var.set( self.project.dd_vasp ) # default values are retrieved from the current project self.dd_pydef_var.set( self.project.dd_pydef ) # default values are retrieved from the current project # Entry fields ttk.Entry(self.dd_input_frame, textvariable=self.dd_vasp_var, width=40).grid(row=0, column=1, sticky='we', padx=5, pady=3) ttk.Entry(self.dd_input_frame, textvariable=self.dd_pydef_var, width=40).grid(row=1, column=1, sticky='we', padx=5, pady=3) # --------------------------------------------------- BUTTONS -------------------------------------------------- self.button_frame = ttk.Frame( self.main_frame) # Frame for the OK and Cancel buttons self.button_frame.grid(row=1, column=0) self.button_frame.grid_columnconfigure(0, weight=1) def save_parameters(): """ Save the default directories as attributes of the project """ self.project.dd_vasp = self.dd_vasp_var.get() self.project.dd_pydef = self.dd_pydef_var.get() self.destroy() ttk.Button(self.button_frame, text='OK', command=save_parameters).pack(side='left', padx=5, pady=3) ttk.Button(self.button_frame, text='Cancel', command=self.destroy).pack(side='left', padx=5, pady=3) ukf.centre_window(self)
def __init__(self, parent, defect): tk.Toplevel.__init__(self, parent) self.title(defect.ID) self.resizable(False, False) self.bind('<Control-w>', lambda event: self.destroy()) self.project = parent.project self.parent = parent self.main_frame = ttk.Frame(self) self.main_frame.pack(expand=True, fill='both') ttk.Label(self.main_frame, text='Type: %s' % defect.defect_type).grid(row=0, columnspan=2, padx=5, pady=3) if defect.defect_type == 'Vacancy' or defect.defect_type == 'Interstitial': if defect.defect_type == 'Vacancy': textlabel = 'Atom removed' else: textlabel = 'Atom added' self.atom_frame_label = ttk.Label(self, text=textlabel, font="-weight bold") self.atom_frame = ttk.LabelFrame(self.main_frame, labelwidget=self.atom_frame_label, labelanchor='n') self.atom_frame.grid(row=1, padx=5, pady=3) ttk.Label(self.atom_frame, text='Atom: %s' % defect.atom[0]).grid(row=0) ttk.Label(self.atom_frame, text='Chemical potential: %s eV' % defect.chem_pot_input[0]).grid(row=1) if defect.defect_type == 'Substitutional': self.atom_frame1_label = ttk.Label(self, text='Atom removed', font="-weight bold") self.atom_frame1 = ttk.LabelFrame( self.main_frame, labelwidget=self.atom_frame1_label, labelanchor='n') self.atom_frame1.grid(row=1, column=0, padx=5, pady=3) ttk.Label(self.atom_frame1, text='Atom: %s' % defect.atom[0]).grid(row=0) ttk.Label(self.atom_frame1, text='Chemical potential: %s eV' % defect.chem_pot_input[0]).grid(row=1) self.atom_frame2_label = ttk.Label(self, text='Atom added', font="-weight bold") self.atom_frame2 = ttk.LabelFrame( self.main_frame, labelwidget=self.atom_frame2_label, labelanchor='n') self.atom_frame2.grid(row=1, column=1, padx=5, pady=3) ttk.Label(self.atom_frame2, text='Atom: %s' % defect.atom[1]).grid(row=0) ttk.Label(self.atom_frame2, text='Chemical potential: %s eV' % defect.chem_pot_input[1]).grid(row=1) ukf.centre_window(self)
def __init__(self, parent): tk.Toplevel.__init__(self, parent) self.title('Defect Label') self.main_window = parent # PyDEF main window self.parent = parent # parent window self.project = parent.project # current project self.icon = parent.icon self.tk.call('wm', 'iconphoto', self._w, self.icon) self.main_frame = ttk.Frame(self) # main ttk frame self.main_frame.pack(expand=True, fill='both') self.main_frame.grid_columnconfigure(0, weight=1) self.main_frame.grid_rowconfigure(1, weight=1) # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # ----------------------------------------------------- MENU --------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.menubar = tk.Menu(self) self.defects_menu = tk.Menu(self.menubar, tearoff=0) self.defects_menu.add_command(label='Save defect label(s)...', command=self.save_selected_defects, accelerator='Ctrl+S') self.defects_menu.add_command(label='Load defect label(s)...', command=self.open_saved_defects, accelerator='Ctrl+O') self.menubar.add_cascade(label='File', menu=self.defects_menu) self.help_menu = tk.Menu(self.menubar, tearoff=0) self.help_menu.add_command(label='About', command=self.parent.open_about_window, accelerator='Shift+Ctrl+A') self.help_menu.add_command(label='Documentation', command=self.parent.open_user_guide, accelerator='Shift+Ctrl+D') self.help_menu.add_command(label='Parameters', command=self.parent.open_parameters_window, accelerator='Shift+Ctrl+P') self.menubar.add_cascade(label='Help', menu=self.help_menu) self.config(menu=self.menubar) # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # --------------------------------------------- KEYBOARD SHORCUTS ---------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.bind('<Control-s>', lambda event: self.save_selected_defects()) self.bind('<Control-o>', lambda event: self.open_saved_defects()) self.bind('<Control-w>', lambda event: self.parent.close_defects_window()) # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # ------------------------------------------------- INPUT FRAME ------------------------------------------------ # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.input_frame = ttk.Frame(self.main_frame) self.input_frame.grid(row=0, column=0, sticky='nswe', padx=10, pady=3) self.input_frame.grid_columnconfigure(0, weight=1) # Labels ttk.Label(self.input_frame, text='Name').grid(row=0, column=0, padx=5, pady=3) ttk.Label(self.input_frame, text='Defect type').grid(row=1, column=0, padx=5, pady=3) # Variables self.defect_id_var = tk.StringVar() self.defect_type_var = tk.StringVar() self.defect_id_var.set('automatic') # Inputs self.id_entry = ttk.Entry(self.input_frame, textvariable=self.defect_id_var) self.id_entry.grid(row=0, column=1, sticky='we', padx=5, pady=3) self.defect_type_ccb = ttk.Combobox( self.input_frame, values=['Vacancy', 'Interstitial', 'Substitutional'], textvariable=self.defect_type_var, state='readonly') self.defect_type_ccb.grid(row=1, column=1, sticky='we', padx=5, pady=3) self.defect_type_ccb.bind('<<ComboboxSelected>>', lambda event: self.display_choices()) # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # ------------------------------------------------- DEFECTS LIST ----------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.defects_list_frame = ttk.Frame(self.main_frame) self.defects_list_frame.grid(row=1, column=0, sticky='nswe') self.defects_list_frame.grid_rowconfigure(0, weight=1) self.yscrollbar = ttk.Scrollbar( self.defects_list_frame, orient='vertical') # scrollbar for the y-axis self.defects_list = tk.Listbox(self.defects_list_frame, selectmode='extended', width=40) self.yscrollbar.pack(side='right', fill='y') self.defects_list.pack(side='left', fill='both', expand=True) self.yscrollbar.config(command=self.defects_list.yview) self.defects_list.config(yscrollcommand=self.yscrollbar.set) self.defects_list.insert(0, *self.project.Defects) def open_defect_properties_window(event): """ Open the plot properties window when 'event' happens """ selection = self.defects_list.curselection() if len(selection) != 0: defect_id = self.defects_list.get(selection[0]) Defect_Properties_Window(self, self.project.Defects[defect_id]) self.defects_list.bind('<Double-Button-1>', open_defect_properties_window) # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # ---------------------------------------------------- BUTTONS ------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- # -------------------------------------------------------------------------------------------------------------- self.button_frame = ttk.Frame(self.input_frame) self.button_frame.grid(row=3, column=0, columnspan=3, sticky='nswe', padx=5, pady=3) self.button_frame.grid_columnconfigure(0, weight=1) self.button_frame.grid_columnconfigure(1, weight=1) def create_defect(): """ Create a Defect object from the value in the fields and add it to the listbox below if a Defect object with the same name was previously added, it is overwritten """ defect_type = self.defect_type_var.get() if defect_type == '': mb.showwarning('Attention', 'Select first a defect type', parent=self) return None if hasattr(self, 'atoms_frame') is False: mb.showwarning('Attention', 'You must import a VASP calculation first', parent=self) return None defect_id = self.defect_id_var.get() # defect ID if ',' in defect_id: mb.showwarning( 'Attention', 'The name of a defect label can not contain a comma', parent=self) return None if defect_type == 'Vacancy' or defect_type == 'Interstitial': atom = self.atom1_var.get() # atom selected try: chem_pot = self.chem_pot1_var.get( ) # chemical potential set except ValueError: mb.showwarning('Attention', 'The chemical potential must be a number') return None if atom == '' or chem_pot == '': # create the Defect object if the field are not vacant mb.showwarning('Attention', 'One of the field is missing', parent=self) return None else: defect = pd.Defect(defect_type, [atom], [chem_pot]) if defect_type == 'Substitutional': atom1 = self.atom1_var.get() atom2 = self.atom2_var.get() try: chem_pot1 = self.chem_pot1_var.get( ) # chemical potential set except ValueError: mb.showwarning('Attention', 'The chemical potential must be a number') return None try: chem_pot2 = self.chem_pot2_var.get( ) # chemical potential set except ValueError: mb.showwarning('Attention', 'The chemical potential must be a number') return None if atom1 == '' or atom2 == '' or chem_pot1 == '' or chem_pot2 == '': mb.showerror('Error', 'One of the field is missing', parent=self) return None else: defect = pd.Defect(defect_type, [atom1, atom2], [chem_pot1, chem_pot2]) if defect_id != '' and defect_id != 'automatic': defect.ID = defect_id self.load_defect(defect) def delete_defect(): """ Remove the selected defects from the list and from the dictionary """ selected = self.defects_list.curselection() if len(selected) == 0: mb.showwarning('Error', 'Select one defect label in the list first', parent=self) else: defect_id = self.defects_list.get( selected ) # get the ID of the selected defects in the listbox self.defects_list.delete( selected) # remove the defect form the listbox self.project.Defects.pop( defect_id) # remove the defect from the dictionary print('Defect "%s" deleted' % defect_id) ttk.Button(self.button_frame, text='Create defect label', command=create_defect).grid(row=0, column=0, padx=5, pady=3) ttk.Button(self.button_frame, text='Delete defect label', command=delete_defect).grid(row=0, column=1, padx=5, pady=3) ukf.centre_window(self)