def _delete_card(self, card: str): print(card) db = io_.SQLiteImporter(self.deck) out = io_.SQLiteExporter(self.deck) out.cursor.execute("DELETE FROM DECK WHERE FRONT = ?", (card, )) out.conn.commit() out.cursor.execute("DELETE FROM DATE_ WHERE CARD = ?", (card, )) out.conn.commit() db.cursor.execute("SELECT FRONT, BACK, IMG FROM DECK") tmp_deck = db.cursor.fetchall() out.cursor.execute("DROP TABLE DECK") out.conn.commit() out.createTable("DECK") self.cards_data = [] for key, val in enumerate(tmp_deck): data = (key + 1, ) + val out.writeToDB(data, "DECK") self.cards_data.append(data) db.cursor.execute("SELECT CARD, LAST_REVIEW, NEXT_REVIEW FROM DATE_") tmp_date = db.cursor.fetchall() out.cursor.execute("DROP TABLE DATE_") out.conn.commit() out.createTable("DATE_") for key, val in enumerate(tmp_date): data = (key + 1, ) + val out.writeToDB(data, "DATE_") self._createCardsList()
def _save_single_card(self): inp = io_.SQLiteImporter(self.deck) index = len(inp.fetch_from_db_Deck()) + 1 out = io_.SQLiteExporter(self.deck) front: str = self.front_box.toPlainText() back: str = self.back_box.toPlainText() if not (front.isspace() or back.isspace()): # try: img_file = os.path.basename(self.img_file) # except: # pass data_card = (index, front, back, f"{IMG_DIR}/{self.deck}/{img_file}") data_date = (index, front, None, date.today()) try: out.writeToDB(data_card, "DECK") out.writeToDB(data_date, "DATE_") except sql.IntegrityError: self._send_message(f"Card '{front}' is already exist", "Card exist") if self.img_file != "": shutil.copyfile(self.img_file, f"{IMG_DIR}/{self.deck}/{img_file}") else: pass self.close() else: self._send_message( "The front and back of the card must not be empty")
def record_learning_process(self): exporter = io_.SQLiteExporter(self.deck) importer = io_.SQLiteImporter(self.deck) # date_ = importer.fetch_from_db_Date_() for item in self.cards_list.keys(): card = item status = self.cards_status[card] last_review = date.today() next_review = date.today() if status["writing"] and status["multiple choice"]: print(f"{card}: 2/2") next_review += timedelta(days=5) elif status["writing"] or status["multiple choice"]: print(f"{card}: 1/2") next_review += timedelta(days=1) else: print(f"{card}: 0/2") next_review += timedelta(days=0) exporter.updateTable( table="DATE_", column_to_change="LAST_REVIEW", data=last_review, condition=card ) exporter.updateTable( table="DATE_", column_to_change="NEXT_REVIEW", data=next_review, condition=card )
def _createCardsLists(self): inp = io_.SQLiteImporter(self.deck) raw_deck = inp.fetch_from_db_Deck() decks_list = {} for i in raw_deck: decks_list[i[1]] = [i[2], i[3]] return decks_list
def _evaluateNumOfCards(self): deck_name = self.getDeckName() inp = io_.SQLiteImporter(deck_name) try: number = len(inp.fetch_from_db_Deck()) except shutil.Error: number = 0 text = f'{number} card' if number == 1 else f'{number} cards' self._num_of_cards.setText(text)
def _evaluateNumOfCardsToReview(self): deck_name = self.getDeckName() inp = io_.SQLiteImporter(deck_name) dates = inp.fetch_from_db_Date_() number = 0 for rows in dates: if datetime.today() >= datetime.strptime(rows[3], "%Y-%m-%d"): number += 1 text = f'{number} card to review' if number == 1 else f'{number} cards to review' self._cards_to_review.setText(text)
def __insertInfo(self): inp = io_.SQLiteImporter(self.deck) print(inp.selectFromDBDeck(self.front)) self.card_info = inp.selectFromDBDeck(self.front)[0] _, self.front_text, self.back_text, self.img_link = self.card_info self._img_file = "" self._front.setText(self.front_text) self._back_box.insertPlainText(self.back_text) pixmap = QtGui.QPixmap(self.img_link) if not pixmap.isNull(): self._img_preview.setPixmap(pixmap) else: self._img_preview.setText("")
def _createCardsList(self): """ Generate cards list from local database "Cards" a.k.a customized groupboxes are placed in grid layout inside a QScrollArea Responsive layout is implemented in this method, but needs some improvement (e.g smooth and faster arrange the 'cards') """ inp = io_.SQLiteImporter(self.deck) try: raw_cards_data = inp.fetch_from_db_Deck() except shutil.Error: raw_cards_data = () num_of_cards = len(raw_cards_data) if num_of_cards > 0: for card in reversed(range(self.getCardsArea().count())): tmp_widget = self.getCardsArea().itemAt(card).widget() self.getCardsArea().removeWidget(tmp_widget) tmp_widget.setParent(None) tmp_widget.deleteLater() columns = self._all_cards_area.width() // 230 rows = num_of_cards // columns remainder = num_of_cards % columns for row in range(rows): for col in range(columns): index = columns * row + col card_info = self.CardInfo(self, raw_cards_data[index], self.deck) self.getCardsArea().addWidget(card_info, row, col) if remainder != 0: new_row = rows for i in range(remainder): index = new_row * columns + i card_info = self.CardInfo(self, raw_cards_data[index], self.deck) self.getCardsArea().addWidget(card_info, new_row, i) else: for card in reversed(range(self.getCardsArea().count())): tmp_widget = self.getCardsArea().itemAt(card).widget() self.getCardsArea().removeWidget(tmp_widget) tmp_widget.setParent(None) tmp_widget.deleteLater() add_card_icon = QtSvg.QSvgWidget(ADD_CARDS_ICON, self) add_card_icon.setMaximumSize(200, 200) add_card_label = QtWidgets.QLabel("Please add some cards", self) add_card_label.setAlignment(QtCore.Qt.AlignCenter) self.getCardsArea().addWidget(add_card_icon, 0, 0) self.getCardsArea().addWidget(add_card_label, 1, 0)
def set_deck(self, deck): self.deck = deck importer = io_.SQLiteImporter(self.deck) tmp_cards_list = importer.fetch_from_db_Deck() cards_data: dict = {} for card in tmp_cards_list: cards_data.update( { card[1]: { "back": card[2], "img": card[3] } } ) date_data = importer.fetch_from_db_Date_() # if len(tmp_cards_list) >= 5: self.cards_list = {} for item in date_data: # print(item) if datetime.strptime(item[3], "%Y-%m-%d") <= datetime.today(): front = item[1] self.cards_list.update( { front: { "back": cards_data[front]["back"], "img": cards_data[front]["img"] } } ) # print("card_list: ", cards_list) init_question = self.create_question(self.cards_list) for item in reversed(range(self.revised_widget.layout().count())): tmp_widget = self.revised_widget.layout().itemAt(item).widget() self.getDecksArea().removeWidget(tmp_widget) tmp_widget.setParent(None) tmp_widget.deleteLater() if init_question: self.show_questions(self.question_num)