text
stringlengths
81
112k
Notify all stackeditors about LSP server availability. def lsp_server_ready(self, language, configuration): """Notify all stackeditors about LSP server availability.""" for editorstack in self.editorstacks: editorstack.notify_server_ready(language, configuration)
DockWidget visibility has changed def visibility_changed(self, enable): """DockWidget visibility has changed""" SpyderPluginWidget.visibility_changed(self, enable) if self.dockwidget is None: return if self.dockwidget.isWindow(): self.dock_toolbar.show() ...
Perform actions before parent main window is closed def closing_plugin(self, cancelable=False): """Perform actions before parent main window is closed""" state = self.splitter.saveState() self.set_option('splitter_state', qbytearray_to_str(state)) filenames = [] editorstack...
Return a list of actions related to plugin def get_plugin_actions(self): """Return a list of actions related to plugin""" # ---- File menu and toolbar ---- self.new_action = create_action( self, _("&New file..."), icon=ima.icon('filenew'), t...
Register plugin in Spyder's main window def register_plugin(self): """Register plugin in Spyder's main window""" self.main.restore_scrollbar_position.connect( self.restore_scrollbar_position) self.main.console.edit_goto.connect(self.load) self.exec_in_extconsole.connect...
Update font from Preferences def update_font(self): """Update font from Preferences""" font = self.get_plugin_font() color_scheme = self.get_color_scheme() for editorstack in self.editorstacks: editorstack.set_default_font(font, color_scheme) completion_siz...
Helper function to create a checkable action. Args: text (str): Text to be displayed in the action. conf_name (str): configuration setting associated with the action editorstack_method (str): name of EditorStack class that will be used to update the cha...
Handle the toogle of a checkable action. Update editorstacks and the configuration. Args: checked (bool): State of the action. editorstack_method (str): name of EditorStack class that will be used to update the changes in each editorstack. co...
Called when sig_option_changed is received. If option being changed is autosave_mapping, then synchronize new mapping with all editor stacks except the sender. def received_sig_option_changed(self, option, value): """ Called when sig_option_changed is received. If optio...
Removing editorstack only if it's not the last remaining def unregister_editorstack(self, editorstack): """Removing editorstack only if it's not the last remaining""" self.remove_last_focus_editorstack(editorstack) if len(self.editorstacks) > 1: index = self.editorstacks.index(e...
Setup toolbars and menus for 'New window' instances def setup_other_windows(self): """Setup toolbars and menus for 'New window' instances""" self.toolbar_list = ((_("File toolbar"), "file_toolbar", self.main.file_toolbar_actions), (_("Sea...
Set focus to *filename* if this file has been opened. Return the editor instance associated to *filename*. def set_current_filename(self, filename, editorwindow=None, focus=True): """Set focus to *filename* if this file has been opened. Return the editor instance associated to *filename*...
Enable/disable file dependent actions (only if dockwidget is visible) def refresh_file_dependent_actions(self): """Enable/disable file dependent actions (only if dockwidget is visible)""" if self.dockwidget and self.dockwidget.isVisible(): enable = self.get_current_edit...
Enable 'Save All' if there are files to be saved def refresh_save_all_action(self): """Enable 'Save All' if there are files to be saved""" editorstack = self.get_current_editorstack() if editorstack: state = any(finfo.editor.document().isModified() or finfo.newly_created ...
Update warning list menu def update_warning_menu(self): """Update warning list menu""" editor = self.get_current_editor() check_results = editor.get_current_warnings() self.warning_menu.clear() filename = self.get_current_filename() for message, line_number in chec...
Update todo list menu def update_todo_menu(self): """Update todo list menu""" editorstack = self.get_current_editorstack() results = editorstack.get_todo_results() self.todo_menu.clear() filename = self.get_current_filename() for text, line0 in results: ...
Synchronize todo results between editorstacks Refresh todo list navigation buttons def todo_results_changed(self): """ Synchronize todo results between editorstacks Refresh todo list navigation buttons """ editorstack = self.get_current_editorstack() resul...
Opened files list has changed: --> open/close file action --> modification ('*' added to title) --> current edited file has changed def opened_files_list_changed(self): """ Opened files list has changed: --> open/close file action --> modification ('*' add...
Update actions in the warnings menu. def update_code_analysis_actions(self): """Update actions in the warnings menu.""" editor = self.get_current_editor() # To fix an error at startup if editor is None: return results = editor.get_current_warnings() # ...
Receive bookmark changes and save them. def save_bookmarks(self, filename, bookmarks): """Receive bookmark changes and save them.""" filename = to_text_string(filename) bookmarks = to_text_string(bookmarks) filename = osp.normpath(osp.abspath(filename)) bookmarks = eval(boo...
Load temporary file from a text file in user home directory def __load_temp_file(self): """Load temporary file from a text file in user home directory""" if not osp.isfile(self.TEMPFILE_PATH): # Creating temporary file default = ['# -*- coding: utf-8 -*-', ...
Set current script directory as working directory def __set_workdir(self): """Set current script directory as working directory""" fname = self.get_current_filename() if fname is not None: directory = osp.dirname(osp.abspath(fname)) self.open_dir.emit(directory)
Add to recent file list def __add_recent_file(self, fname): """Add to recent file list""" if fname is None: return if fname in self.recent_files: self.recent_files.remove(fname) self.recent_files.insert(0, fname) if len(self.recent_files) > self.ge...
Clone file (*src_editor* widget) in all editorstacks Cloning from the first editorstack in which every single new editor is created (when loading or creating a new file) def _clone_file_everywhere(self, finfo): """Clone file (*src_editor* widget) in all editorstacks Cloning from the...
Create a new file - Untitled fname=None --> fname will be 'untitledXX.py' but do not create file fname=<basestring> --> create file def new(self, fname=None, editorstack=None, text=None): """ Create a new file - Untitled fname=None --> fname will be 'untitledXX.py' but ...
Update recent file menu def update_recent_file_menu(self): """Update recent file menu""" recent_files = [] for fname in self.recent_files: if self.is_file_opened(fname) is None and osp.isfile(fname): recent_files.append(fname) self.recent_file_menu.clea...
Load a text file editorwindow: load in this editorwindow (useful when clicking on outline explorer with multiple editor windows) processevents: determines if processEvents() should be called at the end of this method (set to False to prevent keyboard events from creeping thr...
Print current file def print_file(self): """Print current file""" editor = self.get_current_editor() filename = self.get_current_filename() printer = Printer(mode=QPrinter.HighResolution, header_font=self.get_plugin_font('printer_header')) printDi...
Print preview for current file def print_preview(self): """Print preview for current file""" from qtpy.QtPrintSupport import QPrintPreviewDialog editor = self.get_current_editor() printer = Printer(mode=QPrinter.HighResolution, header_font=self.get_plugi...
Save file def save(self, index=None, force=False): """Save file""" editorstack = self.get_current_editorstack() return editorstack.save(index=index, force=force)
Save *as* the currently edited file def save_as(self): """Save *as* the currently edited file""" editorstack = self.get_current_editorstack() if editorstack.save_as(): fname = editorstack.get_current_filename() self.__add_recent_file(fname)
Find slot def find(self): """Find slot""" editorstack = self.get_current_editorstack() editorstack.find_widget.show() editorstack.find_widget.search_text.setFocus()
Reopens the last closed tab. def open_last_closed(self): """ Reopens the last closed tab.""" editorstack = self.get_current_editorstack() last_closed_files = editorstack.get_last_closed_files() if (len(last_closed_files) > 0): file_to_open = last_closed_files[0] ...
Close file from its name def close_file_from_name(self, filename): """Close file from its name""" filename = osp.abspath(to_text_string(filename)) index = self.editorstacks[0].has_filename(filename) if index is not None: self.editorstacks[0].close_file(index)
Directory was removed in project explorer widget def removed_tree(self, dirname): """Directory was removed in project explorer widget""" dirname = osp.abspath(to_text_string(dirname)) for fname in self.get_filenames(): if osp.abspath(fname).startswith(dirname): ...
File was renamed in file explorer widget or in project explorer def renamed(self, source, dest): """File was renamed in file explorer widget or in project explorer""" filename = osp.abspath(to_text_string(source)) index = self.editorstacks[0].has_filename(filename) if index is not N...
Directory was renamed in file explorer or in project explorer. def renamed_tree(self, source, dest): """Directory was renamed in file explorer or in project explorer.""" dirname = osp.abspath(to_text_string(source)) tofile = to_text_string(dest) for fname in self.get_filenames(): ...
Run winpdb to debug current file def run_winpdb(self): """Run winpdb to debug current file""" if self.save(): fname = self.get_current_filename() runconf = get_run_configuration(fname) if runconf is None: args = [] wdir = None ...
Cursor was just moved: 'go to def cursor_moved(self, filename0, position0, filename1, position1): """Cursor was just moved: 'go to'""" if position0 is not None: self.add_cursor_position_to_history(filename0, position0) self.add_cursor_position_to_history(filename1, position1)
Open 'go to line' dialog def go_to_line(self, line=None): """Open 'go to line' dialog""" editorstack = self.get_current_editorstack() if editorstack is not None: editorstack.go_to_line(line)
Set/Clear breakpoint def set_or_clear_breakpoint(self): """Set/Clear breakpoint""" editorstack = self.get_current_editorstack() if editorstack is not None: self.switch_to_plugin() editorstack.set_or_clear_breakpoint()
Set/Edit conditional breakpoint def set_or_edit_conditional_breakpoint(self): """Set/Edit conditional breakpoint""" editorstack = self.get_current_editorstack() if editorstack is not None: self.switch_to_plugin() editorstack.set_or_edit_conditional_breakpoint()
Clear breakpoints in all files def clear_all_breakpoints(self): """Clear breakpoints in all files""" self.switch_to_plugin() clear_all_breakpoints() self.breakpoints_saved.emit() editorstack = self.get_current_editorstack() if editorstack is not None: ...
Remove a single breakpoint def clear_breakpoint(self, filename, lineno): """Remove a single breakpoint""" clear_breakpoint(filename, lineno) self.breakpoints_saved.emit() editorstack = self.get_current_editorstack() if editorstack is not None: index = self.is_f...
Debug actions def debug_command(self, command): """Debug actions""" self.switch_to_plugin() self.main.ipyconsole.write_to_stdin(command) focus_widget = self.main.ipyconsole.get_focus_widget() if focus_widget: focus_widget.setFocus()
Run script inside current interpreter or in a new one def run_file(self, debug=False): """Run script inside current interpreter or in a new one""" editorstack = self.get_current_editorstack() if editorstack.save(): editor = self.get_current_editor() fname = osp.absp...
Debug current script def debug_file(self): """Debug current script""" self.switch_to_plugin() current_editor = self.get_current_editor() if current_editor is not None: current_editor.sig_debug_start.emit() self.run_file(debug=True)
Re-run last script def re_run_file(self): """Re-run last script""" if self.get_option('save_all_before_run'): self.save_all() if self.__last_ec_exec is None: return (fname, wdir, args, interact, debug, python, python_args, current, systerm, ...
Save current line and position as bookmark. def save_bookmark(self, slot_num): """Save current line and position as bookmark.""" bookmarks = CONF.get('editor', 'bookmarks') editorstack = self.get_current_editorstack() if slot_num in bookmarks: filename, line_num, column...
Set cursor to bookmarked file and position. def load_bookmark(self, slot_num): """Set cursor to bookmarked file and position.""" bookmarks = CONF.get('editor', 'bookmarks') if slot_num in bookmarks: filename, line_num, column = bookmarks[slot_num] else: ret...
Zoom in/out/reset def zoom(self, factor): """Zoom in/out/reset""" editor = self.get_current_editorstack().get_current_editor() if factor == 0: font = self.get_plugin_font() editor.set_font(font) else: font = editor.font() size = fo...
Apply configuration file's plugin settings def apply_plugin_settings(self, options): """Apply configuration file's plugin settings""" if self.editorstacks is not None: # --- syntax highlight and text rendering settings color_scheme_n = 'color_scheme_name' color_...
Get the list of open files in the current stack def get_open_filenames(self): """Get the list of open files in the current stack""" editorstack = self.editorstacks[0] filenames = [] filenames += [finfo.filename for finfo in editorstack.data] return filenames
Set the recent opened files on editor based on active project. If no project is active, then editor filenames are saved, otherwise the opened filenames are stored in the project config info. def set_open_filenames(self): """ Set the recent opened files on editor based on active pr...
Open the list of saved files per project. Also open any files that the user selected in the recovery dialog. def setup_open_files(self): """ Open the list of saved files per project. Also open any files that the user selected in the recovery dialog. """ self.se...
Guess filename def guess_filename(filename): """Guess filename""" if osp.isfile(filename): return filename if not filename.endswith('.py'): filename += '.py' for path in [getcwd_or_home()] + sys.path: fname = osp.join(path, filename) if osp.isfile(fname): ...
Redirects stds def redirect_stds(self): """Redirects stds""" if not self.debug: sys.stdout = self.stdout_write sys.stderr = self.stderr_write sys.stdin = self.stdin_read
Restore stds def restore_stds(self): """Restore stds""" if not self.debug: sys.stdout = self.initial_stdout sys.stderr = self.initial_stderr sys.stdin = self.initial_stdin
For raw_input builtin function emulation def raw_input_replacement(self, prompt=''): """For raw_input builtin function emulation""" self.widget_proxy.wait_input(prompt) self.input_condition.acquire() while not self.widget_proxy.data_available(): self.input_condition.wai...
For help builtin function emulation def help_replacement(self, text=None, interactive=False): """For help builtin function emulation""" if text is not None and not interactive: return pydoc.help(text) elif text is None: pyver = "%d.%d" % (sys.version_info[0], sys.ve...
Run command in interpreter def run_command(self, cmd, new_prompt=True): """Run command in interpreter""" if cmd == 'exit()': self.exit_flag = True self.write('\n') return # -- Special commands type I # (transformed into commands executed in ...
Return thread id def get_thread_id(self): """Return thread id""" if self._id is None: for thread_id, obj in list(threading._active.items()): if obj is self: self._id = thread_id return self._id
Exec filename def execfile(self, filename): """Exec filename""" source = open(filename, 'r').read() try: try: name = filename.encode('ascii') except UnicodeEncodeError: name = '<executed_script>' code = compile(source, ...
Run filename args: command line arguments (string) def runfile(self, filename, args=None): """ Run filename args: command line arguments (string) """ if args is not None and not is_text_string(args): raise TypeError("expected a character buffer object"...
Evaluate text and return (obj, valid) where *obj* is the object represented by *text* and *valid* is True if object evaluation did not raise any exception def eval(self, text): """ Evaluate text and return (obj, valid) where *obj* is the object represented by *text* ...
Return True if object is defined def is_defined(self, objtxt, force_import=False): """Return True if object is defined""" return isdefined(objtxt, force_import=force_import, namespace=self.locals)
Text has changed def text_changed(self): """Text has changed""" # Save text as bytes, if it was initially bytes if self.is_binary: self.text = to_binary_string(self.edit.toPlainText(), 'utf8') else: self.text = to_text_string(self.edit.toPlainText()) ...
Initialize the logger for this thread. Sets the log level to ERROR (0), WARNING (1), INFO (2), or DEBUG (3), depending on the argument `level`. def logger_init(level): """ Initialize the logger for this thread. Sets the log level to ERROR (0), WARNING (1), INFO (2), or DEBUG (3), depending on...
Restore signal handlers to their original settings. def restore(self): """Restore signal handlers to their original settings.""" signal.signal(signal.SIGINT, self.original_sigint) signal.signal(signal.SIGTERM, self.original_sigterm) if os.name == 'nt': signal.signal(signal.S...
Show warning using Tkinter if available def show_warning(message): """Show warning using Tkinter if available""" try: # If Tkinter is installed (highly probable), showing an error pop-up import Tkinter, tkMessageBox root = Tkinter.Tk() root.withdraw() tkMessageBox...
Check sys.path: is Spyder properly installed? def check_path(): """Check sys.path: is Spyder properly installed?""" dirname = osp.abspath(osp.join(osp.dirname(__file__), osp.pardir)) if dirname not in sys.path: show_warning("Spyder must be installed properly " "(e.g. from ...
Check Qt binding requirements def check_qt(): """Check Qt binding requirements""" qt_infos = dict(pyqt5=("PyQt5", "5.6")) try: import qtpy package_name, required_ver = qt_infos[qtpy.API] actual_ver = qtpy.PYQT_VERSION if LooseVersion(actual_ver) < LooseVersion(require...
Check spyder-kernel requirement. def check_spyder_kernels(): """Check spyder-kernel requirement.""" try: import spyder_kernels required_ver = '1.0.0' actual_ver = spyder_kernels.__version__ if LooseVersion(actual_ver) < LooseVersion(required_ver): show_warning...
Register plugin in Spyder's main window def register_plugin(self): """Register plugin in Spyder's main window""" self.breakpoints.edit_goto.connect(self.main.editor.load) #self.redirect_stdio.connect(self.main.redirect_internalshell_stdio) self.breakpoints.clear_all_breakpoints.conn...
Determine if the lock of the given name is held or not. @type name: C{str} @param name: The filesystem path to the lock to test @rtype: C{bool} @return: True if the lock is held, False otherwise. def isLocked(name): """Determine if the lock of the given name is held or not. @type na...
Acquire this lock. @rtype: C{bool} @return: True if the lock is acquired, false otherwise. @raise: Any exception os.symlink() may raise, other than EEXIST. def lock(self): """ Acquire this lock. @rtype: C{bool} @return: True if the lock is a...
Release this lock. This deletes the directory with the given name. @raise: Any exception os.readlink() may raise, or ValueError if the lock is not owned by this process. def unlock(self): """ Release this lock. This deletes the directory with the given name. ...
Start thread to render a given documentation def render(self, doc, context=None, math_option=False, img_path='', css_path=CSS_PATH): """Start thread to render a given documentation""" # If the thread is already running wait for it to finish before # starting it again. if ...
Qt Override. def sortByName(self): """Qt Override.""" self.servers = sorted(self.servers, key=lambda x: x.language) self.reset()
Qt Override. def data(self, index, role=Qt.DisplayRole): """Qt Override.""" row = index.row() if not index.isValid() or not (0 <= row < len(self.servers)): return to_qvariant() server = self.servers[row] column = index.column() if role == Qt.DisplayRole: ...
Qt Override. def headerData(self, section, orientation, role=Qt.DisplayRole): """Qt Override.""" if role == Qt.TextAlignmentRole: if orientation == Qt.Horizontal: return to_qvariant(int(Qt.AlignHCenter | Qt.AlignVCenter)) return to_qvariant(int(Qt.AlignRight | Qt...
Qt Override. def focusInEvent(self, e): """Qt Override.""" super(LSPServerTable, self).focusInEvent(e) self.selectRow(self.currentIndex().row())
Update selected row. def selection(self, index): """Update selected row.""" self.update() self.isActiveWindow() self._parent.delete_btn.setEnabled(True)
Adjust column size based on contents. def adjust_cells(self): """Adjust column size based on contents.""" self.resizeColumnsToContents() fm = self.horizontalHeader().fontMetrics() names = [fm.width(s.cmd) for s in self.source_model.servers] if names: self.setColumnWi...
Move to next row from currently selected row. def next_row(self): """Move to next row from currently selected row.""" row = self.currentIndex().row() rows = self.source_model.rowCount() if row + 1 == rows: row = -1 self.selectRow(row + 1)
Move to previous row from currently selected row. def previous_row(self): """Move to previous row from currently selected row.""" row = self.currentIndex().row() rows = self.source_model.rowCount() if row == 0: row = rows self.selectRow(row - 1)
Qt Override. def keyPressEvent(self, event): """Qt Override.""" key = event.key() if key in [Qt.Key_Enter, Qt.Key_Return]: self.show_editor() elif key in [Qt.Key_Backtab]: self.parent().reset_btn.setFocus() elif key in [Qt.Key_Up, Qt.Key_Down, Qt.Key_Left...
Handle convention changes. def setup_docstring_style_convention(self, text): """Handle convention changes.""" if text == 'Custom': self.docstring_style_select.label.setText( _("Show the following errors:")) self.docstring_style_ignore.label.setText( ...
Adds an external path to the combobox if it exists on the file system. If the path is already listed in the combobox, it is removed from its current position and added back at the end. If the maximum number of paths is reached, the oldest external path is removed from the list. def add_exter...
Returns a list of the external paths listed in the combobox. def get_external_paths(self): """Returns a list of the external paths listed in the combobox.""" return [to_text_string(self.itemText(i)) for i in range(EXTERNAL_PATHS, self.count())]
Returns the path corresponding to the currently selected item in the combobox. def get_current_searchpath(self): """ Returns the path corresponding to the currently selected item in the combobox. """ idx = self.currentIndex() if idx == CWD: re...
Handles when the current index of the combobox changes. def path_selection_changed(self): """Handles when the current index of the combobox changes.""" idx = self.currentIndex() if idx == SELECT_OTHER: external_path = self.select_directory() if len(external_path) > ...
Select directory def select_directory(self): """Select directory""" self.__redirect_stdio_emit(False) directory = getexistingdirectory( self, _("Select directory"), self.path) if directory: directory = to_unicode_from_fs(osp.abspath(directory)) ...
Sets the project path and disables the project search in the combobox if the value of path is None. def set_project_path(self, path): """ Sets the project path and disables the project search in the combobox if the value of path is None. """ if path is None: ...
Used to handle key events on the QListView of the combobox. def eventFilter(self, widget, event): """Used to handle key events on the QListView of the combobox.""" if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Delete: index = self.view().currentIndex().row() i...
Searches through the parent tree to see if it is possible to emit the redirect_stdio signal. This logic allows to test the SearchInComboBox select_directory method outside of the FindInFiles plugin. def __redirect_stdio_emit(self, value): """ Searches through the parent tre...
Get options def get_options(self, to_save=False): """Get options""" text_re = self.edit_regexp.isChecked() exclude_re = self.exclude_regexp.isChecked() case_sensitive = self.case_button.isChecked() # Return current options for them to be saved when closing # Spyd...
Reimplemented to handle key events def keyPressEvent(self, event): """Reimplemented to handle key events""" ctrl = event.modifiers() & Qt.ControlModifier shift = event.modifiers() & Qt.ShiftModifier if event.key() in (Qt.Key_Enter, Qt.Key_Return): self.find.emit() ...
Double-click event def activated(self, item): """Double-click event""" itemdata = self.data.get(id(self.currentItem())) if itemdata is not None: filename, lineno, colno = itemdata self.sig_edit_goto.emit(filename, lineno, self.search_text)
Enable result sorting after search is complete. def set_sorting(self, flag): """Enable result sorting after search is complete.""" self.sorting['status'] = flag self.header().setSectionsClickable(flag == ON)