def script_speakInfo(self, gesture): try: fg = api.getForegroundObject() s2 = fg.firstChild.next.next.next.next.next.firstChild.next.name s3 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.name s4 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.next.name s7 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.next.next.next.next.name s8 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.next.next.next.next.next.name if not s8: s7 = "" s5 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.next.next.next.next.next.next.next.next.name s6 = fg.firstChild.next.next.next.next.next.firstChild.next.next.next.next.next.next.next.next.next.next.next.next.next.next.name infoString = (" %s %s %s %s %s %s %s" % (s2, s3, s4, s7, s8, s5, s6)) infoString2 = (" %s %s %s %s %s %s %s" % (s2, s3, s4, s7, s8, s5, s6)) #infoString2 = s2+" - "+s4+" - "+s6 infoString3 = ("%s %s %s %s %s %s" % (s3, s4, s7, s8, s5, s6)) #infoString3 = s4+" - "+s6 if scriptHandler.getLastScriptRepeatCount() == 1: #double press api.copyToClip(infoString3) tones.beep(1500, 120) else: num = int(gesture.mainKeyName[-1]) if num == 2: if not s6: s6 = "no song information found!" if not s4: s4 = "no station information found!" ui.browseableMessage(infoString2, title="Now playing on " + s4, isHtml=False) else: ui.message(infoString) except AttributeError: pass
def script_sent(self, gesture): global orig fg = api.getForegroundObject() try: handle = windowUtils.findDescendantWindow( fg.windowHandle, className="RichEdit20WPT", controlID=4098) if handle: # found handle w = NVDAObjects.IAccessible.getNVDAObjectFromEvent( handle, winUser.OBJID_CLIENT, 0) if scriptHandler.getLastScriptRepeatCount() == 2: # trible press, copy to clipboard and set focus to original field api.copyToClip(w.value) ui.message(_("Copied to clipboard")) api.setNavigatorObject(w, isFocus=True) orig.setFocus() elif scriptHandler.getLastScriptRepeatCount() == 1: # double press, set focus in field winUser.setForegroundWindow(handle) else: # single press ui.message(" %s %s" % (w.name, w.value)) orig = api.getFocusObject() except LookupError: # for RSS mails try: handle = windowUtils.findDescendantWindow( fg.windowHandle, className="RichEdit20WPT", controlID=4105) if handle: # found handle w = NVDAObjects.IAccessible.getNVDAObjectFromEvent( handle, winUser.OBJID_CLIENT, 0) ui.message(" %s %s" % (w.name, w.value)) except LookupError: tones.beep(440, 20)
def sendCaptcha(self, **kwargs): kwargs['soft_id'] = 1665 kwargs['regsense'] = int(_config.conf['regsense']) kwargs['language'] = _config.conf['language'] response = requestAPI(**kwargs) speech.cancelSpeech() if not response.startswith('OK|'): errorHandler(response) return ui.message( _('Captcha successfully sent to the recognition. You will be notified when the result will be ready' )) time.sleep(3) while self._running: status = requestAPI(action='get', id=response[3:]) if (status != 'CAPCHA_NOT_READY') and self._running: break time.sleep(2) else: return if status.startswith('OK|'): api.copyToClip(status.decode('utf-8')[3:]) ui.message( _('Captcha solved successfully! The result copied to the clipboard' )) else: errorHandler(status)
def showResult(self, response): # Translators: Message added before recognition result # when user do not use result viewer result_prefix = _(u"Recognition result:") ocrResult = self.extract_text(response) if ocrResult.isspace(): # Translators: Reported when recognition result is empty self.showMessageInNetworkThread( _(u"Recognition result is blank. This engine cannot extract anny content from this image." )) self.cleanUp() return resultText = result_prefix + ocrResult if config.conf["onlineOCRGeneral"]["copyToClipboard"]: api.copyToClip(resultText) if self.text_result: if config.conf["onlineOCRGeneral"]["useBrowseableMessage"]: self.showBrowseableMessageInNetworkThread(resultText) else: self.showMessageInNetworkThread(resultText) else: self.onResult( LinesWordsResult(self.convert_to_line_result_format(response), self.imageInfo))
def selectIndentationBlock(self, selectMultiple=False, successMessage=""): count = scriptHandler.getLastScriptRepeatCount() if selectMultiple and count >= 1: # Just copy selection to the clipboard focus = api.getFocusObject() textInfo = focus.makeTextInfo(textInfos.POSITION_SELECTION) api.copyToClip(textInfo.text) ui.message(successMessage) with self.getLineManager() as lm: if count >= 1: textInfo = lm.getTextInfo() textInfo.collapse() textInfo.updateCaret() # Get the current indentation level text = lm.getText() originalTextInfo = lm.getTextInfo() indentationLevel = self.getIndentLevel(text) onEmptyLine = speech.isBlank(text) if onEmptyLine: return self.endOfDocument(_("Nothing to select")) # Scan each line forward as long as indentation level is greater than current line = lm.getLine() indentLevels = [] while True: result = lm.move(1) if result == 0: if not selectMultiple and count >= 1: core.callLater(100, self.endOfDocument, _("No more indentation blocks!")) break text = lm.getText() newIndentation = self.getIndentLevel(text) if speech.isBlank(text): continue if newIndentation < indentationLevel: if not selectMultiple and count >= 1: core.callLater(100, self.endOfDocument, _("No more indentation blocks!")) #self.endOfDocument(_("No more indentation blocks!")) break elif newIndentation == indentationLevel: if selectMultiple: pass elif count > 0: count -= 1 else: break else: # newIndentation > indentationLevel pass line = lm.getLine() indentLevels.append(newIndentation) selection = originalTextInfo.copy() if line is not None: textInfo = lm.getTextInfo(line) selection.setEndPoint(textInfo, "endToEnd") selection.updateSelection() self.crackle(indentLevels) speech.speakTextInfo(textInfo, unit=textInfos.UNIT_LINE)
def script_TCAclip(self, gesture): tsu.t_obj(self) if self.v_obj is not False: api.copyToClip('"{}"'.format(self.v_obj)) ui.message(_('Ruta copiada ')) else: ui.message(_("No se pudo copiar la ruta"))
def callback(repeatCount): text = getPlayInfos() if repeatCount: api.copyToClip(text) ui.message(_("Informations copied to clipboard")) else: ui.message(text)
def onInstall(): import wx, api # Translators: donation dialog title. dialogTitle = _("Would you like to donate?") # Translators: donation dialog message. ret = wx.MessageBox(_("If you like my work, please consider donating. Any contribution you can give helps me to keep going. My paypal E-mail is [email protected]. Would you like to copy it to your clipboard? You can always find it under nvda settings/screen wrapping"), dialogTitle, style=wx.YES_NO) if ret == wx.YES: api.copyToClip("*****@*****.**")
def script_copyLast(self, gesture): import scriptHandler repeat = scriptHandler.getLastScriptRepeatCount() if repeat > 0: if api.copyToClip(history[history_pos].strip()): tones.beep(1500, 120) else: if api.copyToClip(history[history_pos]): tones.beep(1000, 120)
def captchaHandler(self, resp, err): if err is not None: ui.message(err) return api.copyToClip(resp) ui.message( _("Captcha solved successfully! The result copied to the clipboard" ))
def script_copyMarkdownToClip(self, gesture): metadata, text = getMetadataAndTextForMarkDown() if not metadata: return res = convertToMD(text, metadata, display=False) if res: api.copyToClip(res) ui.message(_("Markdown copied to clipboard")) else: ui.message(_("An error occured"))
def applyCorrections(self): self.Close() KeyboardInputGesture.fromName("Control+home").send() KeyboardInputGesture.fromName("Control+Shift+end").send() api.copyToClip(str(allText)) time.sleep(2.0) KeyboardInputGesture.fromName("Control+v").send() spellCheckerDialog._instance = None super (spellCheckerDialog, self).Destroy()
def script_copyHTMLSrcToClip(self, gesture): text, err = getText() if err: return ui.message(err) if not text: return ui.message(_("No text")) metadata, text = extractMetadata(text) api.copyToClip(convertToHTML(text, metadata, src=True, display=False, useTemplateHTML=False)) ui.message(_("HTML source copied to clipboard"))
def translateHandler(self, status, request): if not status: self.errorHandler(request) return self.llastTranslatedText = "\n".join(request["text"]) ui.message(self.llastTranslatedText) if config.conf["YandexTranslate"]["copyToClipBoard"]: api.copyToClip(self.llastTranslatedText)
def script_copyLastTranslation(self, gesture): global _lastTranslatedText if _lastTranslatedText is not None and len(_lastTranslatedText) > 0: api.copyToClip(_lastTranslatedText) ui.message( _("translation {text} ¨copied to clipboard".format( text=_lastTranslatedText))) else: ui.message(_("No translation to copy"))
def onActivatedListItem(self, evt): clipSelection = self.getClipListSelection() if clipSelection == [-1]: return False self.Hide() clip = self.clipList.GetItemText(self.clipList.FocusedItem) api.copyToClip(clip) paste = KeyboardInputGesture.fromName("control+v") paste.send() self.Close() evt.Skip()
def onCopy(self, evt): address = self.body.findall("outline")[self.filteredItems[ self.sel]].get("xmlUrl") if gui.messageBox( # Translators: the label of a message box dialog. _("Do you want to copy feed address to the clipboard\r\n\r\n{feedAddress}?" .format(feedAddress=address)), # Translators: the title of a message box dialog. _("Copy feed address"), wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION) == wx.YES: api.copyToClip(address)
def script_TCAclip(self, gesture): f = api.getForegroundObject() try: obj = f.children[1].children[2].children[0].children[0].children[0] except: obj = f.children[1].children[0].children[2].children[0].children[ 0].children[0] c_obj = obj.name a = c_obj.replace('Dirección: ', '') api.copyToClip('"{}"'.format(a)) ui.message('Ruta copiada ')
def script_copieCell(self, gesture): if scriptHandler.getLastScriptRepeatCount() == 0: value = self._tableau.getCell().name speech.speakMessage(u"copie de la cellule") else: value = "" for c in self._tableau.getRow().getCells(): value += c.brlText() + " " speech.speakMessage(u"copie de la ligne ") speech.speakMessage(value) api.copyToClip(value)
def confirmCopy(self): text = self.getSelectedText() # Translators: Label of a dialog. if gui.messageBox(_("Please, confirm if you want to copy to the clipboard"), # Translators: Title of a dialog. _("Copying to clipboard"), wx.OK|wx.CANCEL) != wx.OK: return if text: api.copyToClip(text) else: wx.CallLater(200, self.copy)
def onCopyToClipBtn(self, event): self.updateMetadata() metadata = self.metadata destFormatChoices_ = self.destFormatListBox.GetSelection() if destFormatChoices_ == 0: copyToClipAsHTML(convertToHTML(self.text, metadata, display=False)) elif destFormatChoices_ == 1: api.copyToClip( convertToHTML(self.text, metadata, src=True, display=False)) else: api.copyToClip(convertToMD(self.text, metadata, display=False)) self.Destroy()
def onArticlesListInfo(self, evt): articleInfo = "{title}\r\n\r\n{address}".format( title=self.articlesList.StringSelection, address=self.Parent.feed.getArticleLink( self.articlesList.Selection)) if gui.messageBox( # Translators: the label of a message box dialog. _("%sDo you want to copy article title and link to the clipboard?" % (articleInfo + "\r\n\r\n")), # Translators: the title of a message box dialog. _("Article information"), wx.YES | wx.NO | wx.CANCEL | wx.ICON_QUESTION) == wx.YES: api.copyToClip(articleInfo)
def onCopyClipboard (self, event): if self.textoDestino.GetValue() == "": # Translators: Error message, nothing to copy to clipboard msg = \ _("""No hay ninguna URL acortada. Tiene que generar una antes para copiarla al portapapeles.""") gui.messageBox(msg, # Translators: Message window title: Error _("Error"), wx.ICON_ERROR) self.textoOrigen.SetFocus() else: api.copyToClip(self.textoDestino.GetValue()) ui.message(_("Se a copiado la URL al portapapeles. Ya puede compartirla."))
def currentCharDesc(): ch = getCurrentChar() c = ord(ch) if c != '': s = '%c: %s; %s; %s; %s'% (ch, hex(c), c, oct(c), bin(c)) if scriptHandler.getLastScriptRepeatCount() == 0: ui.message(s) elif (scriptHandler.getLastScriptRepeatCount() == 1): brch = getTextInBraille(ch) ui.browseableMessage('%s\n%s (%s)' % (s, brch, unicodeBrailleToDescription(brch)), r'\x%d - Char info' % c) else: api.copyToClip(s) ui.message('"{0}" copied to clipboard.'.format(s)) else: ui.message(_('Not a character.'))
def translate(self, text: str, isHtml: bool = False) -> None: """Retrieve the dictionary entry for the given word or phrase and display/announce the result. This method must always be called in a separate thread so as not to block NVDA. @param text: a word or phrase to look up in a dictionary @type text: str @param isHtml: a sign of whether it is necessary to display the result of work in the form of HTML page @type isHtml: bool """ active = config.conf[addonName]['active'] langs = services[active].langs pairs = [(self.source, self.target)] if self.isAutoSwap: if langs.isAvailable(self.target, self.source): pairs.append((self.target, self.source)) for lFrom, lInto in pairs: translator = translateWithCaching(lFrom, lInto, text, hashForCache(active)) if translator.error: translateWithCaching.cache_clear( ) # reset cache when HTTP errors occur self._cacheInfo = str(translateWithCaching.cache_info( )) # - to check the current status of queries cache if translator.plaintext: break else: if not translator.plaintext: # Translators: Notification of missing dictionary entry for current request ui.message(_("No results")) self._messages.clear() return self._lastTranslator = translator setattr(self._lastTranslator, 'id', active) if isHtml: ui.browseableMessage(message=translator.html, title='%s-%s' % (langs[translator.langFrom].name, langs[translator.langTo].name), isHtml=isHtml) else: self._messages.append('%s - %s' % (langs[translator.langFrom].name, langs[translator.langTo].name)) self._messages.append(translator.plaintext) message = '...'.join(self._messages) self._messages.clear() queueFunction(eventQueue, messageWithLangDetection, { 'text': message, 'lang': translator.langTo }) if self.isCopyToClipboard: api.copyToClip(translator.plaintext, notify=True)
def script_speakAndCopyMemory(self, gesture): """When pressed, this key speaks and copies the text saved at this position of the NVDA memory to the clipboard.""" keyCode = gesture.vkCode try: data = self.memory[keyCode] if getLastScriptRepeatCount() == 0: ui.message(data) elif getLastScriptRepeatCount() >= 1: api.copyToClip(data) ui.message(f"Copied {data}") # Paste the selected text keyboardHandler.KeyboardInputGesture.fromName("CONTROL+V").send() except KeyError: ui.message("No data at this position")
def script_copyLastResult(self, gesture: InputGesture) -> None: """Copy the last received dictionary entry to the clipboard. @param gesture: gesture assigned to this method @type gesture: InputGesture """ if not self._lastTranslator: # Translators: Notification that no dictionary entries have been received in the current session ui.message(_("There is no dictionary queries")) return service = services[getattr(self._lastTranslator, 'id', config.conf[addonName]['active'])] api.copyToClip(self._lastTranslator.plaintext, notify=True) ui.message('%s - %s' % ( service.langs[self._lastTranslator.langFrom].name, service.langs[self._lastTranslator.langTo].name))
def _paste_safe(self, text, obj=None, label=False): try: temp = api.getClipData() except: temp = '' api.copyToClip(text) if label == True: KIGesture.fromName('p').send() KIGesture.fromName('control+alt+v').send() else: KIGesture.fromName('control+v').send() api.processPendingEvents() if obj: obj.reportFocus() api.copyToClip(temp)
def script_descriptionAnnounce(self, gesture): obj = api.getFocusObject() try: if getLastScriptRepeatCount() == 1: for child in obj.children: if child.UIAAutomationId == 'Message': api.copyToClip(child.name) # Translators: Anuncia que el mensaje ha sido copiado message(_('copiado')) return else: if obj.firstChild.UIAAutomationId == 'Message': message(obj.firstChild.name) except: pass
def script_navigatorObject_current(self,gesture): curObject=api.getNavigatorObject() if not isinstance(curObject,NVDAObject): speech.speakMessage(_("no navigator object")) return if scriptHandler.getLastScriptRepeatCount()>=1: if curObject.TextInfo!=NVDAObjectTextInfo: textList=[] if curObject.name and isinstance(curObject.name, basestring) and not curObject.name.isspace(): textList.append(curObject.name) try: info=curObject.makeTextInfo(textInfos.POSITION_SELECTION) if not info.isCollapsed: textList.append(info.text) else: info.expand(textInfos.UNIT_LINE) if not info.isCollapsed: textList.append(info.text) except (RuntimeError, NotImplementedError): # No caret or selection on this object. pass else: textList=[prop for prop in (curObject.name, curObject.value) if prop and isinstance(prop, basestring) and not prop.isspace()] text=" ".join(textList) if len(text)>0 and not text.isspace(): if scriptHandler.getLastScriptRepeatCount()==1: speech.speakSpelling(text) else: if api.copyToClip(text): speech.speakMessage(_("%s copied to clipboard")%text) else: speech.speakObject(curObject,reason=speech.REASON_QUERY)
def copyToClipboard(self): """Copy the content of this instance to the clipboard. @return: C{True} if successful, C{False} otherwise. @rtype: bool """ import api return api.copyToClip(self.clipboardText)
def script_title(self,gesture): obj=api.getForegroundObject() title=obj.name if not isinstance(title,basestring) or not title or title.isspace(): title=obj.appModule.appName if obj.appModule else None if not isinstance(title,basestring) or not title or title.isspace(): title=_("no title") repeatCount=scriptHandler.getLastScriptRepeatCount() if repeatCount==0: ui.message(title) elif repeatCount==1: speech.speakSpelling(title) else: if api.copyToClip(title): ui.message(_("%s copied to clipboard")%title)
def script_copyCurrentBookmarksFile(self, gesture): obj=api.getFocusObject() if not controlTypes.STATE_MULTILINE in obj.states: treeInterceptor=obj.treeInterceptor if not (hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough) and controlTypes.STATE_MULTILINE not in obj.states: gesture.send() return fileName = getFile("bookmarks") if not api.copyToClip(os.path.basename(fileName)): ui.message( # Translators: message presented when cannot copy the file name corresponding to place markers. _("Cannot copy file name for place markers")) return ui.message( # Translators: message presented when file name for place markers is copied to clipboard. _("Place markers file name copied to clipboard"))
def doFindText(text, reverse=False, caseSensitive=False): if not text: return obj=api.getFocusObject() treeInterceptor=obj.treeInterceptor if isinstance(treeInterceptor, BrowseModeDocumentTreeInterceptor) and not treeInterceptor.passThrough: obj=treeInterceptor obj.doFindText(text=text, reverse=reverse, caseSensitive=caseSensitive) elif obj.role != controlTypes.ROLE_EDITABLETEXT: return else: CursorManager._lastFindText = text CursorManager._lastCaseSensitivity = caseSensitive try: info=obj.makeTextInfo(textInfos.POSITION_CARET) except (NotImplementedError, RuntimeError): info=obj.makeTextInfo(textInfos.POSITION_FIRST) try: res=info.find(text,reverse=reverse, caseSensitive=caseSensitive) except WindowsError: wx.CallAfter(gui.messageBox, # Message translated in NVDA core. translate('text "%s" not found') % text, # Message translated in NVDA core. translate("Find Error"), wx.OK|wx.ICON_ERROR) except: if api.copyToClip(text): # Translators: message presented when a string of text has been copied to the clipboard. ui.message(_("%s copied to clipboard") % text) return if res: if hasattr(obj,'selection'): obj.selection=info else: info.updateCaret() speech.cancelSpeech() info.move(textInfos.UNIT_LINE,1,endPoint="end") speech.speakTextInfo(info,reason=controlTypes.REASON_CARET) else: wx.CallAfter(gui.messageBox, # Message translated in NVDA core. translate('text "%s" not found') % text, # Message translated in NVDA core. translate("Find Error"), wx.OK|wx.ICON_ERROR)
def set_clipboard_text(self, text): api.copyToClip(text=text)
def copyPlaylistTranscriptsToClipboard(playlistTranscripts): # Only text style transcript such as pure text and Markdown supports copying contents to clipboard. import api api.copyToClip(u"\r\n".join(playlistTranscripts)) ui.message(_("Playlist data copied to clipboard"))
def set_clipboard_text(self, text, **kwargs): api.copyToClip(text=text)
def on_copy_link_item(self, evt): session = self.master_session or self.slave_session url = session.get_connection_info().get_url_to_connect() api.copyToClip(unicode(url))