Exemplo n.º 1
0
 def receivePrivateChat(self, connectingUser):
     global conversationBoxList
     print("CHAT PRIVATA in arrivo con "+connectingUser)
         
     newWindow = Toplevel(self.parent)
     newWindow.title("Python Chat requested by "+connectingUser)
     newWindow.minsize(400, 475)
     newWindow.focus()
     
     def disconnectPM():
         del conversationBoxList[connectingUser]
         newWindow.destroy()
     newWindow.protocol('WM_DELETE_WINDOW', disconnectPM)
     
     #label = Label(newWindow, text="PROVA PROVA")
     #label.pack(side="top", fill="both", padx=10, pady=10)
     frame = Frame(newWindow)
     frame.pack(fill=BOTH, expand=1, side=LEFT)
     
     box = ScrolledText(frame, wrap=WORD, relief = GROOVE, width=30, height=18, font=self.customFontMessage)
     box.config(state=DISABLED)
     box.pack(expand="yes", fill=BOTH, side=TOP)
     
     textarea = Text(frame, width=30, height=5)
     textarea.bind("<KeyRelease-Return>", lambda event : self.getprivatetext(event, textarea, connectingUser)) 
     textarea.pack(expand="yes", fill=BOTH, side=TOP)
     
     #aggiungo alla mappa globale il box di conversazione
     conversationBoxList[connectingUser] = box
Exemplo n.º 2
0
def show_more_window(values_to_tree):
    frame = Toplevel(takefocus=True)
    frame.focus()
    frame.title('Show More')

    label = Label(frame, text='More details about picked positions')
    label.pack()

    tree = ttk.Treeview(frame, columns=[1, 2, 3], height=10, show='headings')
    tree.pack(side='left', fill='x')
    tree.heading(1, text='Title')
    tree.heading(2, text='Author')
    tree.heading(3, text='Updated')
    tree.column(1, width=500)
    tree.column(2, width=200)
    tree.column(3, width=300)

    scroll_hor = ttk.Scrollbar(frame, orient='vertical', command=tree.yview)
    scroll_hor.pack(side='right', fill='y')

    tree.configure(yscrollcommand=scroll_hor.set)

    for value in values_to_tree:
        tree.insert('', 'end', values=(value[0], value[1], value[2]))

    button = Button(frame, text='Ok', command=frame.destroy)
    button.pack(side='top', padx=10, ipadx=10, pady=60, ipady=10)

    frame.mainloop()
Exemplo n.º 3
0
def error_window():
    frame = Toplevel(takefocus=True)
    frame.focus()
    frame.title('Error Window')
    frame.geometry('250x100')
    label = Label(frame, text="You didn't selected a position from the list")
    label.pack()
    button = Button(frame, text='Ok', command=frame.destroy)
    button.pack()
    frame.mainloop()
Exemplo n.º 4
0
def show_all():
    show_root=Toplevel()
    show_root.grab_set()
    show_root.focus()
    show_root.geometry('795x500+100+150')
    show_root.resizable(False,False)
    show_root.config(bg='firebrick1')

    frame=tk.Frame(show_root,bg='gold2',relief='groove',borderwidth=5)
    frame.place(x=0,y=0,width=795,height=500)

    scroll_x=tk.Scrollbar(frame,orient='horizontal')
    scroll_x.pack(side='bottom',fill='x')
    
    scroll_y=tk.Scrollbar(frame,orient='vertical')
    scroll_y.pack(side='right',fill='y')

    members_table=ttk.Treeview(frame,columns=('Id','Name','Mobile No','Address','Gender','D.O.B'),
                              yscrollcommand=scroll_y,xscrollcommand=scroll_x)

    members_table.pack(fill='both',expand=1)
    scroll_x.config(command=members_table.xview)
    scroll_y.config(command=members_table.yview)
    
    style =ttk.Style()
    style.configure('Treeview.Heading',foreground='blue',font=('helvetica',16))
    style.configure('Treeview',foreground='green',font=('times new roman',15),background='cyan',fg='green',bg='red')

    members_table.heading('Id',text='Id')
    members_table.heading('Name',text='Name')
    members_table.heading('Mobile No',text='Mobile No')
    members_table.heading('Address',text='Address')
    members_table.heading('Gender',text='Gender')
    members_table.heading('D.O.B',text='D.O.B')
    members_table['show']='headings'

    members_table.column('Id',width=50)
    members_table.column('Name',width=300)
    members_table.column('Mobile No',width=140)
    members_table.column('Address',width=260)
    members_table.column('Gender',width=100)
    members_table.column('D.O.B',width=100)
    try:
        strr ='select * from membersdata'
        my_cursor.execute(strr)
        datas = my_cursor.fetchall()
        members_table.delete(*members_table.get_children())
        for i in datas:
            val = [i[0],i[1],i[2],i[3],i[4],i[5]]
            members_table.insert('', 'end',
                 values=(val))
    except:
        show_root.destroy()
        m_box.showerror('Notification','Please connect to Database first')
    show_root.mainloop()
Exemplo n.º 5
0
class SpeciesListDialog():
    
    def __init__(self, parent):
        self.parent = parent
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()
        
        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(1, weight=1)
        
        Label(self.gui, text="Registered Species:").grid(row=0, column=0, pady=5, padx=5, sticky="w")
        self.listRegisteredSpecies = Listbox(self.gui, width=70)
        self.buttonAdd = Button(self.gui, text=" + ")
        self.buttonDel = Button(self.gui, text=" - ")
        self.listRegisteredSpecies.grid(row=1, column=0, columnspan=3, sticky="nswe", pady=5, padx=5)
        self.buttonAdd.grid(row=2, column=1, pady=5, padx=5)
        self.buttonDel.grid(row=2, column=2, pady=5, padx=5)
        
        # Set (minimum + max) Window size 
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
#         self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())
        
        self.actionUpdate(None)
        self.gui.bind("<<Update>>", self.actionUpdate)
        self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
        
        self.buttonDel.bind("<ButtonRelease>", self.actionDel)
        self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
        
        
        self.gui.mainloop()
        
    def actionClose(self):
        self.parent.guiRoot.event_generate("<<Update>>", when="tail")
        self.gui.destroy()
        
    def actionUpdate(self, event):
        self.listRegisteredSpecies.delete(0, "end")
        for (taxid, name) in self.parent.optimizer.speciesList:
            self.listRegisteredSpecies.insert("end", taxid + ": " + name)
            
    def actionDel(self, event):
        try:
            selection = self.listRegisteredSpecies.selection_get()
            selectionSplit = selection.split(": ")            
            self.parent.optimizer.speciesList.remove((selectionSplit[0], selectionSplit[1]))
            self.gui.event_generate("<<Update>>")
        except tkinter.TclError :
            # no selection
            pass
        
    def actionAdd(self, Event):
        SpeciesSearchDialog(self.parent, self)
Exemplo n.º 6
0
def start_error_window():
    frame = Toplevel(takefocus=True)
    frame.focus()
    frame.title('Error Window')
    frame.geometry('250x100')
    label = Label(frame, text="You didn't input valid RSS link")
    label.pack()
    button = Button(frame, text='Ok', command=frame.destroy)
    button.pack()

    frame.mainloop()
Exemplo n.º 7
0
class AddRestrictionDialog():
    
    def __init__(self, parent):
        self.parent = parent
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()
        
        self.gui.columnconfigure(0, weight=1)
        self.gui.columnconfigure(1, weight=1)
        
        Label(self.gui, text="Enzyme:").grid(row=0, column=0, sticky="e", padx=5)
        self.entryEnzyme = Entry(self.gui)
        self.entryEnzyme.grid(row=0, column=1, sticky="w", padx=5, pady=10)
        self.frameButtonGroup = Frame(self.gui)
        self.frameButtonGroup.grid(row=1, column=0, columnspan=2, pady=10)
        self.buttonOK = Button(self.frameButtonGroup, text=" OK ")
        self.buttonCancel = Button(self.frameButtonGroup, text=" Cancel ")
        self.buttonOK.grid(row=0, column=1, sticky="w", padx=5)
        self.buttonCancel.grid(row=0, column=0, sticky="e", padx=5)
        
        # Set (minimum + max) Window size 
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
        self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())
        
        self.entryEnzyme.focus()
        
        self.buttonOK.bind("<ButtonRelease>", self.actionOK)
        self.buttonCancel.bind("<ButtonRelease>", self.actionCancel)
        self.entryEnzyme.bind("<Return>", self.actionOK)
        
        self.gui.mainloop()
#         self.gui.grab_release()
#         self.gui.destroy()

    def actionOK(self, event):
        enzymeString = self.entryEnzyme.get()
        if enzymeString in rest_dict.keys():
            
            if enzymeString in self.parent.optimizer.restrictionEnzymeList:
                showinfo("", (enzymeString + " was already added to the list"))
                return
                
            self.parent.optimizer.restrictionEnzymeList.append(enzymeString)
            self.parent.guiRoot.event_generate("<<Update>>", when="tail")
            self.gui.destroy()
        else:
            showinfo("", (enzymeString + " is not a valid restriction enzyme"))
    
    def actionCancel(self, event):
        self.gui.destroy()
class AddRestrictionDialog:
    def __init__(self, parent):
        self.parent = parent
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()

        self.gui.columnconfigure(0, weight=1)
        self.gui.columnconfigure(1, weight=1)

        Label(self.gui, text="Enzyme:").grid(row=0, column=0, sticky="e", padx=5)
        self.entryEnzyme = Entry(self.gui)
        self.entryEnzyme.grid(row=0, column=1, sticky="w", padx=5, pady=10)
        self.frameButtonGroup = Frame(self.gui)
        self.frameButtonGroup.grid(row=1, column=0, columnspan=2, pady=10)
        self.buttonOK = Button(self.frameButtonGroup, text=" OK ")
        self.buttonCancel = Button(self.frameButtonGroup, text=" Cancel ")
        self.buttonOK.grid(row=0, column=1, sticky="w", padx=5)
        self.buttonCancel.grid(row=0, column=0, sticky="e", padx=5)

        # Set (minimum + max) Window size
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
        self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())

        self.entryEnzyme.focus()

        self.buttonOK.bind("<ButtonRelease>", self.actionOK)
        self.buttonCancel.bind("<ButtonRelease>", self.actionCancel)
        self.entryEnzyme.bind("<Return>", self.actionOK)

        self.gui.mainloop()

    #         self.gui.grab_release()
    #         self.gui.destroy()

    def actionOK(self, event):
        enzymeString = self.entryEnzyme.get()
        if enzymeString in rest_dict.keys():

            if enzymeString in self.parent.optimizer.restrictionEnzymeList:
                showinfo("", (enzymeString + " was already added to the list"))
                return

            self.parent.optimizer.restrictionEnzymeList.append(enzymeString)
            self.parent.guiRoot.event_generate("<<Update>>", when="tail")
            self.gui.destroy()
        else:
            showinfo("", (enzymeString + " is not a valid restriction enzyme"))

    def actionCancel(self, event):
        self.gui.destroy()
Exemplo n.º 9
0
        def displayDetails() :
            window=Toplevel(root ,background="white")
            window.focus()
            window.resizable(width=False ,height=False)

            details=Text(window ,background="white" ,height=9 ,width=42 ,borderwidth=4 )
            details.pack(side="top")

            details.insert("insert" ,application_details)
            details["state"]="disabled"

            exitButton=Button(window ,text="Ok" ,borderwidth=2 ,font=("Calibri" , 11) ,width=8 ,command=lambda : window.destroy() ,background="white")
            exitButton.pack(pady=10)

            window.mainloop()
Exemplo n.º 10
0
 def show_about(self):
     about = Toplevel(self.master)
     about.title('About {}'.format(self.version[:-5]))
     about.focus()
     about.resizable(0, 0)
     logo_lbl = Label(about, image=self.logo)
     logo_lbl.image = self.logo
     logo_lbl.grid(row=0, column=0, padx='7 11', pady=13, sticky='n')
     about_frame = Frame(about, padding='0 10 10 10')
     about_frame.grid(row=0, column=1)
     Label(about_frame, text=self.version).grid(sticky='w')
     Label(about_frame, text='Developer:  Joel W. Dafoe').grid(pady='6', sticky='w')
     link = Link(about_frame, text='http://cyberdatx.com', foreground='blue', cursor='hand2')
     link.grid(sticky='w')
     link.bind('<Button-1>', lambda e: webbrowser.open('http://cyberdatx.com'))
     Label(about_frame, text=self.description, wraplength=292).grid(columnspan=2, pady=6, sticky='w')
     cls_btn = Button(about_frame, text='OK', command=about.destroy)
     cls_btn.grid(column=1, sticky='e')
     cls_btn.focus()
     about.bind('<Return>', lambda e: cls_btn.invoke())
Exemplo n.º 11
0
 def new_sunday():
     def new_sun():
         try:
             global new_table
             new_table='sarathi'+date_entry.get()
             rr = f'create table {new_table} (user_id int primary key,foreign key(user_id) references membersdata(id ))'
             my_cursor.execute(rr)
             m_box.showinfo('Notification','Fresh Sunday',parent=date)
             all_mem()
             date.destroy()
         except NameError:
             todays_mem_root.destroy()
             date.destroy()
             m_box.showerror('Error','Please connect to Database First')
         except:
             res = m_box.askyesnocancel('Confirmation','Is it todays Date?',parent=date)
             if res:
                 all_mem()
                 date.destroy()
     date=Toplevel()
     date.grab_set()
     date.focus()
     date.geometry('490x180+300+300')
     date.resizable(False,False)
     date.config(bg='black')
     theme_name=tk.Label(date,text='Date should be like this:10May2020 ',bg='light green',fg='blue',font=('times new roman',18),
                   width=30,borderwidth=5,anchor='center',relief='groove')
     theme_name.pack()
     
     date_name=tk.Label(date,text='Add Todays Date : ',bg='light green',fg='blue',font=('times new roman',18),
                   width=15,borderwidth=5,anchor='w',relief='groove')
     date_name.place(x=0,y=50)
     
     date_entry=tk.Entry(date,fg='blue',font=('times new roman',18),
                       width=20,borderwidth=5,relief='groove')
     date_entry.place(x=240,y=50)
     
     submit_date=tk.Button(date,text='Submit',command=new_sun,bg='light green',fg='blue',font=('times new roman',18),
                   width=5,borderwidth=5,anchor='center',relief='groove')
     submit_date.place(x=190,y=110)
Exemplo n.º 12
0
def update_sarathian():
    global enter_id_root
    enter_id_root=Toplevel()
    enter_id_root.grab_set()
    enter_id_root.focus()
    enter_id_root.geometry('400x110+300+300')
    enter_id_root.config(bg='red')
    
    id_label=tk.Label(enter_id_root,text='Enter Id to update : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='w',relief='groove')
    id_label.place(x=10,y=10)

    global enter_id_var
    enter_id_var=tk.StringVar()
    id_entry=tk.Entry(enter_id_root,fg='blue',textvariable=enter_id_var,font=('times new roman',18),
                      width=12,borderwidth=5,relief='groove')
    id_entry.place(x=230,y=10)
    id_entry.focus()
    
    submit_btn=tk.Button(enter_id_root,width=6,text='Upadate',command=update,bg='light green',fg='blue',
                        activebackground='gold2',activeforeground='blue',font=('times new roman',18))
    submit_btn.place(x=130,y=60)
Exemplo n.º 13
0
    def new_body_mem():
        def new_mem():
            try:
                global new_body_db
                new_body_db='ExecutiveBody'+exe_entry.get()
                rr = f'create table {new_body_db} (body_id int primary key,foreign key(body_id) references membersdata(id ),mem_post varchar(50))'
                my_cursor.execute(rr)
                m_box.showinfo('Notification','Fresh Executive Body',parent=ex)
                all_mems()
                ex.destroy()
            except NameError:
                m_box.showerror('Error','Please connect to Database First',parent=ex)
                ex.destroy()
                Exe_body_root.destroy()
            except:
                res = m_box.askyesnocancel('Confirmation',f'Is it {exe_entry.get()} Executive body?',parent=ex)
                if res:
                    all_mems()
                    ex.destroy()

        ex=Toplevel()
        ex.grab_set()
        ex.title('Executive Body')
        ex.focus()
        ex.geometry('490x180+300+300')
        ex.resizable(False,False)
        ex.config(bg='black')
        
        exe_label=tk.Label(ex,text='Add Executive Body Number Below',bg='light green',fg='blue',font=('times new roman',18),
                      width=40,borderwidth=5,anchor='center',relief='groove')
        exe_label.place(x=0,y=0)
        
        exe_entry=tk.Entry(ex,fg='blue',font=('times new roman',18),
                          width=6,borderwidth=5,relief='groove')
        exe_entry.place(x=190,y=60)
        exe_entry.focus()
        submit_exe=tk.Button(ex,text='Submit',command=new_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=5,borderwidth=5,anchor='center',relief='groove')
        submit_exe.place(x=190,y=110)
Exemplo n.º 14
0
class SpriteSelector(object):
    def __init__(self, parent, callback, adjuster=False):
        if is_bundled():
            self.deploy_icons()
        self.parent = parent
        self.window = Toplevel(parent)
        self.window.geometry("800x650")
        self.sections = []
        self.callback = callback
        self.adjuster = adjuster

        self.window.wm_title("TAKE ANY ONE YOU WANT")
        self.window['padx'] = 5
        self.window['pady'] = 5
        self.all_sprites = []

        def open_official_sprite_listing(_evt):
            webbrowser.open("http://alttpr.com/sprite_preview")

        def open_unofficial_sprite_dir(_evt):
            open_file(self.unofficial_sprite_dir)

        def open_spritesomething_listing(_evt):
            webbrowser.open(
                "https://artheau.github.io/SpriteSomething/?mode=zelda3/link")

        official_frametitle = Frame(self.window)
        official_title_text = Label(official_frametitle,
                                    text="Official Sprites")
        official_title_link = Label(official_frametitle,
                                    text="(open)",
                                    fg="blue",
                                    cursor="hand2")
        official_title_text.pack(side=LEFT)
        official_title_link.pack(side=LEFT)
        official_title_link.bind("<Button-1>", open_official_sprite_listing)

        unofficial_frametitle = Frame(self.window)
        unofficial_title_text = Label(unofficial_frametitle,
                                      text="Unofficial Sprites")
        unofficial_title_link = Label(unofficial_frametitle,
                                      text="(open)",
                                      fg="blue",
                                      cursor="hand2")
        unofficial_title_text.pack(side=LEFT)
        unofficial_title_link.pack(side=LEFT)
        unofficial_title_link.bind("<Button-1>", open_unofficial_sprite_dir)
        spritesomething_title_link = Label(unofficial_frametitle,
                                           text="(SpriteSomething)",
                                           fg="blue",
                                           cursor="hand2")
        spritesomething_title_link.pack(side=LEFT)
        spritesomething_title_link.bind("<Button-1>",
                                        open_spritesomething_listing)

        self.icon_section(
            official_frametitle, self.official_sprite_dir + '/*',
            'Official sprites not found. Click "Update official sprites" to download them.'
        )
        self.icon_section(
            unofficial_frametitle, self.unofficial_sprite_dir + '/*',
            'Put sprites in the unofficial sprites folder (see open link above) to have them appear here.'
        )

        frame = Frame(self.window)
        frame.pack(side=BOTTOM, fill=X, pady=5)

        button = Button(frame,
                        text="Browse for file...",
                        command=self.browse_for_sprite)
        button.pack(side=RIGHT, padx=(5, 0))

        button = Button(frame,
                        text="Update official sprites",
                        command=self.update_official_sprites)
        button.pack(side=RIGHT, padx=(5, 0))

        button = Button(frame,
                        text="Default Link sprite",
                        command=self.use_default_link_sprite)
        button.pack(side=LEFT, padx=(0, 5))

        button = Button(frame,
                        text="Random sprite",
                        command=self.use_random_sprite)
        button.pack(side=LEFT, padx=(0, 5))

        if adjuster:
            button = Button(frame,
                            text="Current sprite from rom",
                            command=self.use_default_sprite)
            button.pack(side=LEFT, padx=(0, 5))

        set_icon(self.window)
        self.window.focus()

    def icon_section(self, frame_label, path, no_results_label):
        frame = LabelFrame(self.window,
                           labelwidget=frame_label,
                           padx=5,
                           pady=5)
        canvas = Canvas(frame, borderwidth=0)
        y_scrollbar = Scrollbar(frame, orient="vertical", command=canvas.yview)
        y_scrollbar.pack(side="right", fill="y")
        content_frame = Frame(canvas)
        canvas.pack(side="left", fill="both", expand=True)
        canvas.create_window((4, 4), window=content_frame, anchor="nw")
        canvas.configure(yscrollcommand=y_scrollbar.set)

        def onFrameConfigure(canvas):
            """Reset the scroll region to encompass the inner frame"""
            canvas.configure(scrollregion=canvas.bbox("all"))

        content_frame.bind(
            "<Configure>",
            lambda event, canvas=canvas: onFrameConfigure(canvas))
        frame.pack(side=TOP, fill=X)

        sprites = []

        for file in glob(output_path(path)):
            sprites.append(Sprite(file))

        sprites.sort(key=lambda s: str.lower(s.name or "").strip())

        i = 0
        for sprite in sprites:
            image = get_image_for_sprite(sprite)
            if image is None:
                continue
            self.all_sprites.append(sprite)
            button = Button(content_frame,
                            image=image,
                            command=lambda spr=sprite: self.select_sprite(spr))
            ToolTips.register(
                button, sprite.name +
                ("\nBy: %s" %
                 sprite.author_name if sprite.author_name else ""))
            button.image = image
            button.grid(row=i // 16, column=i % 16)
            i += 1

        if i == 0:
            label = Label(content_frame, text=no_results_label)
            label.pack()

    def update_official_sprites(self):
        # need to wrap in try catch. We don't want errors getting the json or downloading the files to break us.
        self.window.destroy()
        self.parent.update()

        def work(task):
            resultmessage = ""
            successful = True

            def finished():
                task.close_window()
                if successful:
                    messagebox.showinfo("Sprite Updater", resultmessage)
                else:
                    messagebox.showerror("Sprite Updater", resultmessage)
                SpriteSelector(self.parent, self.callback, self.adjuster)

            try:
                task.update_status("Downloading official sprites list")
                with urlopen('https://alttpr.com/sprites') as response:
                    sprites_arr = json.loads(response.read().decode("utf-8"))
            except Exception as e:
                resultmessage = "Error getting list of official sprites. Sprites not updated.\n\n%s: %s" % (
                    type(e).__name__, e)
                successful = False
                task.queue_event(finished)
                return

            try:
                task.update_status("Determining needed sprites")
                current_sprites = [
                    os.path.basename(file)
                    for file in glob(self.official_sprite_dir + '/*')
                ]
                official_sprites = [
                    (sprite['file'],
                     os.path.basename(urlparse(sprite['file']).path))
                    for sprite in sprites_arr
                ]
                needed_sprites = [(sprite_url, filename)
                                  for (sprite_url,
                                       filename) in official_sprites
                                  if filename not in current_sprites]
                bundled_sprites = [
                    os.path.basename(file)
                    for file in glob(self.local_official_sprite_dir + '/*')
                ]
                # todo: eventually use the above list to avoid downloading any sprites that we already have cached in the bundle.

                official_filenames = [
                    filename for (_, filename) in official_sprites
                ]
                obsolete_sprites = [
                    sprite for sprite in current_sprites
                    if sprite not in official_filenames
                ]
            except Exception as e:
                resultmessage = "Error Determining which sprites to update. Sprites not updated.\n\n%s: %s" % (
                    type(e).__name__, e)
                successful = False
                task.queue_event(finished)
                return

            updated = 0
            for (sprite_url, filename) in needed_sprites:
                try:
                    task.update_status("Downloading needed sprite %g/%g" %
                                       (updated + 1, len(needed_sprites)))
                    target = os.path.join(self.official_sprite_dir, filename)
                    with urlopen(sprite_url) as response, open(target,
                                                               'wb') as out:
                        shutil.copyfileobj(response, out)
                except Exception as e:
                    resultmessage = "Error downloading sprite. Not all sprites updated.\n\n%s: %s" % (
                        type(e).__name__, e)
                    successful = False
                updated += 1

            deleted = 0
            for sprite in obsolete_sprites:
                try:
                    task.update_status("Removing obsolete sprite %g/%g" %
                                       (deleted + 1, len(obsolete_sprites)))
                    os.remove(os.path.join(self.official_sprite_dir, sprite))
                except Exception as e:
                    resultmessage = "Error removing obsolete sprite. Not all sprites updated.\n\n%s: %s" % (
                        type(e).__name__, e)
                    successful = False
                deleted += 1

            if successful:
                resultmessage = "official sprites updated successfully"

            task.queue_event(finished)

        BackgroundTaskProgress(self.parent, work, "Updating Sprites")

    def browse_for_sprite(self):
        sprite = filedialog.askopenfilename(filetypes=[("All Sprite Sources", (
            ".zspr", ".spr", ".sfc",
            ".smc")), ("ZSprite files",
                       ".zspr"), ("Sprite files",
                                  ".spr"), ("Rom Files",
                                            (".sfc",
                                             ".smc")), ("All Files", "*")])
        try:
            self.callback(Sprite(sprite))
        except Exception:
            self.callback(None)
        self.window.destroy()

    def use_default_sprite(self):
        self.callback(None, False)
        self.window.destroy()

    def use_default_link_sprite(self):
        self.callback(Sprite.default_link_sprite(), False)
        self.window.destroy()

    def use_random_sprite(self):
        self.callback(
            random.choice(self.all_sprites) if self.all_sprites else None,
            True)
        self.window.destroy()

    def select_sprite(self, spritename):
        self.callback(spritename, False)
        self.window.destroy()

    def deploy_icons(self):
        if not os.path.exists(self.unofficial_sprite_dir):
            os.makedirs(self.unofficial_sprite_dir)
        if not os.path.exists(self.official_sprite_dir):
            shutil.copytree(self.local_official_sprite_dir,
                            self.official_sprite_dir)

    @property
    def official_sprite_dir(self):
        if is_bundled():
            return output_path("sprites/official")
        return self.local_official_sprite_dir

    @property
    def local_official_sprite_dir(self):
        return local_path("data/sprites/official")

    @property
    def unofficial_sprite_dir(self):
        if is_bundled():
            return output_path("sprites/unofficial")
        return self.local_unofficial_sprite_dir

    @property
    def local_unofficial_sprite_dir(self):
        return local_path("data/sprites/unofficial")
Exemplo n.º 15
0
def todays_members():
    m_box.showinfo('Notification','First click on \"Enter Date\"Button \n Then Enter Id')
    def new_sunday():
        def new_sun():
            try:
                global new_table
                new_table='sarathi'+date_entry.get()
                rr = f'create table {new_table} (user_id int primary key,foreign key(user_id) references membersdata(id ))'
                my_cursor.execute(rr)
                m_box.showinfo('Notification','Fresh Sunday',parent=date)
                all_mem()
                date.destroy()
            except NameError:
                todays_mem_root.destroy()
                date.destroy()
                m_box.showerror('Error','Please connect to Database First')
            except:
                res = m_box.askyesnocancel('Confirmation','Is it todays Date?',parent=date)
                if res:
                    all_mem()
                    date.destroy()
        date=Toplevel()
        date.grab_set()
        date.focus()
        date.geometry('490x180+300+300')
        date.resizable(False,False)
        date.config(bg='black')
        theme_name=tk.Label(date,text='Date should be like this:10May2020 ',bg='light green',fg='blue',font=('times new roman',18),
                      width=30,borderwidth=5,anchor='center',relief='groove')
        theme_name.pack()
        
        date_name=tk.Label(date,text='Add Todays Date : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='w',relief='groove')
        date_name.place(x=0,y=50)
        
        date_entry=tk.Entry(date,fg='blue',font=('times new roman',18),
                          width=20,borderwidth=5,relief='groove')
        date_entry.place(x=240,y=50)
        
        submit_date=tk.Button(date,text='Submit',command=new_sun,bg='light green',fg='blue',font=('times new roman',18),
                      width=5,borderwidth=5,anchor='center',relief='groove')
        submit_date.place(x=190,y=110)
    def del_sar():
        try:
            now_del=new_table
            added_mem=add_member_entry_var.get()
            strr = f'delete from {now_del} where user_id = %s'
            my_cursor.execute(strr,(added_mem))
            con.commit()
            all_mems()
            m_box.showinfo('Notification',f'id {added_mem} deleted successfull...',parent=todays_mem_root)
        except:
            m_box.showinfo('Notification','Id Doesnt exist',parent=todays_mem_root)
            
    def add_members():
        try:
            now_insert=new_table
            added_mem=add_member_entry_var.get()
            strr =  f"INSERT INTO  {now_insert} (user_id) VALUES (%s)"
            my_cursor.execute(strr,(added_mem))
            all_mem()
            con.commit()
            add_member_entry_var.set('')
        except NameError:
            m_box.showerror('Notification','Enter Id number',parent=todays_mem_root)
            add_member_entry_var.set('')
            return
        except:
            m_box.showerror('Notification','Already Addded',parent=todays_mem_root)
            add_member_entry_var.set('')

    global all_mem
    def all_mem():
        try:
            now_insert=new_table
            strr =f'select * from membersdata inner join {now_insert} on membersdata.id={now_insert}.user_id '
            my_cursor.execute(strr)
            datas = my_cursor.fetchall()
            members_table.delete(*members_table.get_children())
            for i in datas:
                val = [i[0],i[1],i[2],i[3],i[4],i[5]]
                print(val)
                members_table.insert('', 'end',
                values=(val))
        except:
            pass
    todays_mem_root=Toplevel()
    todays_mem_root.grab_set()
    todays_mem_root.focus()
    todays_mem_root.geometry('795x550+100+100')
    todays_mem_root.resizable(False,False)
    todays_mem_root.config(bg='black')

    frame=tk.Frame(todays_mem_root,bg='gold2',relief='groove',borderwidth=5)
    frame.place(x=0,y=40,width=795,height=460)

    scroll_x=tk.Scrollbar(frame,orient='horizontal')
    scroll_x.pack(side='bottom',fill='x')
    
    scroll_y=tk.Scrollbar(frame,orient='vertical')
    scroll_y.pack(side='right',fill='y')

    members_table=ttk.Treeview(frame,columns=('Id','Name','Mobile No','Address','Gender','D.O.B'),
                              yscrollcommand=scroll_y,xscrollcommand=scroll_x)
    members_table.pack(fill='both',expand=1)
    scroll_x.config(command=members_table.xview)
    scroll_y.config(command=members_table.yview)
    
    style =ttk.Style()
    style.configure('Treeview.Heading',foreground='blue',font=('helvetica',16))
    style.configure('Treeview',foreground='green',font=('times new roman',15),background='cyan',fg='green',bg='red')

    members=tk.Label(todays_mem_root,text=': Todays Sarthians : ',bg='light yellow',fg='red',font=('times new roman',18),
                      width=16,borderwidth=5,anchor='center',relief='groove')
    members.place(x=320,y=0)
    
    add_member=tk.Button(todays_mem_root,text='Add Sarthian : ',command=add_members,bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    add_member.place(x=0,y=500)

    add_member=tk.Button(todays_mem_root,text='Remove Sarthian : ',command=del_sar,bg='light green',fg='blue',font=('times new roman',18),
                      width=14,borderwidth=5,anchor='w',relief='groove')
    add_member.place(x=270,y=500)

    add_member_entry_var=tk.StringVar()
    add_member_entry=tk.Entry(todays_mem_root,textvariable=add_member_entry_var,fg='blue',font=('times new roman',18),
                      width=5,borderwidth=10,relief='groove')
    add_member_entry.place(x=180,y=500)
    add_member_entry.focus()
    
    new_sun=tk.Button(todays_mem_root,text='Enter Date : ',command=new_sunday,bg='light green',fg='blue',font=('times new roman',18),
                      width=10,borderwidth=5,anchor='w',relief='groove')
    new_sun.place(x=650,y=500)
    new_sun=tk.Button(todays_mem_root,text=':Show All : ',command=all_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=8,borderwidth=5,anchor='w',relief='groove')
    new_sun.place(x=500,y=500)

    members_table.heading('Id',text='Id')
    members_table.heading('Name',text='Name')
    members_table.heading('Mobile No',text='Mobile No')
    members_table.heading('Address',text='Address')
    members_table.heading('Gender',text='Gender')
    members_table.heading('D.O.B',text='D.O.B')
    members_table['show']='headings'

    members_table.column('Id',width=50)
    members_table.column('Name',width=300)
    members_table.column('Mobile No',width=140)
    members_table.column('Address',width=260)
    members_table.column('Gender',width=100)
    members_table.column('D.O.B',width=100)

    todays_mem_root.mainloop()
Exemplo n.º 16
0
def update():
    def updated():
        id=id_var.get()
        name=name_var.get()
        dob=dob_var.get()
        mob=mob_var.get()
        gender=gender_var.get()
        address=address_var.get()
        try:
            strr='update membersdata set name =%s ,dob=%s,mobile=%s,gender=%s,address=%s where id =%s'
            my_cursor.execute(strr,(name,dob,mob,gender,address,id))
            con.commit()
            res = m_box.askyesnocancel('Notification',f'Updated Successfully! \n Do you want to exit')
            if res:update_root.destroy()
        except NameError:
            m_box.showerror('Error','Please connect to Database First')
    enter_id_root.destroy()
    global update_root
    update_root=Toplevel()
    update_root.grab_set()
    update_root.focus()
    update_root.geometry('400x350+300+300')
    update_root.config(bg='firebrick1')
    id_label=tk.Label(update_root,text='Update Id : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    id_label.place(x=10,y=10)

    name_label=tk.Label(update_root,text='Update Name : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    name_label.place(x=10,y=60)

    dob_label=tk.Label(update_root,text='Update DOB : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    dob_label.place(x=10,y=110)

    gender_label=tk.Label(update_root,text='Select Gender : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    gender_label.place(x=10,y=160)

    mob_label=tk.Label(update_root,text='Update Mobile : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    mob_label.place(x=10,y=210)
    address_label=tk.Label(update_root,text='Update Address : ',bg='light green',fg='blue',font=('times new roman',18),
                  width=12,borderwidth=3,anchor='w',relief='groove')
    address_label.place(x=10,y=260)

    id_var=tk.StringVar()   
    name_var=tk.StringVar()
    dob_var=tk.StringVar()
    mob_var=tk.StringVar()
    address_var=tk.StringVar()

    id_entry=tk.Entry(update_root,fg='blue',textvariable=id_var,font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    id_entry.place(x=190,y=10)
    id_entry.focus()

    name_entry=tk.Entry(update_root,textvariable=name_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    name_entry.place(x=190,y=60)

    dob_entry=tk.Entry(update_root,textvariable=dob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    dob_entry.place(x=190,y=110)

    gender_var=tk.StringVar()
    gender_combobox=ttk.Combobox(update_root,width=15,font=('times new roman',18),textvariable=gender_var,state='readonly')
    gender_combobox['values']=('Male','Female','Other')
    gender_combobox.current(0)
    gender_combobox.place(x=190,y=160)

    mob_entry=tk.Entry(update_root,textvariable=mob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    mob_entry.place(x=190,y=210)
    address_entry=tk.Entry(update_root,textvariable=address_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    address_entry.place(x=190,y=260)

    submit_btn=tk.Button(update_root,width=6,text='Update',command=updated,bg='light green',fg='blue',
                        activebackground='gold2',activeforeground='blue',font=('times new roman',18))
    submit_btn.place(x=140,y=305)
    
    v=enter_id_var.get()
    try:
        strr =f'select * from membersdata where id = %s'
        my_cursor.execute(strr,v)
        d = my_cursor.fetchall()
        id_var.set(d[0][0])
        name_var.set(d[0][1])
        address_var.set(d[0][3])
        dob_var.set(d[0][5])
        gender_var.set(d[0][4])
        mob_var.set(d[0][2])
    except NameError:
        update_root.destroy()
        m_box.showerror('Error','Please connect to Database First')
    update_root.mainloop()
Exemplo n.º 17
0
    def search ():
        id=id_var.get()
        name=name_var.get()
        dob=dob_var.get()
        mob=mob_var.get()
        gender=gender_var.get()
        if id !=( ''):
            search_by='id'
            m=id
        if name != (''):
            search_by='name'
            m=name
        if dob != '':
            search_by='dob'
            m=dob
        if mob != '':
            search_by='mobile'
            m=mob
        if gender != '':
            search_by='gender'
            m=gender
            
        show_root=Toplevel()
        show_root.grab_set()
        show_root.focus()
        show_root.geometry('795x500+100+150')
        show_root.resizable(False,False)
        show_root.config(bg='firebrick1')
        frame=tk.Frame(show_root,bg='gold2',relief='groove',borderwidth=5)
        frame.place(x=0,y=0,width=795,height=500)

        scroll_x=tk.Scrollbar(frame,orient='horizontal')
        scroll_x.pack(side='bottom',fill='x')
        
        scroll_y=tk.Scrollbar(frame,orient='vertical')
        scroll_y.pack(side='right',fill='y')

        members_table=ttk.Treeview(frame,columns=('Id','Name','Mobile No','Address','Gender','D.O.B'),
                                  yscrollcommand=scroll_y,xscrollcommand=scroll_x)

        members_table.pack(fill='both',expand=1)
        scroll_x.config(command=members_table.xview)
        scroll_y.config(command=members_table.yview)
        
        style =ttk.Style()
        style.configure('Treeview.Heading',foreground='blue',font=('helvetica',16))
        style.configure('Treeview',foreground='green',font=('times new roman',15),background='cyan',fg='green')

        members_table.heading('Id',text='Id')
        members_table.heading('Name',text='Name')
        members_table.heading('Mobile No',text='Mobile No')
        members_table.heading('Address',text='Address')
        members_table.heading('Gender',text='Gender')
        members_table.heading('D.O.B',text='D.O.B')
        members_table['show']='headings'
        
        members_table.column('Id',width=50)
        members_table.column('Name',width=300)
        members_table.column('Mobile No',width=140)
        members_table.column('Address',width=260)
        members_table.column('Gender',width=100)
        members_table.column('D.O.B',width=110)
        try:
            strr =f'select * from membersdata where {search_by} = %s'
            my_cursor.execute(strr,m)
            datas = my_cursor.fetchall()
            members_table.delete(*members_table.get_children())
            for i in datas:
                val = [i[0],i[1],i[2],i[3],i[4],i[5]]
                members_table.insert('', 'end',
                     values=(val))
        except  UnboundLocalError:
            search_root.destroy()
            m_box.showerror('Error','Please Connect to Database First',parent=show_root)
            show_root.destroy()
        show_root.mainloop()
Exemplo n.º 18
0
def search_sarathian():
    def search ():
        id=id_var.get()
        name=name_var.get()
        dob=dob_var.get()
        mob=mob_var.get()
        gender=gender_var.get()
        if id !=( ''):
            search_by='id'
            m=id
        if name != (''):
            search_by='name'
            m=name
        if dob != '':
            search_by='dob'
            m=dob
        if mob != '':
            search_by='mobile'
            m=mob
        if gender != '':
            search_by='gender'
            m=gender
            
        show_root=Toplevel()
        show_root.grab_set()
        show_root.focus()
        show_root.geometry('795x500+100+150')
        show_root.resizable(False,False)
        show_root.config(bg='firebrick1')
        frame=tk.Frame(show_root,bg='gold2',relief='groove',borderwidth=5)
        frame.place(x=0,y=0,width=795,height=500)

        scroll_x=tk.Scrollbar(frame,orient='horizontal')
        scroll_x.pack(side='bottom',fill='x')
        
        scroll_y=tk.Scrollbar(frame,orient='vertical')
        scroll_y.pack(side='right',fill='y')

        members_table=ttk.Treeview(frame,columns=('Id','Name','Mobile No','Address','Gender','D.O.B'),
                                  yscrollcommand=scroll_y,xscrollcommand=scroll_x)

        members_table.pack(fill='both',expand=1)
        scroll_x.config(command=members_table.xview)
        scroll_y.config(command=members_table.yview)
        
        style =ttk.Style()
        style.configure('Treeview.Heading',foreground='blue',font=('helvetica',16))
        style.configure('Treeview',foreground='green',font=('times new roman',15),background='cyan',fg='green')

        members_table.heading('Id',text='Id')
        members_table.heading('Name',text='Name')
        members_table.heading('Mobile No',text='Mobile No')
        members_table.heading('Address',text='Address')
        members_table.heading('Gender',text='Gender')
        members_table.heading('D.O.B',text='D.O.B')
        members_table['show']='headings'
        
        members_table.column('Id',width=50)
        members_table.column('Name',width=300)
        members_table.column('Mobile No',width=140)
        members_table.column('Address',width=260)
        members_table.column('Gender',width=100)
        members_table.column('D.O.B',width=110)
        try:
            strr =f'select * from membersdata where {search_by} = %s'
            my_cursor.execute(strr,m)
            datas = my_cursor.fetchall()
            members_table.delete(*members_table.get_children())
            for i in datas:
                val = [i[0],i[1],i[2],i[3],i[4],i[5]]
                members_table.insert('', 'end',
                     values=(val))
        except  UnboundLocalError:
            search_root.destroy()
            m_box.showerror('Error','Please Connect to Database First',parent=show_root)
            show_root.destroy()
        show_root.mainloop()
        
    
    entry_box=tk.Button(win,width=15,text='All Members',command=show_all,bg='light green',
                        activebackground='yellow',activeforeground='red',fg='blue',font=('times new roman',15))
    entry_box.place(x=0,y=400)
    
    search_root=Toplevel()
    search_root.grab_set()
    search_root.focus()
    search_root.geometry('400x310+300+300')
    search_root.config(bg='red')
    id_label=tk.Label(search_root,text='Enter Id : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    id_label.place(x=10,y=10)

    name_label=tk.Label(search_root,text='Enter Name : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    name_label.place(x=10,y=60)

    dob_label=tk.Label(search_root,text='Enter DOB : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    dob_label.place(x=10,y=110)

    gender_label=tk.Label(search_root,text='Select Gender : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    gender_label.place(x=10,y=160)

    mob_label=tk.Label(search_root,text='Enter Mobile : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    mob_label.place(x=10,y=210)

    id_var=tk.StringVar()   
    name_var=tk.StringVar()
    dob_var=tk.StringVar()
    mob_var=tk.StringVar()
    id_entry=tk.Entry(search_root,fg='blue',textvariable=id_var,font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    id_entry.place(x=190,y=10)
    id_entry.focus()

    name_entry=tk.Entry(search_root,textvariable=name_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    name_entry.place(x=190,y=60)

    dob_entry=tk.Entry(search_root,textvariable=dob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    dob_entry.place(x=190,y=110)

    gender_var=tk.StringVar()
    gender_combobox=ttk.Combobox(search_root,width=15,font=('times new roman',18),textvariable=gender_var,state='readonly')
    gender_combobox['values']=('Male','Female','Other',"")
    gender_combobox.place(x=190,y=160)

    mob_entry=tk.Entry(search_root,textvariable=mob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    mob_entry.place(x=190,y=210)

    submit_btn=tk.Button(search_root,width=6,text='Search',command=search,bg='light green',fg='blue',
                        activebackground='gold2',activeforeground='blue',font=('times new roman',18))
    submit_btn.place(x=140,y=260)
    
    search_root.mainloop()
Exemplo n.º 19
0
def add_sarathian():
    def add():
        id=id_var.get()
        name=name_var.get()
        dob=dob_var.get()
        mob=mob_var.get()
        gender=gender_var.get()
        address=address_var.get()
        try:
            strr =  "INSERT INTO membersdata (id,name, mobile ,address,gender,dob) VALUES (%s, %s,%s, %s,%s, %s)"
            my_cursor.execute(strr,(id,name, mob ,address,gender,dob))
            con.commit()
            res = m_box.askyesnocancel('Notification',f'Id {id} Name "\ {name} "\ Added successfully . and want to clean the form',parent=add_root)
            if res:
                id_var.set('')
                name_var.set('')
                dob_var.set('')
                mob_var.set('')
                address_var.set('')
        except NameError:
            m_box.showerror('Notification','Please connect to database',parent=add_root)
            add_root.destroy()
        except:
            m_box.showerror('Notification','Id already Exist try another one',parent=add_root)
    add_root=Toplevel()
    add_root.grab_set()
    add_root.focus()
    add_root.title('Add New Sarathian')
    add_root.geometry('400x350+300+300')
    add_root.config(bg='gold2')
    id_label=tk.Label(add_root,text='Enter Id : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    id_label.place(x=10,y=10)

    name_label=tk.Label(add_root,text='Enter Name : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    name_label.place(x=10,y=60)

    dob_label=tk.Label(add_root,text='Enter DOB : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    dob_label.place(x=10,y=110)

    gender_label=tk.Label(add_root,text='Select Gender : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    gender_label.place(x=10,y=160)

    mob_label=tk.Label(add_root,text='Enter Mobile : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    mob_label.place(x=10,y=210)

    address_label=tk.Label(add_root,text='Enter Address : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=3,anchor='w',relief='groove')
    address_label.place(x=10,y=260)

    id_var=tk.StringVar()   
    name_var=tk.StringVar()
    dob_var=tk.StringVar()
    mob_var=tk.StringVar()
    address_var=tk.StringVar()
    id_entry=tk.Entry(add_root,fg='blue',textvariable=id_var,font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    id_entry.place(x=190,y=10)
    id_entry.focus()

    name_entry=tk.Entry(add_root,textvariable=name_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    name_entry.place(x=190,y=60)

    dob_entry=tk.Entry(add_root,textvariable=dob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    dob_entry.place(x=190,y=110)

    gender_var=tk.StringVar()
    gender_combobox=ttk.Combobox(add_root,width=15,font=('times new roman',18),textvariable=gender_var,state='readonly')
    gender_combobox['values']=('Male','Female','Other')
    gender_combobox.current(0)
    gender_combobox.place(x=190,y=160)

    mob_entry=tk.Entry(add_root,textvariable=mob_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    mob_entry.place(x=190,y=210)
    
    adress_entry=tk.Entry(add_root,textvariable=address_var,fg='blue',font=('times new roman',18),
                      width=16,borderwidth=5,relief='groove')
    adress_entry.place(x=190,y=260)

    submit_btn=tk.Button(add_root,width=6,text='Submit',command=add,bg='light green',fg='blue',
                        activebackground='gold2',activeforeground='blue',font=('times new roman',18))
    submit_btn.place(x=140,y=305)

    add_root.mainloop()
Exemplo n.º 20
0
def connectdb():
    def submitdb():
        global con,my_cursor
        host = host_var.get()
        user = user_var.get()
        password = password_var.get()
        try:
            con = pymysql.connect(host=host ,user=user,password=password)
            my_cursor = con.cursor()
            m_box.showinfo("Notification",'successfully connected')
            dbroot.destroy()
        except:
            m_box.showerror("Notification",'Data is incorrect please try again',parent=dbroot)
            return

        try:
            strr = 'create database sarathimanagementsystem'
            my_cursor.execute(strr)
            strr = 'use sarathimanagementsystem'
            my_cursor.execute(strr)
            strr = 'create table membersdata (id int ,name varchar(30),mobile varchar(12),address varchar(100),gender varchar(10),dob varchar(20))'
            my_cursor.execute(strr)
            strr = 'alter table membersdata modify column id int not null'
            my_cursor.execute(strr)
            strr = 'alter table membersdata modify column id int primary key'
            my_cursor.execute(strr)
        except:
            strr ='use sarathimanagementsystem'
            my_cursor.execute(strr)
    dbroot =Toplevel()
    dbroot.grab_set()
    dbroot.geometry('400x205+320+180')
    dbroot.focus()
    dbroot.resizable(False,False)
    dbroot.config(bg='blue')

    host_label=tk.Label(dbroot,text='Enter Host : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    host_label.place(x=10,y=10)

    user_label=tk.Label(dbroot,text='Enter User : '******'light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    user_label.place(x=10,y=60)

    password_label=tk.Label(dbroot,text='Enter Password : '******'light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    password_label.place(x=10,y=110)

    host_var=tk.StringVar()
    user_var=tk.StringVar()
    password_var=tk.StringVar()
    
    host_entry=tk.Entry(dbroot,textvariable=host_var,fg='blue',font=('times new roman',18),
                      width=14,borderwidth=5,relief='groove')
    host_entry.place(x=200,y=10)
    host_entry.focus()

    user_entry=tk.Entry(dbroot,textvariable=user_var,fg='blue',font=('times new roman',18),
                      width=14,borderwidth=5,relief='groove')
    user_entry.place(x=200,y=60)

    password_entry=tk.Entry(dbroot,textvariable=password_var,fg='blue',font=('times new roman',18),
                      width=14,borderwidth=5,relief='groove')
    password_entry.place(x=200,y=110)

    submit_btn=tk.Button(dbroot,width=5,text='Submit',command=submitdb,bg='light green',fg='blue',
                        activebackground='gold2',activeforeground='blue',font=('times new roman',18))
    submit_btn.place(x=144,y=155)

    dbroot.mainloop()
Exemplo n.º 21
0
class Search(Module):
    def __init__(self, app):
        self.app = app
        self.window = None

        self.context_size = 3
        self.results = []
        self.regex = StringVar(self.app)

        # if anything ever changes the contents of any intervals
        # it should call SearchModule.loadIntervals()
        self.intervals = []
        self.loadIntervals()

    def handleClose(self, event=None):
        self.window.destroy()
        self.window = None

    def createWindow(self):
        self.window = Toplevel(self.app)
        self.window.title('Search')
        self.window.protocol("WM_DELETE_WINDOW", self.handleClose)
        self.input = Entry(self.window, textvariable=self.regex)
        self.input.grid(row=0, column=0)
        self.input.bind('<Return>', self.search)
        self.input.bind('<Escape>', lambda ev: self.window.focus())
        self.searchButton = Button(self.window,
                                   text='Search',
                                   command=self.search,
                                   takefocus=0)
        self.searchButton.grid(row=0, column=1)
        self.resultCount = Label(self.window, text='0 results')
        self.resultCount.grid(row=0, column=2)
        cols = ('File', 'Tier', 'Time', 'Text')
        self.scroll = Scrollbar(self.window, orient='vertical')
        self.resultList = Treeview(self.window,
                                   columns=cols,
                                   show="headings",
                                   yscrollcommand=self.scroll.set,
                                   selectmode='browse')
        self.scroll.config(command=self.resultList.yview)
        for col in cols:
            self.resultList.heading(col, text=col)
        self.resultList.grid(row=2, column=0, columnspan=3, sticky='news')
        self.resultList.bind('<Double-1>', self.onClick)
        Grid.rowconfigure(self.window, 2, weight=1)
        Grid.columnconfigure(self.window, 0, weight=1)
        self.scroll.grid(row=2, column=3, sticky='ns')

    def openSearch(self):
        if self.window == None:
            self.createWindow()
        self.window.lift()
        self.input.focus()

    def loadIntervals(self):
        filecount = len(self.app.Data.getTopLevel('files'))
        self.intervals = []
        for f in range(filecount):
            filename = self.app.Data.getFileLevel('name', f)
            tg = self.app.Data.checkFileLevel('.TextGrid',
                                              f,
                                              shoulderror=False)
            if tg:
                grid = self.app.TextGrid.fromFile(tg)
                for tier in grid:
                    if TextGrid.isIntervalTier(tier):
                        for el in tier:
                            if el.mark:
                                self.intervals.append(
                                    (el, tier.name, filename))

    def search(self, event=None):
        if self.regex.get() == '':
            self.results = []
        else:
            pat = re.compile(self.regex.get(),
                             re.IGNORECASE | re.MULTILINE | re.DOTALL)
            self.results = []
            for i in self.intervals:
                s = pat.search(i[0].mark)
                if s:
                    disp = i[0].mark
                    a = max(0, s.start() - self.context_size)
                    b = min(s.end() + self.context_size, len(disp))
                    self.results.append(i +
                                        (('...' if a > 0 else '') + disp[a:b] +
                                         ('...' if b < len(disp) else ''), ))
        self.resultCount.configure(text='%s results' % len(self.results))
        for kid in self.resultList.get_children():
            self.resultList.delete(kid)
        for row, res in enumerate(self.results):
            ls = (res[2], res[1], '%s-%s' % (res[0].minTime, res[0].maxTime),
                  res[3])
            self.resultList.insert('', 'end', iid=str(row), values=ls)

    def onClick(self, event=None):
        self.jumpTo(int(self.resultList.selection()[0]))

    def jumpTo(self, index):
        self.app.filesJumpTo(self.results[index][2])
        self.app.TextGrid.selectedTier.set(self.results[index][1])
        self.app.TextGrid.start = self.results[index][0].minTime
        self.app.TextGrid.end = self.results[index][0].maxTime
        for i, f in enumerate(self.app.TextGrid.frameTier):
            if f.time >= self.results[index][0].minTime:
                self.app.frameSV.set(str(i))
                self.app.framesJumpTo()
                break
        self.app.TextGrid.fillCanvases()

    def reset(self, *args, **kwargs):
        raise NotImplementedError('cannot call SearchModule::reset')

    def update(self, *args, **kwargs):
        raise NotImplementedError('cannot call SearchModule::update')

    def grid(self, *args, **kwargs):
        raise NotImplementedError('cannot call SearchModule::grid')

    def grid_remove(self, *args, **kwargs):
        raise NotImplementedError('cannot call SearchModule::grid_remove')
def guess(*event):
    global nm
    try:
        if num == entry_num_var.get():
            PlaySound('nice-work.wav', SND_FILENAME)
            won = Toplevel()
            won.title('Congratulation !')
            won.geometry('+310+250')
            won.resizable(False, False)
            won.grab_set()
            won.focus()
            again()
            entry_num.delete(0, tk.END)
            sorry_label = tk.Label(won,
                                   text='Amazing you won !' + '\n' +
                                   f'You guessed number in {nm} times',
                                   font=('times new roman', 20),
                                   fg='red',
                                   bg='gold2')
            sorry_label.grid(row=0, columnspan=5)
            nm = 1
            entry_num.delete(0, tk.END)
            gues_again = tk.Button(won,
                                   text='Guess Again',
                                   command=won.destroy,
                                   font=('helvetica', 15),
                                   width=12,
                                   bg='light green',
                                   fg='blue')
            gues_again.grid(row=3, column=2)

        else:
            if 100 < entry_num_var.get():
                MessageBeep(type=10)
                nm += 1
                msg = 'Enter number beween 1-100'
            elif (num - entry_num_var.get()) <= 5 and (
                    num - entry_num_var.get()) >= 0:
                MessageBeep(type=10)
                nm += 1
                msg = "You are close to this !" + '\n' + 'Increase Your Number '
            elif abs(num - entry_num_var.get()) <= 5:
                MessageBeep(type=10)
                nm += 1
                msg = "You are close to this !" + '\n' + 'Decrease Your Number '
            elif (num - entry_num_var.get()) <= 10 and (
                    num - entry_num_var.get()) >= 0:
                MessageBeep(type=10)
                nm += 1
                msg = "Sorry number is low !" + '\n' + 'Increase Your Number '
            elif abs(num - entry_num_var.get()) <= 10 and (
                    num - entry_num_var.get()) >= 0:
                MessageBeep(type=10)
                nm += 1
                msg = "Sorry number is high !" + '\n' + 'Increase Your Number '
            elif num < entry_num_var.get():
                MessageBeep(type=10)
                msg = 'Sorry number is too high !'
                nm += 1
            else:
                MessageBeep(type=0)
                nm += 1
                msg = 'Sorry number is too low !'
            won = Toplevel()
            won.grab_set()
            won.focus()
            won.title('OOP\'s !')
            won.geometry('+350+250')
            won.config(bg='gold2')
            won.resizable(False, False)
            sorry_label = tk.Label(won,
                                   text=msg,
                                   font=('times new roman', 20),
                                   fg='red',
                                   bg='light yellow',
                                   anchor='center')
            sorry_label.pack()
            guess_again = tk.Button(won,
                                    text='Guess Again',
                                    command=won.destroy,
                                    font=('helvetica', 15),
                                    width=12,
                                    bg='light green',
                                    fg='blue')
            guess_again.pack(pady=20)
            guess_again.focus()
            entry_num.delete(0, tk.END)
    except:
        m_box.showerror('Wrong Input', 'Type only numbers !')
        entry_num.delete(0, tk.END)
Exemplo n.º 23
0
def body_members():
    m_box.showinfo('Notification','First click on \"Enter Body\"Button')
    def new_body_mem():
        def new_mem():
            try:
                global new_body_db
                new_body_db='ExecutiveBody'+exe_entry.get()
                rr = f'create table {new_body_db} (body_id int primary key,foreign key(body_id) references membersdata(id ),mem_post varchar(50))'
                my_cursor.execute(rr)
                m_box.showinfo('Notification','Fresh Executive Body',parent=ex)
                all_mems()
                ex.destroy()
            except NameError:
                m_box.showerror('Error','Please connect to Database First',parent=ex)
                ex.destroy()
                Exe_body_root.destroy()
            except:
                res = m_box.askyesnocancel('Confirmation',f'Is it {exe_entry.get()} Executive body?',parent=ex)
                if res:
                    all_mems()
                    ex.destroy()

        ex=Toplevel()
        ex.grab_set()
        ex.title('Executive Body')
        ex.focus()
        ex.geometry('490x180+300+300')
        ex.resizable(False,False)
        ex.config(bg='black')
        
        exe_label=tk.Label(ex,text='Add Executive Body Number Below',bg='light green',fg='blue',font=('times new roman',18),
                      width=40,borderwidth=5,anchor='center',relief='groove')
        exe_label.place(x=0,y=0)
        
        exe_entry=tk.Entry(ex,fg='blue',font=('times new roman',18),
                          width=6,borderwidth=5,relief='groove')
        exe_entry.place(x=190,y=60)
        exe_entry.focus()
        submit_exe=tk.Button(ex,text='Submit',command=new_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=5,borderwidth=5,anchor='center',relief='groove')
        submit_exe.place(x=190,y=110)

    def add_body_members():
        def del_body_mem():
            try:
                now_del=new_body_db
                added_mem_id=exe_id_entry_var.get()
                strr = f'delete from {now_del} where body_id = %s'
                my_cursor.execute(strr,(added_mem_id))
                con.commit()
                all_mems()
                m_box.showinfo('Notification',f'id {added_mem_id} deleted successfull...',parent=exe)
                exe_id_entry_var.set('')
            except NameError:
                m_box.showerror('Error','Please connect to Database First',parent=exe)
                Exe_body_root.destroy()
                exe.destroy()
            except:
                m_box.showinfo('Notification','Id Doesnt exist',parent=exe)
                exe_id_entry_var.set('')
                
        def all_mem():
            try:
                now_insert=new_body_db
                added_mem_id=exe_id_entry_var.get()
                added_mem_post=mem_post_entry_var.get()
                strr =  f"INSERT INTO  {now_insert} (body_id,mem_post) VALUES (%s,%s)"
                my_cursor.execute(strr,(added_mem_id,added_mem_post))
                con.commit()
                m_box.showinfo('Notification','Added Successfull',parent=exe)
                all_mems()
                exe_id_entry_var.set('')
                mem_post_entry_var.set('')
            except NameError:
                m_box.showerror('Error','First enter Body Number Into \n Enter Body',parent=exe)
                exe.destroy()
            except NameError:
                m_box.showerror('Notification','Enter Id number',parent=exe)
                return
            except pymysql.err.IntegrityError:
                m_box.showerror('New Sarathian','First add into Add Sarthian ',parent=exe)
            except:
                m_box.showerror('Notification','Already Addded',parent=exe)
                exe_id_entry_var.set('')
                mem_post_entry_var.set('')

        exe=Toplevel()
        exe.grab_set()
        exe.title('Add Or Delete')
        exe.focus()
        exe.geometry('490x180+300+300')
        exe.resizable(False,False)
        exe.config(bg='black')

        exe_id_entry_var=tk.StringVar()
        mem_post_entry_var=tk.StringVar()
        exe_id_label=tk.Label(exe,text='Add Member Id :',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='center',relief='groove')
        exe_id_label.place(x=0,y=0)
        

        exe_id_entry=tk.Entry(exe,fg='blue',textvariable=exe_id_entry_var,font=('times new roman',18),
                          width=20,borderwidth=5,relief='groove')
        exe_id_entry.place(x=240,y=0)
        exe_id_entry.focus()

        
        mem_post=tk.Label(exe,text='Add Member Post : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='w',relief='groove')
        mem_post.place(x=0,y=50)
        
        mem_post_entry=tk.Entry(exe,fg='blue',textvariable=mem_post_entry_var,font=('times new roman',18),
                          width=20,borderwidth=5,relief='groove')
        mem_post_entry.place(x=240,y=50)
        
        del_exe=tk.Button(exe,text='Delete Member',command=del_body_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='center',relief='groove')
        del_exe.place(x=300,y=110)
        
        
        submit_exe=tk.Button(exe,text='Submit',command=all_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=5,borderwidth=5,anchor='center',relief='groove')
        submit_exe.place(x=190,y=110)
            
    global all_mems
    def all_mems():
        try:
            now_insert=new_body_db
            strr =f'select * from membersdata inner join {now_insert} on membersdata.id={now_insert}.body_id '
            my_cursor.execute(strr)
            datas = my_cursor.fetchall()
            members_table.delete(*members_table.get_children())
            for i in datas:
                val = [i[0],i[1],i[7],i[2],i[3],i[4],i[5]]
                members_table.insert('', 'end',
                values=(val))
        except:
            pass
    
    Exe_body_root=Toplevel()
    Exe_body_root.grab_set()
    Exe_body_root.title('Executive Body Members')
    Exe_body_root.focus()
    Exe_body_root.geometry('795x550+100+100')
    Exe_body_root.resizable(False,False)
    Exe_body_root.config(bg='black')

    frame=tk.Frame(Exe_body_root,bg='gold2',relief='groove',borderwidth=5)
    frame.place(x=0,y=40,width=795,height=460)

    scroll_x=tk.Scrollbar(frame,orient='horizontal')
    scroll_x.pack(side='bottom',fill='x')
    
    scroll_y=tk.Scrollbar(frame,orient='vertical')
    scroll_y.pack(side='right',fill='y')

    members_table=ttk.Treeview(frame,columns=('Id','Name','Member Post','Mobile','Address','Gender','D.O.B'),
                              yscrollcommand=scroll_y,xscrollcommand=scroll_x)
    members_table.pack(fill='both',expand=1)
    
    scroll_x.config(command=members_table.xview)
    scroll_y.config(command=members_table.yview)
    
    style =ttk.Style()
    style.configure('Treeview.Heading',foreground='blue',font=('helvetica',16))
    style.configure('Treeview',foreground='green',font=('times new roman',15),background='cyan',fg='green',bg='red')

    members=tk.Label(Exe_body_root,text=': Executive Body Members : ',bg='light yellow',fg='red',font=('times new roman',18),
                      width=20,borderwidth=5,anchor='center',relief='groove')
    members.place(x=280,y=0)
    
    add_member=tk.Button(Exe_body_root,text='Add Member : ',command=add_body_members,fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='w',relief='groove')
    add_member.place(x=0,y=500)

    new_sun=tk.Button(Exe_body_root,text='Enter Body: ',command=new_body_mem,fg='blue',font=('times new roman',18),
                      width=10,borderwidth=5,anchor='w',relief='groove')
    new_sun.place(x=650,y=500)
    new_sun=tk.Button(Exe_body_root,text=':Show All : ',command=all_mems,fg='blue',font=('times new roman',18),
                      width=8,borderwidth=5,anchor='w',relief='groove')
    new_sun.place(x=400,y=500)

    members_table.heading('Id',text='Id')
    members_table.heading('Name',text='Name')
    members_table.heading('Member Post',text='Member Post')
    members_table.heading('Mobile',text='Mobile No')
    members_table.heading('Address',text='Address')
    members_table.heading('Gender',text='Gender')
    members_table.heading('D.O.B',text='D.O.B')
    members_table['show']='headings'

    members_table.column('Id',width=50)
    members_table.column('Name',width=260)
    members_table.column('Member Post',width=150)
    members_table.column('Mobile',width=140)
    members_table.column('Address',width=260)
    members_table.column('Gender',width=100)
    members_table.column('D.O.B',width=100)
    
    Exe_body_root.mainloop()
class SpeciesSearchDialog:
    def __init__(self, parent, caller):
        # main window
        self.parent = parent
        # dialog that called this second dialog
        self.caller = caller
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()

        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(1, weight=1)

        self.entrySearch = Entry(self.gui)

        self.buttonSearch = Button(self.gui, text=" Search ")
        self.buttonAdd = Button(self.gui, text=" Add Species ")
        self.buttonClose = Button(self.gui, text=" Close Window ")

        self.frameResults = Frame(self.gui)
        self.frameResults.columnconfigure(0, weight=1)
        self.frameResults.rowconfigure(0, weight=1)
        self.scrollResults = Scrollbar(self.frameResults, orient="vertical")
        self.scrollResults.grid(row=0, column=1, sticky="ns")
        self.listResults = Listbox(self.frameResults, width=70, height=20)
        self.listResults.grid(row=0, column=0, sticky="nswe")

        self.listResults.config(yscrollcommand=self.scrollResults.set)
        self.scrollResults.config(command=self.listResults.yview)

        self.entrySearch.grid(row=0, column=0, columnspan=2, sticky="we", padx=5, pady=5)
        self.frameResults.grid(row=1, column=0, columnspan=3, sticky="nswe", padx=5, pady=5)
        self.buttonSearch.grid(row=0, column=2, padx=5, pady=5, sticky="e")
        self.buttonAdd.grid(row=2, column=1, padx=5, pady=5, sticky="e")
        self.buttonClose.grid(row=2, column=2, padx=5, pady=5, sticky="e")

        self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)
        self.buttonClose.bind("<ButtonRelease>", self.actionClose)
        self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
        self.buttonSearch.bind("<ButtonRelease>", self.actionSearch)
        self.entrySearch.bind("<Return>", self.actionSearch)

        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())

        self.gui.mainloop()

    def actionAdd(self, event):
        try:
            selection = self.listResults.selection_get()
            selectionSplit = selection.split(":\t", 1)
            selectionSplit2 = selectionSplit[1].split("\t")
            if not (selectionSplit[0], selectionSplit2[0]) in self.parent.optimizer.speciesList:
                self.parent.optimizer.speciesList.append((selectionSplit[0], selectionSplit2[0].strip()))
            self.caller.gui.event_generate("<<Update>>")
        except tkinter.TclError:
            # no selection
            pass

    def actionSearch(self, event):
        query = self.entrySearch.get()
        if query:

            self.listResults.delete(0, "end")

            results = self.parent.optimizer.SPSUMHandler.search(query)
            # sort results by nr of CDS
            results = sorted(results.items(), reverse=True, key=lambda x: (int(x[1][1])))
            for name, (taxid, ncs) in results:
                self.listResults.insert("end", taxid + ":\t " + name + " \t(" + ncs + " CDS)")

    def actionClose(self, event=None):
        self.caller.gui.event_generate("<<Update>>", when="tail")
        self.gui.destroy()
Exemplo n.º 25
0
class SpeciesSearchDialog():
    
    def __init__(self, parent, caller):
        # main window
        self.parent=parent
        # dialog that called this second dialog
        self.caller=caller
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()
        
        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(1, weight=1)
        
        self.entrySearch = Entry(self.gui)
        
        self.buttonSearch = Button(self.gui, text=" Search ")
        self.buttonAdd = Button(self.gui, text=" Add Species ")
        self.buttonClose = Button(self.gui, text=" Close Window ")
        
        self.frameResults = Frame(self.gui)
        self.frameResults.columnconfigure(0, weight=1)
        self.frameResults.rowconfigure(0, weight=1)
        self.scrollResults = Scrollbar(self.frameResults, orient="vertical")
        self.scrollResults.grid(row=0, column=1, sticky="ns")
        self.listResults = Listbox(self.frameResults, width=70, height=20)
        self.listResults.grid(row=0, column=0, sticky="nswe")
        
        self.listResults.config(yscrollcommand=self.scrollResults.set)
        self.scrollResults.config(command=self.listResults.yview)
        
        
        self.entrySearch.grid(row=0, column=0, columnspan=2, sticky="we", padx=5, pady=5)
        self.frameResults.grid(row=1, column=0, columnspan=3, sticky="nswe", padx=5, pady=5)
        self.buttonSearch.grid(row=0, column=2, padx=5, pady=5, sticky="e")
        self.buttonAdd.grid(row=2, column=1, padx=5, pady=5, sticky="e")
        self.buttonClose.grid(row=2, column=2, padx=5, pady=5, sticky="e")
        
        self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)        
        self.buttonClose.bind("<ButtonRelease>", self.actionClose)
        self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)
        self.buttonSearch.bind("<ButtonRelease>", self.actionSearch)
        self.entrySearch.bind("<Return>", self.actionSearch)
        
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
        
        self.gui.mainloop()
        
    def actionAdd(self, event):
        try:
            selection = self.listResults.selection_get()
            selectionSplit = selection.split(":\t", 1)
            selectionSplit2 = selectionSplit[1].split("\t")
            if not (selectionSplit[0], selectionSplit2[0]) in self.parent.optimizer.speciesList:   
                self.parent.optimizer.speciesList.append((selectionSplit[0], selectionSplit2[0].strip()))
            self.caller.gui.event_generate("<<Update>>")
        except tkinter.TclError :
            # no selection
            pass
    
    def actionSearch(self, event):
        query = self.entrySearch.get()
        if(query):
            
            self.listResults.delete(0, "end")
            
            results = self.parent.optimizer.SPSUMHandler.search(query)
            # sort results by nr of CDS
            results = sorted(results.items(), reverse=True, key=lambda x: (int(x[1][1])))
            for name, (taxid, ncs) in results:
                self.listResults.insert("end", taxid + ":\t " + name + " \t(" + ncs + " CDS)")
        
    def actionClose(self, event=None):
        self.caller.gui.event_generate("<<Update>>", when="tail")
        self.gui.destroy()
Exemplo n.º 26
0
class SubMenu:

    def __init__(self, loader, name, w, h, checker, addElements, maxNum):
        self.__loader = loader
        self.__loader.subMenus.append(self)
        self.__loader.subMenuDict[name] = self
        self.__name = name

        if len(self.__loader.subMenus)>maxNum:
            from threading import Thread
            t = Thread(target=self.killOther)
            t.daemon = True
            t.start()

        self.stopThread = False
        self.__loader.stopThreads.append(self)

        self.__config = self.__loader.config
        self.__dictionaries = self.__loader.dictionaries
        self.__screenSize = self.__loader.screenSize

        self.__topLevel = Toplevel()
        self.__topLevel.title(self.__dictionaries.getWordFromCurrentLanguage(name))
        self.__topLevel.geometry("%dx%d+%d+%d" % (w, h, (self.__screenSize[0]/2-w/2), (self.__screenSize[1]/2-h/2-50)))
        self.__topLevel.resizable(False, False)

        self.__topLevel.config(bg=self.__loader.colorPalettes.getColor("window"))
        #self.__topLevel.protocol('WM_DELETE_WINDOW', self.__closeWindow)

        try:
            self.__topLevel.iconbitmap("others/img/"+name+".ico")
        except:
            self.__topLevel.iconbitmap("others/img/icon.ico")

        self.__loader.topLevels.append(self.__topLevel)
        self.__topLevel.deiconify()
        self.__topLevel.focus()

        from threading import Thread
        if checker!=None:
            self.__checker = checker
            check = Thread(target=self.__checker)
            check.daemon = True
            check.start()

        if addElements!=None:
            self.__addElements = addElements
            add = Thread(target=self.__addElements, args=[self])
            add.daemon=True
            add.start()

        self.changeWindowState(True, maxNum-1)
        self.__topLevel.wait_window()
        try:
            self.changeWindowState(False, maxNum-1)
        except:
            pass

        try:
            self.__loader.subMenus.pop(-1)
            self.__loader.subMenus.remove(self)
        except Exception as e:
            self.__loader.logger.errorLog(e)

        from threading import Thread

        t = Thread(target=self.__killIfKilled)
        t.daemon = True
        t.start()

    def changeWindowState(self, state, last):
        self.__loader.mainWindow.editor.attributes('-disabled', state)
        if last > 0:
            for num in range(last):
                self.__loader.topLevels[num].attributes('-disabled', state)

        if state == False:
            if last == 0:
                self.__loader.mainWindow.editor.deiconify()
                self.__loader.mainWindow.editor.focus()
            else:
                self.__loader.topLevels[last-1].deiconify()
                self.__loader.topLevels[last-1].focus()


    def __killIfKilled(self):
        from time import sleep
        while self.__topLevel.winfo_exists():
            sleep(0.0005)
        del self.__loader.subMenuDict[self.__name]

    def killOther(self):
        num = 10

        from time import sleep

        while num > 0:
            sleep(1)

            try:
                self.__loader.subMenus[-2].dead = True
                self.__loader.subMenus[-2].getTopLevel().destroy()
                self.__loader.subMenus.pop(-2)
                num = 0
            except:
                num -= 1


    def getTopLevel(self):
        return(self.__topLevel)

    def getTopLevelDimensions(self):
        return(self.__topLevel.winfo_width(), self.__topLevel.winfo_height())

    #def __closeWindow(self):

    #    self.__topLevel.destroy()
Exemplo n.º 27
0
def topGetStringName(root=None,
                     titulo="Sin tutulo",
                     modal=True,
                     stringDefault="Dame el nombre de la carpeta"):
    """
    Metodo que se encarga de contruir un toplevel que puede ser modal y muetra un string como ayuda

    :param modal: Booleano que identifica si la ventana sera modal o no
    :param stringDefault: El valor por defecto del texto de ayuda que se mostrara
    :return:None
    """

    x = root.winfo_x()
    y = root.winfo_y()

    global respuesta
    # se inicia la respuesta en None para eliminar la basura
    answer = None

    # se crea el toplevel
    toplevel = Toplevel(root)

    #Se establece el titulo
    toplevel.title(titulo)

    #se posiciona el toplevel enfrente de la ventana principal
    toplevel.geometry("+%d+%d" % (x + 200, y + 200))

    #se evita que se redimencione la pantalla
    toplevel.resizable(0, 0)

    # se agrgan los elementos y los separadores
    frameprincipal = Frame(master=toplevel)
    frameprincipal.pack()
    separador = Separator(frameprincipal, orient=HORIZONTAL)
    separador.pack(expand=True, pady=5)
    label = Label(frameprincipal, text=stringDefault)
    label.pack()
    separador = Separator(frameprincipal, orient=HORIZONTAL)
    separador.pack(expand=True, pady=5, padx=100)
    entry = Entry(frameprincipal)
    entry.pack()
    separador = Separator(frameprincipal, orient=VERTICAL)
    separador.pack(side=LEFT, pady=10, padx=10)
    button = Button(frameprincipal,
                    text="Aceptar",
                    command=lambda: getAnswer(entry.get(), toplevel))
    button.pack(side=LEFT)
    separador = Separator(frameprincipal, orient=HORIZONTAL)
    separador.pack(side=LEFT, fill=X, pady=10, padx=50)
    button = Button(frameprincipal,
                    text="Cancelar",
                    command=lambda: getAnswer(None, toplevel))
    button.pack(side=LEFT)
    separador = Separator(frameprincipal, orient=HORIZONTAL)
    separador.pack(fill=X, pady=20, padx=10)

    #se agrega un protocolo para manejar la destruccion del toplevel
    toplevel.protocol("WM_DELETE_WINDOW", lambda: getAnswer(None, toplevel))

    # Si es modal se configura la ventana
    if modal:
        toplevel.transient(root)
        toplevel.grab_set()
        toplevel.focus()
        root.wait_window(toplevel)
    return respuesta
Exemplo n.º 28
0
class OptionEditor(object):
    # Parses default.cfg configuration file and sets up a window where those
    # properties markes as "editable" can be altered. See the remarks in
    # default.cfg for the format.

    def __init__(self, configobj):
        self.window = Toplevel()
        # self.window.option_add("*Background", "white")
        self.window.protocol('WM_DELETE_WINDOW', self.cancel)

        f0 = Frame(self.window)
        f0.pack(side='top', anchor='w', expand=False, fill='x')
        t = _(
            'Note that most changes become effective only after restarting the program.'
        )
        text = Text(f0, height=len(t) // 80 + 1, width=80, wrap='word')
        text.insert(1.0, _(t))
        text.config(state='disabled')
        text.pack(side='left', expand=True, fill='x')
        Button(f0, text=_('Save'), command=self.save,
               bg='lightgreen').pack(side='right', anchor='e')
        Button(f0, text=_('Cancel'), command=self.cancel,
               bg='orange').pack(side='right', anchor='e')

        self.configobj = configobj
        self.variables = {
        }  # will store the Tkinter variables containing the values
        special_values = [
            '# -----',
            '# section',
            '# label',
            '# editable',
            '# values',
        ]

        sf = ScrolledFrame(self.window, usehullsize=1, hull_height=500)
        sf.pack(side='top', anchor='w', expand=True, fill='both')
        f = sf.interior()
        ctr = -1

        for prop in configobj['options']:
            comments = configobj['options'].comments[prop]

            # new "section"?
            sec = self.retrieve('# section:', comments)
            if sec:
                ctr += 1
                Label(f,
                      text=_(sec),
                      justify='left',
                      bg='#eeeeee',
                      font=('Helvetica', 14, 'bold')).grid(row=ctr,
                                                           column=0,
                                                           columnspan=3,
                                                           sticky='we',
                                                           pady=10)

            if '# editable' in comments:
                ctr += 1

                label = self.retrieve('# label:', comments) or prop
                label = label.strip()
                values = self.retrieve('# values:', comments)
                if values:
                    values = values.split(', ')
                else:
                    values = []
                help_text = ' '.join(
                    x[1:].strip() for x in comments
                    if not any(x.startswith(v)
                               for v in special_values)).strip()

                if 'BOOLEAN' in values:
                    self.variables[prop] = BooleanVar()
                else:
                    self.variables[prop] = StringVar()

                if '--' in values and configobj['options'][prop] == '':
                    self.variables[prop].set('--')
                else:
                    self.variables[prop].set(configobj['options'][prop])

                if 'BOOLEAN' in values:
                    Checkbutton(f,
                                text=_(label),
                                indicatoron=1,
                                variable=self.variables[prop]).grid(
                                    row=ctr, column=1, sticky='nw', pady=5)
                elif values and not 'INT' in values:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Combobox(
                        f,
                        justify='left',
                        textvariable=self.variables[prop],
                        values=values,
                    ).grid(row=ctr, column=1, sticky='nw', pady=5)
                else:
                    Label(f, text=_(label), justify='left').grid(row=ctr,
                                                                 column=0,
                                                                 sticky='nw',
                                                                 pady=5)
                    Entry(f, width=20,
                          textvariable=self.variables[prop]).grid(row=ctr,
                                                                  column=1,
                                                                  sticky='nw',
                                                                  pady=5)
                if help_text:
                    ht = _(help_text)
                    text = Text(f,
                                height=len(ht) // 60 + 1,
                                width=60,
                                borderwidth=0,
                                wrap='word')
                    text.insert(1.0, _(help_text))
                    text.config(state='disabled')
                    text.grid(row=ctr, column=2, sticky='nsew', pady=5)

        self.window.update_idletasks()

        self.window.focus()
        self.window.grab_set()
        self.window.wait_window()

    def cancel(self):
        self.window.destroy()

    def save(self):
        for prop in self.configobj['options']:
            comments = self.configobj['options'].comments[prop]
            if '# editable' in comments:
                # validate:
                values = self.retrieve('# values:', comments)
                if values:
                    values = values.split(', ')
                else:
                    values = []
                if 'INT' in values:
                    try:
                        self.configobj['options'][prop] = int(
                            self.variables[prop].get())
                    except ValueError:
                        pass
                elif 'BOOLEAN' in values:
                    self.configobj['options'][prop] = self.variables[prop].get(
                    )
                elif not values:
                    self.configobj['options'][prop] = self.variables[prop].get(
                    )
                else:
                    if '--' in values and self.variables[prop].get() == '--':
                        self.configobj['options'][prop] = ''
                    elif self.variables[prop].get() in values:
                        self.configobj['options'][prop] = self.variables[
                            prop].get()
        self.window.destroy()

    def retrieve(self, s, comments):
        return ''.join(x[len(s):].strip() for x in comments if x.startswith(s))
Exemplo n.º 29
0
    def add_body_members():
        def del_body_mem():
            try:
                now_del=new_body_db
                added_mem_id=exe_id_entry_var.get()
                strr = f'delete from {now_del} where body_id = %s'
                my_cursor.execute(strr,(added_mem_id))
                con.commit()
                all_mems()
                m_box.showinfo('Notification',f'id {added_mem_id} deleted successfull...',parent=exe)
                exe_id_entry_var.set('')
            except NameError:
                m_box.showerror('Error','Please connect to Database First',parent=exe)
                Exe_body_root.destroy()
                exe.destroy()
            except:
                m_box.showinfo('Notification','Id Doesnt exist',parent=exe)
                exe_id_entry_var.set('')
                
        def all_mem():
            try:
                now_insert=new_body_db
                added_mem_id=exe_id_entry_var.get()
                added_mem_post=mem_post_entry_var.get()
                strr =  f"INSERT INTO  {now_insert} (body_id,mem_post) VALUES (%s,%s)"
                my_cursor.execute(strr,(added_mem_id,added_mem_post))
                con.commit()
                m_box.showinfo('Notification','Added Successfull',parent=exe)
                all_mems()
                exe_id_entry_var.set('')
                mem_post_entry_var.set('')
            except NameError:
                m_box.showerror('Error','First enter Body Number Into \n Enter Body',parent=exe)
                exe.destroy()
            except NameError:
                m_box.showerror('Notification','Enter Id number',parent=exe)
                return
            except pymysql.err.IntegrityError:
                m_box.showerror('New Sarathian','First add into Add Sarthian ',parent=exe)
            except:
                m_box.showerror('Notification','Already Addded',parent=exe)
                exe_id_entry_var.set('')
                mem_post_entry_var.set('')

        exe=Toplevel()
        exe.grab_set()
        exe.title('Add Or Delete')
        exe.focus()
        exe.geometry('490x180+300+300')
        exe.resizable(False,False)
        exe.config(bg='black')

        exe_id_entry_var=tk.StringVar()
        mem_post_entry_var=tk.StringVar()
        exe_id_label=tk.Label(exe,text='Add Member Id :',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='center',relief='groove')
        exe_id_label.place(x=0,y=0)
        

        exe_id_entry=tk.Entry(exe,fg='blue',textvariable=exe_id_entry_var,font=('times new roman',18),
                          width=20,borderwidth=5,relief='groove')
        exe_id_entry.place(x=240,y=0)
        exe_id_entry.focus()

        
        mem_post=tk.Label(exe,text='Add Member Post : ',bg='light green',fg='blue',font=('times new roman',18),
                      width=15,borderwidth=5,anchor='w',relief='groove')
        mem_post.place(x=0,y=50)
        
        mem_post_entry=tk.Entry(exe,fg='blue',textvariable=mem_post_entry_var,font=('times new roman',18),
                          width=20,borderwidth=5,relief='groove')
        mem_post_entry.place(x=240,y=50)
        
        del_exe=tk.Button(exe,text='Delete Member',command=del_body_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=12,borderwidth=5,anchor='center',relief='groove')
        del_exe.place(x=300,y=110)
        
        
        submit_exe=tk.Button(exe,text='Submit',command=all_mem,bg='light green',fg='blue',font=('times new roman',18),
                      width=5,borderwidth=5,anchor='center',relief='groove')
        submit_exe.place(x=190,y=110)
Exemplo n.º 30
0
class CustomMenus:
    def __init__(self, master):
        self.mainMenu = master.mainMenu
        self.master = master
        self.htmlpath = os.curdir
        self.windowOpen = 0
        self.path = v.get_configfile_directory()

    def buildMenus(self, reload=1, alternativePath=''):
        """
        format of menuList entries:
        { 'name' : name (which will be displayed in the menu),
          'entries': [list of entries]
          'subm' : [list of submenus]  }

        format of entry:
        { 'name' : name which will be displayed in the menu,
          'file' : name of a html file which will be displayed upon clicking
                   this entry (or empty),
          'gisearch' : parameters of a game info search to be done when
                       this is chosen,
          'psearch' : pattern and options for a pattern search }

        format of submenu: {} as in menuList
        """

        if reload:

            fallback = b"(lp1\n(dp2\nS'subm'\np3\n(lp4\nsS'name'\np5\nS'Fuseki'\np6\nsS'entries'\np7\n(lp8\n(dp9\nS'gisearch'\np10\n(tsS'reset'\np11\nI1\nsS'psearch'\np12\n(((I0\nI0\ntp13\n(I18\nI18\ntt(dp14\n(I7\nI3\ntp15\nS'.'\ns(I16\nI9\ntp16\nS'.'\ns(I8\nI5\ntp17\nS'.'\ns(I9\nI0\ntp18\nS'.'\ns(I-1\nI14\ntp19\nS'.'\ns(I10\nI7\ntp20\nS'.'\ns(I0\nI17\ntp21\nS'.'\ns(I14\nI1\ntp22\nS'.'\ns(I12\nI17\ntp23\nS'.'\ns(I-1\nI16\ntp24\nS'.'\ns(I15\nI4\ntp25\nS'.'\ns(I3\nI2\ntp26\nS'.'\ns(I4\nI5\ntp27\nS'.'\ns(I2\nI2\ntp28\nS'O'\ns(I16\nI0\ntp29\nS'.'\ns(I17\nI13\ntp30\nS'.'\ns(I8\nI12\ntp31\nS'.'\ns(I16\nI-1\ntp32\nS'.'\ns(I9\nI9\ntp33\nS'.'\ns(I10\nI14\ntp34\nS'.'\ns(I11\nI15\ntp35\nS'.'\ns(I14\nI8\ntp36\nS'.'\ns(I12\nI8\ntp37\nS'.'\ns(I15\nI13\ntp38\nS'.'\ns(I13\nI13\ntp39\nS'.'\ns(I0\nI14\ntp40\nS'.'\ns(I3\nI11\ntp41\nS'.'\ns(I1\nI15\ntp42\nS'.'\ns(I4\nI12\ntp43\nS'.'\ns(I2\nI12\ntp44\nS'.'\ns(I5\nI1\ntp45\nS'.'\ns(I3\nI17\ntp46\nS'.'\ns(I16\nI7\ntp47\nS'.'\ns(I6\nI14\ntp48\nS'.'\ns(I17\nI6\ntp49\nS'.'\ns(I7\nI15\ntp50\nS'.'\ns(I10\nI9\ntp51\nS'.'\ns(I11\nI4\ntp52\nS'.'\ns(I12\nI7\ntp53\nS'.'\ns(I-1\nI2\ntp54\nS'.'\ns(I15\nI10\ntp55\nS'.'\ns(I13\nI6\ntp56\nS'.'\ns(I0\nI5\ntp57\nS'.'\ns(I1\nI0\ntp58\nS'.'\ns(I4\nI11\ntp59\nS'.'\ns(I2\nI7\ntp60\nS'.'\ns(I5\nI10\ntp61\nS'.'\ns(I6\nI1\ntp62\nS'.'\ns(I4\nI17\ntp63\nS'.'\ns(I7\nI4\ntp64\nS'.'\ns(I17\nI17\ntp65\nS'.'\ns(I8\nI0\ntp66\nS'.'\ns(I-1\nI5\ntp67\nS'.'\ns(I1\nI-1\ntp68\nS'.'\ns(I16\nI11\ntp69\nS'.'\ns(I17\nI10\ntp70\nS'.'\ns(I8\nI7\ntp71\nS'.'\ns(I9\nI6\ntp72\nS'.'\ns(I-1\nI12\ntp73\nS'.'\ns(I10\nI5\ntp74\nS'.'\ns(I11\nI8\ntp75\nS'.'\ns(I14\nI7\ntp76\nS'.'\ns(I15\nI6\ntp77\nS'.'\ns(I0\nI9\ntp78\nS'.'\ns(I3\nI4\ntp79\nS'.'\ns(I4\nI7\ntp80\nS'.'\ns(I10\nI-1\ntp81\nS'.'\ns(I5\nI6\ntp82\nS'.'\ns(I16\nI2\ntp83\nS'.'\ns(I17\nI3\ntp84\nS'.'\ns(I7\nI16\ntp85\nS'.'\ns(I8\nI14\ntp86\nS'.'\ns(I9\nI15\ntp87\nS'.'\ns(I10\nI12\ntp88\nS'.'\ns(I11\nI1\ntp89\nS'.'\ns(I9\nI17\ntp90\nS'.'\ns(I14\nI14\ntp91\nS'O'\ns(I12\nI10\ntp92\nS'.'\ns(I15\nI15\ntp93\nS'.'\ns(I13\nI11\ntp94\nS'.'\ns(I2\nI16\ntp95\nS'.'\ns(I0\nI0\ntp96\nS'.'\ns(I3\nI13\ntp97\nS'.'\ns(I1\nI13\ntp98\nS'.'\ns(I4\nI14\ntp99\nS'.'\ns(I2\nI10\ntp100\nS'.'\ns(I5\nI15\ntp101\nS'.'\ns(I9\nI-1\ntp102\nS'.'\ns(I6\nI12\ntp103\nS'.'\ns(I17\nI4\ntp104\nS'.'\ns(I7\nI9\ntp105\nS'.'\ns(I11\nI6\ntp106\nS'.'\ns(I14\nI17\ntp107\nS'.'\ns(I12\nI1\ntp108\nS'.'\ns(I-1\nI0\ntp109\nS'.'\ns(I10\nI17\ntp110\nS'.'\ns(I13\nI4\ntp111\nS'.'\ns(I0\nI7\ntp112\nS'.'\ns(I1\nI6\ntp113\nS'.'\ns(I2\nI5\ntp114\nS'.'\ns(I5\nI8\ntp115\nS'.'\ns(I6\nI7\ntp116\nS'.'\ns(I7\nI6\ntp117\nS'.'\ns(I8\nI2\ntp118\nS'.'\ns(I9\nI3\ntp119\nS'.'\ns(I-1\nI11\ntp120\nS'.'\ns(I14\nI2\ntp121\nS'X'\ns(I3\nI1\ntp122\nS'.'\ns(I16\nI13\ntp123\nS'.'\ns(I6\nI16\ntp124\nS'.'\ns(I17\nI8\ntp125\nS'.'\ns(I17\nI-1\ntp126\nS'.'\ns(I8\nI9\ntp127\nS'.'\ns(I9\nI4\ntp128\nS'.'\ns(I10\nI3\ntp129\nS'.'\ns(I4\nI-1\ntp130\nS'.'\ns(I11\nI10\ntp131\nS'.'\ns(I14\nI5\ntp132\nS'.'\ns(I12\nI13\ntp133\nS'.'\ns(I1\nI16\ntp134\nS'.'\ns(I15\nI0\ntp135\nS'.'\ns(I13\nI16\ntp136\nS'.'\ns(I0\nI11\ntp137\nS'.'\ns(I3\nI6\ntp138\nS'.'\ns(I1\nI10\ntp139\nS'.'\ns(I4\nI1\ntp140\nS'.'\ns(I5\nI4\ntp141\nS'.'\ns(I16\nI4\ntp142\nS'.'\ns(I6\nI11\ntp143\nS'.'\ns(I17\nI1\ntp144\nS'.'\ns(I9\nI13\ntp145\nS'.'\ns(I10\nI10\ntp146\nS'.'\ns(I11\nI3\ntp147\nS'.'\ns(I3\nI-1\ntp148\nS'.'\ns(I14\nI12\ntp149\nS'.'\ns(I12\nI4\ntp150\nS'.'\ns(I15\nI9\ntp151\nS'.'\ns(I13\nI9\ntp152\nS'.'\ns(I0\nI2\ntp153\nS'.'\ns(I3\nI15\ntp154\nS'.'\ns(I1\nI3\ntp155\nS'.'\ns(I4\nI8\ntp156\nS'.'\ns(I2\nI8\ntp157\nS'.'\ns(I5\nI13\ntp158\nS'.'\ns(I6\nI2\ntp159\nS'.'\ns(I7\nI11\ntp160\nS'.'\ns(I16\nI17\ntp161\nS'.'\ns(I12\nI3\ntp162\nS'.'\ns(I-1\nI6\ntp163\nS'.'\ns(I13\nI2\ntp164\nS'.'\ns(I1\nI4\ntp165\nS'.'\ns(I2\nI3\ntp166\nS'.'\ns(I12\nI-1\ntp167\nS'.'\ns(I6\nI5\ntp168\nS'.'\ns(I7\nI0\ntp169\nS'.'\ns(I5\nI16\ntp170\nS'.'\ns(I16\nI8\ntp171\nS'.'\ns(I8\nI4\ntp172\nS'.'\ns(I9\nI1\ntp173\nS'.'\ns(I-1\nI9\ntp174\nS'.'\ns(I10\nI6\ntp175\nS'.'\ns(I0\nI16\ntp176\nS'.'\ns(I14\nI0\ntp177\nS'.'\ns(I12\nI16\ntp178\nS'.'\ns(I15\nI5\ntp179\nS'.'\ns(I3\nI3\ntp180\nS'.'\ns(I11\nI-1\ntp181\nS'.'\ns(I4\nI4\ntp182\nS'.'\ns(I16\nI15\ntp183\nS'.'\ns(I17\nI14\ntp184\nS'.'\ns(I8\nI11\ntp185\nS'.'\ns(I9\nI10\ntp186\nS'.'\ns(I10\nI1\ntp187\nS'.'\ns(I8\nI17\ntp188\nS'.'\ns(I11\nI12\ntp189\nS'.'\ns(I14\nI11\ntp190\nS'.'\ns(I12\nI15\ntp191\nS'.'\ns(I15\nI2\ntp192\nS'.'\ns(I13\nI14\ntp193\nS'.'\ns(I0\nI13\ntp194\nS'.'\ns(I3\nI8\ntp195\nS'.'\ns(I1\nI8\ntp196\nS'.'\ns(I4\nI3\ntp197\nS'.'\ns(I2\nI15\ntp198\nS'.'\ns(I5\nI2\ntp199\nS'.'\ns(I16\nI6\ntp200\nS'.'\ns(I6\nI9\ntp201\nS'.'\ns(I17\nI7\ntp202\nS'.'\ns(I7\nI12\ntp203\nS'.'\ns(I10\nI8\ntp204\nS'.'\ns(I11\nI5\ntp205\nS'.'\ns(I12\nI6\ntp206\nS'.'\ns(I15\nI11\ntp207\nS'.'\ns(I13\nI7\ntp208\nS'.'\ns(I0\nI4\ntp209\nS'.'\ns(I1\nI1\ntp210\nS'.'\ns(I4\nI10\ntp211\nS'.'\ns(I2\nI6\ntp212\nS'.'\ns(I5\nI11\ntp213\nS'.'\ns(I6\nI0\ntp214\nS'.'\ns(I4\nI16\ntp215\nS'.'\ns(I7\nI5\ntp216\nS'.'\ns(I6\nI-1\ntp217\nS'.'\ns(I-1\nI4\ntp218\nS'.'\ns(I15\nI16\ntp219\nS'.'\ns(I13\nI0\ntp220\nS'.'\ns(I11\nI16\ntp221\nS'.'\ns(I2\nI1\ntp222\nS'.'\ns(I7\nI2\ntp223\nS'.'\ns(I16\nI10\ntp224\nS'.'\ns(I17\nI11\ntp225\nS'.'\ns(I8\nI6\ntp226\nS'.'\ns(I9\nI7\ntp227\nS'.'\ns(I5\nI-1\ntp228\nS'.'\ns(I2\nI-1\ntp229\nS'.'\ns(I-1\nI15\ntp230\nS'.'\ns(I10\nI4\ntp231\nS'.'\ns(I11\nI9\ntp232\nS'.'\ns(I14\nI6\ntp233\nS'.'\ns(I-1\nI17\ntp234\nS'.'\ns(I15\nI7\ntp235\nS'.'\ns(I0\nI8\ntp236\nS'.'\ns(I3\nI5\ntp237\nS'.'\ns(I4\nI6\ntp238\nS'.'\ns(I5\nI7\ntp239\nS'.'\ns(I16\nI1\ntp240\nS'.'\ns(I17\nI12\ntp241\nS'.'\ns(I7\nI17\ntp242\nS'.'\ns(I8\nI13\ntp243\nS'.'\ns(I9\nI8\ntp244\nS'.'\ns(I10\nI15\ntp245\nS'.'\ns(I11\nI14\ntp246\nS'.'\ns(I14\nI9\ntp247\nS'.'\ns(I12\nI9\ntp248\nS'.'\ns(I15\nI12\ntp249\nS'.'\ns(I13\nI12\ntp250\nS'.'\ns(I0\nI15\ntp251\nS'.'\ns(I14\nI-1\ntp252\nS'.'\ns(I3\nI10\ntp253\nS'.'\ns(I1\nI14\ntp254\nS'.'\ns(I4\nI13\ntp255\nS'.'\ns(I2\nI13\ntp256\nS'.'\ns(I5\nI0\ntp257\nS'.'\ns(I3\nI16\ntp258\nS'.'\ns(I6\nI15\ntp259\nS'.'\ns(I17\nI5\ntp260\nS'.'\ns(I7\nI14\ntp261\nS'.'\ns(I11\nI7\ntp262\nS'.'\ns(I14\nI16\ntp263\nS'.'\ns(I12\nI0\ntp264\nS'.'\ns(I-1\nI3\ntp265\nS'.'\ns(I10\nI16\ntp266\nS'.'\ns(I13\nI5\ntp267\nS'.'\ns(I0\nI6\ntp268\nS'.'\ns(I1\nI7\ntp269\nS'.'\ns(I13\nI-1\ntp270\nS'.'\ns(I2\nI4\ntp271\nS'.'\ns(I5\nI9\ntp272\nS'.'\ns(I6\nI6\ntp273\nS'.'\ns(I7\nI7\ntp274\nS'.'\ns(I17\nI16\ntp275\nS'.'\ns(I8\nI1\ntp276\nS'.'\ns(I-1\nI10\ntp277\nS'.'\ns(I16\nI12\ntp278\nS'.'\ns(I17\nI9\ntp279\nS'.'\ns(I8\nI8\ntp280\nS'.'\ns(I9\nI5\ntp281\nS'.'\ns(I-1\nI13\ntp282\nS'.'\ns(I10\nI2\ntp283\nS'.'\ns(I11\nI11\ntp284\nS'.'\ns(I14\nI4\ntp285\nS'.'\ns(I12\nI12\ntp286\nS'.'\ns(I1\nI17\ntp287\nS'.'\ns(I15\nI1\ntp288\nS'.'\ns(I13\nI17\ntp289\nS'.'\ns(I0\nI10\ntp290\nS'.'\ns(I3\nI7\ntp291\nS'.'\ns(I1\nI11\ntp292\nS'.'\ns(I4\nI0\ntp293\nS'.'\ns(I5\nI5\ntp294\nS'.'\ns(I16\nI3\ntp295\nS'.'\ns(I6\nI10\ntp296\nS'.'\ns(I17\nI2\ntp297\nS'.'\ns(I8\nI15\ntp298\nS'.'\ns(I9\nI14\ntp299\nS'.'\ns(I10\nI13\ntp300\nS'.'\ns(I11\nI0\ntp301\nS'.'\ns(I9\nI16\ntp302\nS'.'\ns(I14\nI15\ntp303\nS'.'\ns(I12\nI11\ntp304\nS'.'\ns(I15\nI14\ntp305\nS'.'\ns(I13\nI10\ntp306\nS'.'\ns(I2\nI17\ntp307\nS'.'\ns(I0\nI1\ntp308\nS'.'\ns(I3\nI12\ntp309\nS'.'\ns(I1\nI12\ntp310\nS'.'\ns(I4\nI15\ntp311\nS'.'\ns(I2\nI11\ntp312\nS'.'\ns(I5\nI14\ntp313\nS'.'\ns(I6\nI13\ntp314\nS'.'\ns(I7\nI8\ntp315\nS'.'\ns(I16\nI16\ntp316\nS'.'\ns(I7\nI-1\ntp317\nS'.'\ns(I12\nI2\ntp318\nS'.'\ns(I-1\nI1\ntp319\nS'.'\ns(I13\nI3\ntp320\nS'.'\ns(I1\nI5\ntp321\nS'.'\ns(I-1\nI-1\ntp322\nS'.'\ns(I6\nI4\ntp323\nS'.'\ns(I7\nI1\ntp324\nS'.'\ns(I5\nI17\ntp325\nS'.'\ns(I8\nI3\ntp326\nS'.'\ns(I9\nI2\ntp327\nS'.'\ns(I-1\nI8\ntp328\nS'.'\ns(I14\nI3\ntp329\nS'.'\ns(I0\nI-1\ntp330\nS'.'\ns(I3\nI0\ntp331\nS'.'\ns(I16\nI14\ntp332\nS'.'\ns(I6\nI17\ntp333\nS'.'\ns(I17\nI15\ntp334\nS'.'\ns(I8\nI10\ntp335\nS'.'\ns(I9\nI11\ntp336\nS'.'\ns(I10\nI0\ntp337\nS'.'\ns(I8\nI16\ntp338\nS'.'\ns(I11\nI13\ntp339\nS'.'\ns(I14\nI10\ntp340\nS'.'\ns(I12\nI14\ntp341\nS'.'\ns(I15\nI3\ntp342\nS'.'\ns(I15\nI-1\ntp343\nS'.'\ns(I13\nI15\ntp344\nS'.'\ns(I0\nI12\ntp345\nS'.'\ns(I3\nI9\ntp346\nS'.'\ns(I1\nI9\ntp347\nS'.'\ns(I4\nI2\ntp348\nS'.'\ns(I2\nI14\ntp349\nS'X'\ns(I5\nI3\ntp350\nS'.'\ns(I16\nI5\ntp351\nS'.'\ns(I6\nI8\ntp352\nS'.'\ns(I17\nI0\ntp353\nS'.'\ns(I7\nI13\ntp354\nS'.'\ns(I9\nI12\ntp355\nS'.'\ns(I10\nI11\ntp356\nS'.'\ns(I11\nI2\ntp357\nS'.'\ns(I14\nI13\ntp358\nS'.'\ns(I12\nI5\ntp359\nS'.'\ns(I15\nI8\ntp360\nS'.'\ns(I13\nI8\ntp361\nS'.'\ns(I0\nI3\ntp362\nS'.'\ns(I3\nI14\ntp363\nS'.'\ns(I1\nI2\ntp364\nS'.'\ns(I4\nI9\ntp365\nS'.'\ns(I2\nI9\ntp366\nS'.'\ns(I5\nI12\ntp367\nS'.'\ns(I6\nI3\ntp368\nS'.'\ns(I8\nI-1\ntp369\nS'.'\ns(I7\nI10\ntp370\nS'.'\ns(I-1\nI7\ntp371\nS'.'\ns(I15\nI17\ntp372\nS'.'\ns(I13\nI1\ntp373\nS'.'\ns(I11\nI17\ntp374\nS'.'\ns(I2\nI0\ntp375\nS'.'\nsI0\nI1\nI250\nI0\ntp376\nsg5\nS'Diagonal hoshi'\np377\nsS'file'\np378\nS''\nsa(dp379\ng10\n(tsg11\nI1\nsg12\n(((I10\nI0\nt(I18\nI18\nttp380\n(dp381\n(I6\nI9\ntp382\nS'.'\ns(I11\nI11\ntp383\nS'.'\ns(I10\nI17\ntp384\nS'.'\ns(I7\nI12\ntp385\nS'.'\ns(I12\nI12\ntp386\nS'.'\ns(I1\nI17\ntp387\nS'.'\ns(I13\nI17\ntp388\nS'.'\ns(I14\nI17\ntp389\nS'.'\ns(I0\nI10\ntp390\nS'.'\ns(I1\nI11\ntp391\nS'.'\ns(I-1\nI14\ntp392\nS'.'\ns(I6\nI10\ntp393\nS'.'\ns(I0\nI17\ntp394\nS'.'\ns(I15\nI11\ntp395\nS'.'\ns(I12\nI17\ntp396\nS'.'\ns(I-1\nI16\ntp397\nS'.'\ns(I8\nI15\ntp398\nS'.'\ns(I4\nI10\ntp399\nS'.'\ns(I9\nI14\ntp400\nS'.'\ns(I16\nI15\ntp401\nS'.'\ns(I5\nI11\ntp402\nS'.'\ns(I10\nI13\ntp403\nS'.'\ns(I4\nI16\ntp404\nS'.'\ns(I-1\nI11\ntp405\nS'.'\ns(I9\nI16\ntp406\nS'.'\ns(I14\nI15\ntp407\nS'.'\ns(I12\nI11\ntp408\nS'.'\ns(I17\nI13\ntp409\nS'.'\ns(I15\nI14\ntp410\nS'.'\ns(I13\nI10\ntp411\nS'.'\ns(I2\nI17\ntp412\nS'.'\ns(I3\nI12\ntp413\nS'.'\ns(I1\nI12\ntp414\nS'.'\ns(I8\nI12\ntp415\nS'.'\ns(I4\nI15\ntp416\nS'.'\ns(I2\nI11\ntp417\nS'.'\ns(I9\nI9\ntp418\nS'.'\ns(I5\nI14\ntp419\nS'.'\ns(I10\nI14\ntp420\nS'.'\ns(I6\nI13\ntp421\nS'.'\ns(I11\nI15\ntp422\nS'.'\ns(I15\nI16\ntp423\nS'.'\ns(I6\nI16\ntp424\nS'.'\ns(I11\nI16\ntp425\nS'.'\ns(I15\nI13\ntp426\nS'.'\ns(I13\nI13\ntp427\nS'.'\ns(I0\nI14\ntp428\nS'.'\ns(I3\nI11\ntp429\nS'.'\ns(I1\nI15\ntp430\nS'.'\ns(I8\nI9\ntp431\nS'.'\ns(I4\nI12\ntp432\nS'.'\ns(I2\nI12\ntp433\nS'.'\ns(I16\nI14\ntp434\nS'.'\ns(I3\nI17\ntp435\nS'.'\ns(I14\nI9\ntp436\nS'.'\ns(I6\nI14\ntp437\nS'.'\ns(I11\nI10\ntp438\nS'.'\ns(I7\nI15\ntp439\nS'.'\ns(I12\nI13\ntp440\nS'.'\ns(I1\nI16\ntp441\nS'.'\ns(I17\nI11\ntp442\nS'.'\ns(I13\nI16\ntp443\nS'.'\ns(I0\nI11\ntp444\nS'.'\ns(I16\nI9\ntp445\nS'.'\ns(I1\nI10\ntp446\nS'.'\ns(I10\nI9\ntp447\nS'.'\ns(I16\nI17\ntp448\nS'.'\ns(I-1\nI15\ntp449\nS'.'\ns(I6\nI11\ntp450\nS'.'\ns(I5\nI17\ntp451\nS'.'\ns(I11\nI9\ntp452\nS'.'\ns(I15\nI10\ntp453\nS'.'\ns(I-1\nI17\ntp454\nS'.'\ns(I4\nI11\ntp455\nS'.'\ns(I9\nI13\ntp456\nS'.'\ns(I5\nI10\ntp457\nS'.'\ns(I10\nI10\ntp458\nS'.'\ns(I16\nI13\ntp459\nS'.'\ns(I4\nI17\ntp460\nS'.'\ns(I14\nI12\ntp461\nS'.'\ns(I17\nI12\ntp462\nS'.'\ns(I7\nI17\ntp463\nS'.'\ns(I13\nI9\ntp464\nS'.'\ns(I17\nI17\ntp465\nS'.'\ns(I3\nI15\ntp466\nS'.'\ns(I8\nI13\ntp467\nS'.'\ns(I5\nI13\ntp468\nS'.'\ns(I10\nI15\ntp469\nS'.'\ns(I16\nI16\ntp470\nS'.'\ns(I11\nI14\ntp471\nS'.'\ns(I7\nI11\ntp472\nS'.'\ns(I6\nI17\ntp473\nS'.'\ns(I12\nI9\ntp474\nS'.'\ns(I17\nI15\ntp475\nS'.'\ns(I15\nI12\ntp476\nS'.'\ns(I13\nI12\ntp477\nS'.'\ns(I0\nI15\ntp478\nS'.'\ns(I3\nI10\ntp479\nS'.'\ns(I1\nI14\ntp480\nS'.'\ns(I8\nI10\ntp481\nS'.'\ns(I4\nI13\ntp482\nS'.'\ns(I2\nI13\ntp483\nS'.'\ns(I9\nI11\ntp484\nS'.'\ns(I3\nI16\ntp485\nS'.'\ns(I8\nI16\ntp486\nS'.'\ns(I6\nI15\ntp487\nS'.'\ns(I11\nI13\ntp488\nS'.'\ns(I16\nI10\ntp489\nS'.'\ns(I7\nI14\ntp490\nS'.'\ns(I14\nI10\ntp491\nS'.'\ns(I12\nI14\ntp492\nS'.'\ns(I17\nI10\ntp493\nS'.'\ns(I13\nI15\ntp494\nS'.'\ns(I0\nI12\ntp495\nS'.'\ns(I3\nI9\ntp496\nS'.'\ns(I1\nI9\ntp497\nS'.'\ns(I2\nI14\ntp498\nS'X'\ns(I-1\nI12\ntp499\nS'.'\ns(I14\nI16\ntp500\nS'.'\ns(I5\nI16\ntp501\nS'.'\ns(I10\nI16\ntp502\nS'.'\ns(I7\nI13\ntp503\nS'.'\ns(I15\nI17\ntp504\nS'.'\ns(I0\nI9\ntp505\nS'.'\ns(I9\nI12\ntp506\nS'.'\ns(I5\nI9\ntp507\nS'.'\ns(I10\nI11\ntp508\nS'.'\ns(I-1\nI9\ntp509\nS'.'\ns(I16\nI11\ntp510\nS'.'\ns(I14\nI13\ntp511\nS'.'\ns(I0\nI16\ntp512\nS'.'\ns(I7\nI16\ntp513\nS'.'\ns(I12\nI16\ntp514\nS'.'\ns(I17\nI16\ntp515\nS'.'\ns(I3\nI14\ntp516\nS'.'\ns(I8\nI14\ntp517\nS'X'\ns(I4\nI9\ntp518\nS'.'\ns(I2\nI9\ntp519\nS'.'\ns(I9\nI15\ntp520\nS'.'\ns(I5\nI12\ntp521\nS'.'\ns(I10\nI12\ntp522\nS'.'\ns(I-1\nI10\ntp523\nS'.'\ns(I9\nI17\ntp524\nS'.'\ns(I7\nI10\ntp525\nS'.'\ns(I14\nI14\ntp526\nS'X'\ns(I12\nI10\ntp527\nS'.'\ns(I17\nI14\ntp528\nS'.'\ns(I15\nI15\ntp529\nS'.'\ns(I13\nI11\ntp530\nS'.'\ns(I16\nI12\ntp531\nS'.'\ns(I2\nI16\ntp532\nS'.'\ns(I3\nI13\ntp533\nS'.'\ns(I1\nI13\ntp534\nS'.'\ns(I8\nI11\ntp535\nS'.'\ns(I15\nI9\ntp536\nS'.'\ns(I4\nI14\ntp537\nS'.'\ns(I2\nI10\ntp538\nS'.'\ns(I9\nI10\ntp539\nS'.'\ns(I5\nI15\ntp540\nS'.'\ns(I8\nI17\ntp541\nS'.'\ns(I6\nI12\ntp542\nS'.'\ns(I11\nI12\ntp543\nS'.'\ns(I7\nI9\ntp544\nS'.'\ns(I14\nI11\ntp545\nS'.'\ns(I12\nI15\ntp546\nS'.'\ns(I11\nI17\ntp547\nS'.'\ns(I17\nI9\ntp548\nS'.'\ns(I13\nI14\ntp549\nS'.'\ns(I0\nI13\ntp550\nS'.'\ns(I2\nI15\ntp551\nS'.'\ns(I-1\nI13\ntp552\nS'.'\nsI0\nI0\nI250\nI0\ntp553\nsg5\nS'San ren sei'\np554\nsg378\nS''\nsasa(dp555\ng3\n(lp556\nsg5\nS'Players'\np557\nsg7\n(lp558\n(dp559\ng10\n(S''\nS''\nS'Cho U'\nS''\nS''\nS''\nS''\nI0\ntp560\nsg11\nI1\nsg12\n(tsg5\nS'Cho U'\np561\nsg378\nS''\nsa(dp562\ng10\n(S''\nS''\nS'Go Seigen'\nS''\nS''\nS''\nS''\nI0\ntp563\nsg11\nI1\nsg12\n(tsg5\nS'Go Seigen'\np564\nsg378\nS''\nsasa."

            try:
                file = open(os.path.join(self.path, 'menus.def'), 'rb')
                self.customMenuList = pickle.load(file)
                file.close()
            except IOError:
                if alternativePath:
                    try:
                        file = open(os.path.join(alternativePath, 'menus.def'),
                                    'rb')
                        self.customMenuList = pickle.load(file)
                        file.close()
                    except IOError:
                        self.customMenuList = pickle.loads(fallback)
                else:
                    self.customMenuList = pickle.loads(fallback)

        self.noOfMenus = len(self.customMenuList)

        # build menus

        self.customMenuCommands = []
        self.mmIndex = 3
        self.customMenuList.sort(key=lambda x: x['name'])

        for item in self.customMenuList:
            m = Menu(self.mainMenu)
            self.mainMenu.insert_cascade(self.mmIndex,
                                         menu=m,
                                         label=item['name'])
            self.mmIndex += 1

            self.addMenu(item['subm'], m)
            item['entries'].sort(key=lambda x: x['name'])

            for e in item['entries']:
                m.add_command(label=e['name'],
                              command=lambda self=self, i=len(
                                  self.customMenuCommands): self.doCommand(i))
                self.customMenuCommands.append(
                    (e['file'], e['gisearch'], e['psearch'], e['reset']))

    def addMenu(self, menuList, menu):
        menuList.sort(key=lambda x: x['name'])

        for item in menuList:
            m = Menu(menu)
            menu.add_cascade(label=item['name'], menu=m)
            self.addMenu(item['subm'], m)
            for e in item['entries']:
                m.add_command(label=e['name'],
                              command=lambda self=self, i=len(
                                  self.customMenuCommands): self.doCommand(i))
                self.customMenuCommands.append(
                    (e['file'], e['gisearch'], e['psearch'], e['reset']))

    def removeMenus(self):
        for i in range(self.noOfMenus):
            self.mainMenu.delete(
                3)  # The first custom menu is the 3rd overall menu

    def doCommand(self, i):
        if self.customMenuCommands[i][0]:
            try:
                webbrowser.open(self.customMenuCommands[i][0], new=1)
            except:
                showwarning(_('Error'), _('Failed to open the web browser.'))
        if self.customMenuCommands[i][3]:  # reset game list
            self.master.reset()
        if self.customMenuCommands[i][2]:  # prepare pattern search
            self.displayPattern(self.customMenuCommands[i][2])
        if self.customMenuCommands[i][1]:  # do game info search
            self.displayGI(self.customMenuCommands[i][1])
            self.master.doGISearch()
        if self.customMenuCommands[i][2]:  # do pattern search
            self.master.search()

    def displayPattern(self, data):
        if not data:
            return
        if self.master.dataWindow.filelist.list.curselection():
            index = int(self.master.dataWindow.filelist.list.curselection()[0])
            if self.master.filelist[index][1]:
                self.master.newFile()
        else:
            self.master.newFile()

        self.master.start()

        sel = data[0]
        if sel == ((0, 0), (18, 18)):  # TODO boardsize
            self.master.board.delete('selection')
            self.master.board.selection = sel
        else:
            self.master.board.setSelection(sel[0], sel[1])

        self.master.board.changed.set(1)

        self.master.fixedAnchorVar.set(data[2])
        self.master.fixedColorVar.set(data[3])
        self.master.moveLimit.set(data[4])
        self.master.nextMoveVar.set(data[5])

        d = data[1]
        for ii in range(sel[0][1], sel[1][1] + 1):
            for jj in range(sel[0][0], sel[1][0] + 1):
                if d[(ii - 1, jj - 1)] == 'X':
                    nM = 'AB'
                elif d[(ii - 1, jj - 1)] == 'O':
                    nM = 'AW'
                elif d[(ii - 1, jj - 1)] in ['x', 'o', '*']:
                    wc_type = d[(ii - 1, jj - 1)]
                    x1, x2, y1, y2 = self.master.board.getPixelCoord((jj, ii),
                                                                     1)
                    self.master.board.wildcards[(jj, ii)] = (
                        self.master.board.create_oval(x1 + 4,
                                                      x2 + 4,
                                                      y1 - 4,
                                                      y2 - 4,
                                                      fill={
                                                          '*': 'green',
                                                          'x': 'black',
                                                          'o': 'white'
                                                      }[wc_type],
                                                      tags=('wildcard',
                                                            'non-bg')),
                        wc_type)
                    continue
                else:
                    continue

                pos = chr(jj + ord('a')) + chr(ii + ord('a'))

                try:
                    if ('AB' in self.master.cursor.currentNode()
                            or 'AW' in self.master.cursor.currentNode()
                            or 'AE' in self.master.cursor.currentNode()):
                        if not nM in self.master.cursor.currentNode():
                            self.master.cursor.currentNode()[nM] = []

                        if not pos in self.master.cursor.currentNode()[nM]:
                            self.master.cursor.currentNode(
                            ).add_property_value(nM, [
                                pos,
                            ])

                        color = 'black' if nM == 'AB' else 'white'

                        if not self.master.board.play((jj, ii), color):
                            self.master.board.undostack_append_pass()
                        self.master.board.currentColor = self.master.modeVar.get(
                        )

                        if nM == 'AB':
                            self.master.capB = self.master.capB + len(
                                self.master.board.undostack_top_captures())
                        if nM == 'AW':
                            self.master.capW = self.master.capW + len(
                                self.master.board.undostack_top_captures())
                        self.master.capVar.set(
                            _('Cap - B: {0}, W: {1}').format(
                                self.master.capB, self.master.capW))

                    else:
                        s = ';' + nM + '[' + pos + ']'
                        self.master.cursor.add(s)
                        c = self.master.cursor.currentNode()

                        self.master.board.delMarks()
                        self.master.board.delLabels()

                        self.master.moveno.set(
                            '%d' % (int(self.master.moveno.get()) + 1))

                        self.master.displayNode(c)

                        if nM == 'AB':
                            self.master.capB = self.master.capB + len(
                                self.master.board.undostack_top_captures())
                        if nM == 'AW':
                            self.master.capW = self.master.capW + len(
                                self.master.board.undostack_top_captures())
                        self.master.capVar.set(
                            _('Cap - B: {0}, W: {1}').format(
                                self.master.capB, self.master.capW))
                except SGFError:
                    showwarning(_('Error'), _('SGF Error'))

        self.master.board.currentColor = self.master.modeVar.get()[:5]

    def c_buildList(self, menuList, level):
        for i in range(len(menuList)):
            item = menuList[i]
            self.list.insert('end', '-' * level + ' ' + item['name'])
            self.correspEntry.append([1, item, '-' * level + ' ', menuList,
                                      i])  # 1 = submenu
            self.c_buildList(item['subm'], level + 1)
            for j in range(len(item['entries'])):
                entry = item['entries'][j]
                self.list.insert('end', '-' * level + '* ' + entry['name'])
                self.correspEntry.append(
                    [2, entry, '-' * level + '* ', item['entries'],
                     j])  # 2 = entry

    def count(self, i):
        res = len(i['entries']) + 1
        for j in i['subm']:
            res += self.count(j)
        return res

    def displayGI(self, data):
        if not data:
            return
        varList = [
            self.master.pwVar, self.master.pbVar, self.master.pVar,
            self.master.evVar, self.master.frVar, self.master.toVar,
            self.master.awVar, self.master.referencedVar
        ]

        for i in range(len(varList)):
            varList[i].set(data[i])

    def c_addEntry(self):
        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] != 1:
            return

        # add entry to currently selected submenu, named 'New'

        entry = {
            'name': _('New'),
            'file': '',
            'gisearch': (),
            'psearch': (),
            'reset': 1
        }
        self.correspEntry[index][1]['entries'].append(entry)

        insertIndex = index + self.count(self.correspEntry[index][1]) - 1

        self.correspEntry[insertIndex:insertIndex] = [[
            2, entry, self.correspEntry[index][2][:-1] + '* ',
            self.correspEntry[index][1]['entries'],
            len(self.correspEntry[index][1]['entries']) - 1
        ]]

        self.list.insert(insertIndex,
                         self.correspEntry[index][2][:-1] + '* ' + _('New'))
        self.list.list.select_clear(self.list.list.curselection())
        self.list.list.select_set(insertIndex)

    def c_addSubmenu(self):
        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] == 2:
            return

        # add submenu to currently selected submenu, named 'New'

        submenu = {'name': _('New'), 'entries': [], 'subm': []}

        if self.correspEntry[index][0] == 0:
            self.customMenuList.append(submenu)
            insertIndex = self.list.list.index('end')
            prefix = '- '
            self.correspEntry.append([
                1, submenu, prefix, self.customMenuList,
                len(self.customMenuList) - 1
            ])
        else:
            self.correspEntry[index][1]['subm'].append(submenu)

            insertIndex = index + self.count(
                self.correspEntry[index][1]) - len(
                    self.correspEntry[index][1]['entries']) - 1

            prefix = self.correspEntry[index][2][:-1] + '- '

            self.correspEntry[insertIndex:insertIndex] = [[
                1, submenu, prefix, self.correspEntry[index][1]['subm'],
                len(self.correspEntry[index][1]['subm']) - 1
            ]]

        self.list.insert(insertIndex, prefix + _('New'))
        self.list.list.select_clear(self.list.list.curselection())
        self.list.list.select_set(insertIndex)

    def c_delete(self):

        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] == 0:
            return

        if self.correspEntry[index][0] == 1:
            n = self.count(self.correspEntry[index][1])
        elif self.correspEntry[index][0] == 2:
            n = 1

        del self.correspEntry[index][3][self.correspEntry[index][4]]
        del self.correspEntry[index:index + n]

        self.correspEntry = [[0, '', '', None, None]]
        self.list.delete(1, 'end')
        self.c_buildList(self.customMenuList, 1)

        if self.list.list.index('end') > index:
            self.list.list.select_set(index)
        else:
            self.list.list.select_set('end')
        self.current = None

    def c_addPattern(self):
        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] != 2:
            return

        d = {}

        if self.master.board.selection[0][0] > self.master.board.selection[1][
                0] or self.master.board.selection[0][
                    1] > self.master.board.selection[1][1]:
            self.master.board.selection = ((1, 1), (19, 19))  # TODO boardsize

        sel = self.master.board.selection  # copy this because the selection on the board may
        # be changed by the user although the search is not yet
        # finished

        for i in range(sel[0][1], sel[1][1] + 1):
            for j in range(sel[0][0], sel[1][0] + 1):
                if self.master.board.getStatus(j, i) == 'W':
                    d[(i - 1, j - 1)] = 'O'
                elif self.master.board.getStatus(j, i) == 'B':
                    d[(i - 1, j - 1)] = 'X'
                else:
                    d[(i - 1, j - 1)] = '.'
                if (j, i) in self.master.board.wildcards:
                    d[(i - 1, j - 1)] = self.master.board.wildcards[(j, i)][1]

        self.correspEntry[index][1]['psearch'] = (
            sel, d, self.master.fixedAnchorVar.get(),
            self.master.fixedColorVar.get(), self.master.moveLimit.get(),
            self.master.nextMoveVar.get())

        showinfo(_('Add pattern'), _('Successfully stored pattern.'))
        self.window.lift()

    def c_addGI(self):
        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] != 2:
            return

        self.correspEntry[index][1]['gisearch'] = (
            self.master.pwVar.get(), self.master.pbVar.get(),
            self.master.pVar.get(), self.master.evVar.get(),
            self.master.frVar.get(), self.master.toVar.get(),
            self.master.awVar.get(), self.master.referencedVar.get())

        showinfo(_('Add game info'), _('Successfully stored game info.'))
        self.window.lift()

    def c_OK(self):
        if self.current:
            index = int(self.current[0])
            if self.correspEntry[index][0] == 1:
                entry = self.correspEntry[index][1]
                entry['name'] = self.nameCurrent.get()

            if self.correspEntry[index][0] == 2:
                entry = self.correspEntry[index][1]
                entry['name'] = self.nameCurrent.get()
                entry['file'] = self.htmlCurrent.get()
                entry['reset'] = self.resetVar.get()
        self.removeMenus()
        self.buildMenus(0)

        # save menus ...

        try:
            file = open(os.path.join(self.path, 'menus.def'), 'wb')
            pickle.dump(self.customMenuList, file)
            file.close()
        except IOError:
            showwarning(_('I/O Error'), _('Could not save custom menu file.'))

        self.window.destroy()

    def c_cancel(self):
        self.removeMenus()
        self.buildMenus()
        self.window.destroy()

    def c_setName(self, event=None):
        index = int(self.current[0])
        self.list.delete(index)
        self.correspEntry[index][1]['name'] = self.nameCurrent.get()
        self.list.insert(
            index,
            self.correspEntry[index][2] + self.correspEntry[index][1]['name'])
        # self.htmlE.focus()
        # self.list.list.select_set(index)

    def c_browse(self, event=None):
        if not self.current:
            return
        index = int(self.current[0])
        if self.correspEntry[index][0] != 2:
            return

        filename = tkFileDialog.askopenfilename(filetypes=[
            (_('HTML files'), ('*.html', '*.htm')), (_('All files'), '*')
        ],
                                                initialdir=self.htmlpath)

        self.window.tkraise()

        if filename:
            filename = os.path.normpath(filename)
            self.htmlpath = os.path.split(filename)[0]
            self.correspEntry[index][1]['file'] = filename
            self.htmlCurrent.set(filename)

    def pollList(self):
        now = self.list.list.curselection()
        if not now and self.current:
            self.list.list.select_set(self.current)
        elif now != self.current:
            if self.current:
                index = int(self.current[0])
                if self.correspEntry[index][0] == 1:
                    entry = self.correspEntry[index][1]
                    self.c_setName(None)
                    self.list.list.select_set(now)
                    entry['name'] = self.nameCurrent.get()
                if self.correspEntry[index][0] == 2:
                    entry = self.correspEntry[index][1]
                    self.c_setName(None)
                    self.list.list.select_set(now)
                    entry['file'] = self.htmlCurrent.get()
                    entry['reset'] = self.resetVar.get()

            self.nameCurrent.set('')
            self.htmlCurrent.set('')
            self.resetVar.set(0)
            for widget in [
                    self.addEntryB, self.addSubmenuB, self.deleteB, self.nameE,
                    self.htmlE, self.browseB, self.patternB, self.giB,
                    self.resetB
            ]:
                widget.config(state=DISABLED)
            self.nameE.config(takefocus=0)
            self.htmlE.config(takefocus=0)

            if now:
                self.list.list.see(now)
                index = int(now[0])
                if self.correspEntry[index][0] == 0:
                    for widget in [self.addSubmenuB]:
                        widget.config(state=NORMAL)
                elif self.correspEntry[index][0] == 1:
                    for widget in [
                            self.addEntryB, self.addSubmenuB, self.deleteB,
                            self.nameE
                    ]:
                        widget.config(state=NORMAL)
                    self.nameE.config(takefocus=1)
                    self.nameCurrent.set(self.correspEntry[index][1]['name'])
                elif self.correspEntry[index][0] == 2:
                    for widget in [
                            self.deleteB, self.nameE, self.htmlE, self.browseB,
                            self.patternB, self.giB, self.resetB
                    ]:
                        widget.config(state=NORMAL)

                    self.nameE.config(takefocus=1)
                    self.htmlE.config(takefocus=1)

                    self.nameCurrent.set(self.correspEntry[index][1]['name'])
                    self.htmlCurrent.set(self.correspEntry[index][1]['file'])
                    self.resetVar.set(self.correspEntry[index][1]['reset'])

                    self.displayPattern(self.correspEntry[index][1]['psearch'])
                    self.displayGI(self.correspEntry[index][1]['gisearch'])

            self.current = now

        self.window.after(250, self.pollList)

    def change(self):
        if self.windowOpen:
            return
        else:
            self.windowOpen = 1

        self.window = Toplevel()
        self.window.title(_('Change custom menus'))
        self.window.protocol('WM_DELETE_WINDOW', self.c_cancel)

        # scrolled list with all submenus, entries

        self.list = v.ScrolledList(self.window, width=35, font='Courier')
        self.list.pack()
        self.current = None

        self.correspEntry = [[0, '', '', None, None]]
        self.list.insert('end', '*')
        self.c_buildList(self.customMenuList, 1)

        # buttons ... for currently selected entry

        f = Frame(self.window)
        self.addEntryB = Button(f,
                                text=_('Add entry'),
                                command=self.c_addEntry)
        self.addSubmenuB = Button(f,
                                  text=_('Add submenu'),
                                  command=self.c_addSubmenu)
        self.deleteB = Button(f, text=_('Delete'), command=self.c_delete)
        self.addEntryB.pack(side=LEFT, anchor=W)
        self.addSubmenuB.pack(side=LEFT, anchor=W)
        self.deleteB.pack(side=LEFT, anchor=W)
        f.pack(anchor=W)

        Frame(self.window, background='black', height=1,
              width=100).pack(expand=YES, fill=X, pady=10)

        Label(self.window, text=_('Name:')).pack(anchor=W)

        self.nameCurrent = StringVar()
        self.nameE = Entry(self.window,
                           width=40,
                           textvariable=self.nameCurrent,
                           takefocus=1)
        self.nameE.bind('<Return>', self.c_setName)
        self.nameE.bind('<Tab>', self.c_setName)
        self.nameE.pack(anchor=W)

        Frame(self.window, height=15, width=200).pack()

        Label(self.window, text=_('HTML file:')).pack(anchor=W)

        f = Frame(self.window)
        f.pack(anchor=W)
        self.htmlCurrent = StringVar()
        self.htmlE = Entry(f,
                           width=35,
                           textvariable=self.htmlCurrent,
                           takefocus=1)
        self.htmlE.pack(side=LEFT)

        self.browseB = Button(f,
                              text=_('Browse ...'),
                              command=self.c_browse,
                              height=1)
        self.browseB.pack(side=RIGHT)

        Frame(self.window, height=15, width=200).pack()

        f = Frame(self.window)
        self.patternB = Button(f,
                               text=_('Add pattern info'),
                               command=self.c_addPattern)
        self.patternB.pack(side=LEFT)
        self.giB = Button(f, text=_('Add game info'), command=self.c_addGI)
        self.giB.pack(side=LEFT)

        self.resetVar = IntVar()
        self.resetB = Checkbutton(f,
                                  text=_('Reset game list'),
                                  highlightthickness=0,
                                  variable=self.resetVar)
        self.resetB.pack(side=LEFT)
        f.pack(anchor=W)

        # OK, cancel buttons

        Frame(self.window, background='black', height=1,
              width=100).pack(expand=YES, fill=X, pady=10)

        f = Frame(self.window)
        f.pack(side=BOTTOM, anchor=E)
        Button(f, text=_('Cancel'), command=self.c_cancel).pack(side=RIGHT,
                                                                anchor=E)
        Button(f, text=_('OK'), command=self.c_OK).pack(side=RIGHT, anchor=E)

        self.list.list.select_set(0)
        self.pollList()

        self.window.update_idletasks()
        self.window.focus()
        # self.window.grab_set()
        self.window.wait_window()

        del self.window
        self.windowOpen = 0
Exemplo n.º 31
-1
class SpeciesListDialog:
    def __init__(self, parent):
        self.parent = parent
        self.gui = Toplevel(parent.guiRoot)
        self.gui.grab_set()
        self.gui.focus()

        self.gui.columnconfigure(0, weight=1)
        self.gui.rowconfigure(1, weight=1)

        Label(self.gui, text="Registered Species:").grid(row=0, column=0, pady=5, padx=5, sticky="w")
        self.listRegisteredSpecies = Listbox(self.gui, width=70)
        self.buttonAdd = Button(self.gui, text=" + ")
        self.buttonDel = Button(self.gui, text=" - ")
        self.listRegisteredSpecies.grid(row=1, column=0, columnspan=3, sticky="nswe", pady=5, padx=5)
        self.buttonAdd.grid(row=2, column=1, pady=5, padx=5)
        self.buttonDel.grid(row=2, column=2, pady=5, padx=5)

        # Set (minimum + max) Window size
        self.gui.update()
        self.gui.minsize(self.gui.winfo_width(), self.gui.winfo_height())
        #         self.gui.maxsize(self.gui.winfo_width(), self.gui.winfo_height())

        self.actionUpdate(None)
        self.gui.bind("<<Update>>", self.actionUpdate)
        self.gui.protocol("WM_DELETE_WINDOW", self.actionClose)

        self.buttonDel.bind("<ButtonRelease>", self.actionDel)
        self.buttonAdd.bind("<ButtonRelease>", self.actionAdd)

        self.gui.mainloop()

    def actionClose(self):
        self.parent.guiRoot.event_generate("<<Update>>", when="tail")
        self.gui.destroy()

    def actionUpdate(self, event):
        self.listRegisteredSpecies.delete(0, "end")
        for (taxid, name) in self.parent.optimizer.speciesList:
            self.listRegisteredSpecies.insert("end", taxid + ": " + name)

    def actionDel(self, event):
        try:
            selection = self.listRegisteredSpecies.selection_get()
            selectionSplit = selection.split(": ")
            self.parent.optimizer.speciesList.remove((selectionSplit[0], selectionSplit[1]))
            self.gui.event_generate("<<Update>>")
        except tkinter.TclError:
            # no selection
            pass

    def actionAdd(self, Event):
        SpeciesSearchDialog(self.parent, self)