Code
stringlengths
103
85.9k
Summary
listlengths
0
94
Please provide a description of the function:def _get_parents(folds, linenum): # Note: this might be able to be sped up by finding some kind of # abort-early condition. parents = [] for fold in folds: start, end = fold.range if linenum >= start and linenum <= end: parent...
[ "\n Get the parents at a given linenum.\n\n If parents is empty, then the linenum belongs to the module.\n\n Parameters\n ----------\n folds : list of :class:`FoldScopeHelper`\n linenum : int\n The line number to get parents for. Typically this would be the\n cursor position.\n\n ...
Please provide a description of the function:def update_selected_cb(parents, combobox): if parents is not None and len(parents) == 0: combobox.setCurrentIndex(0) else: item = parents[-1] for i in range(combobox.count()): if combobox.itemData(i) == item: c...
[ "\n Update the combobox with the selected item based on the parents.\n\n Parameters\n ----------\n parents : list of :class:`FoldScopeHelper`\n combobox : :class:`qtpy.QtWidets.QComboBox`\n The combobox to populate\n\n Returns\n -------\n None\n " ]
Please provide a description of the function:def _update_data(self): _old = self.folds self.folds = _get_fold_levels(self.editor) # only update our dropdown lists if the folds have changed. if self.folds != _old: self.classes, self.funcs = _split_classes_and_methods...
[ "Update the internal data values." ]
Please provide a description of the function:def combobox_activated(self): sender = self.sender() data = sender.itemData(sender.currentIndex()) if isinstance(data, FoldScopeHelper): self.editor.go_to_line(data.line + 1)
[ "Move the cursor to the selected definition." ]
Please provide a description of the function:def update_selected(self, linenum): self.parents = _get_parents(self.funcs, linenum) update_selected_cb(self.parents, self.method_cb) self.parents = _get_parents(self.classes, linenum) update_selected_cb(self.parents, self.class_cb)
[ "Updates the dropdowns to reflect the current class and function." ]
Please provide a description of the function:def set_palette(self, background, foreground): palette = QPalette() palette.setColor(QPalette.Base, background) palette.setColor(QPalette.Text, foreground) self.setPalette(palette) # Set the right background color when...
[ "\r\n Set text editor palette colors:\r\n background color and caret (text cursor) color\r\n " ]
Please provide a description of the function:def set_extra_selections(self, key, extra_selections): # use draw orders to highlight current_cell and current_line first draw_order = DRAW_ORDERS.get(key) if draw_order is None: draw_order = DRAW_ORDERS.get('on_top') ...
[ "Set extra selections for a key.\r\n\r\n Also assign draw orders to leave current_cell and current_line\r\n in the backgrund (and avoid them to cover other decorations)\r\n\r\n NOTE: This will remove previous decorations added to the same key.\r\n\r\n Args:\r\n key (str) name...
Please provide a description of the function:def update_extra_selections(self): extra_selections = [] for key, extra in list(self.extra_selections_dict.items()): extra_selections.extend(extra) self.decorations.add(extra_selections)
[ "Add extra selections to DecorationsManager.\r\n\r\n TODO: This method could be remove it and decorations could be\r\n added/removed in set_extra_selections/clear_extra_selections.\r\n " ]
Please provide a description of the function:def clear_extra_selections(self, key): for decoration in self.extra_selections_dict.get(key, []): self.decorations.remove(decoration) self.extra_selections_dict[key] = []
[ "Remove decorations added through set_extra_selections.\r\n\r\n Args:\r\n key (str) name of the extra selections group.\r\n " ]
Please provide a description of the function:def highlight_current_line(self): selection = TextDecoration(self.textCursor()) selection.format.setProperty(QTextFormat.FullWidthSelection, to_qvariant(True)) selection.format.setBackground(self.curr...
[ "Highlight current line" ]
Please provide a description of the function:def highlight_current_cell(self): if self.cell_separators is None or \ not self.highlight_current_cell_enabled: return cursor, whole_file_selected, whole_screen_selected =\ self.select_current_cell_in_visible_p...
[ "Highlight current cell" ]
Please provide a description of the function:def cursor_position_changed(self): if self.bracepos is not None: self.__highlight(self.bracepos, cancel=True) self.bracepos = None cursor = self.textCursor() if cursor.position() == 0: return ...
[ "Brace matching" ]
Please provide a description of the function:def set_wrap_mode(self, mode=None): if mode == 'word': wrap_mode = QTextOption.WrapAtWordBoundaryOrAnywhere elif mode == 'character': wrap_mode = QTextOption.WrapAnywhere else: wrap_mode = QTextOptio...
[ "\r\n Set wrap mode\r\n Valid *mode* values: None, 'word', 'character'\r\n " ]
Please provide a description of the function:def get_selection_as_executable_code(self): ls = self.get_line_separator() _indent = lambda line: len(line)-len(line.lstrip()) line_from, line_to = self.get_selection_bounds() text = self.get_selected_text() if not t...
[ "Return selected text as a processed text,\r\n to be executable in a Python/IPython interpreter" ]
Please provide a description of the function:def is_cell_separator(self, cursor=None, block=None): assert cursor is not None or block is not None if cursor is not None: cursor0 = QTextCursor(cursor) cursor0.select(QTextCursor.BlockUnderCursor) text = to...
[ "Return True if cursor (or text block) is on a block separator" ]
Please provide a description of the function:def select_current_cell(self): cursor = self.textCursor() cursor.movePosition(QTextCursor.StartOfBlock) cur_pos = prev_pos = cursor.position() # Moving to the next line that is not a separator, if we are # exactly at o...
[ "Select cell under cursor\r\n cell = group of lines separated by CELL_SEPARATORS\r\n returns the textCursor and a boolean indicating if the\r\n entire file is selected" ]
Please provide a description of the function:def select_current_cell_in_visible_portion(self): cursor = self.textCursor() cursor.movePosition(QTextCursor.StartOfBlock) cur_pos = prev_pos = cursor.position() beg_pos = self.cursorForPosition(QPoint(0, 0)).position() ...
[ "Select cell under cursor in the visible portion of the file\r\n cell = group of lines separated by CELL_SEPARATORS\r\n returns\r\n -the textCursor\r\n -a boolean indicating if the entire file is selected\r\n -a boolean indicating if the entire visible portion of the file is se...
Please provide a description of the function:def go_to_next_cell(self): cursor = self.textCursor() cursor.movePosition(QTextCursor.NextBlock) cur_pos = prev_pos = cursor.position() while not self.is_cell_separator(cursor): # Moving to the next code cell ...
[ "Go to the next cell of lines" ]
Please provide a description of the function:def go_to_previous_cell(self): cursor = self.textCursor() cur_pos = prev_pos = cursor.position() if self.is_cell_separator(cursor): # Move to the previous cell cursor.movePosition(QTextCursor.PreviousBlock) ...
[ "Go to the previous cell of lines" ]
Please provide a description of the function:def __restore_selection(self, start_pos, end_pos): cursor = self.textCursor() cursor.setPosition(start_pos) cursor.setPosition(end_pos, QTextCursor.KeepAnchor) self.setTextCursor(cursor)
[ "Restore cursor selection from position bounds" ]
Please provide a description of the function:def __duplicate_line_or_selection(self, after_current_line=True): cursor = self.textCursor() cursor.beginEditBlock() start_pos, end_pos = self.__save_selection() if to_text_string(cursor.selectedText()): cursor.setPo...
[ "Duplicate current line or selected text" ]
Please provide a description of the function:def __move_line_or_selection(self, after_current_line=True): cursor = self.textCursor() cursor.beginEditBlock() start_pos, end_pos = self.__save_selection() last_line = False # ------ Select text # Get selec...
[ "Move current line or selected text" ]
Please provide a description of the function:def go_to_new_line(self): self.stdkey_end(False, False) self.insert_text(self.get_line_separator())
[ "Go to the end of the current line and create a new line" ]
Please provide a description of the function:def extend_selection_to_complete_lines(self): cursor = self.textCursor() start_pos, end_pos = cursor.selectionStart(), cursor.selectionEnd() cursor.setPosition(start_pos) cursor.setPosition(end_pos, QTextCursor.KeepAnchor) ...
[ "Extend current selection to complete lines" ]
Please provide a description of the function:def delete_line(self): cursor = self.textCursor() if self.has_selected_text(): self.extend_selection_to_complete_lines() start_pos, end_pos = cursor.selectionStart(), cursor.selectionEnd() cursor.setPosition(...
[ "Delete current line" ]
Please provide a description of the function:def truncate_selection(self, position_from): position_from = self.get_position(position_from) cursor = self.textCursor() start, end = cursor.selectionStart(), cursor.selectionEnd() if start < end: start = max([positi...
[ "Unselect read-only parts in shell, like prompt" ]
Please provide a description of the function:def restrict_cursor_position(self, position_from, position_to): position_from = self.get_position(position_from) position_to = self.get_position(position_to) cursor = self.textCursor() cursor_position = cursor.position() ...
[ "In shell, avoid editing text except between prompt and EOF" ]
Please provide a description of the function:def hide_tooltip_if_necessary(self, key): try: calltip_char = self.get_character(self.calltip_position) before = self.is_cursor_before(self.calltip_position, char_offset=1) ...
[ "Hide calltip when necessary" ]
Please provide a description of the function:def stdkey_home(self, shift, ctrl, prompt_pos=None): move_mode = self.__get_move_mode(shift) if ctrl: self.moveCursor(QTextCursor.Start, move_mode) else: cursor = self.textCursor() if prompt_pos is N...
[ "Smart HOME feature: cursor is first moved at\r\n indentation position, then at the start of the line" ]
Please provide a description of the function:def mousePressEvent(self, event): if sys.platform.startswith('linux') and event.button() == Qt.MidButton: self.calltip_widget.hide() self.setFocus() event = QMouseEvent(QEvent.MouseButtonPress, event.pos(), ...
[ "Reimplement Qt method" ]
Please provide a description of the function:def focusInEvent(self, event): self.focus_changed.emit() self.focus_in.emit() self.highlight_current_cell() QPlainTextEdit.focusInEvent(self, event)
[ "Reimplemented to handle focus" ]
Please provide a description of the function:def focusOutEvent(self, event): self.focus_changed.emit() QPlainTextEdit.focusOutEvent(self, event)
[ "Reimplemented to handle focus" ]
Please provide a description of the function:def wheelEvent(self, event): # This feature is disabled on MacOS, see Issue 1510 if sys.platform != 'darwin': if event.modifiers() & Qt.ControlModifier: if hasattr(event, 'angleDelta'): if event.a...
[ "Reimplemented to emit zoom in/out signals when Ctrl is pressed" ]
Please provide a description of the function:def get_options(argv=None): parser = argparse.ArgumentParser(usage="spyder [options] files") parser.add_argument('--new-instance', action='store_true', default=False, help="Run a new instance of Spyder, even if the single " ...
[ "\n Convert options into commands\n return commands, message\n " ]
Please provide a description of the function:def set_recent_files(self, recent_files): for recent_file in recent_files[:]: if not os.path.isfile(recent_file): recent_files.remove(recent_file) try: self.CONF[WORKSPACE].set('main', 'recent_files', ...
[ "Set a list of files opened by the project." ]
Please provide a description of the function:def get_recent_files(self): try: recent_files = self.CONF[WORKSPACE].get('main', 'recent_files', default=[]) except EnvironmentError: return [] for recent_fi...
[ "Return a list of files opened by the project." ]
Please provide a description of the function:def set_root_path(self, root_path): if self.name is None: self.name = osp.basename(root_path) self.root_path = to_text_string(root_path) config_path = self.__get_project_config_path() if osp.exists(config_path): ...
[ "Set project root path." ]
Please provide a description of the function:def rename(self, new_name): old_name = self.name self.name = new_name pypath = self.relative_pythonpath # ?? self.root_path = self.root_path[:-len(old_name)]+new_name self.relative_pythonpath = pypath # ?? sel...
[ "Rename project and rename its root path accordingly." ]
Please provide a description of the function:def initialize(self): QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() self.start_server()
[ "Start pydoc server" ]
Please provide a description of the function:def start_server(self): if self.server is None: self.port = select_port(default_port=self.DEFAULT_PORT) self.set_home_url('http://localhost:%d/' % self.port) elif self.server.isRunning(): self.server.server_s...
[ "Start pydoc server" ]
Please provide a description of the function:def text_to_url(self, text): if text.startswith('/'): text = text[1:] return QUrl(self.home_url.toString()+text+'.html')
[ "Convert text address into QUrl object" ]
Please provide a description of the function:def do_autosave(self): logger.debug('Autosave triggered') stack = self.editor.get_current_editorstack() stack.autosave.autosave_all() self.start_autosave_timer()
[ "Instruct current editorstack to autosave files where necessary." ]
Please provide a description of the function:def try_recover_from_autosave(self): autosave_dir = get_conf_path('autosave') autosave_mapping = CONF.get('editor', 'autosave_mapping', {}) dialog = RecoveryDialog(autosave_dir, autosave_mapping, parent=self.ed...
[ "Offer to recover files from autosave." ]
Please provide a description of the function:def create_unique_autosave_filename(self, filename, autosave_dir): basename = osp.basename(filename) autosave_filename = osp.join(autosave_dir, basename) if autosave_filename in self.name_mapping.values(): counter = 0 ...
[ "\n Create unique autosave file name for specified file name.\n\n Args:\n filename (str): original file name\n autosave_dir (str): directory in which autosave files are stored\n " ]
Please provide a description of the function:def remove_autosave_file(self, fileinfo): filename = fileinfo.filename if filename not in self.name_mapping: return autosave_filename = self.name_mapping[filename] try: os.remove(autosave_filename) exce...
[ "\n Remove autosave file for specified file.\n\n This function also updates `self.autosave_mapping` and clears the\n `changed_since_autosave` flag.\n " ]
Please provide a description of the function:def get_autosave_filename(self, filename): try: autosave_filename = self.name_mapping[filename] except KeyError: autosave_dir = get_conf_path('autosave') if not osp.isdir(autosave_dir): try: ...
[ "\n Get name of autosave file for specified file name.\n\n This function uses the dict in `self.name_mapping`. If `filename` is\n in the mapping, then return the corresponding autosave file name.\n Otherwise, construct a unique file name and update the mapping.\n\n Args:\n ...
Please provide a description of the function:def autosave(self, index): finfo = self.stack.data[index] document = finfo.editor.document() if not document.changed_since_autosave or finfo.newly_created: return autosave_filename = self.get_autosave_filename(finfo.filena...
[ "\n Autosave a file.\n\n Do nothing if the `changed_since_autosave` flag is not set or the file\n is newly created (and thus not named by the user). Otherwise, save a\n copy of the file with the name given by `self.get_autosave_filename()`\n and clear the `changed_since_autosave` ...
Please provide a description of the function:def autosave_all(self): for index in range(self.stack.get_stack_count()): self.autosave(index)
[ "Autosave all opened files." ]
Please provide a description of the function:def tmpconfig(request): SUBFOLDER = tempfile.mkdtemp() CONF = UserConfig('spyder-test', defaults=DEFAULTS, version=CONF_VERSION, subfolder=SUBFOLDER, raw_mode=True, ...
[ "\n Fixtures that returns a temporary CONF element.\n ", "\n Fixture finalizer to delete the temporary CONF element.\n " ]
Please provide a description of the function:def log_last_error(fname, context=None): fd = open(fname, 'a') log_time(fd) if context: print("Context", file=fd) print("-------", file=fd) print("", file=fd) if PY2: print(u' '.join(context).encode('utf-8...
[ "Log last error in filename *fname* -- *context*: string (optional)" ]
Please provide a description of the function:def log_methods_calls(fname, some_class, prefix=None): # test if file is writable open(fname, 'a').close() FILENAME = fname CLASS = some_class PREFIX = "--[ %(asked)s / %(called)s / %(defined)s ]--" if prefix != None: PREFIX = p...
[ "\r\n Hack `some_class` to log all method calls into `fname` file.\r\n If `prefix` format is not set, each log entry is prefixed with:\r\n --[ asked / called / defined ] --\r\n asked - name of `some_class`\r\n called - name of class for which a method is called\r\n defined - name ...
Please provide a description of the function:def offset(self): vsb = self.editor.verticalScrollBar() style = vsb.style() opt = QStyleOptionSlider() vsb.initStyleOption(opt) # Get the area in which the slider handle may move. groove_rect = style.subControlRect( ...
[ "This property holds the vertical offset of the scroll flag area\n relative to the top of the text editor." ]
Please provide a description of the function:def paintEvent(self, event): make_flag = self.make_flag_qrect # Fill the whole painting area painter = QPainter(self) painter.fillRect(event.rect(), self.editor.sideareas_color) # Paint warnings and todos block = sel...
[ "\n Override Qt method.\n Painting the scroll flag area\n " ]
Please provide a description of the function:def mousePressEvent(self, event): if self.slider and event.button() == Qt.LeftButton: vsb = self.editor.verticalScrollBar() value = self.position_to_value(event.pos().y()) vsb.setValue(value-vsb.pageStep()/2)
[ "Override Qt method" ]
Please provide a description of the function:def keyReleaseEvent(self, event): if event.key() == Qt.Key_Alt: self._alt_key_is_down = False self.update()
[ "Override Qt method." ]
Please provide a description of the function:def keyPressEvent(self, event): if event.key() == Qt.Key_Alt: self._alt_key_is_down = True self.update()
[ "Override Qt method" ]
Please provide a description of the function:def get_scrollbar_position_height(self): vsb = self.editor.verticalScrollBar() style = vsb.style() opt = QStyleOptionSlider() vsb.initStyleOption(opt) # Get the area in which the slider handle may move. groove_rect = ...
[ "Return the pixel span height of the scrollbar area in which\n the slider handle may move" ]
Please provide a description of the function:def get_scrollbar_value_height(self): vsb = self.editor.verticalScrollBar() return vsb.maximum()-vsb.minimum()+vsb.pageStep()
[ "Return the value span height of the scrollbar" ]
Please provide a description of the function:def value_to_position(self, y): vsb = self.editor.verticalScrollBar() return (y-vsb.minimum())*self.get_scale_factor()+self.offset
[ "Convert value to position in pixels" ]
Please provide a description of the function:def position_to_value(self, y): vsb = self.editor.verticalScrollBar() return vsb.minimum()+max([0, (y-self.offset)/self.get_scale_factor()])
[ "Convert position in pixels to value" ]
Please provide a description of the function:def make_flag_qrect(self, value): if self.slider: position = self.value_to_position(value+0.5) # The 0.5 offset is used to align the flags with the center of # their corresponding text edit block before scaling. ...
[ "Make flag QRect" ]
Please provide a description of the function:def make_slider_range(self, cursor_pos): # The slider range indicator position follows the mouse vertical # position while its height corresponds to the part of the file that # is currently visible on screen. vsb = self.editor.vertic...
[ "Make slider range QRect" ]
Please provide a description of the function:def set_painter(self, painter, light_color): painter.setPen(QColor(light_color).darker(120)) painter.setBrush(QBrush(QColor(light_color)))
[ "Set scroll flag area painter pen and brush colors" ]
Please provide a description of the function:def on_first_registration(self): self.main.tabify_plugins(self.main.help, self) self.dockwidget.hide()
[ "Action to be performed on first plugin registration" ]
Please provide a description of the function:def register_plugin(self): self.profiler.datatree.sig_edit_goto.connect(self.main.editor.load) self.profiler.redirect_stdio.connect( self.main.redirect_internalshell_stdio) self.main.add_dockwidget(self) profiler_act = cr...
[ "Register plugin in Spyder's main window" ]
Please provide a description of the function:def run_profiler(self): if self.main.editor.save(): self.switch_to_plugin() self.analyze(self.main.editor.get_current_filename())
[ "Run profiler" ]
Please provide a description of the function:def analyze(self, filename): if self.dockwidget and not self.ismaximized: self.dockwidget.setVisible(True) self.dockwidget.setFocus() self.dockwidget.raise_() pythonpath = self.main.get_spyder_pythonpath() ...
[ "Reimplement analyze method" ]
Please provide a description of the function:def windows_memory_usage(): from ctypes import windll, Structure, c_uint64, sizeof, byref from ctypes.wintypes import DWORD class MemoryStatus(Structure): _fields_ = [('dwLength', DWORD), ('dwMemoryLoad',DWORD), ...
[ "Return physical memory usage (float)\r\n Works on Windows platforms only" ]
Please provide a description of the function:def psutil_phymem_usage(): import psutil # This is needed to avoid a deprecation warning error with # newer psutil versions try: percent = psutil.virtual_memory().percent except: percent = psutil.phymem_usage().percent re...
[ "\r\n Return physical memory usage (float)\r\n Requires the cross-platform psutil (>=v0.3) library\r\n (https://github.com/giampaolo/psutil)\r\n " ]
Please provide a description of the function:def drift_color(base_color, factor=110): base_color = QColor(base_color) if base_color.lightness() > 128: return base_color.darker(factor) else: if base_color == QColor('#000000'): return drift_color(QColor('#101010'), factor + 20...
[ "\n Return color that is lighter or darker than the base color.\n\n If base_color.lightness is higher than 128, the returned color is darker\n otherwise is is lighter.\n\n :param base_color: The base color to drift from\n ;:param factor: drift factor (%)\n :return A lighter or darker color.\n "...
Please provide a description of the function:def get_block_symbol_data(editor, block): def list_symbols(editor, block, character): text = block.text() symbols = [] cursor = QTextCursor(block) cursor.movePosition(cursor.StartOfBlock) pos = text.find(character, 0)...
[ "\n Gets the list of ParenthesisInfo for specific text block.\n\n :param editor: Code editor instance\n :param block: block to parse\n ", "\n Retuns a list of symbols found in the block text\n\n :param editor: code editor instance\n :param block: block to parse\n :param ch...
Please provide a description of the function:def keep_tc_pos(func): @functools.wraps(func) def wrapper(editor, *args, **kwds): sb = editor.verticalScrollBar() spos = sb.sliderPosition() pos = editor.textCursor().position() retval = func(editor, *args, **kwds) ...
[ "\n Cache text cursor position and restore it when the wrapped\n function exits.\n\n This decorator can only be used on modes or panels.\n\n :param func: wrapped function\n ", " Decorator " ]
Please provide a description of the function:def with_wait_cursor(func): @functools.wraps(func) def wrapper(*args, **kwargs): QApplication.setOverrideCursor( QCursor(Qt.WaitCursor)) try: ret_val = func(*args, **kwargs) finally: QApplication.restor...
[ "\n Show a wait cursor while the wrapped function is running. The cursor is\n restored as soon as the function exits.\n\n :param func: wrapped function\n " ]
Please provide a description of the function:def is_empty(self): return (not self.breakpoint and not self.code_analysis and not self.todo and not self.bookmarks)
[ "Return whether the block of user data is empty." ]
Please provide a description of the function:def request_job(self, job, *args, **kwargs): self.cancel_requests() self._job = job self._args = args self._kwargs = kwargs self._timer.start(self.delay)
[ "\n Request a job execution.\n\n The job will be executed after the delay specified in the\n DelayJobRunner contructor elapsed if no other job is requested until\n then.\n\n :param job: job.\n :type job: callable\n :param args: job's position arguments\n :para...
Please provide a description of the function:def cancel_requests(self): self._timer.stop() self._job = None self._args = None self._kwargs = None
[ "Cancels pending requests." ]
Please provide a description of the function:def _exec_requested_job(self): self._timer.stop() self._job(*self._args, **self._kwargs)
[ "Execute the requested job after the timer has timeout." ]
Please provide a description of the function:def goto_line(self, line, column=0, end_column=0, move=True, word=''): line = min(line, self.line_count()) text_cursor = self._move_cursor_to(line) if column: text_cursor.movePosition(text_cursor.Right, text_cursor.MoveAnchor, ...
[ "\n Moves the text cursor to the specified position.\n\n :param line: Number of the line to go to (0 based)\n :param column: Optional column number. Default is 0 (start of line).\n :param move: True to move the cursor. False will return the cursor\n without setting it...
Please provide a description of the function:def unfold_if_colapsed(self, block): try: folding_panel = self._editor.panels.get('FoldingPanel') except KeyError: pass else: from spyder.plugins.editor.utils.folding import FoldScope if not blo...
[ "Unfold parent fold trigger if the block is collapsed.\n\n :param block: Block to unfold.\n " ]
Please provide a description of the function:def word_under_cursor(self, select_whole_word=False, text_cursor=None): editor = self._editor if not text_cursor: text_cursor = editor.textCursor() word_separators = editor.word_separators end_pos = start_pos = text_cursor...
[ "\n Gets the word under cursor using the separators defined by\n :attr:`spyder.plugins.editor.widgets.codeeditor.CodeEditor.word_separators`.\n\n FIXME: This is not working because CodeEditor have no attribute\n word_separators\n\n .. note: Instead of returning the word string, th...
Please provide a description of the function:def word_under_mouse_cursor(self): editor = self._editor text_cursor = editor.cursorForPosition(editor._last_mouse_pos) text_cursor = self.word_under_cursor(True, text_cursor) return text_cursor
[ "\n Selects the word under the **mouse** cursor.\n\n :return: A QTextCursor with the word under mouse cursor selected.\n " ]
Please provide a description of the function:def cursor_position(self): return (self._editor.textCursor().blockNumber(), self._editor.textCursor().columnNumber())
[ "\n Returns the QTextCursor position. The position is a tuple made up of\n the line number (0 based) and the column number (0 based).\n\n :return: tuple(line, column)\n " ]
Please provide a description of the function:def line_text(self, line_nbr): doc = self._editor.document() block = doc.findBlockByNumber(line_nbr) return block.text()
[ "\n Gets the text of the specified line.\n\n :param line_nbr: The line number of the text to get\n\n :return: Entire line's text\n :rtype: str\n " ]
Please provide a description of the function:def set_line_text(self, line_nbr, new_text): editor = self._editor text_cursor = self._move_cursor_to(line_nbr) text_cursor.select(text_cursor.LineUnderCursor) text_cursor.insertText(new_text) editor.setTextCursor(text_cursor)
[ "\n Replace an entire line with ``new_text``.\n\n :param line_nbr: line number of the line to change.\n :param new_text: The replacement text.\n\n " ]
Please provide a description of the function:def remove_last_line(self): editor = self._editor text_cursor = editor.textCursor() text_cursor.movePosition(text_cursor.End, text_cursor.MoveAnchor) text_cursor.select(text_cursor.LineUnderCursor) text_cursor.removeSelectedTe...
[ "Removes the last line of the document." ]
Please provide a description of the function:def clean_document(self): editor = self._editor value = editor.verticalScrollBar().value() pos = self.cursor_position() editor.textCursor().beginEditBlock() # cleanup whitespaces editor._cleaning = True eaten ...
[ "\n Removes trailing whitespaces and ensure one single blank line at the\n end of the QTextDocument.\n\n FIXME: It was deprecated in pyqode, maybe It should be deleted\n " ]
Please provide a description of the function:def select_whole_line(self, line=None, apply_selection=True): if line is None: line = self.current_line_nbr() return self.select_lines(line, line, apply_selection=apply_selection)
[ "\n Selects an entire line.\n\n :param line: Line to select. If None, the current line will be selected\n :param apply_selection: True to apply selection on the text editor\n widget, False to just return the text cursor without setting it\n on the editor.\n :return:...
Please provide a description of the function:def selection_range(self): editor = self._editor doc = editor.document() start = doc.findBlock( editor.textCursor().selectionStart()).blockNumber() end = doc.findBlock( editor.textCursor().selectionEnd()).block...
[ "\n Returns the selected lines boundaries (start line, end line)\n\n :return: tuple(int, int)\n " ]
Please provide a description of the function:def line_pos_from_number(self, line_number): editor = self._editor block = editor.document().findBlockByNumber(line_number) if block.isValid(): return int(editor.blockBoundingGeometry(block).translated( editor.cont...
[ "\n Computes line position on Y-Axis (at the center of the line) from line\n number.\n\n :param line_number: The line number for which we want to know the\n position in pixels.\n :return: The center position of the line.\n " ]
Please provide a description of the function:def line_nbr_from_position(self, y_pos): editor = self._editor height = editor.fontMetrics().height() for top, line, block in editor.visible_blocks: if top <= y_pos <= top + height: return line return -1
[ "\n Returns the line number from the y_pos.\n\n :param y_pos: Y pos in the editor\n :return: Line number (0 based), -1 if out of range\n " ]
Please provide a description of the function:def mark_whole_doc_dirty(self): text_cursor = self._editor.textCursor() text_cursor.select(text_cursor.Document) self._editor.document().markContentsDirty(text_cursor.selectionStart(), text_cu...
[ "\n Marks the whole document as dirty to force a full refresh. **SLOW**\n " ]
Please provide a description of the function:def get_right_character(self, cursor=None): next_char = self.get_right_word(cursor=cursor) if len(next_char): next_char = next_char[0] else: next_char = None return next_char
[ "\n Gets the character that is on the right of the text cursor.\n\n :param cursor: QTextCursor that defines the position where the search\n will start.\n " ]
Please provide a description of the function:def insert_text(self, text, keep_position=True): text_cursor = self._editor.textCursor() if keep_position: s = text_cursor.selectionStart() e = text_cursor.selectionEnd() text_cursor.insertText(text) if keep_po...
[ "\n Inserts text at the cursor position.\n\n :param text: text to insert\n :param keep_position: Flag that specifies if the cursor position must\n be kept. Pass False for a regular insert (the cursor will be at\n the end of the inserted text).\n " ]
Please provide a description of the function:def clear_selection(self): text_cursor = self._editor.textCursor() text_cursor.clearSelection() self._editor.setTextCursor(text_cursor)
[ "Clears text cursor selection." ]
Please provide a description of the function:def move_right(self, keep_anchor=False, nb_chars=1): text_cursor = self._editor.textCursor() text_cursor.movePosition( text_cursor.Right, text_cursor.KeepAnchor if keep_anchor else text_cursor.MoveAnchor, nb_chars) sel...
[ "\n Moves the cursor on the right.\n\n :param keep_anchor: True to keep anchor (to select text) or False to\n move the anchor (no selection)\n :param nb_chars: Number of characters to move.\n " ]
Please provide a description of the function:def select_extended_word(self, continuation_chars=('.',)): cursor = self._editor.textCursor() original_pos = cursor.position() start_pos = None end_pos = None # go left stop = False seps = self._editor.word_sep...
[ "\n Performs extended word selection. Extended selection consists in\n selecting the word under cursor and any other words that are linked\n by a ``continuation_chars``.\n\n :param continuation_chars: the list of characters that may extend a\n word.\n " ]
Please provide a description of the function:def set_state(block, state): if block is None: return user_state = block.userState() if user_state == -1: user_state = 0 higher_part = user_state & 0x7FFF0000 state &= 0x0000FFFF state |= higher...
[ "\n Sets the user state, generally used for syntax highlighting.\n\n :param block: block to modify\n :param state: new state value.\n :return:\n " ]
Please provide a description of the function:def set_fold_lvl(block, val): if block is None: return state = block.userState() if state == -1: state = 0 if val >= 0x3FF: val = 0x3FF state &= 0x7C00FFFF state |= val << 16 ...
[ "\n Sets the block fold level.\n\n :param block: block to modify\n :param val: The new fold level [0-7]\n " ]
Please provide a description of the function:def is_fold_trigger(block): if block is None: return False state = block.userState() if state == -1: state = 0 return bool(state & 0x04000000)
[ "\n Checks if the block is a fold trigger.\n\n :param block: block to check\n :return: True if the block is a fold trigger (represented as a node in\n the fold panel)\n " ]
Please provide a description of the function:def set_fold_trigger(block, val): if block is None: return state = block.userState() if state == -1: state = 0 state &= 0x7BFFFFFF state |= int(val) << 26 block.setUserState(state)
[ "\n Set the block fold trigger flag (True means the block is a fold\n trigger).\n\n :param block: block to set\n :param val: value to set\n " ]