Search is not available for this dataset
text stringlengths 75 104k |
|---|
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) |
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()
else:
self.dock... |
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 = self.editorstacks[0]
active_project_pat... |
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'), tip=_("New file"),
triggered... |
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(self.main.execute_in_external_console)
... |
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_size = CONF.get('main', 'completi... |
def _create_checkable_action(self, text, conf_name, editorstack_method):
"""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 ... |
def _toggle_checkable_action(self, checked, editorstack_method, conf_name):
"""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 ... |
def received_sig_option_changed(self, option, value):
"""
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.
"""
if option == 'autosave_mapping':
... |
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(editorstack)
self.editorstacks.pop(index)
... |
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),
(_("Search toolbar"), "search_toolbar",
... |
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*.
"""
editorstack = self.get_current_editorstack(editorwindow)
return editorstack.set_curren... |
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_editor() is not None
for action in self.file_dependent_actions:
... |
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
for finfo in editorstack.data)
... |
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 check_results:
er... |
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:
icon = ima.icon('todo... |
def todo_results_changed(self):
"""
Synchronize todo results between editorstacks
Refresh todo list navigation buttons
"""
editorstack = self.get_current_editorstack()
results = editorstack.get_todo_results()
index = editorstack.get_stack_index()
i... |
def opened_files_list_changed(self):
"""
Opened files list has changed:
--> open/close file action
--> modification ('*' added to title)
--> current edited file has changed
"""
# Refresh Python file dependent actions:
editor = self.get_current_edit... |
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()
# Update code analysis buttons
... |
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(bookmarks)
save_bookmarks(filename,... |
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 -*-',
'"""', _("Spyder Editor"), '',
... |
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) |
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.get_option('max_recent_file... |
def _clone_file_everywhere(self, finfo):
"""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)"""
for editorstack in self.editorstacks[1:]:
editor = edi... |
def new(self, fname=None, editorstack=None, text=None):
"""
Create a new file - Untitled
fname=None --> fname will be 'untitledXX.py' but do not create file
fname=<basestring> --> create file
"""
# If no text is provided, create default content
empty = Fa... |
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.clear()
if recent_fi... |
def load(self, filenames=None, goto=None, word='',
editorwindow=None, processevents=True, start_column=None,
set_focus=True, add_where='end'):
"""
Load a text file
editorwindow: load in this editorwindow (useful when clicking on
outline explorer with multi... |
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'))
printDialog = QPrintDialog(... |
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_plugin_font('printer_header'))
... |
def save(self, index=None, force=False):
"""Save file"""
editorstack = self.get_current_editorstack()
return editorstack.save(index=index, force=force) |
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) |
def find(self):
"""Find slot"""
editorstack = self.get_current_editorstack()
editorstack.find_widget.show()
editorstack.find_widget.search_text.setFocus() |
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]
last_closed_files.remove... |
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) |
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):
self.close_file_from_name(fname) |
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 None:
for editorstack in self.editorstacks:
... |
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():
if osp.abspath(fname).startswith(dirname):
... |
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
else:
... |
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) |
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) |
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() |
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() |
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:
for data in editorstack.data:
... |
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_file_opened(filename)
... |
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() |
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.abspath(self.get_current_filename())
# Get f... |
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) |
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,
post_mortem, cle... |
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 = bookmarks[slot_num]
if osp.is... |
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:
return
if not osp.isfile(filename):
... |
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 = font.pointSize() + fa... |
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_scheme_o = self.get_color_scheme()
... |
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 |
def set_open_filenames(self):
"""
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.
"""
if self.projects is not None:
... |
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.set_create_new_file_if_empty(False)
active_project_path = None
if self.projects is not None:
... |
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):
return fna... |
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 |
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 |
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.wait()
inp = self.widget_proxy.input... |
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.version_info[1])
self.writ... |
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 the interpreter)
# ... |
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 |
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, name, "exec")
... |
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")
self.namespace['__file__'] = filename
sys... |
def eval(self, text):
"""
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
"""
assert is_text_string(text)
try:
return eval(text, self.loc... |
def is_defined(self, objtxt, force_import=False):
"""Return True if object is defined"""
return isdefined(objtxt, force_import=force_import,
namespace=self.locals) |
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())
if self.btn_sav... |
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 the argument `level`.
"""
levellist = [logging.ERROR, logging.WARNING, logging.INFO, logging.DEBUG]
handler = logging.StreamHandler()
fmt... |
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.SIGBREAK, self.original_sigbreak) |
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.showerror("Spyder", message)
except... |
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 source: 'python setup.py install'),\n"
... |
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(required_ver):
show_warni... |
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("Please check Spyder installation... |
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.connect(
... |
def isLocked(name):
"""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.
"""
l = FilesystemLock(name)
result = None
try:
... |
def lock(self):
"""
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.
"""
clean = True
while True:
try:
... |
def unlock(self):
"""
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.
"""
pid = readlink(self.name)
if int(pid) != os.getp... |
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 self.wait():
self.doc = doc
... |
def sortByName(self):
"""Qt Override."""
self.servers = sorted(self.servers, key=lambda x: x.language)
self.reset() |
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:
if c... |
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.AlignVCenter)... |
def focusInEvent(self, e):
"""Qt Override."""
super(LSPServerTable, self).focusInEvent(e)
self.selectRow(self.currentIndex().row()) |
def selection(self, index):
"""Update selected row."""
self.update()
self.isActiveWindow()
self._parent.delete_btn.setEnabled(True) |
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.setColumnWidth(CMD, max(names))
self.horiz... |
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) |
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) |
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, Qt.Key_Right... |
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(
_("Ignore the following e... |
def add_external_path(self, path):
"""
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 olde... |
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())] |
def get_current_searchpath(self):
"""
Returns the path corresponding to the currently selected item
in the combobox.
"""
idx = self.currentIndex()
if idx == CWD:
return self.path
elif idx == PROJECT:
return self.project_path
... |
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) > 0:
self.add_external_path(external_path)... |
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))
self.__redirect_s... |
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:
self.project_path = None
self.model().item(PROJECT, 0).setEnabled(False)
if s... |
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()
if index >= EXTERNAL_PATHS:
# Remove item and... |
def __redirect_stdio_emit(self, value):
"""
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.
"""
parent = s... |
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
# Spyder.
... |
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()
elif event.key() == Qt.Key_F and... |
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) |
def set_sorting(self, flag):
"""Enable result sorting after search is complete."""
self.sorting['status'] = flag
self.header().setSectionsClickable(flag == ON) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.