def _compute_offsets(self): original_tc = self.editor.textCursor() tc = self.editor.textCursor() start = tc.selectionStart() end = tc.selectionEnd() tc.setPosition(start) start_line = tc.blockNumber() tc.setPosition(end) end_line = tc.blockNumber() th = TextHelper(self.editor) th.select_lines(start=start_line, end=end_line, apply_selection=True) source = th.selected_text() results = get_field_infos(source, self.editor.free_format) self.editor.setTextCursor(original_tc) self.pic_infos_available.emit(results)
def _computeOffsets(self): original_tc = self.editor.textCursor() tc = self.editor.textCursor() assert isinstance(tc, QTextCursor) start = tc.selectionStart() end = tc.selectionEnd() tc.setPosition(start) start_line = tc.blockNumber() + 1 tc.setPosition(end) end_line = tc.blockNumber() + 1 th = TextHelper(self.editor) th.select_lines(start=start_line, end=end_line, apply_selection=True) source = th.selected_text() self.picInfosAvailable.emit(get_field_infos(source)) self.editor.setTextCursor(original_tc)
def _on_item_activated(item, *args): assert isinstance(item, QtWidgets.QTreeWidgetItem) data = item.data(0, QtCore.Qt.UserRole) try: l = data['line'] except TypeError: return # file item or root item start = data['start'] lenght = data['end'] - start if data is not None: # open editor and go to line/column e = editor.open_file(data['path'], data['line'], data['start']) if e is None: return # select text helper = TextHelper(e) try: cursor = helper.select_lines(start=l, end=l) except AttributeError: _logger().debug('failed to select occurent line in editor, not' ' a subclass of QPlainTextEdit') else: assert isinstance(cursor, QtGui.QTextCursor) cursor.movePosition(cursor.StartOfBlock) cursor.movePosition(cursor.Right, cursor.MoveAnchor, start) cursor.movePosition(cursor.Right, cursor.KeepAnchor, lenght) e.setTextCursor(cursor)
def _on_item_activated(item, *args): assert isinstance(item, QtWidgets.QTreeWidgetItem) data = item.data(0, QtCore.Qt.UserRole) try: l = data['line'] except TypeError: return # file item or root item start = data['start'] lenght = data['end'] - start if data is not None: # open editor and go to line/column e = editor.open_file(data['path'], data['line'], data['start']) if e is None: return # select text helper = TextHelper(e) try: cursor = helper.select_lines(start=l, end=l) except AttributeError: _logger().debug('failed to select occurent line in editor, not' ' a subclass of QPlainTextEdit') else: assert isinstance(cursor, QtGui.QTextCursor) cursor.movePosition(cursor.StartOfBlock) cursor.movePosition(cursor.Right, cursor.MoveAnchor, start) cursor.movePosition(cursor.Right, cursor.KeepAnchor, lenght) e.setTextCursor(cursor)
def _on_occurrence_activated(item): assert isinstance(item, QtWidgets.QTreeWidgetItem) data = item.data(0, QtCore.Qt.UserRole) try: l = data['line'] except TypeError: return # file item or root item l = data['line'] start = data['start'] lenght = data['end'] - start if data is not None: # open editor and go to line/column editor = api.editor.open_file(data['path'], data['line'], data['start']) if editor is None: return # select text helper = TextHelper(editor) cursor = helper.select_lines(start=l, end=l) cursor.movePosition(cursor.StartOfBlock) cursor.movePosition(cursor.Right, cursor.MoveAnchor, start) cursor.movePosition(cursor.Right, cursor.KeepAnchor, lenght) editor.setTextCursor(cursor)
def _on_occurrence_activated(item): assert isinstance(item, QtWidgets.QTreeWidgetItem) data = item.data(0, QtCore.Qt.UserRole) try: l = data['line'] except TypeError: return # file item or root item l = data['line'] start = data['start'] lenght = data['end'] - start if data is not None: # open editor and go to line/column editor = api.editor.open_file( data['path'], data['line'], data['start']) if editor is None: return # select text helper = TextHelper(editor) cursor = helper.select_lines(start=l, end=l) cursor.movePosition(cursor.StartOfBlock) cursor.movePosition(cursor.Right, cursor.MoveAnchor, start) cursor.movePosition(cursor.Right, cursor.KeepAnchor, lenght) editor.setTextCursor(cursor)