def __init__(self, language, parent=None): super(LanguageChooser, self).__init__(parent) self.parent = parent self.setWindowTitle('Choose Language') self.resize(300, 0) self.mainVBox = mainVBox = QVBoxLayout(self) mainVBox.chooseHbox = chooseHbox = QHBoxLayout() chooseHbox.addWidget(QLabel("(1) Choose Language")) self.languageCombo = languageCombo = QComboBox() languageCombo.addItem(language.name) languageCombo.setCurrentIndex(0) languageCombo.setEnabled(False) chooseHbox.addWidget(languageCombo) mainVBox.buttonBar = buttonBar = QBoxLayout(QBoxLayout.RightToLeft) cancelButton = QPushButton("Cancel") mw.connect(cancelButton, SIGNAL('clicked()'), self.closeWindows) buttonBar.addWidget(cancelButton) okButton = QPushButton("Ok") mw.connect(okButton, SIGNAL('clicked()'), self.saveLanguage) buttonBar.addWidget(okButton) mainVBox.addLayout(chooseHbox) mainVBox.addLayout(buttonBar)
def __init__(self, parent=None): super(LanguageChooser, self).__init__(parent) self.parent = parent self.setWindowTitle("Choose Language") self.resize(300, 0) self.mainVBox = mainVBox = QVBoxLayout(self) mainVBox.chooseHbox = chooseHbox = QHBoxLayout() chooseHbox.addWidget(QLabel("(1) Choose Language")) self.languageCombo = languageCombo = QComboBox() languagesNameAvailable = self.parent.languagesService.getAvailableLanguageName() # log(languagesName) for languageName in languagesNameAvailable: languageCombo.addItem(languageName) chooseHbox.addWidget(languageCombo) mainVBox.buttonBar = buttonBar = QBoxLayout(QBoxLayout.RightToLeft) cancelButton = QPushButton("Cancel") mw.connect(cancelButton, SIGNAL("clicked()"), self.closeWindows) buttonBar.addWidget(cancelButton) okButton = QPushButton("Ok") mw.connect(okButton, SIGNAL("clicked()"), self.saveLanguage) buttonBar.addWidget(okButton) mainVBox.addLayout(chooseHbox) mainVBox.addLayout(buttonBar)
def createMenu(): ml = QMenu(mw.mainWin.menubar) ml.setTitle("Lookup") mw.mainWin.menuTools.addAction(ml.menuAction()) mw.mainWin.menuLookup = ml # add actions a = QAction(mw) a.setText("...expression on alc") a.setShortcut("Ctrl+1") ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), onLookupExpression) a = QAction(mw) a.setText("...meaning on alc") a.setShortcut("Ctrl+2") ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), onLookupMeaning) a = QAction(mw) a.setText("...selection on alc") a.setShortcut("Ctrl+3") ml.addAction(a) ml.addSeparator() mw.connect(a, SIGNAL("triggered()"), onLookupAlcSelection) a = QAction(mw) a.setText("...word selection on edict") a.setShortcut("Ctrl+4") ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), onLookupEdictSelection) a = QAction(mw) a.setText("...kanji selection on edict") a.setShortcut("Ctrl+5") ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), onLookupEdictKanjiSelection)
def setupLanguages(self): mainVBox = self.mainVBox deck = self.deck mainVBox.chooseHbox = chooseHbox = QHBoxLayout() chooseHbox.addWidget(QLabel(" (1) Choose Language")) self.languageCombo = languageCombo = QComboBox() languagesNameAvailable = self.parent.languagesService.getAvailableLanguageName() #log(languagesName) currentIndex = 0 languageCombo.addItem("------------------------") for languageName in languagesNameAvailable: languageCode = self.parent.languagesService.getCodeFromLanguageName(languageName) log(languageCode) log(deck.language) if deck.language != None and deck.language.nameId == languageCode: currentIndex = languageCombo.count() languageCombo.addItem(languageName) languageCombo.setCurrentIndex(currentIndex) mw.connect(languageCombo, SIGNAL("activated(int)"), self.chooseLanguage) chooseHbox.addWidget(languageCombo) mainVBox.addLayout(chooseHbox)
def setupModes(self): mainVBox = self.mainVBox deck = self.deck ankiDeck = AnkiHelper.getDeck(deck.path) modesFrame = QGroupBox("(3) Choose Modes") mainVBox.modesBox = modesBox = QVBoxLayout() modesFrame.setLayout(modesBox) definitionBox = QHBoxLayout() self.defintionCB = defintionCB = QCheckBox("Definition Mode") self.definitionCombo = definitionCombo = QComboBox() if deck.definitionField: defintionCB.setChecked(True) definitionCombo.setEnabled(deck.definitionField != None) definitionCombo.addItem("------------ Choose Definition field ------------") mw.connect(defintionCB, SIGNAL('clicked()'), self.enableDefinitionModes) allFields = list() for model in ankiDeck.models: for fieldModel in model.fieldModels: if fieldModel.name not in allFields: allFields.append(fieldModel.name) allFields.sort() selectIndex = 0 i = 1 for fieldName in allFields: definitionCombo.addItem(fieldName) if fieldName == deck.definitionField: selectIndex = i i += 1 definitionCombo.setCurrentIndex(selectIndex) self.definitionKeyCombo = definitionKeyCombo = QComboBox() definitionKeyCombo.setEnabled(deck.definitionField != None) definitionKeyCombo.addItem("---------- Choose Definition Key field ----------") selectIndex = 0 i = 1 for fieldName in allFields: definitionKeyCombo.addItem(fieldName) if fieldName == deck.definitionKeyField: selectIndex = i i += 1 definitionKeyCombo.setCurrentIndex(selectIndex) definitionBox.addWidget(defintionCB) definitionBox.addWidget(definitionCombo) definitionBox.addWidget(definitionKeyCombo) modesBox.addLayout(definitionBox) mainVBox.addWidget(modesFrame) ankiDeck.close()
def init(): mw.mainWin.actionJapaneseAudioDownload = QAction(mw) mw.mainWin.actionJapaneseAudioDownloadQuery = QAction(mw) icon = QIcon() # icon.addPixmap(QPixmap(getLogoFile(u"audio_download.png")),QIcon.Normal,QIcon.Off) icon.addPixmap(QPixmap(getLogoFile(u"speaker_down_32.png")),QIcon.Normal,QIcon.Off) mw.mainWin.actionJapaneseAudioDownload.setIcon(icon) mw.mainWin.actionJapaneseAudioDownload.setIconText(u"Audio Download") # Hmm. I don’t really know what the ‘_’ is about. Copy-and-pasted. mw.mainWin.actionJapaneseAudioDownload.setShortcut(_("Ctrl+J")) mw.mainWin.actionJapaneseAudioDownload.setEnabled(False) mw.connect(mw.mainWin.actionJapaneseAudioDownload,SIGNAL("triggered()"),downloadAudio) # I really want to jiggle the action for each new card/question. # mw.connect(mw,SIGNAL("nextCard()"),toggleDownloadAction) mw.mainWin.actionJapaneseAudioDownloadQuery.setIcon(icon) mw.mainWin.actionJapaneseAudioDownloadQuery.setIconText(u"Audio Download...") mw.mainWin.actionJapaneseAudioDownloadQuery.setShortcut(_("Ctrl+Shift+J")) mw.connect(mw.mainWin.actionJapaneseAudioDownloadQuery,SIGNAL("triggered()"),downloadAudioQuery) mw.mainWin.menuEdit.addSeparator() if not AUTO_DOWNLOAD_AUDIO: mw.mainWin.toolBar.addSeparator() mw.mainWin.toolBar.addAction(mw.mainWin.actionJapaneseAudioDownload) mw.mainWin.menuEdit.addAction(mw.mainWin.actionJapaneseAudioDownload) mw.mainWin.menuEdit.addAction(mw.mainWin.actionJapaneseAudioDownloadQuery) addHook('disableCardMenuItems', disableDownloadAction) addHook('enableCardMenuItems', enableDownloadAction)
def init(): mw.mainWin.actionJapaneseAudioDownload = QAction(mw) mw.mainWin.actionJapaneseAudioDownloadQuery = QAction(mw) icon = QIcon() icon.addPixmap(QPixmap(getLogoFile(u"audio_download.png")), QIcon.Normal, QIcon.Off) mw.mainWin.actionJapaneseAudioDownload.setIcon(icon) mw.mainWin.actionJapaneseAudioDownload.setIconText(u"Audio Download") # Hmm. I don’t really know what the ‘_’ is about. Copy-and-pasted. mw.mainWin.actionJapaneseAudioDownload.setShortcut(_("Ctrl+J")) mw.mainWin.actionJapaneseAudioDownload.setEnabled(False) mw.connect(mw.mainWin.actionJapaneseAudioDownload, SIGNAL("triggered()"), downloadAudio) # I really want to jiggle the action for each new card/question. # mw.connect(mw,SIGNAL("nextCard()"),toggleDownloadAction) mw.mainWin.actionJapaneseAudioDownloadQuery.setIcon(icon) mw.mainWin.actionJapaneseAudioDownloadQuery.setIconText( u"Audio Download...") mw.mainWin.actionJapaneseAudioDownloadQuery.setShortcut(_("Ctrl+Shift+J")) mw.connect(mw.mainWin.actionJapaneseAudioDownloadQuery, SIGNAL("triggered()"), downloadAudioQuery) mw.mainWin.menuEdit.addSeparator() if not AUTO_DOWNLOAD_AUDIO: mw.mainWin.toolBar.addSeparator() mw.mainWin.toolBar.addAction(mw.mainWin.actionJapaneseAudioDownload) mw.mainWin.menuEdit.addAction(mw.mainWin.actionJapaneseAudioDownload) mw.mainWin.menuEdit.addAction(mw.mainWin.actionJapaneseAudioDownloadQuery) addHook('disableCardMenuItems', disableDownloadAction) addHook('enableCardMenuItems', enableDownloadAction)
def onInit(): """ Plugin initialization: - replace context menu - replace flush method - add tools menu entry """ #utils.showInfo("Initializing AnkiIR plugin") # replace context menu global __originalContextMenuEvent, __originalFlush __originalContextMenuEvent = mw.bodyView.body.contextMenuEvent mw.bodyView.body.contextMenuEvent = _contextMenuEvent #__originalFlush = mw.bodyView.flush #mw.bodyView.flush = _flush mw.connect(mw.bodyView.body, SIGNAL("loadFinished(bool)"), _onLoadFinished) # add menu entry menu = QMenu("Incremental Reading", mw) act = QAction(menu) act.setText("Add URL for IR") mw.connect(act, SIGNAL("triggered()"), doAddURL) menu.addAction(act) mw.mainWin.menuTools.addMenu(menu)
def onHardest(): data = mw.deck.s.all(""" select question, cnt from ( select cardId, count() as cnt from reviewHistory where time > :t and ease = 1 group by cardId), cards where cardId = id order by cnt desc limit :d""", t=time.time() - 60*MINUTES, d=MAXCARDS) s = "<h1>Hardest Cards</h1><table>" for (q, cnt) in data: s += "<tr><td>%s</td><td>failed %d times</td></tr>" % (q, cnt) # show dialog diag = QDialog(mw.app.activeWindow()) diag.setWindowTitle("Anki") layout = QVBoxLayout(diag) diag.setLayout(layout) text = QTextEdit() text.setReadOnly(True) text.setHtml(s) layout.addWidget(text) box = QDialogButtonBox(QDialogButtonBox.Close) layout.addWidget(box) mw.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) diag.setMinimumHeight(400) diag.setMinimumWidth(500) diag.exec_()
def init_hook(): mw.mainWin.TagToLessonNo = QtGui.QAction("Tags to lesson numbers", mw) mw.mainWin.TagToLessonNo.setStatusTip("Change tags like " + LESSON_TAG_PREFIX + "N into values for the " + LESSON_FIELD_NAME + " field") mw.mainWin.TagToLessonNo.setEnabled(True) mw.mainWin.TagToLessonNo.setIcon(QtGui.QIcon(":/icons/kanji.png")) mw.connect(mw.mainWin.TagToLessonNo, QtCore.SIGNAL('triggered()'), update_deck) mw.mainWin.menuTools.addAction(mw.mainWin.TagToLessonNo)
def initChineseExampleSentence(): global origDrawAnswer,origCardAnswered,origMoveToState,toggle,next try: pickled except NameError: return origDrawAnswer = mw.bodyView.drawAnswer origCardAnswered = mw.cardAnswered origMoveToState = mw.moveToState mw.moveToState = moveToStateCES mw.cardAnswered = cardAnsweredCES mw.bodyView.drawAnswer = drawAnswerCES mw.mainWin.toolBar.addSeparator() toggle = QAction(mw) icon = QIcon() icon.addPixmap(QPixmap(getLogoFile('zhexsen_logo.png',logo)),QIcon.Normal,QIcon.Off) toggle.setIcon(icon) toggle.setIconText('zhex') toggle.setCheckable(True) toggle.setEnabled(False) mw.connect(toggle,SIGNAL("toggled(bool)"),doToggle) mw.mainWin.toolBar.addAction(toggle) next = QAction(mw) icon = QIcon() icon.addPixmap(QPixmap(getLogoFile('zhexsen_logo_next.png',nextLogo)),QIcon.Normal,QIcon.Off) next.setIcon(icon) next.setIconText('zhex:next') next.setEnabled(False) mw.connect(next,SIGNAL("triggered()"),doNext) mw.mainWin.toolBar.addAction(next)
def init_hook(): """ Initialises the Anki GUI to present an option to invoke the plugin. """ mw.mainWin.action_jlpt_stats = QtGui.QAction("Toggle JLPT Kanji Stats", mw) mw.mainWin.action_jlpt_stats.setStatusTip("Toggle JLPT Kanji Stats") mw.mainWin.action_jlpt_stats.setEnabled(True) mw.connect(mw.mainWin.action_jlpt_stats, QtCore.SIGNAL("triggered()"), slot_sync) mw.mainWin.menuPlugins.addAction(mw.mainWin.action_jlpt_stats)
def replaceMenu(): # create the new menu createTagsMenu() # insert it into the "current" menu mw.mainWin.menuEdit.insertMenu(mw.mainWin.actionSuspendCard, mw.tagsMenu) mw.mainWin.menuEdit.removeAction(mw.mainWin.actionSuspendCard) # the app should do the same things to the menu as it would to the old button mw.mainWin.actionSuspendCard = mw.tagsMenu mw.connect(mw.tagsMenu, SIGNAL("aboutToShow()"), updateMenu)
def setupButtons(self): mainVBox = self.mainVBox mainVBox.buttonBar = buttonBar = QBoxLayout(QBoxLayout.RightToLeft) cancelButton = QPushButton("Cancel") mw.connect(cancelButton, SIGNAL('clicked()'), self.closeWindows) buttonBar.addWidget(cancelButton) okButton = QPushButton("Ok") mw.connect(okButton, SIGNAL('clicked()'), self.controller.saveConfig) buttonBar.addWidget(okButton) mainVBox.addLayout(buttonBar)
def __init__(self,parent=None): QWebView.__init__(self,parent) sizePolicyd = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Minimum) sizePolicyd.setHorizontalStretch(QSizePolicy.GrowFlag+QSizePolicy.ShrinkFlag) sizePolicyd.setVerticalStretch(QSizePolicy.GrowFlag+QSizePolicy.ShrinkFlag) #sizePolicyd.setHeightForWidth(self.sizePolicy().sizeHint())#hasHeightForWidth()) self.setSizePolicy(sizePolicyd) rect=QtGui.QApplication.desktop().availableGeometry() self.setMinimumSize(QtCore.QSize(min(1200,rect.width()), min(600,rect.height()-10))) #self.setMaximumSize(QtCore.QSize(210, 16777215)) self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) mw.connect(self, QtCore.SIGNAL('linkClicked (const QUrl&)'), onClick) self.BridgeToJavascript() # add inside javascript namespace mw.connect(self.page().mainFrame(),QtCore.SIGNAL('javaScriptWindowObjectCleared()'), self.BridgeToJavascript) #in case of rload, maintains in javascript self.hide()
def __init__(self,name,parent=None): QWebView.__init__(self,parent) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth()) self.setSizePolicy(sizePolicy) self.setMinimumSize(QtCore.QSize(410, 400)) self.setMaximumSize(QtCore.QSize(410, 16777215)) self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) # delegates link (to be able to call python function with arguments from HTML) self.connect(self, QtCore.SIGNAL('linkClicked (const QUrl&)'), onClick) # delegates link (to be able to call python function with arguments from HTML) self.name = name #name that javascript will know self.BridgeToJavascript() # add inside javascript namespace mw.connect(self.page().mainFrame(),QtCore.SIGNAL('javaScriptWindowObjectCleared()'), self.BridgeToJavascript) #in case of rload, maintains in javascript self.hide()
def initPlugin(): main.AnkiQt.showAnswerButton = wrap(main.AnkiQt.showAnswerButton, afterShowAnswerButton, "after") main.AnkiQt.keyPressEvent = wrap(main.AnkiQt.keyPressEvent, aroundKeyPressEvent, "around") view.View.drawAnswer = wrap(view.View.drawAnswer, aroundDrawAnswer, "around") menu = QAction(mw) menu.setText("Add Password") mw.connect(menu, SIGNAL("triggered()"), addPassword) menu2 = QAction(mw) menu2.setText("Set GPG User Name") mw.connect(menu2, SIGNAL("triggered()"), setGPGName) mw.mainWin.menuTools.addSeparator() mw.mainWin.menuTools.addAction(menu) mw.mainWin.menuTools.addAction(menu2) config.load() if not config.loaded: setGPGName()
def init_NoWifiSync(): """Initialises the Anki GUI to present an option to invoke the plugin.""" from PyQt4 import QtGui, QtCore # creates menu entry mw.mainWin.actionNDSync = QtGui.QAction('NDSync', mw) mw.mainWin.actionNDSync.setStatusTip('Sync with Anki.nds without wifi') mw.mainWin.actionNDSync.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionNDSync, QtCore.SIGNAL('triggered()'), NoWIfySyncThread.start) # adds the plugin icons in the Anki Toolbar mw.mainWin.toolBar.addAction(mw.mainWin.actionNDSync) # to enable or disable Jstats whenever a deck is opened/closed mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("NDSync",)
def init_NoWifiSync(): """Initialises the Anki GUI to present an option to invoke the plugin.""" from PyQt4 import QtGui, QtCore # creates menu entry mw.mainWin.actionNDSync = QtGui.QAction('NDSync', mw) mw.mainWin.actionNDSync.setStatusTip('Sync with Anki.nds without wifi') mw.mainWin.actionNDSync.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionNDSync, QtCore.SIGNAL('triggered()'), NoWIfySyncThread.start) # adds the plugin icons in the Anki Toolbar mw.mainWin.toolBar.addAction(mw.mainWin.actionNDSync) # to enable or disable Jstats whenever a deck is opened/closed mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("NDSync", )
def init(): mw.actionRunIAnki = QtGui.QAction(mw) mw.actionRunIAnki.setObjectName("actionRunIAnki") mw.actionRunIAnki.setText(_("&iAnki Server")) try: menu = mw.mainWin.menuPlugins except: menu = mw.mainWin.menuTools menu.addSeparator() menu.addAction(mw.actionRunIAnki) def iankiWindow(): ianki_ext.unload() reload(sys.modules["ianki_ext"]) ianki_ext.ui.IAnkiServerDialog(mw) mw.connect(mw.actionRunIAnki, QtCore.SIGNAL("triggered()"), iankiWindow)
def createField(self, fieldName, fieldDefaultValue, fieldEnabled): mmiLayout = QHBoxLayout() checkBox = QCheckBox(fieldName) checkBox.setChecked(fieldEnabled) mmiLayout.addWidget(checkBox) lineEdit = QLineEdit(fieldDefaultValue) lineEdit.setEnabled(fieldEnabled) mmiLayout.addWidget(lineEdit) mw.connect(checkBox, SIGNAL('clicked()'), lambda lx=lineEdit, cx=checkBox: lx.setEnabled(cx.isChecked())) self.fieldsComponents.append((checkBox, lineEdit)) return mmiLayout
def init_JxPlugin(): """Initialises the Anki GUI to present an option to invoke the plugin.""" from PyQt4 import QtGui, QtCore # put JxWindow at the left of the main window widg ={} n = mw.mainWin.hboxlayout.count() for a in reversed(range(0,n)): widg[a+1]=mw.mainWin.hboxlayout.takeAt(a).widget() mw.mainWin.hboxlayout.removeWidget(widg[a+1]) widg[0]=JxWindow for a in range(0,n+1): mw.mainWin.hboxlayout.addWidget(widg[a]) # creates menu entry mw.mainWin.actionJxMenu = QtGui.QAction('JxMenu', mw) mw.mainWin.actionJxMenu.setStatusTip('Stats, Tools ans Settings for Japanese') mw.mainWin.actionJxMenu.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionJxMenu, QtCore.SIGNAL('triggered()'), onJxMenu) # creates graph entry mw.mainWin.actionJxGraphs = QtGui.QAction('JxGraphs', mw) mw.mainWin.actionJxGraphs.setStatusTip('Graphs for Japanese') mw.mainWin.actionJxGraphs.setEnabled(not not mw.deck) mw.connect(mw.mainWin.actionJxGraphs, QtCore.SIGNAL('triggered()'), onJxGraphs) # adds the plugin icons in the Anki Toolbar mw.mainWin.toolBar.addAction(mw.mainWin.actionJxMenu) mw.mainWin.toolBar.addAction(mw.mainWin.actionJxGraphs) # to enable or disable Jstats whenever a deck is opened/closed mw.deckRelatedMenuItems = mw.deckRelatedMenuItems + ("JxMenu","JxGraphs",) # Adding features through hooks ! mw.addHook('drawAnswer', append_JxPlugin) # additional info in answer cards mw.addHook('deckClosed', JxWindow.hide) # hides the main Jxplugin window when the current deck is closed # this is needed for people who open Anki by double clicking on an Anki deck (it bypasses newLoadDeck) if (mw.deck): from database import build_JxDeck build_JxDeck()
def hook_initGui(self, query): """Called after ankiqt.forms.cardlist.Ui_MainWindow.setupUi() sets up the Browser window.""" #Insert a new "History" combobox global searchHistoryCombo searchHistoryCombo = QtGui.QComboBox(self.centralwidget) searchHistoryCombo.setFixedWidth(80) searchHistoryCombo.view().setFixedWidth(250) self.hlayout1.insertWidget(1, searchHistoryCombo) mw.connect(searchHistoryCombo, QtCore.SIGNAL("activated(int)"), searchHistoryChanged) #Set the contents of the combobox (this is retained between uses of the browser via a global variable) global searchHistoryList searchHistoryCombo.clear() searchHistoryCombo.addItem("<History>") searchHistoryCombo.addItems(QtCore.QStringList(searchHistoryList)) searchHistoryCombo.addItem("<Clear>") searchHistoryCombo.setMaxVisibleItems(itemCountLimit+2) #Store a reference to the editbox so we can query it for strings global searchHistoryEdit searchHistoryEdit = self.filterEdit
def addMenu(): a = QAction(mw) a.setText("PDF Export") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), pdfExport) a = QAction(mw) a.setText("LaTeX Export") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), latexExport) a = QAction(mw) a.setText("MediaWiki Export") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), MWExport)
def addCustomDict(): # remove the standard lookup links ml = mw.mainWin.menu_Lookup for i in ("expr", "mean", "as", "es", "esk"): ml.removeAction(getattr(mw.mainWin, "actionLookup_" + i)) # add custom links q = QAction(mw) q.setText("..question") q.setShortcut(_("Ctrl+1")) ml.addAction(q) mw.connect(q, SIGNAL("triggered()"), lookupQ) a = QAction(mw) a.setText("..answer") a.setShortcut(_("Ctrl+2")) ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), lookupA) s = QAction(mw) s.setText("..selection") s.setShortcut(_("Ctrl+3")) ml.addAction(s) mw.connect(s, SIGNAL("triggered()"), lookupS)
from PyQt4.QtGui import * from PyQt4.QtCore import * from ankiqt import mw from anki.utils import genID from ankiqt.ui.utils import showInfo def run(): db = mw.deck.s mw.startProgress() # gather old ids data = [] for id in db.column0("select id from facts"): data.append(dict(new=genID(), old=id)) # update facts db.statements("update facts set id = :new where id = :old", data) # fields db.statements("update fields set id = random(), factId = :new where factId = :old", data) # cards db.statements("update cards set id = random(), factId = :new where factId = :old", data) mw.finishProgress() mw.deck.setModified() mw.deck.save() showInfo("Done.") a = QAction(mw) a.setText("Make Cards Unique") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), run)
#DEBUG: QMessageBox.information(mw, "Information", "Cancelled on card types dialog") else: #DEBUG: QMessageBox.information(mw, "Information", "All required models already exist, importing...") runImport(modelManager, importSettings) else: pass #DEBUG: QMessageBox.warning(mw, "Warning", "Cancelled on import settings dialog") def showHelp(): try: QDesktopServices.openUrl(QUrl("http://wiki.github.com/ridisculous/anki-iknow-importer")) except: QMessageBox.information(mw, "Information", "Please see the smart.fm importer wiki at http://wiki.github.com/ridisculous/anki-iknow-importer.") dialogStart = QAction(mw) dialogStart.setText("Smart.fm Importer") mw.connect(dialogStart, SIGNAL("triggered()"), runDialog) mw.mainWin.menuTools.addAction(dialogStart) mw.actionSmartFMHelp = QtGui.QAction(mw) mw.actionSmartFMHelp.setObjectName("smartfmHelp") mw.actionSmartFMHelp.setText(_("Open Smart.FM Importer Help Wiki")) mw.connect(mw.actionSmartFMHelp, SIGNAL("triggered()"), showHelp) menu = None try: menu = mw.mainWin.menuPlugins except: menu = mw.mainWin.menuTools menu.addSeparator() menu.addAction(mw.actionSmartFMHelp)
""") label.setTextInteractionFlags = Qt.TextSelectableByMouse | Qt.LinksAccessibleByMouse layout.addWidget(label) text = QTextEdit() text.setPlainText(mw.deck.getVar("fontCSS") or "") layout.addWidget(text) box = QDialogButtonBox(QDialogButtonBox.Close) layout.addWidget(box) box.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) def onClose(): mw.deck.setVar("fontCSS", unicode(text.toPlainText())) ui.utils.showInfo("""\ Settings saved. Please see the documentation for the next step.""") diag.connect(diag, SIGNAL("rejected()"), onClose) diag.setMinimumHeight(400) diag.setMinimumWidth(500) diag.exec_() # Setup menu entries menu1 = QAction(mw) menu1.setText("Embedded Fonts...") mw.connect(menu1, SIGNAL("triggered()"),onEdit) mw.mainWin.menuTools.addSeparator() mw.mainWin.menuTools.addAction(menu1)
) def incrementKanji(self): self.determineNextKanji() self.kanjiLabel.setText("<b>" + _("Kanji") + "</b>" + (": %s" % self.currentKanji)) self.fld_story.setText(u"") self.fld_primitives.setText(u"") self.fld_keyword.setText(u"") self.fld_keyword.setFocus() def cancelClicked(self): self.conn.close() self.close() def runDialog(): try: dialog = RTKImportDialog() dialog.show() except: QMessageBox.warning( mw, "Warning", "The RTK Import plugin could not run properly. Please check that you have installed all the necessary files. See the readme file (Settings->Plugins->Show Plugins Directory: file 'RTK_IMPORT_README') for details." ) dialogStart = QAction(mw) dialogStart.setText("RTK - Add Kanji") mw.connect(dialogStart, SIGNAL("triggered()"), runDialog) mw.mainWin.menuTools.addAction(dialogStart)
def init(): q = QAction(mw) q.setText("Bulk Rename") mw.mainWin.menuAdvanced.addSeparator() mw.mainWin.menuAdvanced.addAction(q) mw.connect(q, SIGNAL("triggered()"), bulkrename)
# -*- coding: utf-8 -*- # Copyright: Damien Elmes <*****@*****.**> # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html # # Fix the ordering of cards so that different templates are shown one after # another if the minimum spacing is 0. You only need this if a previous bug in # Anki (now fixed) didn't set the order right. # from ankiqt import mw from ankiqt import ui from PyQt4.QtCore import * from PyQt4.QtGui import * def onFix(): mw.deck.s.execute(""" update cards set created = (select created from facts where cards.factId = facts.id) + cards.ordinal * 0.000001""") mw.deck.s.execute(""" update cards set due = created, combinedDue = max(created,spaceUntil) where type = 2""") ui.utils.showInfo("Ordering fixed.") act = QAction(mw) act.setText("Fix Ordering") mw.connect(act, SIGNAL("triggered()"), onFix) mw.mainWin.menuTools.addAction(act)
def init(): mw.mainWin.morphMan = QAction( 'MorphMan', mw ) mw.connect( mw.mainWin.morphMan, SIGNAL('triggered()'), onMorphMan ) mw.mainWin.toolBar.addAction( mw.mainWin.morphMan )
# -*- coding: utf-8 -*- # Copyright: Damien Elmes <*****@*****.**> # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html # # This plugin adds the ability to toggle full screen mode. It adds an item to # the tools menu. # from PyQt4.QtGui import * from PyQt4.QtCore import * from ankiqt import mw def onFullScreen(): mw.setWindowState(mw.windowState() ^ Qt.WindowFullScreen) a = QAction(mw) a.setText("Toggle Full Screen") a.setShortcut("F11") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), onFullScreen)
# reading is sometimes missing if not f['Reading'] and kakasi: f['Reading'] = kakasi.toFurigana(f['Expression']) except KeyError: f['Reading'] = u"" if includeSounds and sen['sound']: (file, headers) = urllib.urlretrieve(sen['sound']) path = mw.deck.addMedia(file) f['Audio'] = u'[sound:%s]' % path else: f['Audio'] = u"" if includeImages and sen['image']: (file, headers) = urllib.urlretrieve(sen['image']) path = mw.deck.addMedia(file) f['Image'] = u'<img src="%s">' % path else: f['Image'] = u"" mw.deck.addFact(f) diag.cancel() mw.deck.save() act = QAction(mw) act.setText("Smart.fm Import") mw.connect(act, SIGNAL("triggered()"), doImport) mw.mainWin.menuTools.addSeparator() mw.mainWin.menuTools.addAction(act) mw.registerPlugin("Smart.fm Sentence Importer", 1)
epwingLookup(mw.currentCard.fact['Meaning']) def lookupS(): mw.initLookup() mw.lookup.selection(epwingLookup) # remove the standard lookup links ml = mw.mainWin.menu_Lookup for i in ("expr", "mean", "as", "es", "esk"): ml.removeAction(getattr(mw.mainWin, "actionLookup_" + i)) # add custom links q = QAction(mw) q.setText("..question") q.setShortcut(_("Ctrl+1")) ml.addAction(q) mw.connect(q, SIGNAL("triggered()"), lookupQ) a = QAction(mw) a.setText("..answer") a.setShortcut(_("Ctrl+2")) ml.addAction(a) mw.connect(a, SIGNAL("triggered()"), lookupA) s = QAction(mw) s.setText("..selection") s.setShortcut(_("Ctrl+3")) ml.addAction(s) mw.connect(s, SIGNAL("triggered()"), lookupS) mw.registerPlugin("Custom Dictionary Lookup", 5)
def markAndDelete(): undo = _("MarkDelete") mw.deck.setUndoStart(undo) mw.currentCard.fact.tags = canonifyTags(mw.currentCard.fact.tags + "," + "MarkDelete") mw.currentCard.fact.setModified() mw.deck.updateFactTags([mw.currentCard.fact.id]) mw.deck.deleteCard(mw.currentCard.id) mw.reset() mw.deck.setUndoEnd(undo) act = QAction(mw) act.setText("Mark and &Delete") icon = QIcon() icon.addPixmap(QPixmap(":/icons/editdelete.png")) act.setIcon(icon) mw.connect(act, SIGNAL("triggered()"), markAndDelete) old = mw.mainWin.actionDelete act.setEnabled(old.isEnabled()) mw.mainWin.menuEdit.removeAction(mw.mainWin.actionDelete) mw.mainWin.menuEdit.addAction(act) # make sure it's enabled/disabled mw.mainWin.actionDelete = act mw.registerPlugin("Mark and Delete", 8)
from ankiqt.ui.utils import showInfo def run(): db = mw.deck.s mw.startProgress() # gather old ids data = [] for id in db.column0("select id from facts"): data.append(dict(new=genID(), old=id)) # update facts db.statements("update facts set id = :new where id = :old", data) # fields db.statements( "update fields set id = random(), factId = :new where factId = :old", data) # cards db.statements( "update cards set id = random(), factId = :new where factId = :old", data) mw.finishProgress() mw.deck.setModified() mw.deck.save() showInfo("Done.") a = QAction(mw) a.setText("Make Cards Unique") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), run)
def init(): mw.mainWin.jVocab = QAction('jVocab', mw) mw.connect(mw.mainWin.jVocab, SIGNAL('triggered()'), onJVocab) mw.mainWin.toolBar.addAction(mw.mainWin.jVocab)
# -*- coding: utf-8 -*- # Copyright: Damien Elmes <*****@*****.**> # License: GNU GPL, version 3 or later; http://www.gnu.org/copyleft/gpl.html # # Fix floast in the DB which have been mistakenly turned into strings due to # string concatenation. # from ankiqt import mw from ankiqt import ui from PyQt4.QtCore import * from PyQt4.QtGui import * def onFix(): for col in ("created", "due", "combinedDue", "spaceUntil"): mw.deck.s.execute("update cards set %s = cast (%s as float)" % (col, col)) mw.deck.setModified() ui.utils.showInfo("Fixed.") act = QAction(mw) act.setText("Fix Floats") mw.connect(act, SIGNAL("triggered()"), onFix) mw.mainWin.menuTools.addAction(act)
def init(): q = QAction(mw) q.setText("Postpone") mw.mainWin.menuTools.addAction(q) mw.connect(q, SIGNAL("triggered()"), postpone)
label.setTextInteractionFlags = Qt.TextSelectableByMouse | Qt.LinksAccessibleByMouse layout.addWidget(label) text = QTextEdit() text.setPlainText(mw.deck.getVar("fontCSS") or "") layout.addWidget(text) box = QDialogButtonBox(QDialogButtonBox.Close) layout.addWidget(box) box.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) def onClose(): mw.deck.setVar("fontCSS", unicode(text.toPlainText())) ui.utils.showInfo("""\ Settings saved. Please see the documentation for the next step.""") diag.connect(diag, SIGNAL("rejected()"), onClose) diag.setMinimumHeight(400) diag.setMinimumWidth(500) diag.exec_() # Setup menu entries menu1 = QAction(mw) menu1.setText("Embedded Fonts...") mw.connect(menu1, SIGNAL("triggered()"), onEdit) mw.mainWin.menuTools.addSeparator() mw.mainWin.menuTools.addAction(menu1)
def createMenu(): a = QAction(mw) a.setText("Kanji Stats") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), onKanjiStats)
def init(): q = QAction(mw) q.setText("Move Tags") mw.mainWin.menuPlugins.addAction(q) mw.connect(q, SIGNAL("triggered()"), moveTags)
def onHardest(): data = mw.deck.s.all(""" select question, cnt from ( select cardId, count() as cnt from reviewHistory where time > :t and ease = 1 group by cardId), cards where cardId = id order by cnt desc limit :d""", t=time.time() - 60*MINUTES, d=MAXCARDS) s = "<h1>Hardest Cards</h1><table>" for (q, cnt) in data: s += "<tr><td>%s</td><td>failed %d times</td></tr>" % (q, cnt) # show dialog diag = QDialog(mw.app.activeWindow()) diag.setWindowTitle("Anki") layout = QVBoxLayout(diag) diag.setLayout(layout) text = QTextEdit() text.setReadOnly(True) text.setHtml(s) layout.addWidget(text) box = QDialogButtonBox(QDialogButtonBox.Close) layout.addWidget(box) mw.connect(box, SIGNAL("rejected()"), diag, SLOT("reject()")) diag.setMinimumHeight(400) diag.setMinimumWidth(500) diag.exec_() a = QAction(mw) a.setText("Show Hardest Cards") mw.mainWin.menuTools.addAction(a) mw.connect(a, SIGNAL("triggered()"), onHardest)
searchword = field.value.lower().strip() try: if fact['Chinese Definition'] == "": # Generate if empty fact['Chinese Definition'] = findMandarinDef(searchword) except KeyError: pass try: if fact['English Definition'] == "": fact['English Definition'] = findEnglishDef(searchword) except KeyError: pass try: if fact['English Pronunciation'] == "": fact['English Pronunciation'] = findEnglishPro(searchword) except KeyError: pass addHook('fact.focusLost', onFocusLost) # Setup menu entries menu1 = QAction(mw) menu1.setText("Don't Fetch English Pronunciation Audio") mw.connect(menu1, SIGNAL("triggered()"),fetchAudioToggle) mw.mainWin.menuTools.addSeparator() mw.mainWin.menuTools.addAction(menu1) mw.registerPlugin("English Helper for Chinese zh-tw", 0.10)
else: return None return dir def configureDirectory(): if mw.config.get(CONFIG_CUSTOM_MEDIA_DIR, ""): return dir = QFileDialog.getExistingDirectory( mw, _("Choose Media Directory"), mw.documentDir, QFileDialog.ShowDirsOnly) dir = unicode(dir) if not dir: return mw.config[CONFIG_CUSTOM_MEDIA_DIR] = dir mw.config.save() def reconfigureDirectory(): mw.config[CONFIG_CUSTOM_MEDIA_DIR] = "" configureDirectory() Deck.mediaDir = wrap(Deck.mediaDir,newMediaDir,"") # Setup menu entries menu1 = QAction(mw) menu1.setText("Change Media Directory") mw.connect(menu1, SIGNAL("triggered()"),reconfigureDirectory) mw.mainWin.menuAdvanced.addSeparator() mw.mainWin.menuAdvanced.addAction(menu1) addHook("init", configureDirectory)