Пример #1
0
    def apply_button_clicked(self):
        self.book_text = self.book_title_input.text()
        sql_conn = SqliteConnection()

        # Search book by title
        # if returned id is None, open dialog displaying a message that book
        # is not found
        # book_title, year, book_author field is not editable
        book_id = sql_conn.search_book_id_by_title(self.book_text)

        if isinstance(book_id, int) and book_id > 0:
            # if returned id is > 0, pre populate book_title, year, book_author
            (_, book_title, book_year, book_author, book_note) = \
                sql_conn.search_book_by_title(self.book_text)

            self.set_book_tab_text(book_title, book_author, str(book_year),
                                   book_note)

            self.set_qlineedit_enable(False)

        else:
            msg_box = MessageBox('No book is found !!!')
            msg_box.exec_()
            # save to db (source_book tb)
            # should not save to db. open a dialog message saying no recrod
            # found

        self.close()
Пример #2
0
    def add_subject_to_combobox(self):
        # subject is list of tuple
        # i.e. [('Chemistry',)]
        sql_conn = SqliteConnection()
        subject = sql_conn.get_all_subjects()

        self.clear()
        self.addItem('Select .....')
        for subj in subject:
            self.addItem(subj[0])
Пример #3
0
    def apply_button_clicked(self):
        self.text = self.subject_input.text()

        if self.text == '':
            self.close()
            msg = MessageBox('Please enter subject')
            msg.exec_()
        else:
            sql_conn = SqliteConnection()

            sql_conn.add_subject_to_db(self.text)

            self.close()
Пример #4
0
    def display_labels(self, sql_conn: SqliteConnection):
        date_info = sql_conn.get_date_info(self.current_card['date_id'])
        url = sql_conn.get_url(self.current_card['source_id'])
        url_text_template = '<a href=>Link</a>'
        url_text = url_text_template[0:8] + url[0][0] + url_text_template[8::]
        pass_rate = sql_conn.get_pass_rate(self.current_card['card_id'])
        self.pass_rate_data.setText(pass_rate + '%')

        if date_info[0][3] == 'None':
            last_seen = 'N/A'
            self.last_seen_data.setText(last_seen)
        else:
            last_seen = datetime.datetime.strptime(date_info[0][3],
                                                   '%Y-%m-%d %H:%M:%S.%f')
            self.last_seen_data.setText(last_seen.date().strftime('%m/%d/%Y'))
        self.url.setText(url_text)
Пример #5
0
    def update_book_note(self):
        # update_book_note method can only be called if search_book btn
        # has called prior
        book_title = url_book.book_tab.title_input.text()
        book_note = url_book.book_tab.note_input.toPlainText()

        if not (url_book.book_tab.title_input.isEnabled()):
            sql_conn = SqliteConnection()
            book_id = sql_conn.search_book_id_by_title(book_title)
            success = sql_conn.update_book_note_to_db(book_id, book_note)

            if success is None:
                updated_dialog = MessageBox('Success: Updated')
                updated_dialog.exec_()
        else:
            dialog_box = MessageBox('Please Search Book first !!!')
            dialog_box.exec_()
Пример #6
0
 def fail_btn_clicked(self):
     #TODO
     # Increase total_fail_times
     sql_conn = SqliteConnection()
     self.increase_total_fail_times(self.current_card['card_id'], sql_conn)
     now = datetime.datetime.now()
     self.update_last_seen_date(self.current_card['date_id'], now, sql_conn)
     self.flip = False
Пример #7
0
    def start_test(self):
        # get subject
        subject_id = self.test_subject_cb.currentIndex()
        logic = self.test_logic_cb.currentText()

        if subject_id != 0 and logic != 'Select .....':
            sql_stm_dic = {
                'Test all cards in the subject':
                f"SELECT * FROM question_answer WHERE subject_id='{subject_id}'",
                'Test only cards in the subject failed more than test times':
                f"SELECT * FROM question_answer WHERE subject_id='{subject_id}' \
                    AND (total_fail_times - total_test_times) > 0",
                'Test all cards added today':
                f"SELECT * FROM question_answer WHERE date_id IN (SELECT date_id \
                    FROM date WHERE strftime('%Y-%m-%d', created_date)\
                    BETWEEN date('now', '-5 day') AND date('now'))",
                'Test all cards added today, failed > 2 times':
                f"SELECT * FROM question_answer WHERE date_id IN (SELECT date_id \
                    FROM date WHERE strftime('%Y-%m-%d', created_date)\
                    BETWEEN date('now', '-5 day') AND date('now')) AND \
                        total_fail_times > 1"
            }

            # get cards in list
            sql_conn = SqliteConnection()
            # res is in list containing tuple (card_id, question, answer, ... etc)
            cards = sql_conn.get_sql_query(sql_stm_dic[logic])

            for card in cards:
                while not self.flip:
                    self.current_card = self.create_card_dict(card)
                    self.show_card()
                    self.display_labels(sql_conn)
                    self._pass_fail_btn_disabled(True)
                    self.flip_btn.setDisabled(False)
                    qApp.processEvents()
                while self.flip:
                    self.flip_btn.setDisabled(True)
                    self._pass_fail_btn_disabled(False)
                    qApp.processEvents()
            end_message = MessageBox('End of Test')
            end_message.exec_()
            self._clear()
Пример #8
0
    def submit_button_clicked(self):
        question = q_box.question_textbox.toPlainText()
        answer = a_box.answer_textbox.toPlainText().replace("'", "''").\
            replace('"', '""')
        subject_id = s_combo.cb.currentIndex()
        book_title = url_book.book_tab.title_input.text()
        book_author = url_book.book_tab.author_input.text()
        book_year = url_book.book_tab.year_input.text()
        book_note = url_book.book_tab.note_input.toPlainText()
        url = url_book.url_tab.url_input.toPlainText()
        url_note = url_book.url_tab.url_note_input.toPlainText()

        sql_conn = SqliteConnection()
        now = datetime.datetime.now()
        date_id = sql_conn.post_datetime(now, now)

        if url_book.book_url_widget.currentIndex() == 0:
            self.save_book_source_qa(question, answer, subject_id, book_title,
                                     book_author, book_year, book_note,
                                     date_id, sql_conn)
        else:
            self.save_url_source_qa(question, answer, url, url_note, date_id,
                                    subject_id, sql_conn)
Пример #9
0
 def update_last_seen_date(self, date_id: int, now: datetime,
                           sql_conn: SqliteConnection):
     sql_stm = f"UPDATE date SET last_seen_date='{now}' \
         WHERE date_id='{date_id}'"
     sql_conn.post_sql_query(sql_stm)
Пример #10
0
 def increase_total_fail_times(self, card_id: int, sql_conn: SqliteConnection):
     sql_stm = f"UPDATE question_answer SET total_fail_times=\
         total_fail_times + 1 WHERE card_id='{card_id}'"
     sql_conn.post_sql_query(sql_stm)