def getJediScript(source, line, column, srcPath, needSysPath=True): """Provides the jedi Script object considering the current project""" jedi.settings.additional_dynamic_modules = [] paths = GlobalData().originalSysPath[:] if needSysPath else [] # This make relative imports resolvable if os.path.isabs(srcPath): dirName = os.path.dirname(srcPath) if dirName not in paths: paths.append(dirName) project = GlobalData().project if not project.isLoaded(): # Add the other opened files if so mainWindow = GlobalData().mainWindow for path in mainWindow.editorsManager().getOpenedList(): if path[0]: if path[0].lower().endswith('.py'): jedi.settings.additional_dynamic_modules.append(path[0]) return jedi.Script(source, line, column, srcPath, sys_path=paths) for path in project.getImportDirsAsAbsolutePaths(): if path not in paths: paths.append(path) projectDir = project.getProjectDir() if projectDir not in paths: paths.append(projectDir) return jedi.Script(source, line, column, srcPath, sys_path=paths)
def onHighlight(self): """Triggered when Ctrl+' is clicked""" if self.isCursorOnHighlight(): return self.onNextHighlight() word, wasSelection, _, absEnd = self.getCurrentOrSelection() if not word or '\r' in word or '\n' in word: return 0 # Reset match cashe in all the buffers # Otherwise they keep an old highlight when the user switches to them mainWindow = GlobalData().mainWindow mainWindow.editorsManager().resetTextSearchMatchCache() wordFlag = 0 if wasSelection: regExp = re.compile('%s' % re.escape(word), re.IGNORECASE) else: regExp = re.compile('\\b%s\\b' % re.escape(word), re.IGNORECASE) wordFlag = 1 count = self.highlightRegexp(regExp, absEnd, False) self.sigHighlighted.emit(word, wordFlag, count) return count
def downloadAndShow(self): """Triggered when the user wants to download and see the file""" url = self.selectedText.strip() if url.lower().startswith("www."): url = "http://" + url oldTimeout = socket.getdefaulttimeout() newTimeout = 5 # Otherwise the pause is too long socket.setdefaulttimeout(newTimeout) QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) try: response = urllib.request.urlopen(url) content = decodeURLContent(response.read()) # The content has been read sucessfully mainWindow = GlobalData().mainWindow mainWindow.editorsManager().newTabClicked(content, os.path.basename(url)) except Exception as exc: logging.error("Error downloading '" + url + "'\n" + str(exc)) QApplication.restoreOverrideCursor() socket.setdefaulttimeout(oldTimeout)