import globalPluginHandler from speech import cancelSpeech import scriptHandler import api import textInfos import speech import globalVars from ui import message import wx,gui class GlobalPlugin(globalPluginHandler.GlobalPlugin): def terminate(self): try: gui.initialize() except wx.PyDeadObjectError: pass start=None end=None def script_goToLine(self,gesture): d = wx.TextEntryDialog(gui.mainFrame, _("Enter the line number you wish to jump to"), _("Jump to line")) def callback(result): if result == wx.ID_OK: wx.CallLater(100,self.jumping, d.GetValue()) gui.runScriptModalDialog(d, callback) def jumping(self,num): obj=api.getFocusObject() treeInterceptor=obj.treeInterceptor if hasattr(treeInterceptor,'TextInfo') and not treeInterceptor.passThrough: obj=treeInterceptor try: self.start =obj.makeTextInfo(textInfos.POSITION_ALL) except (NotImplementedError, RuntimeError): return try: lineCount=self.start.unitCount(textInfos.UNIT_LINE) except AttributeError: lineCount="unknown" pass if int(num)>lineCount: wx.CallAfter(gui.messageBox, _("This text has {0} lines. Cannot go to line {1}").format(lineCount,num), _("Error"), wx.OK|wx.ICON_ERROR) try: self.start.move(textInfos.UNIT_LINE,int(num)-1,"start") self.start.updateCaret() self.start.expand(textInfos.UNIT_LINE) cancelSpeech() except NotImplementedError: wx.CallAfter(gui.messageBox, _("This doesn't look like a proper text"), _("Error"), wx.OK|wx.ICON_ERROR) pass message(self.start.text) __gestures = { "kb:NVDA+shift+j": "goToLine" }