示例#1
0
    def __init__(self, parent):
        super(WordsView, self).__init__(parent)
        self.setWindowTitle(_trans("ANKINDLE WORDS PREVIEW"))
        self.setWindowIcon(
            QIcon(
                QIcon(
                    os.path.join(os.path.dirname(__file__), "resource",
                                 "word_list.png"))))

        self.tabs = QTabWidget(self,
                               currentChanged=self.on_current_tab_changed)
        self.learned_view = None
        self.new_view = None
        self.btn_refresh = QPushButton(_trans("REFRESH"), clicked=self.refresh)
        self.btn_refresh.setMinimumWidth(100)
        self.btn_mark_as_mature = QPushButton(_trans("MARK MATURE"),
                                              clicked=self.mark_mature)
        self.btn_mark_as_mature.setMinimumWidth(100)

        l = QVBoxLayout(self)
        l.addWidget(self.tabs)

        l_h = QHBoxLayout()
        l_h.addWidget(self.btn_refresh)
        l_h.addWidget(self.btn_mark_as_mature)
        l_h.addSpacerItem(
            QSpacerItem(100, 1, QSizePolicy.Expanding, QSizePolicy.Minimum))
        l.addLayout(l_h)

        self.lang = ''
    def _createButtonsForLocalAnkiword(self):
        updateButton = QPushButton('Update', self)
        updateButton.clicked.connect(self._updateAnkiword)
        self._buttonLayout.addWidget(updateButton)

        removeButton = QPushButton('Remove', self)
        removeButton.clicked.connect(self._removeAnkiword)
        self._buttonLayout.addWidget(removeButton)

        self._buttonLayout.addStretch(1)
示例#3
0
文件: gui.py 项目: t9md/AnKindle
    def select_model(self):
        if not self.mod_list:
            showText(_trans("USER DEFINED TEMPLATE ALERT"), self, "html", title=_trans("AnKindle"))
            importFile(mw, DEFAULT_TEMPLATE)

        edit = QPushButton(_trans("USE LATEST TEMPLATE"),
                           clicked=lambda x: importFile(mw, DEFAULT_TEMPLATE))

        ret = StudyDeck(mw, names=lambda: sorted([f['name'] for f in self.mod_list]),
                        accept=anki.lang._("Choose"), title=_trans("NOTE TYPE"),
                        parent=self, buttons=[edit], help='',
                        cancel=True)
        return ret
示例#4
0
文件: gui.py 项目: t9md/AnKindle
 def on_clicked(self):
     if os.path.isfile(self.help_text_or_file):
         if IS_PY3K:
             with open(self.help_text_or_file, encoding="utf-8") as f:
                 text = f.read()
         else:
             with open(self.help_text_or_file) as f:
                 text = f.read()
                 text = text.decode("utf-8")
     else:
         text = self.help_text_or_file
     dlg, box = showText(text
                         , self.parent(), "html", title=anki.lang._("Help"), run=False)
     online_template_doc = QPushButton(_trans("MORE_DOC"), dlg)
     online_template_doc.clicked.connect(partial(openLink, ONLINE_DOC_URL))
     dlg.layout().insertWidget(1, online_template_doc)
     dlg.exec_()
示例#5
0
文件: gui.py 项目: t9md/AnKindle
    def __init__(self, parent, mod_list_func, deck_list_func):
        """

        :param parent:
        :param mod_list:
        :param deck_list:
        """

        super(Window, self).__init__(parent)
        self.setMinimumWidth(300)
        self.setStyleSheet("font-family: 'Microsoft YaHei UI', Consolas, serif;")
        self.mod_list_func = mod_list_func
        self.deck_list_func = deck_list_func

        # region init controls
        self.lb_db = QLabel(_trans("CANNOT FIND KINDLE VOLUME"), self)
        self.lb_db.setVisible(False)

        self.btn_select_db = _ImageButton(self, os.path.join(os.path.dirname(__file__), "resource", "kindle.png"))
        self.btn_select_db.clicked.connect(partial(self.on_select_kindle_db, True))
        self.btn_select_db.setToolTip(_trans("SELECT KINDLE DB"))
        self.btn_1select_model = QPushButton(_trans("SELECT MODEL"), self)
        self.btn_1select_model.clicked.connect(partial(self.on_select_model_clicked, None))
        self.btn_2select_deck = QPushButton(_trans("SELECT DECK"), self)
        self.btn_2select_deck.clicked.connect(partial(self.on_select_deck_clicked, None))

        self.btn_3select_mdx = QPushButton(_trans("SELECT MDX"), self)
        self.btn_3select_mdx.clicked.connect(partial(self.on_select_mdx, None))
        self.btn_3select_mdx.setEnabled(False)

        self.combo_lang = QComboBox(self)
        self.combo_lang.setMaximumWidth(100)
        self.combo_lang.setEnabled(False)

        self.updater = AddonUpdater(
            self, _trans("AnKindle"), ADDON_CD,
            "https://raw.githubusercontent.com/upday7/AnKindle/master/AnKindle/const.py",
            "",
            mw.pm.addonFolder(),
            __version__
        )

        # region layouts
        self.frm_widgets = _SharedFrame(self, self.updater)
        self.updater.start()

        frm_lists = QFrame(self)
        self.grp = QGroupBox(frm_lists)
        self.l_lists = QVBoxLayout(self.grp)

        l_grp_top = QHBoxLayout()
        self.l_lists.addWidget(self.lb_db, 0, Qt.AlignCenter)
        l_grp_top.addWidget(QLabel(_trans("Mandatory"), self), 0, Qt.AlignLeft)
        self.l_lists.addLayout(l_grp_top)

        l_language = QHBoxLayout()
        l_language.addWidget(self.btn_select_db)
        l_language.addWidget(VLine())
        l_language.addSpacerItem(QSpacerItem(1, 1, QSizePolicy.Minimum, QSizePolicy.Minimum))
        l_language.addWidget(QLabel(_trans("language"), self), 0, Qt.AlignLeft)
        l_language.addWidget(self.combo_lang)
        self.l_lists.addLayout(l_language)
        self.l_lists.addWidget(self.btn_1select_model)
        self.l_lists.addWidget(self.btn_2select_deck)

        l = QHBoxLayout()
        l.addWidget(self.btn_3select_mdx)

        self.l_lists.addWidget(HLine())
        self.l_lists.addWidget(QLabel(_trans("Optional"), self), 0, Qt.AlignLeft)
        self.l_lists.addLayout(l)

        self.btn_import = QPushButton(_trans("ONE CLICK IMPORT"), self, clicked=self.on_import)
        self.btn_import.setEnabled(False)

        self.btn_preview_words = QPushButton(self, clicked=self.on_preview_words)
        self.btn_preview_words.setToolTip(_trans("ANKINDLE WORDS PREVIEW"))
        self.btn_preview_words.setEnabled(False)
        self.btn_preview_words.setIcon(
            QIcon(os.path.join(os.path.dirname(__file__), "resource", "word_list.png"))
        )

        self.ck_import_new = QCheckBox(_trans("ONLY NEW WORDS"), self, clicked=self.on_ck_import_new)

        self.l = QVBoxLayout(self)
        self.l.addWidget(self.frm_widgets)
        self.l.addWidget(self.grp)
        l_import = QHBoxLayout()
        # self.ck_import_new.setFixedWidth(70)
        self.btn_preview_words.setFixedWidth(30)
        l_import.addWidget(self.ck_import_new)
        l_import.addWidget(self.btn_preview_words)
        l_import.addWidget(self.btn_import)
        self.l.addLayout(l_import)
        self.l.addSpacerItem(QSpacerItem(20, 10, QSizePolicy.Expanding, QSizePolicy.Minimum))

        # endregion

        # endregion

        self.model = None
        self.deck = None
        self.mdx = None
        self.builder = None
        self._preload_data = None
        self._lang_config_dict = {}
        self.db = None
        self.preview_words_win = WordsView(self)
        self.on_select_kindle_db(False)

        self.missed_css = set()

        # init actions
        self.btn_import.setDefault(True)
        try:
            self._validate_langs()
        except MemoryError:
            pass
        except:
            showInfo(_trans("ENSURE USB"), mw, type="warning", title=_trans("ANKINDLE"))
示例#6
0
    def __init__(self, parent, ruzu_schedule):
        super().__init__(parent=parent)
        self.anki_utils = AnkiUtils()
        self.ruzu_schedule = ruzu_schedule
        self.config = self.anki_utils.get_config()
        self.logger = logging.getLogger(__name__.split('.')[0])
        ###
        # Top level Window
        ###
        self.setWindowTitle("Ruzu Pop-ups Options")
        self.setGeometry(0, 0, 400, 300)

        ###
        # Options
        ###
        # Deck
        self.deck_select_text = QLabel(text='Deck')
        self.deck_select = QComboBox()
        decks = self.anki_utils.get_decks()
        for deck in decks:
            self.deck_select.addItem(deck.name)
        self.deck_select.setCurrentIndex(
            max(self.deck_select.findText(self.config['deck']), 0))

        # Frequency
        self.freq_select_text = QLabel(text='Pop-up Frequency')
        self.freq_select_map = {
            'Every Minute': 1,
            'Every 3 Minutes': 3,
            'Every 5 Minutes': 5,
            'Every 10 Minutes': 10,
            'Every 15 Minutes': 15,
            'Every 20 Minutes': 20,
            'Every 25 Minutes': 25,
            'Every 30 Minutes': 30,
            'Every 45 Minutes': 45,
            'Every 60 Minutes': 60
        }
        self.freq_select = QComboBox()
        for frequency in self.freq_select_map.keys():
            self.freq_select.addItem(frequency)
        try:
            freq_select_idx = list(self.freq_select_map.values()).index(
                self.config['frequency'])
        except ValueError:
            self.logger.warning(
                'Issue setting frequency dropdown based on config value, '
                'setting frequency dropdown to default (Every 5 Minutes)')
            freq_select_idx = 2
        finally:
            self.freq_select.setCurrentIndex(freq_select_idx)

        # Enable Disable
        self.click_to_reveal_check_text = QLabel(text='Click to reveal')
        self.click_to_reveal_check = QCheckBox()
        self.click_to_reveal_check.setChecked(self.config['click_to_reveal'])

        # Enable Disable
        self.enabled_check_text = QLabel(text='Enable pop-ups')
        self.enabled_check = QCheckBox()
        self.enabled_check.setChecked(self.config['enabled'])

        # OK
        self.ok_btn = QPushButton(text='Save')
        self.ok_btn.clicked.connect(self.update_config)

        # Close
        self.close_btn = QPushButton(text='Close')
        self.close_btn.clicked.connect(self.hide)

        # Show Next Card
        self.show_card_btn = QPushButton(text='Show Next Card')
        self.show_card_btn.clicked.connect(self.ruzu_schedule.exec_schedule)

        ###
        # Layout management - Add objects to main pop-up window
        ###
        self.grid = QGridLayout()
        self.grid.addWidget(self.deck_select, 0, 1)
        self.grid.addWidget(self.deck_select_text, 0, 0)
        self.grid.addWidget(self.freq_select, 1, 1)
        self.grid.addWidget(self.freq_select_text, 1, 0)
        self.grid.addWidget(self.click_to_reveal_check, 2, 1)
        self.grid.addWidget(self.click_to_reveal_check_text, 2, 0)
        self.grid.addWidget(self.enabled_check, 3, 1)
        self.grid.addWidget(self.enabled_check_text, 3, 0)
        self.grid.addWidget(self.show_card_btn, 4, 1)
        self.grid.addWidget(self.ok_btn, 5, 0)
        self.grid.addWidget(self.close_btn, 5, 1)
        self.grid_widget = QWidget()
        self.grid_widget.setLayout(self.grid)
        self.setCentralWidget(self.grid_widget)
    def _createButtonsForWebAnkiword(self):
        saveButton = QPushButton('Save', self)
        saveButton.clicked.connect(self._saveAnkiword)
        self._buttonLayout.addWidget(saveButton)

        self._buttonLayout.addStretch(1)
示例#8
0
    def __init__(self, parent):
        self.parent = parent
        self.anki_utils = AnkiUtils()
        self.current_card_id = None
        self.cur_button_count = 0
        self.logger = logging.getLogger(__name__.split('.')[0])

        # popup_window (QWidget)
        # -grid (QGridLayout)
        # --card_view (QWebEngineView)
        # --bottom_grid (QGridLayout)
        # ---buttons self.btn[0~3] (QPushButton)

        ###
        # Top level Pop-up Window
        ###
        parent.popup_window = self.popup_window = QWidget()
        self.popup_window.setWindowFlag(QtCore.Qt.WindowStaysOnTopHint)
        self.popup_window.setWindowFlag(Qt.FramelessWindowHint)  # Hide the title bar
        self.popup_window.setWindowTitle("Anki Review")  # Set the title (visible in windows taskbar)
        self.popup_window.setGeometry(0, 0, 400, 300)  # Set window geometry

        ###
        # Card View
        ###
        parent.card_view = self.card_view = AnkiWebView()

        ###
        # Buttons
        ###
        btn_width = 100
        btn_height = 20
        btn_padding = 20
        self.btn = []
        self.btn.append(QPushButton(text="Again"))
        self.btn[0].clicked.connect(lambda _: self.send_answer("Again"))
        self.btn[0].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn.append(QPushButton(text="Hard"))
        self.btn[1].clicked.connect(lambda _: self.send_answer("Hard"))
        self.btn[1].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn.append(QPushButton(text="Good"))
        self.btn[2].clicked.connect(lambda _: self.send_answer("Good"))
        self.btn[2].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn.append(QPushButton(text="Easy"))
        self.btn[3].clicked.connect(lambda _: self.send_answer("Easy"))
        self.btn[3].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn.append(QPushButton(text="Show Answer"))
        self.btn[4].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn[4].clicked.connect(lambda _: self.show_answer_popup())
        self.btn.append(QPushButton(text="Reveal Question"))
        self.btn[5].setGeometry(btn_padding, btn_padding, btn_width, btn_height)
        self.btn[5].clicked.connect(lambda _: self.show_question_popup())

        ###
        # Layout management - Add objects to main pop-up window
        ###
        parent.grid = self.grid = QGridLayout()
        parent.bottom_grid = self.bottom_grid = QHBoxLayout()
        # self.bottom_grid.setVerticalSpacing(10)
        self.bottom_grid.setContentsMargins(10, 5, 10, 10)
        for i in range(4):
            self.bottom_grid.addWidget(self.btn[i])
        parent.bottom_grid_2 = self.bottom_grid_2 = QHBoxLayout()  # Used to hide buttons when needed
        parent.bottom_wid_2 = self.bottom_wid_2 = QWidget()  # Used to hide buttons when needed
        self.bottom_wid_2.setLayout(self.bottom_grid_2)  # Used to hide buttons when needed
        self.grid.setContentsMargins(0, 0, 0, 0)
        self.grid.addWidget(self.card_view)
        self.grid.addLayout(self.bottom_grid, 1, 0)
        self.popup_window.setLayout(self.grid)