User:DhanakBot/szulhalGUI.py

A Wikipédiából, a szabad lexikonból.

# -*- coding: utf-8  -*-
"""
Az életrajzi robot GUI kódja.
"""

from Tkinter import *

class SzulHalGUI:
    def __init__(self, people):
        self.people = people
        self.okayed = False

        self.root = Tk()
        self.root.title(u"SzulHalGUI")

        label = Label(self.root, text=u"Válaszd ki azokat, amiket nem sikerült helyesen felismernem:")
        label.pack(side=TOP, anchor=W, padx=5, pady=5)
        
        listframe = Frame(self.root)
        listframe.pack(fill=BOTH, expand=1)

        vscrollbar = Scrollbar(listframe, orient=VERTICAL)
        hscrollbar = Scrollbar(listframe, orient=HORIZONTAL)
        listbox = Listbox(listframe, selectmode=MULTIPLE, yscrollcommand=vscrollbar.set,
                          xscrollcommand=hscrollbar.set, height=25, width=150)
        vscrollbar.config(command=listbox.yview)
        vscrollbar.pack(side=RIGHT, fill=Y)
        hscrollbar.config(command=listbox.xview)
        hscrollbar.pack(side=BOTTOM, fill=X)
        for (line, (name, by, bd, dy, dd, desc)) in people:
            listbox.insert(END, line)
            entry = u"    %s szül: %s. %s." % (name, by, bd)
            if dy and dd:
                entry += u" hal: %s. %s." % (dy, dd)
            listbox.insert(END,  entry + u" leírás: " + desc)
            listbox.insert(END, "")
        listbox.pack(side=LEFT, fill=BOTH, expand=1)
        self.listbox = listbox

        buttonframe = Frame(self.root)
        buttonframe.pack(side=BOTTOM, fill=X, padx=5, pady=5)
        cancel = Button(buttonframe, text="Mégse", command=self.root.destroy, width=15)
        cancel.pack(side=RIGHT)
        ok = Button(buttonframe, text="OK", command=self.ok, width=15)
        ok.pack(side=RIGHT, padx=5)

    def ok(self):
        self.okayed = True
        self.root.quit()
        

    def display(self):
        self.root.mainloop()
        if not self.okayed:
            return None
        else:
            selected = []
            notSelected = []
        
            for i in range(len(self.people)):
                if self.listbox.select_includes(3*i) or self.listbox.select_includes(3*i+1):
                    notSelected.append(self.people[i][1])
                else:
                    selected.append(self.people[i][1])
                    
            self.root.destroy()
            return (selected, notSelected)

if __name__ == "__main__":
    print SzulHalGUI([(u"xxxx", (u"Józsi", "1976", "augusztus 12", None, None, "senkifia")),
                      (u"yyyy", (u"Marcsi", "1982", u"január 23", None, None, u"senkilánya"))]).display()