예제 #1
0
파일: pickle.py 프로젝트: wojas/pomni
 def unload(self):
     self.save(config()["path"])
     log().saved_database()
     self.start_date = None
     self.categories = []
     self.facts = []
     self.fact_views = []
     self.cards = []
     scheduler().clear_queue()
     return True
예제 #2
0
파일: pickle.py 프로젝트: wojas/pomni
 def delete_fact_and_related_data(self, fact):
     old_cat = fact.cat
     for c in self.cards:
         if c.fact == fact:
             self.cards.remove(c)
             try:
                 self.fact_views.remove(c.fact_view)
             except:
                 pass # Its fact view is a card type fact view one.
             log().deleted_card(c)
     self.facts.remove(fact)
     scheduler().rebuild_queue()
     for cat in old_cat:
         self.remove_category_if_unused(cat)
예제 #3
0
파일: cmd_ui.py 프로젝트: wojas/pomni
    def grade_answer(self):
        """ Get grade from the user and process it """

        while True:
            try:
                grade = raw_input(_("Grade your answer:"))
            except SyntaxError:
                print(_("Input error, try again"))
                continue
            if not grade.isdigit():
                print(_("Input error: Grade has to be a number from 0 to 5"))
                continue
            grade = int(grade)
            if not 0 <= grade <= 5:
                print(_("Input error: Grade has to be a number from 0 to 5"))
                continue

            scheduler().process_answer(self.card, grade)
            print("\n")
            break
예제 #4
0
 def new_question(self, learn_ahead=False):
     if database().card_count() == 0:
         self.state = "EMPTY"
         self.card = None
     else:
         self.card = scheduler().get_new_question(learn_ahead)
         if self.card != None:
             self.state = "SELECT SHOW"
         else:
             self.state = "SELECT AHEAD"
     self.update_dialog()
     stopwatch.start()
예제 #5
0
파일: cmd_ui.py 프로젝트: wojas/pomni
    def new_question(self, learn_ahead=False):
        """ Print new question """

        if database().card_count() == 0:
            raise CmdUiControllerException(_("Database is empty"))
        else:
            self.card = scheduler().get_new_question(learn_ahead)
            if self.card:
                print _("Question:"), self.card.question()
            else:
                value = raw_input(_("Learn ahead of schedule" + "? (y/N)"))
                if value in ("y", "Y"):
                    print("\n")
                    self.new_question(True)
                else:
                    raise CmdUiControllerException(_("Finished"))
예제 #6
0
파일: hildon_ui.py 프로젝트: wojas/pomni
    def new_question(self, learn_ahead=False):
        """ Create new question """

        if not database().card_count():
            raise HildonUiControllerException(self.w_tree, \
                _("Database is empty"))

        card = scheduler().get_new_question(learn_ahead)

        if card:
            self.question.set_text(card.question())
        else:
            # FIXME value = raw_input(_("Learn ahead of schedule" + "? (y/N)"))
            self.new_question(True)
            #self.question.set_text(card.question())

        self.answer.set_text("")
        for widget in [getattr(self, "grade%i" % num) for num in range(6)]:
            widget.set_sensitive(False)
        self.get_answer.set_sensitive(True)
        self.card = card
예제 #7
0
파일: card.py 프로젝트: wojas/pomni
    def set_initial_grade(self, grade):

        """This is called after manually adding cards. This code is separated
        out from the constructor, as for imported for imported cards, there is
        no grading information available when there are created, and the
        initial grading is done the first time they are are seen in
        the interactive review process (by similar code in the scheduler).

        This initial grading is seen as the first repetition.

        """

        db = database()
        sch = scheduler()
        self.grade = grade
        self.easiness = db.average_easiness()
        self.acq_reps = 1
        self.acq_reps_since_lapse = 1
        self.last_rep = db.days_since_start()
        new_interval = sch.calculate_initial_interval(grade)
        new_interval += sch.calculate_interval_noise(new_interval)
        self.next_rep = db.days_since_start() + new_interval
예제 #8
0
파일: hildon_ui.py 프로젝트: wojas/pomni
    def grade_answer(self, grade):
        """ Grade the answer """

        scheduler().process_answer(self.card, grade)
        self.new_question()
예제 #9
0
 def update_dialog(self, redraw_all=False):
     w = self.widget
     # Update title.
     database_name = os.path.basename(config()["path"])[:-4]
     title = _("Mnemosyne") + " - " + database_name
     w.set_window_title(title)
     # Update menu bar.
     if config()["only_editable_when_answer_shown"] == True:
         if self.card != None and self.state == "SELECT GRADE":
             w.enable_edit_current_card(True)
         else:
             w.enable_edit_current_card(False)
     else:
         if self.card != None:
             w.enable_edit_current_card(True)
         else:
             w.enable_edit_current_card(False)
     w.enable_delete_current_card(self.card != None)
     w.enable_edit_deck(database().card_count() > 0)
     # Hide/show the question and answer boxes.
     if self.state == "SELECT SHOW":
         w.question_box_visible(True)
         if self.card.fact_view.a_on_top_of_q:
             w.answer_box_visible(False)
     elif self.state == "SELECT GRADE":
         w.answer_box_visible(True)
         if self.card.fact_view.a_on_top_of_q:
             w.question_box_visible(False)
     else:
         w.question_box_visible(True)
         w.answer_box_visible(True)
     # Update question label.
     question_label_text = _("Question:")
     if self.card != None and self.card.fact.cat[0].name != _("<default>"):
         for c in self.card.fact.cat:
             question_label_text += " " + c.name
     w.set_question_label(question_label_text)
     # Update question content.
     if self.card == None:
         w.clear_question()
     elif self.state == "SELECT SHOW" or redraw_all == True:
         w.set_question(self.card.question())
     # Update answer content.
     if self.card == None or self.state == "SELECT SHOW":
         w.clear_answer()
     else:
         w.set_answer(self.card.answer())
     # Update 'Show answer' button.
     if self.state == "EMPTY":
         show_enabled, default, text = False, True, _("Show answer")
         grades_enabled = False
     elif self.state == "SELECT SHOW":
         show_enabled, default, text = True,  True, _("Show answer")
         grades_enabled = False
     elif self.state == "SELECT GRADE":
         show_enabled, default, text = False, True, _("Show answer")
         grades_enabled = True
     elif self.state == "SELECT AHEAD":
         show_enabled, default, text = True,  False, \
                                  _("Learn ahead of schedule")
         grades_enabled = False
     w.update_show_button(text, default, show_enabled)
     # Update grade buttons.
     if self.card != None and self.card.grade in [0,1]:
         i = 0 # Acquisition phase.
         default_4 = False
     else:
         i = 1 # Retention phase.
         default_4 = True
     w.enable_grades(grades_enabled)
     if grades_enabled:
         w.grade_4_default(default_4)            
     # Tooltips and texts for the grade buttons.
     for grade in range(0,6):
         # Tooltip.
         if self.state == "SELECT GRADE" and \
            config()["show_intervals"] == "tooltips":
             w.set_grade_tooltip(grade, tooltip[i][grade] +\
                 self.next_rep_string(scheduler().process_answer(self.card, \
                                     grade, dry_run=True)))
         else:
             w.set_grade_tooltip(grade, tooltip[i][grade])
         # Button text.
         if self.state == "SELECT GRADE" and \
            config()["show_intervals"] == "buttons":
             w.set_grade_text(grade, str(scheduler().process_answer(\
                                         self.card, grade, dry_run=True)))
             w.set_grades_title(_("Pick days until next repetition:"))
         else:
             w.set_grade_text(grade, str(grade))
             w.set_grades_title(_("Grade your answer:"))
         # TODO: accelerator update needed?
         #self.grade_buttons[grade].setAccel(QKeySequence(str(grade)))
     # Update status bar.
     ui_controller_main().widget.update_status_bar()
     # Run possible update code that independent of the controller state.
     # TODO: remove when migration is complete.
     w.update_dialog()
예제 #10
0
 def grade_answer(self, grade):
     interval = scheduler().process_answer(self.card, grade)
     self.new_question()
     if config()["show_intervals"] == "statusbar":
         self.widget.update_sta(_("Returns in") + " " + \
               str(interval) + _(" day(s)."))
예제 #11
0
파일: txt_logger.py 프로젝트: wojas/pomni
 def program_started(self):    
     self.logger.info("Program started : Mnemosyne " + \
                      mnemosyne.version.version\
                      + " " + os.name + " " + sys.platform)
     self.logger.info("Scheduler : " + scheduler().name)