def getsource(obj): """Wrapper around inspect.getsource""" try: src = encoding.to_unicode(inspect.getsource(obj)) except TypeError: if hasattr(obj, '__class__'): src = encoding.to_unicode(inspect.getsource(obj.__class__)) else: # Bindings like VTK or ITK require this case src = getdoc(obj) return src
def getsource(obj): """Wrapper around inspect.getsource""" try: src = encoding.to_unicode( inspect.getsource(obj) ) except TypeError: if hasattr(obj, '__class__'): src = encoding.to_unicode( inspect.getsource(obj.__class__) ) else: # Bindings like VTK or ITK require this case src = getdoc(obj) return src
def add_history(self, filename): """ Add new history tab Slot for SIGNAL('add_history(QString)') emitted by shell instance """ filename = encoding.to_unicode(filename) if filename in self.filenames: return editor = CodeEditor(self) if osp.splitext(filename)[1] == '.py': language = 'py' icon = get_icon('python.png') else: language = 'bat' icon = get_icon('cmdprompt.png') editor.setup_editor(linenumbers=False, language=language, code_folding=True, scrollflagarea=False) self.connect(editor, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()"))) editor.setReadOnly(True) editor.set_font( get_font(self.ID) ) editor.toggle_wrap_mode( CONF.get(self.ID, 'wrap') ) text, _ = encoding.read(filename) editor.set_text(text) editor.set_cursor_position('eof') self.editors.append(editor) self.filenames.append(filename) self.icons.append(icon) index = self.tabwidget.addTab(editor, osp.basename(filename)) self.find_widget.set_editor(editor) self.tabwidget.setTabToolTip(index, filename) self.tabwidget.setTabIcon(index, icon) self.tabwidget.setCurrentIndex(index)
def append_to_history(self, filename, command): """ Append an entry to history filename Slot for SIGNAL('append_to_history(QString,QString)') emitted by shell instance """ filename, command = encoding.to_unicode(filename), unicode(command) index = self.filenames.index(filename) self.editors[index].append(command) self.editors[index].set_cursor_position('eof') self.tabwidget.setCurrentIndex(index)
def data(self, index, role=Qt.DisplayRole): """Cell content""" if not index.isValid(): return to_qvariant() if role == Qt.DisplayRole or role == Qt.EditRole: column = index.column() row = index.row() if column == 0: return to_qvariant(to_text_string(self.df_index[row])) else: value = self.get_value(row, column - 1) if isinstance(value, float): return to_qvariant(self._format % value) else: try: return to_qvariant(to_text_string(value)) except UnicodeDecodeError: return to_qvariant(encoding.to_unicode(value)) elif role == Qt.BackgroundColorRole: return to_qvariant(self.get_bgcolor(index)) elif role == Qt.FontRole: return to_qvariant(get_font('arrayeditor')) return to_qvariant()
def data(self, index, role=Qt.DisplayRole): """Cell content""" if not index.isValid(): return to_qvariant() if role == Qt.DisplayRole or role == Qt.EditRole: column = index.column() row = index.row() if column == 0: return to_qvariant(to_text_string(self.df_index[row])) else: value = self.get_value(row, column-1) if isinstance(value, float): return to_qvariant(self._format % value) else: try: return to_qvariant(to_text_string(value)) except UnicodeDecodeError: return to_qvariant(encoding.to_unicode(value)) elif role == Qt.BackgroundColorRole: return to_qvariant(self.get_bgcolor(index)) elif role == Qt.FontRole: return to_qvariant(get_font('arrayeditor')) return to_qvariant()
def add_history(self, filename): """ Add new history tab Slot for SIGNAL('add_history(QString)') emitted by shell instance """ filename = encoding.to_unicode(filename) if filename in self.filenames: return editor = QsciEditor(self) if osp.splitext(filename)[1] == '.py': language = 'py' icon = get_icon('python.png') else: language = 'bat' icon = get_icon('cmdprompt.png') editor.setup_editor(linenumbers=False, language=language, code_folding=True) self.connect(editor, SIGNAL("focus_changed()"), lambda: self.emit(SIGNAL("focus_changed()"))) editor.setReadOnly(True) editor.set_font(get_font(self.ID)) editor.toggle_wrap_mode(CONF.get(self.ID, 'wrap')) text, _ = encoding.read(filename) editor.set_text(text) editor.set_cursor_position('eof') self.editors.append(editor) self.filenames.append(filename) self.icons.append(icon) index = self.tabwidget.addTab(editor, osp.basename(filename)) self.find_widget.set_editor(editor) self.tabwidget.setTabToolTip(index, filename) self.tabwidget.setTabIcon(index, icon) self.tabwidget.setCurrentIndex(index)
ext = p.all_editable_exts() assert '.cfg' in ext and '.iss' in ext path = p.get_parent_until(os.path.abspath(__file__)) assert path == 'spyderlib.utils.introspection.base' line = 'from spyderlib.widgets.sourcecode.codeeditor import CodeEditor' path = p.python_like_mod_finder(line) assert path.endswith('codeeditor.py') path = p.python_like_mod_finder(line, stop_token='sourcecode') assert path.endswith('__init__.py') and 'sourcecode' in path path = p.get_parent_until(osp.expanduser(r'~/.spyder2/temp.py')) assert path == '.spyder2.temp' code = 'import re\n\nre' path, line = p.get_definition_location_regex(code, len(code), 'dummy.txt') assert path == 'dummy.txt' and line == 1 code = 'self.proxy.widget; self.' comp = p.get_token_completion_list(code, len(code), None) assert comp == ['proxy'] code = 'self.sigMessageReady.emit; self.' comp = p.get_token_completion_list(code, len(code), None) assert comp == ['sigMessageReady'] code = encoding.to_unicode('álfa;á') comp = p.get_token_completion_list(code, len(code), None) assert comp == [encoding.to_unicode('álfa')]
assert path == '.spyder2.temp' code = 'import re\n\nre' path, line = p.get_definition(CodeInfo('definition', code, len(code), 'dummy.txt')) assert path == 'dummy.txt' and line == 1 code = 'self.proxy.widget; self.p' comp = p.get_completions(CodeInfo('completions', code, len(code))) assert comp == ['proxy'] code = 'self.sigMessageReady.emit; self.s' comp = p.get_completions(CodeInfo('completions', code, len(code))) assert comp == ['sigMessageReady'] code = encoding.to_unicode('álfa;á') comp = p.get_completions(CodeInfo('completions', code, len(code))) assert comp == [encoding.to_unicode('álfa')] code = 'from numpy import one' comp = p.get_completions(CodeInfo('completions', code, len(code))) assert 'ones' in comp comp = p.get_completions(CodeInfo('completions', code, len(code), is_python_like=False)) assert not comp code = 'from numpy.testing import (asse' comp = p.get_completions(CodeInfo('completions', code, len(code))) assert 'assert_equal' in comp
def getdoc(obj): """Wrapper around inspect.getdoc""" return encoding.to_unicode( inspect.getdoc(obj) )
def getdoc(obj): """Wrapper around inspect.getdoc""" return encoding.to_unicode(inspect.getdoc(obj))