Example #1
0
def askForAnswer(title: str,
                 message: str,
                 root: tk.Tk = None,
                 topFrame: tk.Frame = None,
                 destroy=True):
    """cancel: 是否取消了回答"""
    def delete(save=True):
        """
        save: 是否返回输入
        """
        root.protocol('WM_DELETE_WINDOW', lambda *a, r=root: r.destroy())
        if not save:
            s.set('')
            cancel[0] = True
        if destroy:
            root.destroy()
        alive[0] = False

    alive = [True]
    cancel = [False]
    if not root:
        root = tk.Tk()
    if not topFrame:
        topFrame = tk.Frame(root)
        topFrame.pack()
    root.title(title)
    root.protocol('WM_DELETE_WINDOW', lambda *a: delete(False))
    s = tk.StringVar()

    tk.Label(topFrame, text=message).pack(expand=True)

    frame = tk.Frame(topFrame)
    frame.pack(expand=True, fill=tk.X)

    tk.Entry(frame, textvariable=s, width=60).pack(side=tk.LEFT,
                                                   expand=True,
                                                   fill=tk.X)
    tk.Button(frame, text='确认', command=delete).pack(side=tk.LEFT,
                                                     expand=True,
                                                     fill=tk.X)

    while alive[0]:
        try:
            root.update()
        except tk.TclError:
            break
    topFrame.forget()
    return s.get(), cancel[0]
Example #2
0
class Main:
    def __init__(self):
        self.root = Tk()
        self.root.geometry('700x600')
        self.root.title('GESTON DE STOCK')

        self.frame_produit = None
        self.frame_categorie = None

        self.menu = Menu(self.root)
        self.root['menu'] = self.menu

        self.menu.add_command(label='Categorie', command=self.show_categorie)
        self.menu.add_command(label='Produit', command=self.show_produit)
        Message(self.root,
                text='Application de gestion de stock').grid(row=0,
                                                             column=0,
                                                             columnspan=4)
        self.root.mainloop()

    def show_categorie(self):
        if self.frame_categorie is None:
            self.frame_categorie = Frame(self.root)
            self.frame_categorie.grid(row=0, column=0)  #afficher les categorie
            if self.frame_produit is not None:
                self.frame_produit.grid_forget(
                )  # retirer la page des produits
            self.frame_produit = None
            CategorieView(self.frame_categorie)

    def show_produit(self):
        if self.frame_produit is None:
            self.frame_produit = Frame(self.root)
            self.frame_produit.grid(row=0, column=0)
            if self.frame_categorie is not None:
                self.frame_categorie.forget()
            self.frame_categorie = None
            ProduitView(self.frame_produit)
class login:
    """ classe de base de login-box utile pour une entrée de nouvel utilisateur

options standards:
-title:le titre de la boite de dialogue(texte)
-mask:le caractère qui sera présenté pour cacher les lettre du mot de passe

methodes /fonctions:
-show: affiche la boite de login et retourne les infos entrées par l'utilisateur
"""
    def __init__(self, title="Log in Box", mask="&"):
        """Constructor of login Box\nargs:title,selected"""
        from tkinter import Tk, Frame, Label, Entry, Button, BooleanVar, Checkbutton
        self.__Entry__ = Entry
        self.__usr__, self.__pwrd__ = None, None
        self.__mask__ = mask
        self.__root__ = Tk()
        self.__frm__ = Frame(self.__root__)
        self.__frm__.pack(side="top")
        self.__frm2__ = Frame(self.__root__)
        self.__frm2__.pack()
        self.__root__.title(title)
        self.__root__.resizable(False, False)
        self.__lbl_usr__ = Label(self.__frm__,
                                 text="User name : ",
                                 bd=4,
                                 relief="groove",
                                 width=13)
        self.__lbl_usr__.grid(row=1, column=1)
        self.__lbl_pwrd__ = Label(self.__frm__,
                                  text="Password : "******"groove",
                                  width=13)
        self.__lbl_pwrd__.grid(row=2, column=1)
        self.__lbl_pwrd2__ = Label(self.__frm2__,
                                   text="Password again: ",
                                   bd=4,
                                   relief="groove",
                                   width=13)
        self.__lbl_pwrd2__.grid(row=1, column=1)
        self.__txt_usr__ = Entry(self.__frm__, width=15)
        self.__txt_usr__.grid(row=1, column=2)
        self.__txt_pwrd__ = Entry(self.__frm__, width=15, show=self.__mask__)
        self.__txt_pwrd__.grid(row=2, column=2)
        self.__txt_pwrd2__ = Entry(self.__frm2__, width=15, show=self.__mask__)
        self.__txt_pwrd2__.grid(row=1, column=2)
        self.__frm___ok_cancel = Frame(self.__root__, width=76)
        self.__frm___ok_cancel.pack(side="bottom")
        self.__btn_ok__ = Button(self.__frm___ok_cancel,
                                 text="Ok",
                                 width=6,
                                 command=self.__func_ok__)
        self.__btn_ok__.pack(side="left", padx=5)
        self.__var_check__ = BooleanVar(self.__root__, True)
        self.__check__ = Checkbutton(self.__frm___ok_cancel,
                                     text="Hide code",
                                     variable=self.__var_check__,
                                     command=self.__Check__)
        self.__check__.pack(side="left", padx=2)
        self.__btn_cancel__ = Button(self.__frm___ok_cancel,
                                     text="Cancel",
                                     width=6,
                                     command=self.__cancel__)
        self.__btn_cancel__.pack(side="right", padx=5)
        self.__root__.bind("<Escape>", self.__cancel__)
        self.__txt_usr__.bind("<Return>", self.__func_ok__)
        self.__txt_pwrd__.bind("<Return>", self.__func_ok__)
        self.__txt_pwrd2__.bind("<Return>", self.__func_ok__)
        self.__btn_ok__.bind("<Return>", self.__func_ok__)
        self.__txt_usr__.focus()

    def __Check__(self, event=None):
        """Check if checkbutton's value is true or false to show or hide the password
and hide or show the password entry"""
        lst = "", "&"
        self.__txt_pwrd__.configure(show=lst[self.__var_check__.get()])
        if self.__var_check__.get() == 0:
            self.__frm2__.forget()
            self.__txt_pwrd__.focus()
            self.__txt_pwrd2__.destroy()
        else:
            self.__txt_pwrd2__ = self.__Entry__(self.__frm2__,
                                                width=15,
                                                show=self.__mask__)
            self.__txt_pwrd2__.grid(row=1, column=2)
            self.__txt_pwrd2__.focus()
            self.__txt_pwrd2__.bind("<Return>", self.__func_ok__)
            self.__frm2__.pack()
        self.__root__.update()

    def show(self):
        """show the login box and wait for the user's codes which would be return"""
        self.__root__.mainloop()
        return self.__usr__, self.__pwrd__

    def __cancel__(self, event=None):
        """Escape from the login-box"""
        self.__root__.destroy()

    def __error__(self, arg):
        """signal an error to the user"""
        from winsound import MessageBeep as snd
        snd(23)
        arg.configure(bg="red")
        arg.after(200, lambda col="SystemWindow": arg.configure(bg=col))
        arg.focus()
        pass

    def __func_ok__(self, event=None):
        """Central function which defines what to do"""
        from winsound import MessageBeep as snd
        self.__usr__, self.__pwrd__ = self.__txt_usr__.get(
        ), self.__txt_pwrd__.get()
        pwrd2 = None
        try:
            pwrd2 = self.__txt_pwrd2__.get()
            self.__frm2__.info()
            show = True
        except:
            show = False
        if self.__usr__ == "":
            self.__error__(self.__txt_usr__)
        elif self.__pwrd__ == "":
            self.__error__(self.__txt_pwrd__)
        elif pwrd2 == "" and show == True:
            self.__error__(self.__txt_pwrd2__)
            pass
        elif pwrd2 != self.__pwrd__ and show == True:
            self.__txt_pwrd2__.destroy()
            self.__txt_pwrd2__ = self.__Entry__(self.__frm2__,
                                                width=15,
                                                show=self.__mask__)
            self.__txt_pwrd2__.grid(row=1, column=2)
            self.__txt_pwrd2__.focus()
            self.__txt_pwrd2__.bind("<Return>", self.__func_ok__)
            self.__txt_pwrd2__.after(750, self.__txt_pwrd2__.focus)
            popup(
                self.__root__,
                message="The 2 passwords are not\nthe sames please try again!")
        else:
            snd(75)
            self.__root__.destroy()

    def __reset__(self):
        """clear the user-name and the password"""
        try:
            self.__txt_usr__.destroy()
            self.__txt_pwrd__.destroy()
        except:
            pass
        try:
            self.__txt_usr__ = self.__Entry__(self.__frm__, width=15)
            self.__txt_usr__.grid(row=1, column=2)
            self.__txt_usr__.focus()
            self.__txt_pwrd__ = self.__Entry__(self.__frm__,
                                               width=15,
                                               show=self.__mask__)
            self.__txt_pwrd__.grid(row=2, column=2)
            self.__txt_usr__.bind("<Return>", self.__func_ok__)
            self.__txt_pwrd__.bind("<Return>", self.__func_ok__)
            self.__txt_usr__.focus()
        except:
            pass
        try:
            self.__root__.update()
        except:
            pass
Example #4
0
class ContentInput(Frame):
    def __init__(self, master, question_number, load_data=None):
        super().__init__(master, bg=StyledTkinter.get_medium_color())

        self.part_of_answer = IntVar(value=1)
        self.display_open = False
        self.question_number = question_number

        self.header = Frame(self, bg=StyledTkinter.get_medium_color())
        self.toggle_text = StringVar(value="+")
        self.toggle_display = StyledTkinter.get_dark_button(
            self.header,
            textvariable=self.toggle_text,
            command=self.toggle_input_display,
            width=2)
        self.head_text_container = Frame(
            self.header,
            bg=StyledTkinter.get_medium_color(),
            highlightcolor=StyledTkinter.get_dark_color(),
            highlightthickness=1,
            highlightbackground=StyledTkinter.get_dark_color())
        self.header_title = Label(self.head_text_container,
                                  bg=StyledTkinter.get_medium_color(),
                                  text="Question " + str(question_number + 1))
        self.header_is_in_solution_indicator = Label(
            self.head_text_container,
            text="In Solution",
            bg=StyledTkinter.get_medium_color())

        self.question_frame = Frame(self, bg=StyledTkinter.get_medium_color())
        self.question_title_row = Frame(self.question_frame,
                                        bg=StyledTkinter.get_medium_color())
        self.question_in_solution = Checkbutton(
            self.question_title_row,
            text='Use in solution',
            variable=self.part_of_answer,
            bg=StyledTkinter.get_medium_color(),
            command=self.update_is_in_solution_indicator)
        self.question_label = Label(self.question_title_row,
                                    bg=StyledTkinter.get_medium_color(),
                                    text="Question")
        self.question = RichTextInput(self.question_frame)

        self.answer_tabs = TabContainer(self)

        answer_frame = self.answer_tabs.create_empty_tab("Answer")
        self.answer = RichTextInput(answer_frame)

        self.fillers = []
        for i in range(3):
            answer_frame = self.answer_tabs.create_empty_tab("Filler " +
                                                             str(i + 1))
            self.fillers.append(RichTextInput(answer_frame))

        self.load(load_data)

    def update_is_in_solution_indicator(self):
        if self.part_of_answer.get():
            self.header_is_in_solution_indicator.config(text="In Solution")
        else:
            self.header_is_in_solution_indicator.config(text="")

    def display(self):
        super().pack(expand=True, fill=X)

        self.header.pack(expand=True, fill=X, pady=(5, 5))
        self.toggle_display.pack(side=LEFT)
        self.head_text_container.pack(side=LEFT, expand=True, fill=BOTH)
        self.header_title.pack(side=LEFT, padx=(0, 5), expand=True, fill=X)
        self.header_is_in_solution_indicator.pack(side=LEFT,
                                                  padx=(0, 5),
                                                  expand=True,
                                                  fill=X)

        self.question_title_row.pack(expand=True, fill=X)
        self.question_label.pack(side=LEFT, padx=(0, 5), pady=(0, 5))
        self.question_in_solution.pack(side=LEFT, padx=(0, 5), pady=(0, 5))
        self.question.display(expand=True, fill=X)

        self.answer.display(expand=True, fill=X)
        for filler in self.fillers:
            filler.display(expand=True, fill=X)

    def fill_with_test_data(self, index):
        ContentInput.update_input(self.question.input,
                                  "Question" + str(index + 1))
        ContentInput.update_input(self.answer.input, "Answer" + str(index + 1))

        for filler in self.fillers:
            filler_index = self.fillers.index(filler)
            ContentInput.update_input(
                filler.input,
                "Q" + str(index + 1) + " Filler" + str(filler_index + 1))

    @staticmethod
    def update_input(input_to_update, text):
        curr_text = input_to_update.get("1.0", END)

        if curr_text.strip() == "":
            input_to_update.insert(INSERT, text)

    def toggle_input_display(self):
        if self.display_open:
            self.close_input_display()
        elif not self.display_open:
            self.open_input_display()

    def open_input_display(self):
        self.question_frame.pack(side=LEFT, expand=True, fill=X, padx=(0, 4))
        self.answer_tabs.display(side=LEFT, expand=True, fill=X)

        self.toggle_text.set("-")
        self.display_open = True

        PyBus.Instance().post(CloseOtherInputs(self.question_number))

    def close_input_display(self):
        self.question_frame.forget()
        self.answer_tabs.forget()
        self.toggle_text.set("+")
        self.display_open = False

    def load(self, load_data):
        if load_data is not None:
            self.part_of_answer.set(load_data['part_of_answer'])
            self.question.load_content(load_data['question'])
            self.answer.load_content(load_data['answer'])

            for filler in load_data['fillers']:
                index = load_data['fillers'].index(filler)
                self.fillers[index].load_content(filler)

    def is_filled(self):
        answer_content = self.answer.get_content()
        if not answer_content["text"] and not answer_content["placed_images"]:
            return False

        question_content = self.question.get_content()
        if not question_content["text"] and not question_content[
                "placed_images"]:
            return False

        for filler in self.fillers:
            filler_content = filler.get_content()

            if not filler_content["text"] and not filler_content[
                    "placed_images"]:
                return False

        return True

    def get_as_dict(self):
        return {
            'part_of_answer': self.part_of_answer.get(),
            'question': self.question.get_content(),
            'answer': self.answer.get_content(),
            'fillers': [x.get_content() for x in self.fillers]
        }
Example #5
0
class InitScreen:
    def __init__(self, master):
        self.funcs = {}
        self.master = master
        self.controller = InitScreenController(master)
        self.master.title('parent')
        self.master.geometry('640x480+200+150')

        self.set_param_init()

        self.frame.pack()

        self.master.mainloop()

    def set_param_init(self):
        self.frame = Frame(width=400, height=300, bd=2)
        self.frame.grid_bbox(2, 4 + default_fields_count)

        self._buttons_init()

        self.entrys = {}
        _vcmd = self.frame.register(self._validate)

        count = 0

        for block_name, block in default_params.items():
            Label(self.frame,
                  text=_convert(block_name),
                  background="#999",
                  justify=LEFT).grid(
                    row=count,
                    column=1
            )
            count += 1

            for name, _default in block.items():
                default, func = _default

                Label(self.frame,
                      text=_convert(name),
                      justify=LEFT).grid(
                        row=count,
                        column=1
                )
                # self.entrys[_convert(name)] = ""
                sv = StringVar(
                        value=default_params[block_name][name][0])
                e = Entry(self.frame)

                self.entrys[name] = sv
                self.funcs[e] = func

                e.config(validate='key',
                         vcmd=(_vcmd, "%P", "%W"),
                         textvariable=sv)
                e.grid(row=count,
                       column=2)

                count += 1

        Label(self.frame,
              text="Количество существ:",
              justify=LEFT).grid(
                row=count,
                column=1
        )

        self.creature_count = \
            Label(self.frame,
                  text='0',
                  justify=LEFT)
        self.creature_count.grid(
                row=count,
                column=2
        )

    def _buttons_init(self):
        self.load_button = Button(self.frame,
                                  text='Загрузить',
                                  command=self.load_button_press)
        self.load_button.grid(row=4 + default_fields_count,
                              column=1)

        self.start_button = Button(self.frame,
                                   text='Старт',
                                   command=self.start_button_press)
        self.start_button.grid(row=4 + default_fields_count,
                               column=2)

        self.master.protocol('WM_DELETE_WINDOW',
                             self.exit)

    def _validate(self, P, W):
        e = self.frame.nametowidget(W)
        func = self.funcs[e]

        try:
            func(P)
        except ValueError:
            return False
        else:
            return True

    def _collect_params(self):
        params = deepcopy(default_params)
        for block in params.values():
            for key in block:
                func = block[key][1]
                block[key] = func(self.entrys[key].get())

        return params

    def start_button_press(self):
        params = self._collect_params()

        if self.controller.model:
            self.game_screen = GameScreen(self.master, params, model=self.controller.model)
        else:
            self.game_screen = GameScreen(self.master, params)

        self.frame.forget()

    def load_button_press(self):

        self.controller.load_button_press()

        model = self.controller.model
        self.creature_count.config(text=str(len(model.creatures)))

        for block in model.params.values():
            for k, v in block.items():
                if k == "in_layers":
                    v = ", ".join([str(x) for x in v])
                self.entrys[k].set(v)

    def exit(self):
        exit()
Example #6
0
class YEPT_window():

    def __init__(self):
        self.root = Tk()
        self.root.resizable(width = False, height = True)
        self._add_icon()
        self.layout()
    
    def layout(self):
        self._layout_main()
        self._layout_blast()
        canvas = Canvas(self.total, width = 14, height = 150)
        canvas.create_line(10, 0, 10, 150, fill = "#D8D8D8", width = 2)
        canvas.pack(after = self.blast, side = LEFT)
        self._layout_primerDesign()
        self.b2 = Button(self.frmbt, 
                         text = 'Get Checking Primers', 
                         font = ("Arial", 12))
        self.b2.bind("<Button-1>", self.openCheckPrimerWindow)
        self._layout_bottom()

    def _add_icon(self):
        self.root.iconbitmap(_iconPath)
    
    def _layout_main(self):
        self.root.title("YEPT - SLST,ShanghaiTech")
        # Up center banner
        l = Label(self.root, 
                  text="Welcome to YEPT!", 
                  font = ("Arial", 13), 
                  width = 15, height = 2)
        l.pack()

        # Main frame
        self.total = Frame(self.root)
        self.total.pack(fill = X)

    def _layout_blast(self):
        # Frame at the left side
        self.blast = Frame(self.total)
        self.blast.pack(pady = 5, padx = 8, side = LEFT)
        
        self.btf = Frame(self.blast)
        self.btf.pack(pady=5,fill=X)
        
        btitle = Label(self.btf, 
                       text = 'BLAST to get AccessionID', 
                       font = ("Arial", 10), width = 19)
        btitle.pack(side = RIGHT)
        
        self.lblast = Label(self.btf, 
                            text = "(Don't like it? Do it yourself.)", 
                            font = ("Arial", 9), fg = 'blue', width = 22)
        self.lblast.bind('<Enter>', self._blast_showlink)
        self.lblast.bind('<Leave>', self._blast_notshowlink)
        self.lblast.bind('<Button-1>', self._blast_gotoBLAST)
        self.lblast.pack(side = RIGHT, padx = 5)

        self._layout_blast_line1()
        self._layout_blast_line2()

        self.tb = Text(self.blast, width = 65, height = 6)
        self.tb.pack(pady = 5, side = RIGHT)

    def _layout_blast_line1(self):
        # BLAST species selection
        b_species = Frame(self.blast)
        b_species.pack(pady = 5, fill = X)
        
        bspl = Label(b_species, 
                     text = "Target pecies:", 
                     font = ("Arial", 10), width = 10)
        self.bsp_var = StringVar()
        self.bsp_var.set(5)
        bIssj = Radiobutton(b_species, 
                            text = "S. japonicus", 
                            variable = self.bsp_var, value = "J")
        bIssj.bind("<Button-1>", self._focusB)
        bIssc = Radiobutton(b_species, 
                            text = "S. cryophilus", 
                            variable = self.bsp_var, value = "C")
        bIssc.bind("<Button-1>", self._focusB)
        bIsso = Radiobutton(b_species, 
                            text = "S. octosporus", 
                            variable = self.bsp_var, value = "O")
        bIsso.bind("<Button-1>", self._focusB)
        bIsso.pack(side = RIGHT)
        bIssc.pack(side = RIGHT)
        bIssj.pack(side = RIGHT)
        bspl.pack(side = RIGHT)
    
    def _layout_blast_line2(self):
        # Gene name entry line
        sp_name = Frame(self.blast)
        sp_name.pack(pady = 5, fill = X)
        
        sp_name_l = Label(sp_name, 
                          text = 'Gene in S. pombe:', 
                          font = ("Arial", 10), width = 13)
        sp_name_l.pack(side = RIGHT)        
        self.sp_name_e = Entry(sp_name, width = 6)
        self.sp_name_e.bind("<Button-1>", self._focusB)
        self.sp_name_e.bind("<Return>", self._BLAST)
        self.sp_name_e.bind("<Key>", self._forgetb2)
        self.sp_name_e.pack(side = RIGHT, padx = 5, before = sp_name_l)

        cov_l = Label(sp_name, 
                      text = 'Cov cutoff:', font = ("Arial", 10), width = 7)
        cov_l.pack(side = RIGHT, before = self.sp_name_e)
        self.cov_cutoff = Entry(sp_name, width = 4)
        self.cov_cutoff.insert(END, '0.15')
        self.cov_cutoff.bind("<Button-1>", self._focusB)
        self.cov_cutoff.bind("<Return>", self._BLAST)
        self.cov_cutoff.bind("<Key>", self._forgetb2)
        self.cov_cutoff.pack(side = RIGHT, padx = 5, before = cov_l)

        ev_l = Label(sp_name, 
                     text = 'evalue cutoff:', font = ("Arial", 10), width = 10)
        ev_l.pack(side = RIGHT, before = self.cov_cutoff)
        self.ev_cutoff = Entry(sp_name, width = 3)
        self.ev_cutoff.insert(END, '1')
        self.ev_cutoff.bind("<Button-1>", self._focusB)
        self.ev_cutoff.bind("<Return>", self._BLAST)
        self.ev_cutoff.bind("<Key>", self._forgetb2) 
        self.ev_cutoff.pack(side = RIGHT, padx = 5, before = ev_l)
        
        self.button_blast = Button(sp_name, text = 'BLAST', 
                                   font = ("Arial", 9))
        self.button_blast.bind('<Button-1>', self._BLAST)
        self.button_blast.bind('<Return>', self._BLAST)
        self.button_blast.pack(side = RIGHT, before = self.ev_cutoff)

    def _blast_showlink(self, event):
        self.lblast.config(bg = "#D8D8D8")
    
    def _blast_notshowlink(self, event):
        self.lblast.forget()
        self.lblast = Label(self.btf, 
                            text = "(Don't like it? Do it yourself.)", 
                            font = ("Arial", 9), fg = 'blue', width = 22)
        self.lblast.bind('<Enter>', self._blast_showlink)
        self.lblast.bind('<Leave>', self._blast_notshowlink)
        self.lblast.bind('<Button-1>', self._blast_gotoBLAST)
        self.lblast.pack(side=RIGHT,padx=5)
    
    def _blast_gotoBLAST(self, event):
        BLASTn_url = "http://blast.ncbi.nlm.nih.gov/Blast.cgi?PROGRAM=blastn&PAGE_TYPE=BlastSearch&LINK_LOC=blasthome"
        webopen(BLASTn_url, new = 2, autoraise = True)

    def _BLAST(self, event):
        self.tb.delete(0.0,END)
        gene_name = self.sp_name_e.get()
        species = self.bsp_var.get()
        ev_cutoff = float(self.ev_cutoff.get())
        cov_cutoff = float(self.cov_cutoff.get())

        if species == '5':
            self.tb.delete(0.0, END)
            self.tb.insert(END, 'Please choose a target species.')
        elif gene_name == '':
            self.tb.delete(0.0, END)
            self.tb.insert(END, 'Please enter a gene identifier.')
        else:
            output = BLAST_by_sp(gene_name, species, cov_cutoff, ev_cutoff)
            self.tb.delete(0.0, END)
            if output == []:
                self.tb.delete(0.0, END)
                self.tb.insert(END, 'No significant hit found.')
            elif output == 'NoName':
                self.tb.delete(0.0, END)
                self.tb.insert(END, 'There is no gene called "%s" in S. pombe.' % gene_name)
                self.tb.insert(END, str(output))
            else:
                self.tb.delete(0.0, END)
                for hit in output:
                    msg = "E-value: {}\tCov%: {:.2f}\tIdent%: {:.2f}\n".format(hit[0], hit[1], hit[2])
                    for cds in hit[3:]:
                        msg += '\t'.join(cds) + '\n'
                    self.tb.insert(END, msg)

    def _layout_primerDesign(self):
        self.options = Frame(self.total)
        self.options.pack(pady = 5, padx = 10, side = RIGHT)

        self.entries = Frame(self.options)
        self.entries.pack(fill = X, pady = 5)
        
        self._layout_primerDesign_line1()
        self._layout_primerDesign_line2()
        self._layout_primerDesign_line3()
        self._layout_primerDesign_line4_1()
        self._layout_primerDesign_line4_2()
        
        self.frmbt = Frame(self.options)
        self.frmbt.pack(pady = 5, fill = X, side = BOTTOM)
        
        self.b1 = Button(self.frmbt, text = 'Get Primer', font = ("Arial", 12))
        self.b1.bind("<Return>", self.getPrimer)
        self.b1.bind("<Button-1>", self.getPrimer)
        self.b1.pack(side = LEFT, pady = 5, ipady = 1, ipadx = 1)
        
        self.b2 = Button(self.frmbt, 
                         text = 'Get Checking Primers', 
                         font = ("Arial", 12))
        self.b2.bind("<Button-1>", self.openCheckPrimerWindow)

    def _layout_bottom(self):

        primer_result = Frame(self.root)
        primer_result.pack(pady = 5)

        rtf = Frame(primer_result) # result title frame
        rtf.pack(fill = X)
        
        result_title = Label(rtf, 
                             text = 'The primer we get is following:', 
                             font = ("Arial", 11))
        result_title.pack(side = LEFT)

        rcf = Frame(primer_result) # result content frame
        rcf.pack(fill = X)
        
        self.t = Text(rcf, width = 125, height = 5)
        self.t.pack(side = LEFT, fill = Y, expand = YES)
        
        scr = Scrollbar(rcf)
        scr.pack(side = RIGHT, fill = Y)
        self.t["yscrollcommand"] = scr.set
        scr['command'] = self.t.yview

    def _layout_primerDesign_line1(self):
        l2 = Label(self.entries, 
                   text = 'Accession ID for all or \ngene symbol in S. pombe:', 
                   font = ("Arial", 10), width = 20)
        l2.pack(side = LEFT)
        
        self.e2 = Entry(self.entries, width = 14)
        self.e2.bind("<Return>", self.getPrimer)
        self.e2.bind("<Key>", self._forgetb2)
        self.e2.pack(side = LEFT)
        
        l3 = Label(self.entries, text = 'length:',
                   font = ("Arial", 10), width = 6)
        l3.pack(side = LEFT)
        
        self.e3 = Entry(self.entries, width = 3)
        self.e3.insert(0, '80')
        self.e3.bind("<Return>", self.getPrimer)
        self.e3.bind("<Key>", self._forgetb2)
        self.e3.pack(side = LEFT)

    def _layout_primerDesign_line2(self):
        check_species = Frame(self.options)
        check_species.pack(fill = X, pady = 5)
        
        sp = Label(check_species, text = 'Species:', 
                   font = ("Arial", 10), width = 6)
        sp.pack(side = LEFT)
        
        self.species_var = StringVar()
        self.species_var.set(1)
        Issp = Radiobutton(check_species, text = "S. pombe", 
                           variable = self.species_var, value = "P")
        Issp.bind("<Button-1>", self._getfocusback)
        Issp.pack(side = LEFT)
        Issj = Radiobutton(check_species, text = "S. japonicus", 
                           variable=self.species_var, value = "J")
        Issj.bind("<Button-1>", self._getfocusback)
        Issj.pack(side = LEFT)
        Issc = Radiobutton(check_species, text = "S. cryophilus", 
                           variable = self.species_var, value = "C")
        Issc.bind("<Button-1>", self._getfocusback)
        Issc.pack(side = LEFT)
        Isso = Radiobutton(check_species, text = "S. octosporus", 
                           variable = self.species_var, value = "O")
        Isso.bind("<Button-1>", self._getfocusback)
        Isso.pack(side = LEFT)

    def _layout_primerDesign_line3(self):
        self.check_mode = Frame(self.options)
        self.check_mode.pack(fill = X, pady = 5)
        
        self.mode_var = StringVar()
        self.mode_var.set(2)
        md = Label(self.check_mode, text = 'Fuction:', 
                   font = ("Arial", 10), width = 6)
        md.pack(side = LEFT)
        Isdel = Radiobutton(self.check_mode,text = "Deletion", 
                            variable = self.mode_var, value="del", 
                            command = self._choose_plasmid)
        Isdel.bind("<Button-1>", self._getfocusback)
        Isdel.pack(side = LEFT)
        IsC = Radiobutton(self.check_mode, text = "C-terminal Tagging", 
                          variable = self.mode_var, value = "C", 
                          command = self._choose_Ctag)
        IsC.bind("<Button-1>", self._getfocusback)
        IsC.pack(side = LEFT)
        IsN = Radiobutton(self.check_mode, text = "N-terminal promoter adding", 
                          variable = self.mode_var, value = "N", 
                          command = self._choose_Ntag)
        IsN.bind("<Button-1>", self._getfocusback)
        IsN.pack(side = LEFT)

    def _layout_primerDesign_line4_1(self):
        self.blankframe = Frame(self.options)
        self.blankframe.pack(after = self.check_mode, pady = 18)
        
        self.check_plsmd = Frame(self.options)
        self.check_plsmd.pack(after = self.check_mode, pady = 5)
        self.check_plsmd.forget()
        
        pl = Label(self.check_plsmd, text = 'Plasmid:', 
                   font = ("Arial", 10), width = 10)
        pl.pack(side = LEFT)
        self.plasmid_var = StringVar()
        self.plasmid_var.set(3)
        IspFA6a = Radiobutton(self.check_plsmd, text = "pFA6a", 
                              variable = self.plasmid_var, value = 'pFA6a')
        IspFA6a.bind("<Button-1>", self._getfocusback)
        IspFA6a.pack(side = LEFT)
        IsKS = Radiobutton(self.check_plsmd, text = "KS-ura4", 
                           variable = self.plasmid_var, value = 'KS-ura4')
        IsKS.bind("<Button-1>", self._getfocusback)
        IsKS.pack(side = LEFT)

    def _layout_primerDesign_line4_2(self):
        self.check_Ntag = Frame(self.options)
        self.check_Ntag.pack(after = self.check_mode, pady = 5)
        self.check_Ntag.forget()
        
        nt = Label(self.check_Ntag, text = 'N-terminal Tag:', 
                   font = ("Arial", 10), width = 10)
        nt.pack(side = LEFT)
        
        self.Ntag_var = StringVar()
        self.Ntag_var.set(' ')
        Isnone = Radiobutton(self.check_Ntag, text = "None", 
                           variable = self.Ntag_var, value = ' ')
        Isnone.bind("<Button-1>", self._getfocusback)
        Isnone.pack(side=LEFT)
        Is3HA = Radiobutton(self.check_Ntag, text = "3HA", 
                          variable = self.Ntag_var, value = '3HA')
        Is3HA.bind("<Button-1>", self._getfocusback)
        Is3HA.pack(side = LEFT)
        IsGST = Radiobutton(self.check_Ntag, text = "GST", 
                          variable = self.Ntag_var, value = 'GST')
        IsGST.bind("<Button-1>", self._getfocusback)
        IsGST.pack(side = LEFT)
        IsGFP = Radiobutton(self.check_Ntag, text = "GFP", 
                            variable = self.Ntag_var, value = 'GFP')
        IsGFP.bind("<Button-1>", self._getfocusback)
        IsGFP.pack(side = LEFT)

    def _choose_Ntag(self):
        self.blankframe.forget()
        self.check_plsmd.forget()
        self.check_Ntag.pack(after = self.check_mode, pady = 5)

    def _choose_plasmid(self):
        self.blankframe.forget()
        self.check_Ntag.forget()
        self.check_plsmd.pack(after = self.check_mode, pady = 5)

    def _choose_Ctag(self):
        self.blankframe.pack(pady = 18)
        self.check_Ntag.forget()
        self.check_plsmd.forget()

    def _noResultMsg(self, keyword, species):
        self.t.delete(0.0, END)
        self.t.insert(END, 
            "No gene matches \"{}\" in {}.".format(keyword, species))

    def _ambResultMsg(self, keyword, species, results):
        self.t.delete(0.0, END)
        nResult, dfRepr = formatMultiResult(results)
        self.t.insert(END, 
            "{0} entries found to match \"{1}\" in {2}:\n{3}".format(nResult, keyword, species, dfRepr))

    def getPrimer(self, event):
        self.b1.focus_set()
        mode = self.mode_var.get()
        species = self.species_var.get()
        gene = self.e2.get()
        plasmid = self.plasmid_var.get()

        if mode != 'del':
            plasmid = 'pFA6a'

        if species == "1" or mode == "2" or plasmid == "3":
            self.t.delete(0.0, END)
            self.t.insert(END, "Please check all the radiobutton needed!\n")
        else:
            fullSpeciesNameMap = {'P': 'S. pombe', 'J': 'S. japonicus', 
                            'C': 'S. cryophilus', 'O': 'S. octosporus'}
            fullSpeciesName = fullSpeciesNameMap[species]
            
            Ntag = self.Ntag_var.get()
            length = int(self.e3.get())
            
            if plasmid == "pFA6a":
                forward_plmd_del = "CGGATCCCCGGGTTAATTAA"
                reverse_plmd_del = "GAATTCGAGCTCGTTTAAAC"
                forward_plmd_N = "GAATTCGAGCTCGTTTAAAC"
                reverse_plmd_N = "CATGATTTAACAAAGCGACTATA"
                reverse_plmd_N_3HA = "GCACTGAGCAGCGTAATCTG"
                reverse_plmd_N_GST = "ACGCGGAACCAGATCCGATT"
                reverse_plmd_N_GFP = "TTTGTATAGTTCATCCATGC"
            elif plasmid == "KS-ura4":
                forward_plmd_del = "CGCCAGGGTTTTCCCAGTCACGAC"
                reverse_plmd_del = "AGCGGATAACAATTTCACACAGGA"

            if mode == 'del':
                primer = get_del_primer(species, gene, length)
                if primer == []:
                    self._noResultMsg(gene, fullSpeciesName)
                elif type(primer) == list and len(primer) > 1:
                    self._ambResultMsg(gene, fullSpeciesName, primer)
                else:
                    self.t.delete(0.0, END)
                    self.t.insert(END, 'Found gene: {}, GenBank: {}, systematic ID: {}\n'.format(primer[2][0], primer[2][1], primer[2][2]))
                    self.t.insert(END, 'Forward primer: {} - {}\n'.format(primer[0], forward_plmd_del))
                    self.t.insert(END, '                %GC content = {} TM = {}\n'.format(GC(primer[0] + forward_plmd_del), TM(primer[0] + forward_plmd_del)))
                    self.t.insert(END, 'Reverse primer: {} - {}\n'.format(primer[1], reverse_plmd_del))
                    self.t.insert(END, '                %GC content = {} TM = {}'.format(GC(primer[1] + reverse_plmd_del), TM(primer[1] + reverse_plmd_del)))
                    self.b2.pack(side = LEFT, pady = 5, padx = 7, ipady = 1, ipadx = 1)
                    self.b2.focus_set()
            elif mode == 'C':
                primer = get_Ctag_primer(species, gene, length)
                if primer == []:
                    self._noResultMsg(gene, fullSpeciesName)
                elif type(primer) == list and len(primer) > 1:
                    self._ambResultMsg(gene, fullSpeciesName, primer)
                else:
                    self.t.delete(0.0, END)
                    self.t.insert(END, 'Found gene: {}, GenBank: {}, systematic ID: {}\n'.format(primer[2][0], primer[2][1], primer[2][2]))
                    self.t.insert(END, 'Forward primer: {} - {}\n'.format(primer[0], forward_plmd_del))
                    self.t.insert(END, '                %GC content = {} TM = {}\n'.format(GC(primer[0] + forward_plmd_del), TM(primer[0] + forward_plmd_del)))
                    self.t.insert(END, 'Reverse primer: {} - {}\n'.format(primer[1], reverse_plmd_del))
                    self.t.insert(END, '                %GC content = {} TM = {}'.format(GC(primer[1] + reverse_plmd_del), TM(primer[1] + reverse_plmd_del)))
                    self.b2.pack(side = LEFT, pady = 5, padx = 7, ipady = 1, ipadx = 1)
                    self.b2.focus_set()
            elif mode == 'N':
                if Ntag == ' ':
                    primer = get_Ntag_none_primer(species, gene,length)
                else:
                    primer = get_Ntag_tag_primer(species, gene,length)
                    if Ntag == "3HA":
                        reverse_plmd_N = reverse_plmd_N_3HA
                    elif Ntag == "GST":
                        reverse_plmd_N = reverse_plmd_N_GST
                    elif Ntag == "GFP":
                        reverse_plmd_N = reverse_plmd_N_GFP
                if primer == []:
                    self._noResultMsg(gene, fullSpeciesName)
                elif type(primer) == list and len(primer) > 1:
                    self._ambResultMsg(gene, fullSpeciesName, primer)
                else:
                    self.t.delete(0.0, END)
                    self.t.insert(END, 'Found gene: {}, GenBank: {}, systematic ID: {}\n'.format(primer[2][0], primer[2][1], primer[2][2]))
                    self.t.insert(END, 'Forward primer: {} - {}\n'.format(primer[0], forward_plmd_N))
                    self.t.insert(END, '                %GC content = {} TM = {}\n'.format(GC(primer[0] + forward_plmd_N), TM(primer[0] + forward_plmd_N)))
                    self.t.insert(END, 'Reverse primer: {} - {}\n'.format(primer[1], reverse_plmd_N))
                    self.t.insert(END, '                %GC content = {} TM = {}'.format(GC(primer[1] + reverse_plmd_N), TM(primer[1] + reverse_plmd_N)))
                    self.b2.pack(side = LEFT, pady = 5, padx = 7, ipady = 1, ipadx = 1)
                    self.b2.focus_set()

    def _backtob3(self, event):
        self.b3.focus_set()

    def _focusB(self, event):
        self.button_blast.focus_set()

    def _getfocusback(self, event):
        self.b1.focus_set()
        self.b2.forget()

    def _forgetb2(self, event):
        self.b2.forget()

    def start(self):
        self.root.mainloop()

    def openCheckPrimerWindow(self, event):
        CheckPrimerWindow(self)