Пример #1
0
    def __init__(self, parent):
        Frame.__init__(self, parent, background="white")
        self.parent = parent
        self.e = SkypeChatlogExporter()
        self.m = SkypeMarkov()
        self.phrase = None
        self.e.load_database(db_path)
        self.m.build_corpus(self.e.get_clean_data())

        self.init_ui()
        print("Ready")
Пример #2
0
class MarkovApp(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent, background="white")
        self.parent = parent
        self.e = SkypeChatlogExporter()
        self.m = SkypeMarkov()
        self.phrase = None
        self.e.load_database(db_path)
        self.m.build_corpus(self.e.get_clean_data())

        self.init_ui()
        print("Ready")

    def init_ui(self):
        self.parent.title("Skype Markov Bot")
        self.parent.resizable(FALSE, FALSE)

        self.main_frame = Frame(self, relief=RAISED, borderwidth=1)
        self.main_frame.pack(fill=BOTH, expand=1)

        self.pack(fill=BOTH, expand=1)

        Label(self.main_frame, text="Loaded from %s" % db_path, height=2,
              wraplength=490).pack()

        self.text = Text(self.main_frame, state=DISABLED, height=10, wrap=WORD)
        self.text.pack()
        self.scale = Scale(self.main_frame, from_=15, to=100, length=100,
                           orient=HORIZONTAL)
        self.scale.set(50)
        Label(self.main_frame, text="Max phrase length (in words)").pack(side=BOTTOM)
        self.scale.pack(side=BOTTOM)

        self.add_buttons()
        self.center_window()

    def generate_phrase(self):
        def callback():
            self.text["state"] = NORMAL
            self.text.delete("1.0", END)
            self.text.insert("1.0", self.m.generate_phrase(self.scale.get()))
            self.text["state"] = DISABLED

        threading.Thread(target=callback).start()

    def copy_to_clipboard(self):
        self.parent.clipboard_clear()
        self.parent.clipboard_append(self.text.get("1.0", END))

    def center_window(self):
        w, h = 500, 400

        sw = self.parent.winfo_screenwidth()
        sh = self.parent.winfo_screenheight()

        x = (sw - w) / 2
        y = (sh - h) / 2
        self.parent.geometry('%dx%d+%d+%d' % (w, h, x, y))

    def add_buttons(self):
        Button(self, text="Quit", command=self.quit).pack(side=RIGHT)
        self.copy = Button(self, text="Copy to Clipboard",
                           command=self.copy_to_clipboard)
        self.copy.pack(side=LEFT)
        self.new_phrase = Button(self, text="New Phrase",
                                 command=self.generate_phrase)
        self.new_phrase.pack(side=LEFT)