Ejemplo n.º 1
0
    def __init__(self, parent, width, height):
        #Call the initializer of the class we're inheriting from
        Frame.__init__(self, parent)

        self.db = SpellingDatabase()

        student_list_frame = Frame(self)
        
        self.student_listpane = ListPane(student_list_frame, height=30, width = 35)
        self.student_listpane.singleClickFunc=self.display_details
        sort_options_list = ['First Name', 'Last Name']
        self.sort_v = StringVar()
        self.sort_v.set(sort_options_list[1])
        self.sort_option = OptionMenu(student_list_frame, self.sort_v, *sort_options_list, command=self.update_sort) 
        sort_label = Label(student_list_frame, text="Sort by:")
        title_label = Label(student_list_frame, text="Student Details")

        title_label.grid(row=0, column=0, sticky=W,pady=5)
        self.student_listpane.grid(row=1, column=0, columnspan=2)
        sort_label.grid(row=2, column=0, sticky=W, padx = 2)
        self.sort_option.grid(row=2, column=0, padx=50, sticky=W)
        
        student_details_frame=Frame(self) 
        
        fname_label = Label(student_details_frame, text="First Name:")
        lname_label = Label(student_details_frame, text="Last Name:")
        age_label = Label(student_details_frame, text="Birthday:")
        comments_label = Label(student_details_frame, text="Comments")

        self.fname_entry = Entry(student_details_frame, width=30)
        self.lname_entry = Entry(student_details_frame, width=30)
        self.age_entry = Entry(student_details_frame, width=30)
        self.comments_text = Text(student_details_frame, width=65, height=10)
        enable_edit_button = Button(student_details_frame, text="Edit Details", command=self.update_student)
        add_student_button = Button(student_details_frame, text="Add Student", command=self.insert_student)
        remove_student_button = Button(student_details_frame, text="Remove Student", command=self.remove_student)

        fname_label.grid(row=0, column=0, sticky=W, padx=3)
        lname_label.grid(row=1, column=0, sticky=W, padx=3)
        age_label.grid(row=2, column=0, sticky=W, padx=3)
        comments_label.grid(row=3, column=0, sticky=W, padx=3)
        self.fname_entry.grid(row=0, column=1, sticky=W)
        self.lname_entry.grid(row=1, column=1, sticky=W)
        self.age_entry.grid(row=2, column=1, sticky=W)
        self.comments_text.grid(row=4, column=0, columnspan=2, sticky=W, padx=10)
        enable_edit_button.grid(row=5, column=0, padx=7)
        add_student_button.grid(row=5, column=1, sticky=W)
        remove_student_button.grid(row=5, column=1, sticky=W, padx=110)
        
        student_list_frame.pack(side=LEFT)
        student_details_frame.pack(side=LEFT)

        #Load student table from database
        student_records = self.db.sql("SELECT last_name, first_name From students ORDER By last_name")
        names_list = []
        for record in student_records:
            names_list.append("%s, %s" % (record[0], record[1]))
        
        self.student_listpane.display(names_list)
Ejemplo n.º 2
0
    def __init__(self, parent, height, width, border_style, border_width, background_colour):
        #Call Frams's __init__
        Frame.__init__(self, parent) 
        #create the frame that holds the widgets on the left
        lists_frame = Frame(self)
        #Add custom ListPane widget
        self.lists_list_pane = ListPane(lists_frame, height = 25)
        self.lists_list_pane.singleClickFunc = self.displayWords
        #Add labels and Buttons
        lists_label = Label(lists_frame, text="Word Lists")
        import_button = Button(lists_frame, text="Import", command=self.importList)
        export_button = Button(lists_frame, text="Export", command=self.exportList)
        #Grid everything
        lists_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
        self.lists_list_pane.grid(row=1, column=0, columnspan=2)
        import_button.grid(row=2, column=0, sticky=W, padx=2)
        export_button.grid(row=2, column=0) 
        
        #create the container frame that holds the widgets on the right
        words_frame = Frame(self)
        #create custom ListPane widget
        self.words_list_pane = ListPane(words_frame,height = 25)
        self.words_list_pane.singleClickFunc = self.displayWordInfo
        #create labels and buttons
        self.speak_word_button = Button(words_frame, text="Speak Word", command=self.speakWord, state=DISABLED)
        self.speak_list_button = Button(words_frame,text="Speak List", command=self.speakList, state=DISABLED)
        stop_speech_button = Button(words_frame,text="Stop Speech", command=self.stopSpeech)
        words_label = Label(words_frame, text="Words in List")
        
        #grid everything
        words_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
        self.words_list_pane.grid(row=1, column=0, columnspan=3)
        self.speak_word_button.grid(row=2, column=0)
        self.speak_list_button.grid(row=2, column=1)
        stop_speech_button.grid(row=2, column=2)
        
        #Create the infoFrame
        info_frame = Frame(self, height=140, width=width, bd=border_width, bg=background_colour, relief=border_style)

        self.info_text = Text(info_frame, state=DISABLED, font=tkFont.Font(family="Tahoma", size=9))
        self.info_text.pack(fill=BOTH)
        
        lists_frame.grid(column=0, row=0)
        words_frame.grid(column=1, row=0)
        info_frame.grid(column=0, row=1, columnspan=2)
        info_frame.pack_propagate(0)
        
        #Create databse and Festival connections
        self.db = SpellingDatabase()
        self.fest = FestivalInterface()

        list_records = self.db.getLists()
        list_names = []
        for row in list_records:
            list_names.append(row[1])
        self.lists_list_pane.display(list_names)
        self.words_list_pane.display(['...'])
Ejemplo n.º 3
0
    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        self.db = SpellingDatabase()
        self.word_list = self.get_dictionary()
        self.list_list = self.get_lists()
        self.festival = FestivalInterface()
        self.init_gui()
Ejemplo n.º 4
0
    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        #Estabilish database connection
        self.db = SpellingDatabase()
        #Get words from database
        self.word_list = self.get_dictionary()
        #Retrieve list of lists from db
        self.list_list = self.get_lists()
        #Start festival process
        self.festival = FestivalInterface()
        #Create screens
        self.init_gui()
Ejemplo n.º 5
0
    def __init__(self, parent):

        self.parent = parent
        self.root = Tk()
        self.db = SpellingDatabase()
    
        self.loginFrame = Frame(self.root)
        self.loginFrame.pack()
        self.userEntry = Entry(self.loginFrame, width=15)
        self.passEntry = Entry(self.loginFrame, width=15, show='*')
        userLabel = Label(self.loginFrame, text="Username:"******"Password:"******"Login", command=self.login)
        buttonRegSwitch = Button(self.loginFrame, text="New User",
                                 command=self.viewRegister)

        userLabel.grid(row=0, column=0)
        self.userEntry.grid(row=0, column=1)
        passLabel.grid(row=1, column=0)
        self.passEntry.grid(row=1, column=1)
        buttonSubmit.grid(row=2, column=1)
        buttonRegSwitch.grid(row=2, column=0, padx=10)

        self.registerFrame = Frame(self.root)
        self.userRegEntry = Entry(self.registerFrame, width=15)
        self.passRegEntry = Entry(self.registerFrame, width=15, show='*')
        userRegLabel = Label(self.registerFrame, text="Username:"******"Password:"******"Register",
                                command=self.register)
        buttonBack = Button(self.registerFrame, text="Back",
                            command=self.viewLogin)

        userRegLabel.grid(row=0, column=0)
        self.userRegEntry.grid(row=0, column=1)
        passRegLabel.grid(row=1, column=0)
        self.passRegEntry.grid(row=1, column=1)
        buttonBack.grid(row=2, column=1)
        buttonRegister.grid(row=2, column=0, padx=10)

        self.root.mainloop()
Ejemplo n.º 6
0
class SpellingGame(Tk):
    """Main class for spelling aid. Manages the other screens and holds festival       and database connections"""
    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        #Estabilish database connection
        self.db = SpellingDatabase()
        #Get words from database
        self.word_list = self.get_dictionary()
        #Retrieve list of lists from db
        self.list_list = self.get_lists()
        #Start festival process
        self.festival = FestivalInterface()
        #Create screens
        self.init_gui()

    def get_lists(self):
        """Retrieve list of lists from database"""
        list_records = self.db.sql("""SELECT * FROM lists""")
        list_list = []
        for wordlist in list_records:
            list_list.append(WordList(wordlist))
        return list_list

    def update_lists(self):
        """Refresh the list-list"""
        self.list_list = self.get_lists()
            
        
    def get_dictionary(self):
        """Get dictionary words from database"""
        word_records = self.db.sql("""SELECT * FROM words WHERE
                              difficulty LIKE 'SB%'""")
        word_list = []
        for word in word_records:
            word_list.append(Word(word))
        return word_list
 

    def get_random_list(self, length):
        """Return a random list of words"""
        words = random.sample(self.word_list, length)
        return words

    def login(self, user):
        """Show the start screen as user logs in"""
        self.user = user
        self.login_frame.pack_forget()
        self.start_frame.welcomeMessage()
        self.start_frame.pack()

    def start_game(self, word_list):
        """Hide start screen and show game screen. Retrieve words for selected 
           list"""
        self.current_list = word_list
        if word_list.name != "Random List":
            word_records = self.db.getWords(word_list.name)
            self.current_list.words = [Word(word) for word in word_records]
        else:
            self.current_list.words = self.get_random_list(15)
        self.list_length = len(self.current_list.words)
        self.start_frame.pack_forget()
        self.results_frame.pack_forget()
        self.game_frame = GameFrame(self)
        self.game_frame.start()
        self.game_frame.pack()

    def show_results(self, time_elapsed):
        """Hide game frame and show results frame"""
        self.game_frame.pack_forget()
        self.results_frame.calculate(self.current_list, time_elapsed)
        self.results_frame.pack()

    def new_list(self):
        """Show start screen, hiding either results or list editor"""
        self.results_frame.pack_forget()
        self.list_editor.pack_forget()
        self.start_frame.update_list()
        self.start_frame.pack()

    def show_editor(self):
        """Hide start frame and show list editor"""
        self.start_frame.pack_forget()
        self.list_editor.pack()

    def init_gui(self):
        """Create the screens"""
        self.login_frame = LoginFrame(self)
        self.login_frame.pack()

        self.start_frame = StartFrame(self)

        self.results_frame = ResultsFrame(self)

        self.list_editor = ListEditor(self)


        self.mainloop()
Ejemplo n.º 7
0
class Login():
    
    def __init__(self, parent):

        self.parent = parent
        self.root = Tk()
        self.db = SpellingDatabase()
    
        self.loginFrame = Frame(self.root)
        self.loginFrame.pack()
        self.userEntry = Entry(self.loginFrame, width=15)
        self.passEntry = Entry(self.loginFrame, width=15, show='*')
        userLabel = Label(self.loginFrame, text="Username:"******"Password:"******"Login", command=self.login)
        buttonRegSwitch = Button(self.loginFrame, text="New User",
                                 command=self.viewRegister)

        userLabel.grid(row=0, column=0)
        self.userEntry.grid(row=0, column=1)
        passLabel.grid(row=1, column=0)
        self.passEntry.grid(row=1, column=1)
        buttonSubmit.grid(row=2, column=1)
        buttonRegSwitch.grid(row=2, column=0, padx=10)

        self.registerFrame = Frame(self.root)
        self.userRegEntry = Entry(self.registerFrame, width=15)
        self.passRegEntry = Entry(self.registerFrame, width=15, show='*')
        userRegLabel = Label(self.registerFrame, text="Username:"******"Password:"******"Register",
                                command=self.register)
        buttonBack = Button(self.registerFrame, text="Back",
                            command=self.viewLogin)

        userRegLabel.grid(row=0, column=0)
        self.userRegEntry.grid(row=0, column=1)
        passRegLabel.grid(row=1, column=0)
        self.passRegEntry.grid(row=1, column=1)
        buttonBack.grid(row=2, column=1)
        buttonRegister.grid(row=2, column=0, padx=10)

        self.root.mainloop()


    def login(self):
        usernameGiven = self.userEntry.get()
        passwordGiven = self.passEntry.get()
        userDetails = self.db.sql("""SELECT * FROM
                                  users WHERE username='******'"""
                                  %(usernameGiven.lower().strip()))
        if len(userDetails)==1:
            passHash = userDetails[0][2]
            if (hashlib.sha1(passwordGiven).hexdigest() == passHash):
                self.root.destroy()
                self.parent.setUser(User(userDetails[0]))
        else:
            print 'Invalid Username or Password'
            self.userEntry.delete(0, END)
            self.passEntry.delete(0, END)

    def register(self):
        username = self.userRegEntry.get()
        passwd = self.passRegEntry.get()
        if username != '' and passwd != '':
            username = username.lower().strip()
            passHash = hashlib.sha1(passwd).hexdigest()
            self.db.sql("""INSERT INTO users (username, passwd) VALUES 
                        ('%s', '%s')"""%(username, passHash))
            self.viewLogin()

    def viewRegister(self):
        self.loginFrame.pack_forget()
        self.registerFrame.pack()

    def viewLogin(self):
        self.registerFrame.pack_forget()
        self.loginFrame.pack()
Ejemplo n.º 8
0
class ListView(Frame):

    def __init__(self, parent, height, width, border_style, border_width, background_colour):
        #Call Frams's __init__
        Frame.__init__(self, parent) 
        #create the frame that holds the widgets on the left
        lists_frame = Frame(self)
        #Add custom ListPane widget
        self.lists_list_pane = ListPane(lists_frame, height = 25)
        self.lists_list_pane.singleClickFunc = self.displayWords
        #Add labels and Buttons
        lists_label = Label(lists_frame, text="Word Lists")
        import_button = Button(lists_frame, text="Import", command=self.importList)
        export_button = Button(lists_frame, text="Export", command=self.exportList)
        #Grid everything
        lists_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
        self.lists_list_pane.grid(row=1, column=0, columnspan=2)
        import_button.grid(row=2, column=0, sticky=W, padx=2)
        export_button.grid(row=2, column=0) 
        
        #create the container frame that holds the widgets on the right
        words_frame = Frame(self)
        #create custom ListPane widget
        self.words_list_pane = ListPane(words_frame,height = 25)
        self.words_list_pane.singleClickFunc = self.displayWordInfo
        #create labels and buttons
        self.speak_word_button = Button(words_frame, text="Speak Word", command=self.speakWord, state=DISABLED)
        self.speak_list_button = Button(words_frame,text="Speak List", command=self.speakList, state=DISABLED)
        stop_speech_button = Button(words_frame,text="Stop Speech", command=self.stopSpeech)
        words_label = Label(words_frame, text="Words in List")
        
        #grid everything
        words_label.grid(row=0, column=0, sticky=W, pady=3, padx=2)
        self.words_list_pane.grid(row=1, column=0, columnspan=3)
        self.speak_word_button.grid(row=2, column=0)
        self.speak_list_button.grid(row=2, column=1)
        stop_speech_button.grid(row=2, column=2)
        
        #Create the infoFrame
        info_frame = Frame(self, height=140, width=width, bd=border_width, bg=background_colour, relief=border_style)

        self.info_text = Text(info_frame, state=DISABLED, font=tkFont.Font(family="Tahoma", size=9))
        self.info_text.pack(fill=BOTH)
        
        lists_frame.grid(column=0, row=0)
        words_frame.grid(column=1, row=0)
        info_frame.grid(column=0, row=1, columnspan=2)
        info_frame.pack_propagate(0)
        
        #Create databse and Festival connections
        self.db = SpellingDatabase()
        self.fest = FestivalInterface()

        list_records = self.db.getLists()
        list_names = []
        for row in list_records:
            list_names.append(row[1])
        self.lists_list_pane.display(list_names)
        self.words_list_pane.display(['...'])


    def importList(self):
        filename = tkFileDialog.askopenfilename(filetypes = (("Tldr Files", "*.tldr"),))
        if str(filename) == "":
            return
        tldr_parse = TldrParser(filename)
        list_name = filename[:-5].split('/')[-1]
        if self.db.importList(list_name, tldr_parse.getWordList(), tldr_parse.getSource(), tldr_parse.getDateEdited(), tldr_parse.getListSize()):
            self.lists_list_pane.insert(list_name)
        else:
            print "List with that name already exists!!!"
        self.db.commit()


    def exportList(self):
        filename = tkFileDialog.asksaveasfilename(filetypes = (("Tldr Files", "*.tldr"),), initialfile = self.lists_list_pane.get())
        if str(filename) == "":
            return
        export_list = self.db.getList(self.lists_list_pane.get())[0]
        word_list = self.db.getWords(self.lists_list_pane.get())
        word_dict = {}
        for word in word_list:
            word = word[0]
            word_record = self.db.getWord(word)[0]
            word_dict[word] = [word_record[2],word_record[3],word_record[4]]
        tldr_parse = TldrParser()
        tldr_parse.setWordList(word_dict)
        tldr_parse.setSource(export_list[2])
        tldr_parse.setDateEdited(str(date.today()))
        tldr_parse.setListSize(export_list[4])
        tldr_parse.writetldr(filename)


    def speakWord(self):
        word = self.words_list_pane.get()
        self.fest.speech(word)
        
    def speakList(self):
        word_list = self.words_list_pane.getDisplayed()
        long_sentence = ""
        for word in word_list:
            long_sentence += " %s," % (word)
        self.fest.speech(long_sentence)
        
    def stopSpeech(self):
        self.fest.resetSpeech()
    
    def displayWords(self, item_index):
        word_records = self.db.getWords(self.lists_list_pane.get(item_index))
        word_names = []
        for row in word_records:
            word_names.append(str(row[1]))
        word_names.sort(key=str.lower)
        self.words_list_pane.display(word_names)
        
        list_record = self.db.getList(self.lists_list_pane.get(item_index))
        if len(list_record) > 0:
            list_record = list_record[0]
            info_string = """List: %s

Source: %s
Date Edited: %s
Number of Words in List: %s""" % (list_record[1], list_record[2], list_record[3], list_record[4])
            self.info_text.configure(state=NORMAL)
            self.info_text.delete(1.0, END)
            self.info_text.insert(1.0, info_string)
            self.info_text.configure(state=DISABLED)

            self.speak_word_button.configure(state=DISABLED)
            self.speak_list_button.configure(state=NORMAL)
        else:
            self.info_text.configure(state=NORMAL)
            self.info_text.delete(1.0, END)
            self.info_text.insert(1.0, "There are no lists in the database.\nImport one or create one")
            self.info_text.configure(state=DISABLED)

    def displayWordInfo(self, item_index): 
        word_record = self.db.getWord(self.words_list_pane.get(item_index))
        if len(word_record) > 0:
            word_record = word_record[0]
            info_string = """Word: %s

Definition: %s
Usage: "%s"
Difficulty: %s""" % (word_record[1], word_record[2], word_record[3], word_record[4])
            self.info_text.configure(state=NORMAL)
            self.info_text.delete(1.0, END)
            self.info_text.insert(1.0, info_string)
            self.info_text.configure(state=DISABLED)
            
            self.speak_word_button.configure(state=NORMAL)
    
    def update(self):        
        list_records = self.db.getLists()
        list_names = []
        for row in list_records:
            list_names.append(row[1])
        self.lists_list_pane.display(list_names)
        self.words_list_pane.display(['...'])
Ejemplo n.º 9
0
class CreateView(Frame):
    """A class describing the list creation page of the UI"""

    def __init__(self, parent, height, width, border_style, border_width,
                 background_colour):

        Frame.__init__(self, parent, height=height, width=width)

        #Connect to the word/list database 
        self.db = SpellingDatabase()
        self.parent = parent
		
        #Create a frame containing a menu for choosing word category
        categorymenu_frame = Frame(self, width=340, height=30, relief=SUNKEN, bd=1)
        categorymenu_frame.pack_propagate(0)
        categorymenu_label = Label(categorymenu_frame, text="Category:")
        wordlist_title = Label(categorymenu_frame, text="Select Words")
        #Menu options: one for each category of word
        optionList = ("Child", "ESOL", "Spelling Bee", "Custom")
        self.category_v = StringVar()
        self.category_v.set(optionList[0])
        #Command causes word browser to be populated with words from chosen category
        self.category_menu = OptionMenu(categorymenu_frame, self.category_v, *optionList, command=self.update_category)
        self.category_menu.config(width=10)
        self.category_menu.pack(side=RIGHT)
        categorymenu_label.pack(side=RIGHT)
        wordlist_title.pack(side=LEFT)
        
        #Create frame for the title of the user list panel
        userlist_title_frame = Frame(self, width=340, height=30)
        userlist_title_frame.pack_propagate(0)
        userlist_title = Label(userlist_title_frame, text="Your New List")
        userlist_title_frame.grid(column=2, row=0)
        userlist_title.pack(side=LEFT)

        #Create frame for middle bar containing transfer buttons
	middlebar_frame = Frame(self, width = 70, height=400)
        middlebar_frame.grid_propagate(0)
        #Buttons transfer words from one list to the other
        transfer_right_button = Button(middlebar_frame, text="->", command=self.transfer_right)
        transfer_left_button = Button(middlebar_frame, text="<-", command=self.transfer_left)
        #Press this button to generate a random list from the current category
        random_list_button = Button(middlebar_frame, text="Create", command=self.random_list)
        random_list_label = Label(middlebar_frame, text="Random\nList")
        self.random_list_entry = Entry(middlebar_frame, width=3, justify=RIGHT)
        self.random_list_entry.insert(0, 15) 
	transfer_left_button.grid(column=0, row=1, padx=15, pady=50)
        transfer_right_button.grid(column=0, row=0, padx=15, pady=50)
        random_list_label.grid(column=0, row=2, pady=3)
        self.random_list_entry.grid(column=0, row=3, pady=3)
        random_list_button.grid(column=0, row=4, pady=3)
        middlebar_frame.grid(column=1, row=1)
        #random_list_button.grid(column=0, row=2)

        #Create frame for "Add New Word" menu
        addword_frame = Frame(self, width=340, height=150, bd=2, relief=SUNKEN)
        addword_frame.grid_propagate(0)
        addword_label = Label(addword_frame, text = "Add a new word:")
        word_label = Label(addword_frame, text="Word:")
        def_label = Label(addword_frame, text="Definition:")
        use_label = Label(addword_frame, text="Example of Use:")
        difficulty_label = Label(addword_frame, text="Difficulty:")
        #Entry boxes and an option menu allowing the user to enter attributes of the new word
        self.addword_entry = Entry(addword_frame, width = 28)
        self.adddefinition_entry = Entry(addword_frame, width=28)
        self.adduse_entry = Entry(addword_frame, width=28)
        self.difficulty_v = StringVar()
        self.difficulty_v.set("1")
        difficulty_list = range(1,9)
        self.difficulty_menu = OptionMenu(addword_frame, self.difficulty_v, *difficulty_list)
        #Pressing this button adds the new word to the database
        addword_button = Button(addword_frame, text = "Add", command = self.add_word)
        addword_label.grid(row=0, column=0, sticky=W)
        addword_button.grid(row=0, column=1, pady=2, sticky=E)
        word_label.grid(row=1, column=0, sticky=W)
        def_label.grid(row=2, column=0, sticky=W)
        use_label.grid(row=3, column=0, sticky=W)
        difficulty_label.grid(row=4, column=0, sticky=W)
        self.addword_entry.grid(row=1, column=1, pady=2, sticky=E)
        self.adddefinition_entry.grid(row=2, column=1, pady=2, sticky=E)
        self.adduse_entry.grid(row=3, column=1, pady=2, sticky=E)
        self.difficulty_menu.grid(row=4, column=1, pady=2, sticky=E)
        addword_frame.grid(column=0, row=2)
        
        #Frame for menu allowing users to save their new lists
        savelist_frame = Frame(self, width=340, height=30, bd=2, relief=SUNKEN)
        savelist_frame.pack_propagate(0)
        savelist_label = Label(savelist_frame, text="List Name:")
        #User enters the name of the new list here
        self.savelist_entry = Entry(savelist_frame, width=25)
        #Pressing this button adds the new list to the database
        savelist_button = Button(savelist_frame, text="Save", command = self.save_list)
        savelist_label.pack(side=LEFT)
        savelist_button.pack(side=RIGHT)
        self.savelist_entry.pack(side=RIGHT, padx=5)
        savelist_frame.grid(column=2, row=2, sticky=N, pady=5)

        #Create list panel for browsing the words stored in database
        self.wordbrowse_frame = ListPane(self, height=25) 
        categorymenu_frame.grid(column=0, row=0)
        self.wordbrowse_frame.grid(column=0, row=1, sticky=N)
        #Populate the list with words from database
        self.update_category()
        #Double-clicking a word has same effect as transfer button
        self.wordbrowse_frame.doubleClickFunc = self.transfer_right

        #Create list panel for holding/displaying the list being built
        self.userlist_frame = ListPane(self, height=25)
        self.userlist_frame.grid(column=2, row=1, sticky=N)
        #Double-clicking a word has same effect as transfer button
        self.userlist_frame.doubleClickFunc = self.transfer_left

    def transfer_right(self, index=None):
        """Moves a word from word browser to user list"""
        if index == None:
            index = self.wordbrowse_frame.listbox.curselection()
        if self.wordbrowse_frame.get()!=None:
            #Add selection to user list
            self.userlist_frame.insert(self.wordbrowse_frame.get())
            #Remove selection from word browser
            word_list = list(self.wordbrowse_frame.getDisplayed())
            word_list.remove(self.wordbrowse_frame.get())
            self.wordbrowse_frame.display(word_list)
            #Ensure current list contents stay visible and select the next word
            self.wordbrowse_frame.listbox.see(index)
            self.wordbrowse_frame.listbox.selection_set(index)

    def transfer_left(self, index=None):
        """Moves a word from user list back to word browser"""
        if index == None:
            index = self.userlist_frame.listbox.curselection()
        if self.userlist_frame.get()!=None:
            word_list = list(self.wordbrowse_frame.getDisplayed())
            word_list.append(self.userlist_frame.get())
            word_list.sort(key=str.lower)
            self.wordbrowse_frame.display(word_list)
            word_list = list(self.userlist_frame.getDisplayed())
            word_list.remove(self.userlist_frame.get())
            self.userlist_frame.display(word_list)
            self.userlist_frame.listbox.see(index)
            self.userlist_frame.listbox.select_set(index)

    def random_list(self):
        source_list = self.wordbrowse_frame.getDisplayed()
        list_size = int(self.random_list_entry.get())
        if list_size > len(source_list):
            list_size = len(source_list)
            self.random_list_entry.delete(0, END)
            self.random_list_entry.insert(0, list_size)
        generated_list = random.sample(source_list, list_size)
        self.userlist_frame.display(generated_list)

    def update_category(self, event=None):
        """Populates the word browser with words from the selected category"""
        category = self.category_v.get()
        if category == "Child":
            category = "CL"
        elif category == "ESOL":
            category = "AL"
        elif category == "Spelling Bee":
            category = "SB"
        else: category = "UL"
        word_records = self.db.sql("SELECT word FROM words WHERE difficulty LIKE '%s%s'"%(category, "%"))
        word_list = []
        for word in word_records:
            word_list.append(str(word[0]))
        word_list.sort(key=str.lower)
        self.wordbrowse_frame.display(word_list)

    def add_word(self):
        """Adds a new word to the database with the attributes entered by the user"""
        if self.addword_entry.get() == "":
            return
        self.db.sql("INSERT INTO words (word, definition, usage, difficulty) VALUES ('%s', '%s', '%s', 'UL%s')"%(self.addword_entry.get(), self.adddefinition_entry.get(), self.adduse_entry.get(), self.difficulty_v.get()))
        self.addword_entry.delete(0, END)
        self.adddefinition_entry.delete(0, END)
        self.adduse_entry.delete(0, END)
        #User words are added to a 'Custom' category
        self.category_v.set("Custom")
        self.update_category(None)
        self.db.commit()

    def save_list(self):
        """Adds the list contained in the user list panel to the database"""
        word_list = self.userlist_frame.getDisplayed()
        self.db.createList(word_list, self.savelist_entry.get())
        self.savelist_entry.delete(0, END)
        self.db.commit()
        self.parent.parent.update_lists()
Ejemplo n.º 10
0
    def __init__(self, parent, height, width, border_style, border_width,
                 background_colour):

        Frame.__init__(self, parent, height=height, width=width)

        #Connect to the word/list database 
        self.db = SpellingDatabase()
        self.parent = parent
		
        #Create a frame containing a menu for choosing word category
        categorymenu_frame = Frame(self, width=340, height=30, relief=SUNKEN, bd=1)
        categorymenu_frame.pack_propagate(0)
        categorymenu_label = Label(categorymenu_frame, text="Category:")
        wordlist_title = Label(categorymenu_frame, text="Select Words")
        #Menu options: one for each category of word
        optionList = ("Child", "ESOL", "Spelling Bee", "Custom")
        self.category_v = StringVar()
        self.category_v.set(optionList[0])
        #Command causes word browser to be populated with words from chosen category
        self.category_menu = OptionMenu(categorymenu_frame, self.category_v, *optionList, command=self.update_category)
        self.category_menu.config(width=10)
        self.category_menu.pack(side=RIGHT)
        categorymenu_label.pack(side=RIGHT)
        wordlist_title.pack(side=LEFT)
        
        #Create frame for the title of the user list panel
        userlist_title_frame = Frame(self, width=340, height=30)
        userlist_title_frame.pack_propagate(0)
        userlist_title = Label(userlist_title_frame, text="Your New List")
        userlist_title_frame.grid(column=2, row=0)
        userlist_title.pack(side=LEFT)

        #Create frame for middle bar containing transfer buttons
	middlebar_frame = Frame(self, width = 70, height=400)
        middlebar_frame.grid_propagate(0)
        #Buttons transfer words from one list to the other
        transfer_right_button = Button(middlebar_frame, text="->", command=self.transfer_right)
        transfer_left_button = Button(middlebar_frame, text="<-", command=self.transfer_left)
        #Press this button to generate a random list from the current category
        random_list_button = Button(middlebar_frame, text="Create", command=self.random_list)
        random_list_label = Label(middlebar_frame, text="Random\nList")
        self.random_list_entry = Entry(middlebar_frame, width=3, justify=RIGHT)
        self.random_list_entry.insert(0, 15) 
	transfer_left_button.grid(column=0, row=1, padx=15, pady=50)
        transfer_right_button.grid(column=0, row=0, padx=15, pady=50)
        random_list_label.grid(column=0, row=2, pady=3)
        self.random_list_entry.grid(column=0, row=3, pady=3)
        random_list_button.grid(column=0, row=4, pady=3)
        middlebar_frame.grid(column=1, row=1)
        #random_list_button.grid(column=0, row=2)

        #Create frame for "Add New Word" menu
        addword_frame = Frame(self, width=340, height=150, bd=2, relief=SUNKEN)
        addword_frame.grid_propagate(0)
        addword_label = Label(addword_frame, text = "Add a new word:")
        word_label = Label(addword_frame, text="Word:")
        def_label = Label(addword_frame, text="Definition:")
        use_label = Label(addword_frame, text="Example of Use:")
        difficulty_label = Label(addword_frame, text="Difficulty:")
        #Entry boxes and an option menu allowing the user to enter attributes of the new word
        self.addword_entry = Entry(addword_frame, width = 28)
        self.adddefinition_entry = Entry(addword_frame, width=28)
        self.adduse_entry = Entry(addword_frame, width=28)
        self.difficulty_v = StringVar()
        self.difficulty_v.set("1")
        difficulty_list = range(1,9)
        self.difficulty_menu = OptionMenu(addword_frame, self.difficulty_v, *difficulty_list)
        #Pressing this button adds the new word to the database
        addword_button = Button(addword_frame, text = "Add", command = self.add_word)
        addword_label.grid(row=0, column=0, sticky=W)
        addword_button.grid(row=0, column=1, pady=2, sticky=E)
        word_label.grid(row=1, column=0, sticky=W)
        def_label.grid(row=2, column=0, sticky=W)
        use_label.grid(row=3, column=0, sticky=W)
        difficulty_label.grid(row=4, column=0, sticky=W)
        self.addword_entry.grid(row=1, column=1, pady=2, sticky=E)
        self.adddefinition_entry.grid(row=2, column=1, pady=2, sticky=E)
        self.adduse_entry.grid(row=3, column=1, pady=2, sticky=E)
        self.difficulty_menu.grid(row=4, column=1, pady=2, sticky=E)
        addword_frame.grid(column=0, row=2)
        
        #Frame for menu allowing users to save their new lists
        savelist_frame = Frame(self, width=340, height=30, bd=2, relief=SUNKEN)
        savelist_frame.pack_propagate(0)
        savelist_label = Label(savelist_frame, text="List Name:")
        #User enters the name of the new list here
        self.savelist_entry = Entry(savelist_frame, width=25)
        #Pressing this button adds the new list to the database
        savelist_button = Button(savelist_frame, text="Save", command = self.save_list)
        savelist_label.pack(side=LEFT)
        savelist_button.pack(side=RIGHT)
        self.savelist_entry.pack(side=RIGHT, padx=5)
        savelist_frame.grid(column=2, row=2, sticky=N, pady=5)

        #Create list panel for browsing the words stored in database
        self.wordbrowse_frame = ListPane(self, height=25) 
        categorymenu_frame.grid(column=0, row=0)
        self.wordbrowse_frame.grid(column=0, row=1, sticky=N)
        #Populate the list with words from database
        self.update_category()
        #Double-clicking a word has same effect as transfer button
        self.wordbrowse_frame.doubleClickFunc = self.transfer_right

        #Create list panel for holding/displaying the list being built
        self.userlist_frame = ListPane(self, height=25)
        self.userlist_frame.grid(column=2, row=1, sticky=N)
        #Double-clicking a word has same effect as transfer button
        self.userlist_frame.doubleClickFunc = self.transfer_left
Ejemplo n.º 11
0
class StudentView(Frame):
    def __init__(self, parent, width, height):
        #Call the initializer of the class we're inheriting from
        Frame.__init__(self, parent)

        self.db = SpellingDatabase()

        student_list_frame = Frame(self)
        
        self.student_listpane = ListPane(student_list_frame, height=30, width = 35)
        self.student_listpane.singleClickFunc=self.display_details
        sort_options_list = ['First Name', 'Last Name']
        self.sort_v = StringVar()
        self.sort_v.set(sort_options_list[1])
        self.sort_option = OptionMenu(student_list_frame, self.sort_v, *sort_options_list, command=self.update_sort) 
        sort_label = Label(student_list_frame, text="Sort by:")
        title_label = Label(student_list_frame, text="Student Details")

        title_label.grid(row=0, column=0, sticky=W,pady=5)
        self.student_listpane.grid(row=1, column=0, columnspan=2)
        sort_label.grid(row=2, column=0, sticky=W, padx = 2)
        self.sort_option.grid(row=2, column=0, padx=50, sticky=W)
        
        student_details_frame=Frame(self) 
        
        fname_label = Label(student_details_frame, text="First Name:")
        lname_label = Label(student_details_frame, text="Last Name:")
        age_label = Label(student_details_frame, text="Birthday:")
        comments_label = Label(student_details_frame, text="Comments")

        self.fname_entry = Entry(student_details_frame, width=30)
        self.lname_entry = Entry(student_details_frame, width=30)
        self.age_entry = Entry(student_details_frame, width=30)
        self.comments_text = Text(student_details_frame, width=65, height=10)
        enable_edit_button = Button(student_details_frame, text="Edit Details", command=self.update_student)
        add_student_button = Button(student_details_frame, text="Add Student", command=self.insert_student)
        remove_student_button = Button(student_details_frame, text="Remove Student", command=self.remove_student)

        fname_label.grid(row=0, column=0, sticky=W, padx=3)
        lname_label.grid(row=1, column=0, sticky=W, padx=3)
        age_label.grid(row=2, column=0, sticky=W, padx=3)
        comments_label.grid(row=3, column=0, sticky=W, padx=3)
        self.fname_entry.grid(row=0, column=1, sticky=W)
        self.lname_entry.grid(row=1, column=1, sticky=W)
        self.age_entry.grid(row=2, column=1, sticky=W)
        self.comments_text.grid(row=4, column=0, columnspan=2, sticky=W, padx=10)
        enable_edit_button.grid(row=5, column=0, padx=7)
        add_student_button.grid(row=5, column=1, sticky=W)
        remove_student_button.grid(row=5, column=1, sticky=W, padx=110)
        
        student_list_frame.pack(side=LEFT)
        student_details_frame.pack(side=LEFT)

        #Load student table from database
        student_records = self.db.sql("SELECT last_name, first_name From students ORDER By last_name")
        names_list = []
        for record in student_records:
            names_list.append("%s, %s" % (record[0], record[1]))
        
        self.student_listpane.display(names_list)
    
    def update_sort(self, option):
        order_by=""
        if option == "First Name": order_by = 'first_name'
        else: order_by = 'last_name'
        
        student_records = self.db.sql("SELECT last_name, first_name From students ORDER By %s" % order_by)
        names_list = []
        for record in student_records:
            if option == "First Name": names_list.append("%s %s" % (record[1], record[0]))
            else: names_list.append("%s, %s" % (record[0], record[1]))
        self.student_listpane.display(names_list)
    
    def display_details(self, item_index):
        if len(self.student_listpane.getDisplayed()) == 0: return
        if self.fname_entry.get() == "" and self.lname_entry.get() == "": return
        self.selected_student = item_index
        first_name = ""
        last_name = ""
        if self.sort_v.get() == "First Name":
            first_name, last_name = self.student_listpane.get(item_index).split(' ')
        else:
            last_name, first_name = self.student_listpane.get(item_index).split(', ')
        student_record = self.db.sql("SELECT * from students where first_name = '%s' and last_name = '%s'" % (first_name, last_name))[0]
        self.fname_entry.delete(0, END)
        self.fname_entry.insert(0, first_name)
        self.lname_entry.delete(0, END)
        self.lname_entry.insert(0, last_name)
        self.age_entry.delete(0, END)
        self.age_entry.insert(0, student_record[3])
        self.comments_text.delete(1.0, END)
        self.comments_text.insert(1.0, student_record[4])

    def remove_student(self):
        if self.fname_entry.get() == "" and self.lname_entry.get() == "":
            return
        first_name = ""
        last_name = ""
        if len(self.student_listpane.get(self.selected_student))==0: return
        if self.sort_v.get() == "First Name":
            first_name, last_name = self.student_listpane.get(self.selected_student).split(' ')
        else:
            last_name, first_name = self.student_listpane.get(self.selected_student).split(', ')
        self.db.sql("DELETE FROM students where first_name = '%s' and last_name = '%s'" % (first_name, last_name))
        self.db.commit()
        self.update_sort(self.sort_v.get())
    
    def update_student(self):
        if len(self.student_listpane.getDisplayed()) == 0: return
        if self.fname_entry.get() == "" and self.lname_entry.get() == "": return

        old_first_name = ""
        old_last_name = ""
        if self.sort_v.get() == "First Name":
            old_first_name, old_last_name = self.student_listpane.get(self.selected_student).split(' ')
        else:
            old_last_name, old_first_name = self.student_listpane.get(self.selected_student).split(', ')
        
        self.db.update_student(old_first_name, old_last_name, self.fname_entry.get(), self.lname_entry.get(), self.age_entry.get(), self.comments_text.get(1.0,END))
        self.db.commit()
        self.update_sort(self.sort_v.get())
            
    def insert_student(self):
        current_students = self.student_listpane.getDisplayed()
        if self.fname_entry.get() == "" and self.lname_entry.get() == "":
            return
        for student in current_students:
            first_name = ""
            last_name = ""
            if self.sort_v.get() == "First Name":
                first_name, last_name = student.split(' ')
            else:
                last_name, first_name = student.split(', ')
           
            if first_name == self.fname_entry.get() and last_name == self.lname_entry.get():
                return

        self.db.addStudent(self.fname_entry.get(), self.lname_entry.get(), self.age_entry.get(), self.comments_text.get(1.0, END))
        self.db.commit()
        self.update_sort(self.sort_v.get())
Ejemplo n.º 12
0
class SpellingGame(Tk):

    def __init__(self):

        Tk.__init__(self)
        self.title('Spelling Game')
        self.db = SpellingDatabase()
        self.word_list = self.get_dictionary()
        self.list_list = self.get_lists()
        self.festival = FestivalInterface()
        self.init_gui()

    def get_lists(self):
        list_records = self.db.sql("""SELECT * FROM lists""")
        list_list = []
        for wordlist in list_records:
            list_list.append(WordList(wordlist))
        return list_list

    def update_lists(self):
        self.list_list = self.get_lists()
            
        
    def get_dictionary(self):
        word_records = self.db.sql("""SELECT * FROM words WHERE
                              difficulty LIKE 'SB%'""")
        word_list = []
        for word in word_records:
            word_list.append(Word(word))
        return word_list
 

    def get_random_list(self, length):
        words = random.sample(self.word_list, length)
        return words

    def login(self, user):
        self.user = user
        self.login_frame.pack_forget()
        self.start_frame.welcomeMessage()
        self.start_frame.pack()

    def start_game(self, word_list):
        self.current_list = word_list
        if word_list.name != "Random List":
            word_records = self.db.getWords(word_list.name)
            self.current_list.words = [Word(word) for word in word_records]
        else:
            self.current_list.words = self.get_random_list(15)
        self.list_length = len(self.current_list.words)
        self.start_frame.pack_forget()
        self.results_frame.pack_forget()
        self.game_frame = GameFrame(self)
        self.game_frame.start()
        self.game_frame.pack()

    def show_results(self, time_elapsed):
        self.game_frame.pack_forget()
        self.results_frame.calculate(self.current_list, time_elapsed)
        self.results_frame.pack()

    def new_list(self):
        self.results_frame.pack_forget()
        self.list_editor.pack_forget()
        self.start_frame.update_list()
        self.start_frame.pack()

    def show_editor(self):
        self.start_frame.pack_forget()
        self.list_editor.pack()

    def init_gui(self):

        self.login_frame = LoginFrame(self)
        self.login_frame.pack()

        self.start_frame = StartFrame(self)

        self.results_frame = ResultsFrame(self)

        self.list_editor = ListEditor(self)


        self.mainloop()