def forvo(self, field_list=expression_fields): "Look up pronunciation on forvo." if field_list: text = self.get_text_from_fields(field_list) else: text = self.get_selection() if len(text) == 0: raise ValueError(u"No text to look up.") new_text = urllib.quote(text.encode("utf-8")) url = ("http://de.forvo.com/search/" + new_text) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def wadoku(self, field_list=expression_fields): "Look up TEXT with Wadoku (German-Japanese)." if field_list: text = self.get_text_from_fields(field_list) else: text = self.get_selection() if len(text) == 0: raise ValueError(u"Kein Text zum nachschlagen.") base_url = "http://www.wadoku.de/wadoku/search/" url = base_url + urllib.quote(text.encode("utf-8")) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def lookup_forvo(field_list): "Look up pronunciation on forvo." if field_list: text = get_text_from_fields(field_list) else: text = get_selection() if len(text) == 0: raise ValueError(u"No text to look up.") new_text = urllib.quote(text.encode("utf-8")) url = ("http://de.forvo.com/search/" + new_text) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def lookup_wadoku(field_list): "Look up text with Wadoku (German-Japanese)." if field_list: text = get_text_from_fields(field_list) else: text = get_selection() if len(text) == 0: raise ValueError(u"Kein Text zum nachschlagen.") base_url = "http://www.wadoku.de/wadoku/search/" url = base_url + urllib.quote(text.encode("utf-8")) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def kanjilexikon(self, field_list=expression_fields): """Look up first kanji in text on Kanji-Lexikon.""" if field_list: kanji = self.get_text_from_fields(field_list) else: kanji = self.get_selection() kanji = self.get_han_characters(kanji) if len(kanji) == 0: raise ValueError("No kanji found.") new_text = urllib.quote(kanji.encode("utf-8")) url = ("http://lingweb.eva.mpg.de/kanji/index.html?kanji=" + new_text) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def lookup_kanjilexikon(field_list): """Look up the kanji in text on Kanji-Lexikon.""" if field_list: kanji = get_text_from_fields(field_list) else: kanji = get_selection() kanji = get_han_characters(kanji) if len(kanji) == 0: raise ValueError("No kanji found.") new_text = urllib.quote(kanji.encode("utf-8")) url = ("http://lingweb.eva.mpg.de/kanji/index.html?kanji=" + new_text) qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def open_browser(word, config): if (not config.get('open_in_browser', True)): return None url = 'https://en.oxforddictionaries.com/definition/' + str(word) tooltip(("Loading..."), period=1000) url = QUrl(url) QDesktopServices.openUrl(url)
def saiga(self, field_list=expression_fields): """Look up first kanji in text on Saiga.""" # I don’t really use this dictionary any more. Feel free to # add it to your menu again. if field_list: kanji = self.get_text_from_fields(field_list) else: kanji = self.get_selection() kanji = self.get_first_han_character(kanji) if len(kanji) == 0: raise ValueError("No kanji found.") new_text = urllib.quote(kanji.encode("utf-8")) url = ("http://www.saiga-jp.com/cgi-bin/dic.cgi?m=search&sc=0&f=0&j=" + new_text + "&g=&e=&s=&rt=0&start=1") qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def lookup_saiga(field_list): """Look up the first kanji in text on Saiga.""" # I don’t really use this dictionary any more. Feel free to # add it to your menu again. if field_list: kanji = get_text_from_fields(field_list) else: kanji = get_selection() kanji = get_first_han_character(kanji) if len(kanji) == 0: raise ValueError("No kanji found.") new_text = urllib.quote(kanji.encode("utf-8")) url = ("http://www.saiga-jp.com/cgi-bin/dic.cgi?m=search&sc=0&f=0&j=" + new_text + "&g=&e=&s=&rt=0&start=1") qurl = QUrl() qurl.setEncodedUrl(url) QDesktopServices.openUrl(qurl)
def gotoLocalFile(self, rootHtmlPath): rootHtmlPath = getResourcePath(rootHtmlPath) # Code from AnkiWebView::_setHtml app = QApplication.instance() # work around webengine stealing focus on setHtml() oldFocus = app.focusWidget() self.web._page.setUrl(QUrl.fromLocalFile(rootHtmlPath)) if oldFocus: oldFocus.setFocus()
def acceptNavigationRequest(self, url, navType, isMainFrame): if not isMainFrame: return True # data: links generated by setHtml() if url.scheme() == "data": return True # catch buggy <a href='#' onclick='func()'> links from aqt import mw if url.matches(QUrl(mw.serverURL()), QUrl.RemoveFragment): print("onclick handler needs to return false") return False # load all other links in browser openLink(url) return False
def show_in_filemanager(filename): """mod of aqt.utils openFolder""" _, path, _, _ = process_path(filename) if isWin: subprocess.Popen(f'explorer /select, "file://{path}" ') elif isMac: with noBundledLibs(): script = """ tell application \"Finder\" activate select POSIX file \"{}\" end tell """.format(path) subprocess.Popen(osascript_to_args(script)) elif isLin: us = gc("File Manager in Linux and its args") us = check_if_executable_exists(us[0]) if not us: return if us: us.append("file://" + path) subprocess.Popen(us, env=env_adjust()) else: select_supported = ["dolphin", "nautilus" ] # caja 1.24 doesn't have "--select" for fm in select_supported: if which(fm) is not None: subprocess.Popen([fm, "--select", "file://" + path], env=env_adjust()) else: showInfo( "The file manager will show your media folder. The name of the file you " f"clicked is:\n\n{os.path.dirname(path)}") with noBundledLibs(): QDesktopServices.openUrl( QUrl("file://" + os.path.dirname(path)))
def showAnswerGrid(self, card, rev, baseURL): dialog = self view = dialog.ui.gridView # set commands on the custom page to recognise special link handler view.page().setSpecialLinks( [GridDlg._closepopupCommand, GridDlg._replayaudioCommand]) cardFrontHtml = renderOneQA(rev, card, "question") klass = "card card{}".format(card.ord + 1) width = int(0.96 * self.size().width()) height = int(0.96 * self.size().height()) buffer = 60 # e.g. for the window's title bar, and a bottom 'margin' html = gridHtml('', klass, width, height - buffer) htmlFinal = html.replace("##fgCardFront##", cardFrontHtml) gridw = GridDlg._gridSize size = gridw**2 # still assuming a square grid (for now anyway) dummy = '\nnot found\n' cards = [dummy for i in range(size)] # i.e. 4 or 9 dummies cards[dialog.correct - 1] = renderOneQA( rev, card, "answer") # put in the real answer deckName = mw.col.decks.current()['name'] search = '-is:suspended deck:"{}"'.format(deckName) cardsFound = mw.col.findCards( search ) # e.g. '-is:suspended deck:indonesian-lift-dictionary-Orig' cardsFound = cardsFound or [ ] # using object or evaluation to ensure list random.shuffle(cardsFound) i = 0 for c in cardsFound: # at most; but usually we'll quit after gridw*gridh if c is None: # If c is empty, do no more continue id = i + 1 # these are offset by one since grid's id-numbering is 1-based but array is 0-based if id > size: break if c == card.id or id == dialog.correct: # don't use current card nor steal its cell i += 1 continue else: cellCard = mw.col.getCard(c) if cellCard is None or (cellCard.template() != card.template()): # do NOT increment i continue # something went wrong finding that card (throw exception?) thecard = renderOneQA(rev, cellCard, "answer") if thecard is None: continue # Did not get a valid card, so get the next one cards[i] = thecard i += 1 counter = 0 # We use a counter so we can handle missing cells for i in range(size): drop = True try: drop = cards[i] == '\nnot found\n' except IndexError: continue # Do nothing if drop: cards[i] = "" # empty cell? else: counter += 1 # increment id = i + 1 cards[i] = '<td class="{}">{}</td>'.format( klass, gridHtmlCell(id, cards[i])) if counter % gridw == 0 and id < size: # use modulus to identify/create end of row cards[i] += gridHtmlBetweenRows() toInsert = '\n'.join(cards) toInsert = '''<table class="{}"><tbody><tr> {} </tr></tbody></table>'''.format(klass, toInsert) htmlFinal = htmlFinal.replace("##fgCardGridArea##", toInsert) # enable for debug saving: # htmlRender(htmlFinal) view.page().setHtml(htmlFinal, QUrl.fromLocalFile(baseURL))
def setUrl(self, url: str): self._browser.load(QUrl(url))
def lookup_online(url, searchterm): # searches based on a url and a term if searchterm: QDesktopServices.openUrl(QUrl(url % searchterm))
def openFolder(path): if isWin: subprocess.Popen(["explorer", "file://"+path]) else: with noBundledLibs(): QDesktopServices.openUrl(QUrl("file://" + path))
def openLink(link): tooltip(_("Loading..."), period=1000) with noBundledLibs(): QDesktopServices.openUrl(QUrl(link))
def get_help() -> None: "Launch the documentation for this dialog in a browser." url = QUrl( r"https://sobjornstad.github.io/TiddlyRemember/#Configuring%20the%20Anki%20add-on" ) QDesktopServices.openUrl(url)