def start_file(filename): """Generalized os.startfile for all platforms supported by Qt (this function is simply wrapping QDesktopServices.openUrl) Returns True if successfull, otherwise returns False.""" from spyderlib.qt.QtGui import QDesktopServices from spyderlib.qt.QtCore import QUrl url = QUrl() url.setUrl(filename) return QDesktopServices.openUrl(url)
def start_file(filename): """Generalized os.startfile for all platforms supported by Qt (this function is simply wrapping QDesktopServices.openUrl) Returns True if successfull, otherwise returns False.""" from spyderlib.qt.QtGui import QDesktopServices from spyderlib.qt.QtCore import QUrl # We need to use setUrl instead of setPath because this is the only # cross-platform way to open external files. setPath fails completely on # Mac and doesn't open non-ascii files on Linux. # Fixes Issue 740 url = QUrl() url.setUrl(filename) return QDesktopServices.openUrl(url)
def startDrag(self, dropActions): """Reimplement Qt Method - handle drag event""" data = QMimeData() data.setUrls([QUrl(fname) for fname in self.get_selected_filenames()]) drag = QDrag(self) drag.setMimeData(data) drag.exec_()
def go_to(self, url_or_text): """Go to page *address*""" if is_text_string(url_or_text): url = QUrl(url_or_text) else: url = url_or_text self.webview.load(url)
def show_intro_message(self): intro_message = _("Here you can get help of any object by pressing " "%s in front of it, either on the Editor or the " "Console.%s" "Help can also be shown automatically after writing " "a left parenthesis next to an object. You can " "activate this behavior in %s.") prefs = _("Preferences > Object Inspector") if sys.platform == 'darwin': shortcut = "Cmd+I" else: shortcut = "Ctrl+I" if self.is_rich_text_mode(): title = _("Usage") tutorial_message = _("New to Spyder? Read our") tutorial = _("tutorial") intro_message = intro_message % ( "<b>" + shortcut + "</b>", "<br><br>", "<i>" + prefs + "</i>") self.set_rich_text_html( usage(title, intro_message, tutorial_message, tutorial), QUrl.fromLocalFile(CSS_PATH)) else: install_sphinx = "\n\n%s" % _("Please consider installing Sphinx " "to get documentation rendered in " "rich text.") intro_message = intro_message % (shortcut, "\n\n", prefs) intro_message += install_sphinx self.set_plain_text(intro_message, is_code=False)
def show_intro_message(self): intro_message = _("Here you can get help of any object by pressing " "%s in front of it, either on the Editor or the " "Console.%s" "Help can also be shown automatically after writing " "a left parenthesis next to an object. You can " "activate this behavior in %s.") prefs = _("Preferences > Help") if sys.platform == 'darwin': shortcut = "Cmd+I" else: shortcut = "Ctrl+I" if self.is_rich_text_mode(): title = _("Usage") tutorial_message = _("New to Spyder? Read our") tutorial = _("tutorial") intro_message = intro_message % ("<b>"+shortcut+"</b>", "<br><br>", "<i>"+prefs+"</i>") self.set_rich_text_html(usage(title, intro_message, tutorial_message, tutorial), QUrl.fromLocalFile(CSS_PATH)) else: install_sphinx = "\n\n%s" % _("Please consider installing Sphinx " "to get documentation rendered in " "rich text.") intro_message = intro_message % (shortcut, "\n\n", prefs) intro_message += install_sphinx self.set_plain_text(intro_message, is_code=False)
def handle_link_clicks(self, url): url = to_text_string(url.toString()) if url == "spy://tutorial": self.show_tutorial() elif url.startswith('http'): programs.start_file(url) else: self.rich_text.webview.load(QUrl(url))
def _show_rich_help(self, text): """Use our Object Inspector to show IPython help texts in rich mode""" from spyderlib.utils.inspector import sphinxify as spx context = spx.generate_context(name='', argspec='', note='', math=False) html_text = spx.sphinxify(text, context) inspector = self.inspector inspector.visibility_changed(True) inspector.raise_() inspector.switch_to_rich_text() inspector.set_rich_text_html(html_text, QUrl.fromLocalFile(spx.CSS_PATH))
def text_to_url(self, text): """Convert text address into QUrl object""" if text.startswith('/'): text = text[1:] return QUrl(self.home_url.toString() + text + '.html')
def is_valid(self, qstr=None): """Return True if string is valid""" if qstr is None: qstr = self.currentText() return QUrl(qstr).isValid()
def set_home_url(self, text): """Set home URL""" self.home_url = QUrl(text)
def _on_sphinx_thread_html_ready(self, html_text): """Set our sphinx documentation based on thread result""" self.set_rich_text_html(html_text, QUrl.fromLocalFile(CSS_PATH))
def text_to_url(self, text): """Convert text address into QUrl object""" return QUrl(text)
def _on_sphinx_thread_html_ready(self, html_text): """Set our sphinx documentation based on thread result""" self._sphinx_thread.wait() self.set_rich_text_html(html_text, QUrl.fromLocalFile(CSS_PATH))
html_text = sphinxify(text) except Exception, error: import sphinx QMessageBox.critical(self, _('Object inspector'), _("The following error occured when calling " "<b>Sphinx %s</b>. <br>Please check if this " "version of Sphinx is supported by Spyder." "<br><br>Error message:<br>%s" ) % (sphinx.__version__, str(error))) self.plain_text_action.setChecked(True) return else: html_text = '<div id=\"warning\">'+self.no_doc_string+'</div>' html_text = HTML_HEAD + html_text + HTML_TAIL self.set_rich_text_html(html_text, QUrl.fromLocalFile(CSS_PATH)) def show_help(self, obj_text, ignore_unknown=False): """Show help""" if self.shell is None: return self._check_if_shell_is_running() if self.shell is None: return obj_text = unicode(obj_text) if self.shell.is_defined(obj_text): shell = self.shell elif self.get_option('automatic_import') and \ self.internal_shell.is_defined(obj_text, force_import=True): shell = self.internal_shell