def __init__(self, parent, updater=None): super(_SharedFrame, self).__init__(parent) self.l_h_widgets = QHBoxLayout(self) wx = WeChatButton(self, os.path.join(os.path.dirname(__file__), "resource", "AnKindle.jpg")) wx.setIcon(os.path.join(os.path.dirname(__file__), "resource", "wechat.png")) wx.setObjectName("wx") self.l_h_widgets.addWidget(wx) vt = VoteButton(self, ADDON_CD) vt.setObjectName("vt") vt.setIcon(os.path.join(os.path.dirname(__file__), "resource", "upvote.png")) self.l_h_widgets.addWidget(vt) mr = MoreAddonButton(self) mr.setObjectName("mr") mr.setIcon(os.path.join(os.path.dirname(__file__), "resource", "more.png")) self.l_h_widgets.addWidget(mr) self.help_btn = _HelpBtn(self) self.l_h_widgets.addSpacerItem(QSpacerItem(10, 10, QSizePolicy.Expanding, QSizePolicy.Minimum, )) self.l_h_widgets.addWidget(self.help_btn) if updater: up_btn = UpgradeButton(self, updater) up_btn.setIcon(os.path.join(os.path.dirname(__file__), "resource", "update.png")) self.l_h_widgets.addWidget(up_btn) if isWin: up_btn.clicked.disconnect() up_btn.clicked.connect( lambda: showText(_trans("WIN UPDATE") % ADDON_CD, parent, title=_trans("ANKINDLE")))
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 _setupUI(self): layout = QVBoxLayout() self.setLayout(layout) preferredRegion = self._ankiInterface.config['preferredRegion'] self._ankiwordAttributeEditor = AnkiwordAttributeEditor( self, preferredRegion=preferredRegion) layout.addWidget(self._ankiwordAttributeEditor) self._buttonLayout = QHBoxLayout() layout.addLayout(self._buttonLayout)
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"))
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)