Ejemplo n.º 1
0
    def __init__(self):
        self.timer_id = 0
        self.trainer = Quiz_Trainer()
        # gconf #
        self.gconf_watcher = Gconf_Prefs()
        quiz_file_path = self.gconf_watcher.gconf_client.get_string(
                self.gconf_watcher.DEFAULT_QUIZ_KEY)
        # widgets #
        xml = gtk.glade.XML(self.GLADE_FILE, "main_window", APP)
        gw = xml.get_widget
        self.main_window = gw("main_window")
        self.edit_menuitem = gw("edit_menuitem")
        self.main_notbook_tabs = {
                "multi"  : [ gw("multi_tab_label"), gw("multi_tab_vbox") ], 
                "simple" : [ gw("simple_tab_label"), gw("simple_tab_vbox") ], 
                "flash"  : [ gw("flash_tab_label"), gw("flash_tab_vbox") ] }
        self.subquiz_combobox = gw("subquiz_combobox")
        self.word_treeview = gw("word_treeview")
        self.multi_answer_vbuttonbox = gw("multi_answer_vbuttonbox")
        self.simple_answer_entry = gw("simple_answer_entry")
        self.question_topic_labels = [ gw("multi_question_topic_label"),
                gw("simple_question_topic_label"),
                gw("flash_question_topic_label") ]
        self.question_labels = [ gw("multi_question_label"), 
                gw("simple_question_label"), gw("flash_question_label") ]
        self.multi_question_buttons = [ gw("mq_button0"), 
                gw("mq_button1"), gw("mq_button2"), gw("mq_button3"), 
                gw("mq_button4"), gw("mq_button5"), gw("mq_button6") ]
        self.simple_question_button = gw("simple_question_button")
        self.flash_notebook = gw("flash_notebook")
        self.flash_answer_buttons = [ 
                gw("flash_answer_button_no"), gw("flash_answer_button_yes") ]
        self.flash_answer_label = gw("flash_answer_label")
        self.progressbar1 = gw("progressbar1")
        sb = self.statusbar1 = gw("statusbar1")
        self.statusbar_contextid = { "last_answer" : 
                sb.get_context_id( "The answer to the last asked question." ) }
        #
        try:
            self.trainer.load_quiz(quiz_file_path)
        except IOError:
            quiz_file_path = resource_filename(__name__, 
                    '../quizzes/deu-fra.drill')
            self.trainer.load_quiz(quiz_file_path)

        # connect signals #
        xml.signal_autoconnect(self)
        self.trainer.connect('quiz_changed', self.on_quiz_switch)
        self.trainer.connect('question_changed', self.update_gui)
        self.trainer.connect('break_time', self.end_testing_interval)
        self.trainer.connect('direction_changed', 
                self.on_question_direction_changed)
        #
        self.on_quiz_switch()
Ejemplo n.º 2
0
    def __init__(self):
        self.timer_id = 0
        self.trainer = Quiz_Trainer()
        # gconf #
        self.gconf_watcher = Gconf_Prefs()
        quiz_file_path = self.gconf_watcher.gconf_client.get_string(
            self.gconf_watcher.DEFAULT_QUIZ_KEY)
        # widgets #
        xml = gtk.glade.XML(self.GLADE_FILE, "main_window", APP)
        gw = xml.get_widget
        self.main_window = gw("main_window")
        self.edit_menuitem = gw("edit_menuitem")
        self.main_notbook_tabs = {
            "multi": [gw("multi_tab_label"),
                      gw("multi_tab_vbox")],
            "simple": [gw("simple_tab_label"),
                       gw("simple_tab_vbox")],
            "flash": [gw("flash_tab_label"),
                      gw("flash_tab_vbox")]
        }
        self.subquiz_combobox = gw("subquiz_combobox")
        self.word_treeview = gw("word_treeview")
        self.multi_answer_vbuttonbox = gw("multi_answer_vbuttonbox")
        self.simple_answer_entry = gw("simple_answer_entry")
        self.question_topic_labels = [
            gw("multi_question_topic_label"),
            gw("simple_question_topic_label"),
            gw("flash_question_topic_label")
        ]
        self.question_labels = [
            gw("multi_question_label"),
            gw("simple_question_label"),
            gw("flash_question_label")
        ]
        self.multi_question_buttons = [
            gw("mq_button0"),
            gw("mq_button1"),
            gw("mq_button2"),
            gw("mq_button3"),
            gw("mq_button4"),
            gw("mq_button5"),
            gw("mq_button6")
        ]
        self.simple_question_button = gw("simple_question_button")
        self.flash_notebook = gw("flash_notebook")
        self.flash_answer_buttons = [
            gw("flash_answer_button_no"),
            gw("flash_answer_button_yes")
        ]
        self.flash_answer_label = gw("flash_answer_label")
        self.progressbar1 = gw("progressbar1")
        sb = self.statusbar1 = gw("statusbar1")
        self.statusbar_contextid = {
            "last_answer":
            sb.get_context_id("The answer to the last asked question.")
        }
        #
        try:
            self.trainer.load_quiz(quiz_file_path)
        except IOError:
            quiz_file_path = resource_filename(__name__,
                                               '../quizzes/deu-fra.drill')
            self.trainer.load_quiz(quiz_file_path)

        # connect signals #
        xml.signal_autoconnect(self)
        self.trainer.connect('quiz_changed', self.on_quiz_switch)
        self.trainer.connect('question_changed', self.update_gui)
        self.trainer.connect('break_time', self.end_testing_interval)
        self.trainer.connect('direction_changed',
                             self.on_question_direction_changed)
        #
        self.on_quiz_switch()
Ejemplo n.º 3
0
class Gui(object):
    GLADE_FILE = resource_filename(__name__, "data/quizdrill.glade")
    SHOW_TABS = { "vocabulary" : [ True, True, True], 
            "questionnaire" : [ True, True, True ],
            "flashcard" : [ False, False, True ],
            "all" : [ True, True, True ] }

    def __init__(self):
        self.timer_id = 0
        self.trainer = Quiz_Trainer()
        # gconf #
        self.gconf_watcher = Gconf_Prefs()
        quiz_file_path = self.gconf_watcher.gconf_client.get_string(
                self.gconf_watcher.DEFAULT_QUIZ_KEY)
        # widgets #
        xml = gtk.glade.XML(self.GLADE_FILE, "main_window", APP)
        gw = xml.get_widget
        self.main_window = gw("main_window")
        self.edit_menuitem = gw("edit_menuitem")
        self.main_notbook_tabs = {
                "multi"  : [ gw("multi_tab_label"), gw("multi_tab_vbox") ], 
                "simple" : [ gw("simple_tab_label"), gw("simple_tab_vbox") ], 
                "flash"  : [ gw("flash_tab_label"), gw("flash_tab_vbox") ] }
        self.subquiz_combobox = gw("subquiz_combobox")
        self.word_treeview = gw("word_treeview")
        self.multi_answer_vbuttonbox = gw("multi_answer_vbuttonbox")
        self.simple_answer_entry = gw("simple_answer_entry")
        self.question_topic_labels = [ gw("multi_question_topic_label"),
                gw("simple_question_topic_label"),
                gw("flash_question_topic_label") ]
        self.question_labels = [ gw("multi_question_label"), 
                gw("simple_question_label"), gw("flash_question_label") ]
        self.multi_question_buttons = [ gw("mq_button0"), 
                gw("mq_button1"), gw("mq_button2"), gw("mq_button3"), 
                gw("mq_button4"), gw("mq_button5"), gw("mq_button6") ]
        self.simple_question_button = gw("simple_question_button")
        self.flash_notebook = gw("flash_notebook")
        self.flash_answer_buttons = [ 
                gw("flash_answer_button_no"), gw("flash_answer_button_yes") ]
        self.flash_answer_label = gw("flash_answer_label")
        self.progressbar1 = gw("progressbar1")
        sb = self.statusbar1 = gw("statusbar1")
        self.statusbar_contextid = { "last_answer" : 
                sb.get_context_id( "The answer to the last asked question." ) }
        #
        try:
            self.trainer.load_quiz(quiz_file_path)
        except IOError:
            quiz_file_path = resource_filename(__name__, 
                    '../quizzes/deu-fra.drill')
            self.trainer.load_quiz(quiz_file_path)

        # connect signals #
        xml.signal_autoconnect(self)
        self.trainer.connect('quiz_changed', self.on_quiz_switch)
        self.trainer.connect('question_changed', self.update_gui)
        self.trainer.connect('break_time', self.end_testing_interval)
        self.trainer.connect('direction_changed', 
                self.on_question_direction_changed)
        #
        self.on_quiz_switch()

    def update_gui(self):
        """
        (re-)set all the user-non-editable text (labels etc.).
        Used when a new question is asked.
        """
        for label in self.question_labels:
            label.set_text(self.trainer.current_quiz.question[
                self.trainer.current_quiz.ask_from])
        self.simple_answer_entry.set_text("")
        self.progressbar1.set_fraction(
                float(self.trainer.current_quiz.answered) / \
                self.trainer.current_quiz.session_length)
        # set multiquiz answers #
        for button in self.multi_question_buttons:
            button.set_label('-')
            button.set_sensitive(False)
        for button, text in zip(self.multi_question_buttons, 
                self.trainer.current_quiz.multi_choices):
            button.set_label(text[self.trainer.current_quiz.answer_to])
            button.set_sensitive(True)
        # set flash card to front side #
        self.flash_notebook.set_current_page(0)

    def redisplay_correctly_answered(self):
        """
        Displays the last answer (currently on the StatusBar). This is so
        the user has the possibility to review again especially after many
        faulty answers (simple quiz) or surprised/unknows right answer (multi
        choice). No use on flashcard.
        """
        previous_question = self.trainer.current_quiz.previous_question
        if previous_question == None:
            text = ""
        else:
            # TRANSLATORS: This is displayed on the statusbar so try to keep it 
            #    short. The answer should be shown rather then the text or the 
            #    question if the bar is too short.
            text = _("'%(answer)s' to '%(question)s' was correct.") % {
                    "answer" : self.trainer.current_quiz.previous_question[
                        self.trainer.current_quiz.answer_to],
                    "question" : self.trainer.current_quiz.previous_question[
                        self.trainer.current_quiz.ask_from] }
        self.statusbar1.pop(self.statusbar_contextid["last_answer"])
        self.statusbar1.push(self.statusbar_contextid["last_answer"], text)

    def on_question_direction_changed(self):
        new_status = self.trainer.current_quiz.ask_from
        self.main_window.set_title(_('Quiz') + ': ' + 
                self.trainer.current_filer.all_subquizzes[new_status])
        if len(self.trainer.current_filer.question_topic) > 1:
            for label in self.question_topic_labels:
                label.set_text(
                        self.trainer.current_filer.question_topic[new_status])
        self.trainer.current_quiz.new_question()

    def on_quiz_switch(self):
        """
        Update the Userinterface when the quiz has been switched.

        Note: This is obsolete. It will be replaced with 
              Gui_Quiz_Manger.on_quiz_selected.
        """
        self.on_question_direction_changed()
        # show and hide notebookpanels #
        if self.trainer.current_filer.quiz_type in self.SHOW_TABS:
            quiz_type = self.trainer.current_filer.quiz_type
        else:
            print _('Warning: unknown quiz type "%s".') % \
                    self.trainer.current_filer.quiz_type
            quiz_type = "all"
        for tab, visi in zip(self.main_notbook_tabs.itervalues(),
                self.SHOW_TABS[quiz_type]):
            for widget in tab:   # tab is tab-label + tab-content
                if visi:
                    widget.show()
                else:
                    widget.hide()
        # show, hide and settext of combobox #
        if self.trainer.current_filer.all_subquizzes == []:
            self.subquiz_combobox.hide()
        else:
            for i in range(2):            # dirty clear combobox
                self.subquiz_combobox.remove_text(0)
            for subquiz in self.trainer.current_filer.all_subquizzes:
                self.subquiz_combobox.append_text(subquiz)
            self.subquiz_combobox.set_active(
                    self.trainer.current_quiz.ask_from)
            self.subquiz_combobox.show()
        #
        for label in self.question_topic_labels:
            label.set_markup("<b>%s</b>" % 
                    self.trainer.current_filer.question_topic[
                        self.trainer.current_quiz.ask_from])
        # treeview #
        ## Question/Answer-Columns ##
        for column in self.word_treeview.get_columns():
            self.word_treeview.remove_column(column)
        for i, title in enumerate(self.trainer.current_filer.data_name):
            tvcolumn = gtk.TreeViewColumn(title,
                    gtk.CellRendererText(), text=i)
            self.word_treeview.append_column(tvcolumn)
        ## toggler ##
        toggler = gtk.CellRendererToggle()
        toggler.connect( 'toggled', self.on_treeview_toogled )
        tvcolumn = gtk.TreeViewColumn(_("test"), toggler)
        tvcolumn.add_attribute(toggler, "active", 2)
        self.word_treeview.append_column(tvcolumn)
        self.word_treeview.set_model(self.trainer.current_filer.treestore)
        # clean statusbar #
        self.statusbar1.pop(self.statusbar_contextid["last_answer"])
        #
        self.update_gui()

    # Timer #

    def end_testing_interval(self):
        """
        start_relax_time and switch to next quiz.
        """
        self.trainer.switch_quiz()
        self.start_relax_time(self.gconf_watcher.break_length)

    def start_relax_time(self, break_length, minimize=True):
        """
        Iconify window as a break and deiconify it when it's over.
        """
        def ms2min(ms):
            """
            Convert milliseconds to minutes.
            """
            return ms * 60000

        if not self.gconf_watcher.use_timer:
            return
        if self.timer_id:
            gobject.source_remove(self.timer_id)
        if minimize:
            self.main_window.iconify()
        self.timer_id = gobject.timeout_add(ms2min(break_length), 
                self.on_end_relax_time)

    def on_end_relax_time(self):
        self.main_window.deiconify()
        self.timer_id = 0

    # main_window handlers #

    ## all (or indebendant of) tabs ##

    def on_quit(self, widget):
        for filer in self.trainer.quiz_filer_list:
            filer.write_score_file()
        self.gconf_watcher.save_quiz_path(self.trainer.current_filer.file_path)
        gtk.main_quit()

    def on_main_window_window_state_event(self, widget, event):
        """ Snooze when minimized """
        if 'iconified' in event.new_window_state.value_nicks and \
                not self.timer_id:
            self.start_relax_time(self.gconf_watcher.snooze_length, False)
        elif not 'iconified' in event.new_window_state.value_nicks \
                and self.timer_id:
            gobject.source_remove(self.timer_id)
            self.timer_id = 0

    def on_about_activate(self, widget):
        "Open the about-dialog and close it when close button is pressed."
        def on_dialog_close(widget): widget.window.destroy()
        xml = gtk.glade.XML(self.GLADE_FILE, "aboutdialog1", APP)
        close_button = xml.get_widget("aboutdialog1").get_children()[0]\
                .get_children()[1].get_children()[2]       # XXX dirty
        close_button.connect('clicked', on_dialog_close)

    def on_preferences_activate(self, widget):
        Gui_Preferences()

    def on_open_activate(self, widget):
        create_open_dialog(self.trainer)

    def on_manage_activate(self, widget):
        "Creates the Gui_Quiz_Manger-Window."
        Gui_Quiz_Manger(self.trainer)

    def on_main_notebook_switch_page(self, widget, gpointer, new_tab):
        if new_tab == 2:  # "Simple Quiz"-tab
            self.simple_question_button.grab_default()

    ## words-/settings-tab ##

    def on_subquiz_combobox_changed(self, widget):
        new_status = widget.get_active()
        self.trainer.current_quiz.set_question_direction(new_status)

    def on_treeview_toogled(self, cell, path ):
        """ toggle selected CellRendererToggle Row """
        self.trainer.current_filer.toggle_questions(path)

    ## questionaskting-tabs (simple/multi/flash) ##

    def on_multi_question_answer_button_clicked(self, widget, data=None):
        answer = widget.get_label()
        if self.trainer.current_quiz.check(answer):
            self.redisplay_correctly_answered()
            self.multi_question_buttons[0].grab_focus()
        else:
            widget.set_sensitive(False)
            # statusbar1: show question to selected answer #
            text = _("To '%(quest)s' '%(ans)s' would be the correct answer.") \
                    % { "ans" : answer, "quest" : self.trainer.current_quiz.\
                    get_question_to_answer_from_multichoices(answer) }
            self.statusbar1.pop(self.statusbar_contextid["last_answer"])
            self.statusbar1.push(self.statusbar_contextid["last_answer"], text)

    def on_multi_question_button_key_press_event(self, widget, event):
        """
        Use 'j' and 'k' to switch multi_choice_buttons focus in addition to 
        the arrows.
        """
        if event.keyval == 106:   # 'j'
            direction = 1
        elif event.keyval == 107:   # 'k'
            direction = -1
        else:
            return
        self.multi_question_buttons[ 
                (int(widget.get_name()[-1]) + direction) % 7 ].grab_focus()

    def on_simple_question_button_clicked(self, widget, data=None):
        if self.trainer.current_quiz.check(
                self.simple_answer_entry.get_text().strip()):
            self.redisplay_correctly_answered()
        else:
            self.statusbar1.pop(self.statusbar_contextid["last_answer"])
    
    def on_simple_question_hint_button_clicked(self, widget, data=None):
        self.simple_answer_entry.set_text( self.trainer.current_quiz.hint(
            self.simple_answer_entry.get_text().strip()))

    def on_flash_question_button_clicked(self, widget, date=None):
        self.flash_answer_label.set_text( self.trainer.current_quiz.question[
            self.trainer.current_quiz.answer_to])
        self.flash_notebook.set_current_page(1)

    def on_flash_answer_button_clicked(self, widget, data=None):
        if isinstance(self.trainer.current_quiz, Weighted_Quiz):
            self.trainer.current_quiz.set_answer_quality(
                    self.flash_answer_buttons.index(widget))
Ejemplo n.º 4
0
class Gui(object):
    GLADE_FILE = resource_filename(__name__, "data/quizdrill.glade")
    SHOW_TABS = {
        "vocabulary": [True, True, True],
        "questionnaire": [True, True, True],
        "flashcard": [False, False, True],
        "all": [True, True, True]
    }

    def __init__(self):
        self.timer_id = 0
        self.trainer = Quiz_Trainer()
        # gconf #
        self.gconf_watcher = Gconf_Prefs()
        quiz_file_path = self.gconf_watcher.gconf_client.get_string(
            self.gconf_watcher.DEFAULT_QUIZ_KEY)
        # widgets #
        xml = gtk.glade.XML(self.GLADE_FILE, "main_window", APP)
        gw = xml.get_widget
        self.main_window = gw("main_window")
        self.edit_menuitem = gw("edit_menuitem")
        self.main_notbook_tabs = {
            "multi": [gw("multi_tab_label"),
                      gw("multi_tab_vbox")],
            "simple": [gw("simple_tab_label"),
                       gw("simple_tab_vbox")],
            "flash": [gw("flash_tab_label"),
                      gw("flash_tab_vbox")]
        }
        self.subquiz_combobox = gw("subquiz_combobox")
        self.word_treeview = gw("word_treeview")
        self.multi_answer_vbuttonbox = gw("multi_answer_vbuttonbox")
        self.simple_answer_entry = gw("simple_answer_entry")
        self.question_topic_labels = [
            gw("multi_question_topic_label"),
            gw("simple_question_topic_label"),
            gw("flash_question_topic_label")
        ]
        self.question_labels = [
            gw("multi_question_label"),
            gw("simple_question_label"),
            gw("flash_question_label")
        ]
        self.multi_question_buttons = [
            gw("mq_button0"),
            gw("mq_button1"),
            gw("mq_button2"),
            gw("mq_button3"),
            gw("mq_button4"),
            gw("mq_button5"),
            gw("mq_button6")
        ]
        self.simple_question_button = gw("simple_question_button")
        self.flash_notebook = gw("flash_notebook")
        self.flash_answer_buttons = [
            gw("flash_answer_button_no"),
            gw("flash_answer_button_yes")
        ]
        self.flash_answer_label = gw("flash_answer_label")
        self.progressbar1 = gw("progressbar1")
        sb = self.statusbar1 = gw("statusbar1")
        self.statusbar_contextid = {
            "last_answer":
            sb.get_context_id("The answer to the last asked question.")
        }
        #
        try:
            self.trainer.load_quiz(quiz_file_path)
        except IOError:
            quiz_file_path = resource_filename(__name__,
                                               '../quizzes/deu-fra.drill')
            self.trainer.load_quiz(quiz_file_path)

        # connect signals #
        xml.signal_autoconnect(self)
        self.trainer.connect('quiz_changed', self.on_quiz_switch)
        self.trainer.connect('question_changed', self.update_gui)
        self.trainer.connect('break_time', self.end_testing_interval)
        self.trainer.connect('direction_changed',
                             self.on_question_direction_changed)
        #
        self.on_quiz_switch()

    def update_gui(self):
        """
        (re-)set all the user-non-editable text (labels etc.).
        Used when a new question is asked.
        """
        for label in self.question_labels:
            label.set_text(self.trainer.current_quiz.question[
                self.trainer.current_quiz.ask_from])
        self.simple_answer_entry.set_text("")
        self.progressbar1.set_fraction(
                float(self.trainer.current_quiz.answered) / \
                self.trainer.current_quiz.session_length)
        # set multiquiz answers #
        for button in self.multi_question_buttons:
            button.set_label('-')
            button.set_sensitive(False)
        for button, text in zip(self.multi_question_buttons,
                                self.trainer.current_quiz.multi_choices):
            button.set_label(text[self.trainer.current_quiz.answer_to])
            button.set_sensitive(True)
        # set flash card to front side #
        self.flash_notebook.set_current_page(0)

    def redisplay_correctly_answered(self):
        """
        Displays the last answer (currently on the StatusBar). This is so
        the user has the possibility to review again especially after many
        faulty answers (simple quiz) or surprised/unknows right answer (multi
        choice). No use on flashcard.
        """
        previous_question = self.trainer.current_quiz.previous_question
        if previous_question == None:
            text = ""
        else:
            # TRANSLATORS: This is displayed on the statusbar so try to keep it
            #    short. The answer should be shown rather then the text or the
            #    question if the bar is too short.
            text = _("'%(answer)s' to '%(question)s' was correct.") % {
                "answer":
                self.trainer.current_quiz.previous_question[
                    self.trainer.current_quiz.answer_to],
                "question":
                self.trainer.current_quiz.previous_question[
                    self.trainer.current_quiz.ask_from]
            }
        self.statusbar1.pop(self.statusbar_contextid["last_answer"])
        self.statusbar1.push(self.statusbar_contextid["last_answer"], text)

    def on_question_direction_changed(self):
        new_status = self.trainer.current_quiz.ask_from
        self.main_window.set_title(
            _('Quiz') + ': ' +
            self.trainer.current_filer.all_subquizzes[new_status])
        if len(self.trainer.current_filer.question_topic) > 1:
            for label in self.question_topic_labels:
                label.set_text(
                    self.trainer.current_filer.question_topic[new_status])
        self.trainer.current_quiz.new_question()

    def on_quiz_switch(self):
        """
        Update the Userinterface when the quiz has been switched.

        Note: This is obsolete. It will be replaced with 
              Gui_Quiz_Manger.on_quiz_selected.
        """
        self.on_question_direction_changed()
        # show and hide notebookpanels #
        if self.trainer.current_filer.quiz_type in self.SHOW_TABS:
            quiz_type = self.trainer.current_filer.quiz_type
        else:
            print _('Warning: unknown quiz type "%s".') % \
                    self.trainer.current_filer.quiz_type
            quiz_type = "all"
        for tab, visi in zip(self.main_notbook_tabs.itervalues(),
                             self.SHOW_TABS[quiz_type]):
            for widget in tab:  # tab is tab-label + tab-content
                if visi:
                    widget.show()
                else:
                    widget.hide()
        # show, hide and settext of combobox #
        if self.trainer.current_filer.all_subquizzes == []:
            self.subquiz_combobox.hide()
        else:
            for i in range(2):  # dirty clear combobox
                self.subquiz_combobox.remove_text(0)
            for subquiz in self.trainer.current_filer.all_subquizzes:
                self.subquiz_combobox.append_text(subquiz)
            self.subquiz_combobox.set_active(
                self.trainer.current_quiz.ask_from)
            self.subquiz_combobox.show()
        #
        for label in self.question_topic_labels:
            label.set_markup("<b>%s</b>" %
                             self.trainer.current_filer.question_topic[
                                 self.trainer.current_quiz.ask_from])
        # treeview #
        ## Question/Answer-Columns ##
        for column in self.word_treeview.get_columns():
            self.word_treeview.remove_column(column)
        for i, title in enumerate(self.trainer.current_filer.data_name):
            tvcolumn = gtk.TreeViewColumn(title,
                                          gtk.CellRendererText(),
                                          text=i)
            self.word_treeview.append_column(tvcolumn)
        ## toggler ##
        toggler = gtk.CellRendererToggle()
        toggler.connect('toggled', self.on_treeview_toogled)
        tvcolumn = gtk.TreeViewColumn(_("test"), toggler)
        tvcolumn.add_attribute(toggler, "active", 2)
        self.word_treeview.append_column(tvcolumn)
        self.word_treeview.set_model(self.trainer.current_filer.treestore)
        # clean statusbar #
        self.statusbar1.pop(self.statusbar_contextid["last_answer"])
        #
        self.update_gui()

    # Timer #

    def end_testing_interval(self):
        """
        start_relax_time and switch to next quiz.
        """
        self.trainer.switch_quiz()
        self.start_relax_time(self.gconf_watcher.break_length)

    def start_relax_time(self, break_length, minimize=True):
        """
        Iconify window as a break and deiconify it when it's over.
        """
        def ms2min(ms):
            """
            Convert milliseconds to minutes.
            """
            return ms * 60000

        if not self.gconf_watcher.use_timer:
            return
        if self.timer_id:
            gobject.source_remove(self.timer_id)
        if minimize:
            self.main_window.iconify()
        self.timer_id = gobject.timeout_add(ms2min(break_length),
                                            self.on_end_relax_time)

    def on_end_relax_time(self):
        self.main_window.deiconify()
        self.timer_id = 0

    # main_window handlers #

    ## all (or indebendant of) tabs ##

    def on_quit(self, widget):
        for filer in self.trainer.quiz_filer_list:
            filer.write_score_file()
        self.gconf_watcher.save_quiz_path(self.trainer.current_filer.file_path)
        gtk.main_quit()

    def on_main_window_window_state_event(self, widget, event):
        """ Snooze when minimized """
        if 'iconified' in event.new_window_state.value_nicks and \
                not self.timer_id:
            self.start_relax_time(self.gconf_watcher.snooze_length, False)
        elif not 'iconified' in event.new_window_state.value_nicks \
                and self.timer_id:
            gobject.source_remove(self.timer_id)
            self.timer_id = 0

    def on_about_activate(self, widget):
        "Open the about-dialog and close it when close button is pressed."

        def on_dialog_close(widget):
            widget.window.destroy()

        xml = gtk.glade.XML(self.GLADE_FILE, "aboutdialog1", APP)
        close_button = xml.get_widget("aboutdialog1").get_children()[0]\
                .get_children()[1].get_children()[2]       # XXX dirty
        close_button.connect('clicked', on_dialog_close)

    def on_preferences_activate(self, widget):
        Gui_Preferences()

    def on_open_activate(self, widget):
        create_open_dialog(self.trainer)

    def on_manage_activate(self, widget):
        "Creates the Gui_Quiz_Manger-Window."
        Gui_Quiz_Manger(self.trainer)

    def on_main_notebook_switch_page(self, widget, gpointer, new_tab):
        if new_tab == 2:  # "Simple Quiz"-tab
            self.simple_question_button.grab_default()

    ## words-/settings-tab ##

    def on_subquiz_combobox_changed(self, widget):
        new_status = widget.get_active()
        self.trainer.current_quiz.set_question_direction(new_status)

    def on_treeview_toogled(self, cell, path):
        """ toggle selected CellRendererToggle Row """
        self.trainer.current_filer.toggle_questions(path)

    ## questionaskting-tabs (simple/multi/flash) ##

    def on_multi_question_answer_button_clicked(self, widget, data=None):
        answer = widget.get_label()
        if self.trainer.current_quiz.check(answer):
            self.redisplay_correctly_answered()
            self.multi_question_buttons[0].grab_focus()
        else:
            widget.set_sensitive(False)
            # statusbar1: show question to selected answer #
            text = _("To '%(quest)s' '%(ans)s' would be the correct answer.") \
                    % { "ans" : answer, "quest" : self.trainer.current_quiz.\
                    get_question_to_answer_from_multichoices(answer) }
            self.statusbar1.pop(self.statusbar_contextid["last_answer"])
            self.statusbar1.push(self.statusbar_contextid["last_answer"], text)

    def on_multi_question_button_key_press_event(self, widget, event):
        """
        Use 'j' and 'k' to switch multi_choice_buttons focus in addition to 
        the arrows.
        """
        if event.keyval == 106:  # 'j'
            direction = 1
        elif event.keyval == 107:  # 'k'
            direction = -1
        else:
            return
        self.multi_question_buttons[(int(widget.get_name()[-1]) + direction) %
                                    7].grab_focus()

    def on_simple_question_button_clicked(self, widget, data=None):
        if self.trainer.current_quiz.check(
                self.simple_answer_entry.get_text().strip()):
            self.redisplay_correctly_answered()
        else:
            self.statusbar1.pop(self.statusbar_contextid["last_answer"])

    def on_simple_question_hint_button_clicked(self, widget, data=None):
        self.simple_answer_entry.set_text(
            self.trainer.current_quiz.hint(
                self.simple_answer_entry.get_text().strip()))

    def on_flash_question_button_clicked(self, widget, date=None):
        self.flash_answer_label.set_text(self.trainer.current_quiz.question[
            self.trainer.current_quiz.answer_to])
        self.flash_notebook.set_current_page(1)

    def on_flash_answer_button_clicked(self, widget, data=None):
        if isinstance(self.trainer.current_quiz, Weighted_Quiz):
            self.trainer.current_quiz.set_answer_quality(
                self.flash_answer_buttons.index(widget))