signature stringlengths 8 3.44k | body stringlengths 0 1.41M | docstring stringlengths 1 122k | id stringlengths 5 17 |
|---|---|---|---|
@foundations.exceptions.handle_exceptions(foundations.exceptions.FileExistsError)<EOL>def get_sections_file_parser(file): | if not foundations.common.path_exists(file):<EOL><INDENT>raise foundations.exceptions.FileExistsError(<EOL>"<STR_LIT>".format(__name__, file))<EOL><DEDENT>sections_file_parser = SectionsFileParser(file)<EOL>sections_file_parser.parse()<EOL>return sections_file_parser<EOL> | Returns a sections file parser.
:param file: File.
:type file: unicode
:return: Parser.
:rtype: SectionsFileParser | f13154:m4 |
@foundations.exceptions.handle_exceptions(TypeError)<EOL>def store_last_browsed_path(data): | if type(data) in (tuple, list, QStringList):<EOL><INDENT>data = [foundations.strings.to_string(path) for path in data]<EOL>last_browsed_path = foundations.common.get_first_item(data)<EOL><DEDENT>elif type(data) in (unicode, QString):<EOL><INDENT>data = last_browsed_path = foundations.strings.to_string(data)<EOL><DEDENT>else:<EOL><INDENT>raise TypeError("<STR_LIT>".format(__name__, type(data)))<EOL><DEDENT>if foundations.common.path_exists(last_browsed_path):<EOL><INDENT>last_browsed_path = os.path.normpath(last_browsed_path)<EOL>if os.path.isfile(last_browsed_path):<EOL><INDENT>last_browsed_path = os.path.dirname(last_browsed_path)<EOL><DEDENT>LOGGER.debug("<STR_LIT>", last_browsed_path)<EOL>RuntimeGlobals.last_browsed_path = last_browsed_path<EOL><DEDENT>return data<EOL> | Defines a wrapper method used to store the last browsed path.
:param data: Path data.
:type data: QString or QList
:return: Last browsed path.
:rtype: unicode | f13154:m5 |
def QVariant_to_string(data): | if isinstance(data, QVariant):<EOL><INDENT>data = data.toString()<EOL><DEDENT>data = QString(data)<EOL>return foundations.strings.to_string(data)<EOL> | Returns given `QVariant <http://doc.qt.nokia.com/qvariant.html>`_ data as a string.
:param data: Given data.
:type data: object
:return: QVariant data as string.
:rtype: unicode | f13154:m6 |
def parents_walker(object): | while object.parent():<EOL><INDENT>object = object.parent()<EOL>yield object<EOL><DEDENT> | Defines a generator used to retrieve the chain of parents of the given :class:`QObject` instance.
:param object: Given path.
:type object: QObject
:yield: Object parent. ( QObject ) | f13154:m7 |
def signals_blocker(instance, attribute, *args, **kwargs): | value = None<EOL>try:<EOL><INDENT>hasattr(instance, "<STR_LIT>") and instance.blockSignals(True)<EOL>value = attribute(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>hasattr(instance, "<STR_LIT>") and instance.blockSignals(False)<EOL>return value<EOL><DEDENT> | Blocks given instance signals before calling the given attribute with \
given arguments and then unblocks the signals.
:param instance: Instance object.
:type instance: QObject
:param attribute: Attribute to call.
:type attribute: QObject
:param \*args: Arguments.
:type \*args: \*
:param \*\*kwargs: Keywords arguments.
:type \*\*kwargs: \*\*
:return: Object.
:rtype: object | f13154:m8 |
def show_wait_cursor(object): | @functools.wraps(object)<EOL>def show_wait_cursorWrapper(*args, **kwargs):<EOL><INDENT>"""<STR_LIT>"""<EOL>QApplication.setOverrideCursor(Qt.WaitCursor)<EOL>value = None<EOL>try:<EOL><INDENT>value = object(*args, **kwargs)<EOL><DEDENT>finally:<EOL><INDENT>QApplication.restoreOverrideCursor()<EOL>return value<EOL><DEDENT><DEDENT>return show_wait_cursorWrapper<EOL> | Shows a wait cursor while processing.
:param object: Object to decorate.
:type object: object
:return: Object.
:rtype: object | f13154:m9 |
def set_toolBox_height(tool_box, height=<NUM_LIT:32>): | for button in tool_box.findChildren(QAbstractButton):<EOL><INDENT>button.setMinimumHeight(height)<EOL><DEDENT>return True<EOL> | Sets given height to given QToolBox widget.
:param toolbox: ToolBox.
:type toolbox: QToolBox
:param height: Height.
:type height: int
:return: Definition success.
:rtype: bool | f13154:m10 |
def set_children_padding(widget, types, height=None, width=None): | for type in types:<EOL><INDENT>for child in widget.findChildren(type):<EOL><INDENT>child.setStyleSheet("<STR_LIT>".format(<EOL>type.__name__,<EOL>child.fontMetrics().height() + (height if height is not None else <NUM_LIT:0>) * <NUM_LIT:2>,<EOL>child.fontMetrics().width(child.text()) + (width if width is not None else <NUM_LIT:0>) * <NUM_LIT:2>))<EOL><DEDENT><DEDENT>return True<EOL> | Sets given Widget children padding.
:param widget: Widget to sets the children padding.
:type widget: QWidget
:param types: Children types.
:type types: tuple or list
:param height: Height padding.
:type height: int
:param width: Width padding.
:type width: int
:return: Definition success.
:rtype: bool | f13154:m11 |
def __init__(self, **kwargs): | LOGGER.debug("<STR_LIT>".format(self.__class__.__name__))<EOL>foundations.data_structures.Structure.__init__(self, **kwargs)<EOL> | Initializes the class.
:param \*\*kwargs: directories, files, filters_in, filters_out, targets.
:type \*\*kwargs: dict | f13154:c0:m0 |
def get_format(**kwargs): | settings = foundations.data_structures.Structure(**{"<STR_LIT>": QTextCharFormat(),<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": None,<EOL>"<STR_LIT>": False})<EOL>settings.update(kwargs)<EOL>format = QTextCharFormat(settings.format)<EOL>settings.background_color and format.setBackground(settings.background_color)<EOL>settings.color and format.setForeground(settings.color)<EOL>settings.font_weight and format.setFontWeight(settings.font_weight)<EOL>settings.font_point_size and format.setFontPointSize(settings.font_point_size)<EOL>settings.italic and format.setFontItalic(True)<EOL>return format<EOL> | Returns a `QTextCharFormat <http://doc.qt.nokia.com/qtextcharformat.html>`_ format.
:param \*\*kwargs: Format settings.
:type \*\*kwargs: dict
:return: Format.
:rtype: QTextCharFormat | f13155:m0 |
def highlight_current_line(editor): | format = editor.language.theme.get("<STR_LIT>")<EOL>if not format:<EOL><INDENT>return False<EOL><DEDENT>extra_selections = editor.extraSelections() or []<EOL>if not editor.isReadOnly():<EOL><INDENT>selection = QTextEdit.ExtraSelection()<EOL>selection.format.setBackground(format.background())<EOL>selection.format.setProperty(QTextFormat.FullWidthSelection, True)<EOL>selection.cursor = editor.textCursor()<EOL>selection.cursor.clearSelection()<EOL>extra_selections.append(selection)<EOL><DEDENT>editor.setExtraSelections(extra_selections)<EOL>return True<EOL> | Highlights given editor current line.
:param editor: Document editor.
:type editor: QWidget
:return: Method success.
:rtype: bool | f13156:m0 |
def highlight_occurences(editor): | format = editor.language.theme.get("<STR_LIT>")<EOL>if not format:<EOL><INDENT>return False<EOL><DEDENT>extra_selections = editor.extraSelections() or []<EOL>if not editor.isReadOnly():<EOL><INDENT>word = editor.get_word_under_cursor()<EOL>if not word:<EOL><INDENT>return False<EOL><DEDENT>block = editor.document().findBlock(<NUM_LIT:0>)<EOL>cursor = editor.document().find(word,<EOL>block.position(),<EOL>QTextDocument.FindCaseSensitively | QTextDocument.FindWholeWords)<EOL>while block.isValid() and cursor.position() != -<NUM_LIT:1>:<EOL><INDENT>selection = QTextEdit.ExtraSelection()<EOL>selection.format.setBackground(format.background())<EOL>selection.cursor = cursor<EOL>extra_selections.append(selection)<EOL>cursor = editor.document().find(word,<EOL>cursor.position(),<EOL>QTextDocument.FindCaseSensitively | QTextDocument.FindWholeWords)<EOL>block = block.next()<EOL><DEDENT><DEDENT>editor.setExtraSelections(extra_selections)<EOL>return True<EOL> | Highlights given editor current line.
:param editor: Document editor.
:type editor: QWidget
:return: Method success.
:rtype: bool | f13156:m1 |
def highlight_matching_symbols_pairs(editor): | format = editor.language.theme.get("<STR_LIT>")<EOL>if not format:<EOL><INDENT>return False<EOL><DEDENT>extra_selections = editor.extraSelections() or []<EOL>if not editor.isReadOnly():<EOL><INDENT>start_selection = QTextEdit.ExtraSelection()<EOL>start_selection.format.setBackground(format.background())<EOL>end_selection = QTextEdit.ExtraSelection()<EOL>end_selection.format.setBackground(format.background())<EOL>cursor = editor.textCursor()<EOL>if cursor.hasSelection():<EOL><INDENT>text = foundations.strings.to_string(cursor.selectedText())<EOL><DEDENT>else:<EOL><INDENT>cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)<EOL>text = foundations.strings.to_string(cursor.selectedText())<EOL><DEDENT>start_selection.cursor = cursor<EOL>if text in editor.language.symbols_pairs.keys():<EOL><INDENT>extra_selections.append(start_selection)<EOL>end_selection.cursor = editor.get_matching_symbols_pairs(cursor,<EOL>text,<EOL>editor.language.symbols_pairs[text])<EOL><DEDENT>elif text in editor.language.symbols_pairs.values():<EOL><INDENT>extra_selections.append(start_selection)<EOL>end_selection.cursor = editor.get_matching_symbols_pairs(cursor,<EOL>text,<EOL>editor.language.symbols_pairs.get_first_key_from_value(<EOL>text),<EOL>True)<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT>extra_selections.append(end_selection)<EOL><DEDENT>editor.setExtraSelections(extra_selections)<EOL>return True<EOL> | Highlights given editor matching pairs.
:param editor: Document editor.
:type editor: QWidget
:return: Method success.
:rtype: bool | f13156:m2 |
def get_object_from_language_accelerators(accelerator): | return LANGUAGES_ACCELERATORS.get(accelerator)<EOL> | Returns the object associated to given accelerator.
:param accelerator: Accelerator.
:type accelerator: unicode
:return: Object.
:rtype: object | f13157:m0 |
@foundations.exceptions.handle_exceptions(LanguageGrammarError)<EOL>def get_language_description(grammar_file): | LOGGER.debug("<STR_LIT>".format(grammar_file))<EOL>sections_file_parser = foundations.parsers.SectionsFileParser(grammar_file)<EOL>sections_file_parser.parse(strip_quotation_markers=False)<EOL>name = sections_file_parser.get_value("<STR_LIT:Name>", "<STR_LIT>")<EOL>if not name:<EOL><INDENT>raise LanguageGrammarError("<STR_LIT>".format(__name__,<EOL>"<STR_LIT>",<EOL>grammar_file))<EOL><DEDENT>extensions = sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>if not extensions:<EOL><INDENT>raise LanguageGrammarError("<STR_LIT>".format(__name__,<EOL>"<STR_LIT>",<EOL>grammar_file))<EOL><DEDENT>highlighter = get_object_from_language_accelerators(sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>"))<EOL>completer = get_object_from_language_accelerators(sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>"))<EOL>pre_input_accelerators = sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>pre_input_accelerators = pre_input_accelerators and [get_object_from_language_accelerators(accelerator)<EOL>for accelerator in pre_input_accelerators.split("<STR_LIT:|>")] or ()<EOL>post_input_accelerators = sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>post_input_accelerators = post_input_accelerators and [get_object_from_language_accelerators(accelerator)<EOL>for accelerator in post_input_accelerators.split("<STR_LIT:|>")] or ()<EOL>visual_accelerators = sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>visual_accelerators = visual_accelerators and [get_object_from_language_accelerators(accelerator)<EOL>for accelerator in visual_accelerators.split("<STR_LIT:|>")] or ()<EOL>indent_marker = sections_file_parser.section_exists("<STR_LIT>") and sections_file_parser.get_value("<STR_LIT>",<EOL>"<STR_LIT>") orDEFAULT_INDENT_MARKER<EOL>comment_marker = sections_file_parser.section_exists("<STR_LIT>") andsections_file_parser.get_value("<STR_LIT>", "<STR_LIT>") or "<STR_LIT>"<EOL>comment_block_marker_start = sections_file_parser.section_exists("<STR_LIT>") andsections_file_parser.get_value("<STR_LIT>", "<STR_LIT>") or "<STR_LIT>"<EOL>comment_block_marker_end = sections_file_parser.section_exists("<STR_LIT>") andsections_file_parser.get_value("<STR_LIT>", "<STR_LIT>") or "<STR_LIT>"<EOL>symbols_pairs = sections_file_parser.section_exists("<STR_LIT>") andsections_file_parser.get_value("<STR_LIT>", "<STR_LIT>") or {}<EOL>if symbols_pairs:<EOL><INDENT>associated_pairs = foundations.data_structures.Lookup()<EOL>for pair in symbols_pairs.split("<STR_LIT:|>"):<EOL><INDENT>associated_pairs[pair[<NUM_LIT:0>]] = pair[<NUM_LIT:1>]<EOL><DEDENT>symbols_pairs = associated_pairs<EOL><DEDENT>indentation_symbols = sections_file_parser.section_exists("<STR_LIT>") andsections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>indentation_symbols = indentation_symbols and indentation_symbols.split("<STR_LIT:|>") or ()<EOL>rules = []<EOL>attributes = sections_file_parser.sections.get("<STR_LIT>")<EOL>if attributes:<EOL><INDENT>for attribute in sections_file_parser.sections["<STR_LIT>"]:<EOL><INDENT>pattern = sections_file_parser.get_value(attribute, "<STR_LIT>")<EOL>rules.append(umbra.ui.highlighters.Rule(name=foundations.namespace.remove_namespace(attribute),<EOL>pattern=QRegExp(pattern)))<EOL><DEDENT><DEDENT>tokens = []<EOL>dictionary = sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")<EOL>if dictionary:<EOL><INDENT>dictionary_file = os.path.join(os.path.dirname(grammar_file), dictionary)<EOL>if foundations.common.path_exists(dictionary_file):<EOL><INDENT>with open(dictionary_file, "<STR_LIT:r>") as file:<EOL><INDENT>for line in iter(file):<EOL><INDENT>line = line.strip()<EOL>line and tokens.append(line)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>LOGGER.warning(<EOL>"<STR_LIT>".format(__name__,<EOL>dictionary_file))<EOL><DEDENT><DEDENT>theme = get_object_from_language_accelerators(sections_file_parser.get_value("<STR_LIT>", "<STR_LIT>")) orumbra.ui.highlighters.DEFAULT_THEME<EOL>attributes = {"<STR_LIT:name>": name,<EOL>"<STR_LIT:file>": grammar_file,<EOL>"<STR_LIT>": sections_file_parser,<EOL>"<STR_LIT>": extensions,<EOL>"<STR_LIT>": highlighter,<EOL>"<STR_LIT>": completer,<EOL>"<STR_LIT>": pre_input_accelerators,<EOL>"<STR_LIT>": post_input_accelerators,<EOL>"<STR_LIT>": visual_accelerators,<EOL>"<STR_LIT>": indent_marker,<EOL>"<STR_LIT>": comment_marker,<EOL>"<STR_LIT>": comment_block_marker_start,<EOL>"<STR_LIT>": comment_block_marker_end,<EOL>"<STR_LIT>": symbols_pairs,<EOL>"<STR_LIT>": indentation_symbols,<EOL>"<STR_LIT>": rules,<EOL>"<STR_LIT>": tokens,<EOL>"<STR_LIT>": theme}<EOL>for attribute, value in sorted(attributes.iteritems()):<EOL><INDENT>if attribute == "<STR_LIT>":<EOL><INDENT>LOGGER.debug("<STR_LIT>".format(len(value)))<EOL><DEDENT>elif attribute == "<STR_LIT>":<EOL><INDENT>LOGGER.debug("<STR_LIT>".format(len(value)))<EOL><DEDENT>else:<EOL><INDENT>LOGGER.debug("<STR_LIT>".format(attribute, value))<EOL><DEDENT><DEDENT>return Language(**attributes)<EOL> | Gets the language description from given language grammar file.
:param grammar_file: Language grammar.
:type grammar_file: unicode
:return: Language description.
:rtype: Language | f13157:m1 |
def get_python_language(): | return get_language_description(PYTHON_GRAMMAR_FILE)<EOL> | Returns the Python language description.
:return: Python language description.
:rtype: Language | f13157:m2 |
def get_logging_language(): | return get_language_description(LOGGING_GRAMMAR_FILE)<EOL> | Returns the Logging language description.
:return: Logging language description.
:rtype: Language | f13157:m3 |
def get_text_language(): | return get_language_description(TEXT_GRAMMAR_FILE)<EOL> | Returns the Text language description.
:return: Text language description.
:rtype: Language | f13157:m4 |
def __init__(self, **kwargs): | LOGGER.debug("<STR_LIT>".format(self.__class__.__name__))<EOL>foundations.data_structures.Structure.__init__(self, **kwargs)<EOL> | Initializes the class.
:param \*\*kwargs: name, file, parser, extensions, highlighter, completer, pre_input_accelerators,
post_input_accelerators, visual_accelerators, indent_marker, comment_marker, comment_block_marker_start,
comment_block_marker_end, symbols_pairs, indentation_symbols, rules, tokens, theme. | f13157:c0:m0 |
def get_editor_capability(editor, capability): | if not hasattr(editor, "<STR_LIT>"):<EOL><INDENT>return<EOL><DEDENT>return editor.language.get(capability)<EOL> | Returns given editor capability.
:param editor: Document editor.
:type editor: QWidget
:param capability: Capability to retrieve.
:type capability: unicode
:return: Capability.
:rtype: object | f13158:m0 |
def is_symbols_pair_complete(editor, symbol): | symbols_pairs = get_editor_capability(editor, "<STR_LIT>")<EOL>if not symbols_pairs:<EOL><INDENT>return<EOL><DEDENT>cursor = editor.textCursor()<EOL>cursor.movePosition(QTextCursor.StartOfLine, QTextCursor.MoveAnchor)<EOL>cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.KeepAnchor)<EOL>selected_text = foundations.strings.to_string(cursor.selectedText())<EOL>if symbol == symbols_pairs[symbol]:<EOL><INDENT>return selected_text.count(symbol) % <NUM_LIT:2> == <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>return selected_text.count(symbol) == selected_text.count(symbols_pairs[symbol])<EOL><DEDENT> | Returns if the symbols pair is complete on current editor line.
:param editor: Document editor.
:type editor: QWidget
:param symbol: Symbol to check.
:type symbol: unicode
:return: Is symbols pair complete.
:rtype: bool | f13158:m1 |
def perform_completion(editor): | completion_prefix = editor.get_partial_word_under_cursor()<EOL>if not completion_prefix:<EOL><INDENT>return<EOL><DEDENT>words = editor.get_words()<EOL>completion_prefix in words and words.remove(completion_prefix)<EOL>editor.completer.update_model(words)<EOL>editor.completer.setCompletionPrefix(completion_prefix)<EOL>if editor.completer.completionCount() == <NUM_LIT:1>:<EOL><INDENT>completion = editor.completer.completionModel().data(<EOL>editor.completer.completionModel().index(<NUM_LIT:0>, <NUM_LIT:0>)).toString()<EOL>cursor = editor.textCursor()<EOL>cursor.insertText(completion[len(completion_prefix):])<EOL>editor.setTextCursor(cursor)<EOL><DEDENT>else:<EOL><INDENT>popup = editor.completer.popup()<EOL>popup.setCurrentIndex(editor.completer.completionModel().index(<NUM_LIT:0>, <NUM_LIT:0>))<EOL>completer_rectangle = editor.cursorRect()<EOL>hasattr(editor, "<STR_LIT>") and completer_rectangle.moveTo(<EOL>completer_rectangle.topLeft().x() + editor.margin_area_LinesNumbers_widget.get_width(),<EOL>completer_rectangle.topLeft().y())<EOL>completer_rectangle.setWidth(editor.completer.popup().sizeHintForColumn(<NUM_LIT:0>) +<EOL>editor.completer.popup().verticalScrollBar().sizeHint().width())<EOL>editor.completer.complete(completer_rectangle)<EOL><DEDENT>return True<EOL> | Performs the completion on given editor.
:param editor: Document editor.
:type editor: QWidget
:return: Method success.
:rtype: bool | f13158:m2 |
def indentation_pre_event_input_accelerators(editor, event): | process_event = True<EOL>if not hasattr(editor, "<STR_LIT>"):<EOL><INDENT>return process_event<EOL><DEDENT>if event.key() == Qt.Key_Tab:<EOL><INDENT>process_event = editor.indent() and False<EOL><DEDENT>elif event.key() == Qt.Key_Backtab:<EOL><INDENT>process_event = editor.unindent() and False<EOL><DEDENT>return process_event<EOL> | Implements indentation pre event input accelerators.
:param editor: Document editor.
:type editor: QWidget
:param event: Event being handled.
:type event: QEvent
:return: Process event.
:rtype: bool | f13158:m3 |
def indentation_post_event_input_accelerators(editor, event): | if event.key() in (Qt.Key_Enter, Qt.Key_Return):<EOL><INDENT>cursor = editor.textCursor()<EOL>block = cursor.block().previous()<EOL>if block.isValid():<EOL><INDENT>indent = match = re.match(r"<STR_LIT>", foundations.strings.to_string(block.text())).group(<NUM_LIT:1>)<EOL>cursor.insertText(indent)<EOL>indentation_symbols = get_editor_capability(editor, "<STR_LIT>")<EOL>if not indentation_symbols:<EOL><INDENT>return True<EOL><DEDENT>if not block.text():<EOL><INDENT>return True<EOL><DEDENT>if not foundations.strings.to_string(block.text())[-<NUM_LIT:1>] in indentation_symbols:<EOL><INDENT>return True<EOL><DEDENT>symbols_pairs = get_editor_capability(editor, "<STR_LIT>")<EOL>if not symbols_pairs:<EOL><INDENT>return True<EOL><DEDENT>cursor.insertText(editor.indent_marker)<EOL>position = cursor.position()<EOL>cursor.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor)<EOL>cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)<EOL>cursor.movePosition(QTextCursor.PreviousCharacter, QTextCursor.KeepAnchor)<EOL>previous_character = foundations.strings.to_string(cursor.selectedText())<EOL>cursor.setPosition(position)<EOL>next_character = editor.get_next_character()<EOL>if previous_character in symbols_pairs:<EOL><INDENT>if next_character in symbols_pairs.values():<EOL><INDENT>cursor.insertBlock()<EOL>cursor.insertText(match)<EOL>cursor.movePosition(QTextCursor.PreviousBlock, QTextCursor.MoveAnchor)<EOL>cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)<EOL>editor.setTextCursor(cursor)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return True<EOL> | Implements indentation post event input accelerators.
:param editor: Document editor.
:type editor: QWidget
:param event: Event being handled.
:type event: QEvent
:return: Method success.
:rtype: bool | f13158:m4 |
def completion_pre_event_input_accelerators(editor, event): | process_event = True<EOL>if editor.completer:<EOL><INDENT>if editor.completer.popup().isVisible():<EOL><INDENT>if event.key() in (Qt.Key_Enter, Qt.Key_Return, Qt.Key_Escape, Qt.Key_Tab, Qt.Key_Backtab):<EOL><INDENT>event.ignore()<EOL>process_event = False<EOL>return process_event<EOL><DEDENT><DEDENT><DEDENT>if event.modifiers() in (Qt.ControlModifier, Qt.MetaModifier) and event.key() == Qt.Key_Space:<EOL><INDENT>process_event = False<EOL>if not editor.completer:<EOL><INDENT>return process_event<EOL><DEDENT>perform_completion(editor)<EOL><DEDENT>return process_event<EOL> | Implements completion pre event input accelerators.
:param editor: Document editor.
:type editor: QWidget
:param event: Event being handled.
:type event: QEvent
:return: Process event.
:rtype: bool | f13158:m5 |
def completion_post_event_input_accelerators(editor, event): | if editor.completer:<EOL><INDENT>if editor.completer.popup().isVisible():<EOL><INDENT>perform_completion(editor)<EOL><DEDENT><DEDENT>return True<EOL> | Implements completion post event input accelerators.
:param editor: Document editor.
:type editor: QWidget
:param event: Event being handled.
:type event: QEvent
:return: Process event.
:rtype: bool | f13158:m6 |
def symbols_expanding_pre_event_input_accelerators(editor, event): | process_event = True<EOL>symbols_pairs = get_editor_capability(editor, "<STR_LIT>")<EOL>if not symbols_pairs:<EOL><INDENT>return process_event<EOL><DEDENT>text = foundations.strings.to_string(event.text())<EOL>if text in symbols_pairs:<EOL><INDENT>cursor = editor.textCursor()<EOL>if not is_symbols_pair_complete(editor, text):<EOL><INDENT>cursor.insertText(event.text())<EOL><DEDENT>else:<EOL><INDENT>if not cursor.hasSelection():<EOL><INDENT>cursor.insertText(event.text())<EOL>cursor.insertText(symbols_pairs[text])<EOL>cursor.movePosition(QTextCursor.Left, QTextCursor.MoveAnchor)<EOL><DEDENT>else:<EOL><INDENT>selected_text = cursor.selectedText()<EOL>cursor.insertText(event.text())<EOL>cursor.insertText(selected_text)<EOL>cursor.insertText(symbols_pairs[text])<EOL><DEDENT><DEDENT>editor.setTextCursor(cursor)<EOL>process_event = False<EOL><DEDENT>if event.key() in (Qt.Key_Backspace,):<EOL><INDENT>cursor = editor.textCursor()<EOL>cursor.movePosition(QTextCursor.Left, QTextCursor.KeepAnchor)<EOL>left_text = cursor.selectedText()<EOL>foundations.common.repeat(lambda: cursor.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor), <NUM_LIT:2>)<EOL>right_text = cursor.selectedText()<EOL>if symbols_pairs.get(foundations.strings.to_string(left_text)) == foundations.strings.to_string(right_text):<EOL><INDENT>cursor.deleteChar()<EOL><DEDENT><DEDENT>return process_event<EOL> | Implements symbols expanding pre event input accelerators.
:param editor: Document editor.
:type editor: QWidget
:param event: Event being handled.
:type event: QEvent
:return: Process event.
:rtype: bool | f13158:m7 |
def __new__(cls, *args, **kwargs): | instance = super(GraphModel, cls).__new__(cls)<EOL>GraphModel._GraphModel__models_instances[id(instance)] = instance<EOL>return instance<EOL> | Constructor of the class.
:param \*args: Arguments.
:type \*args: \*
:param \*\*kwargs: Keywords arguments.
:type \*\*kwargs: \*\*
:return: Class instance.
:rtype: AbstractNode | f13159:c0:m0 |
def __init__(self,<EOL>parent=None,<EOL>root_node=None,<EOL>horizontal_headers=None,<EOL>vertical_headers=None,<EOL>default_node=None): | LOGGER.debug("<STR_LIT>".format(self.__class__.__name__))<EOL>QAbstractItemModel.__init__(self, parent)<EOL>self.__root_node = None<EOL>self.root_node = root_node or umbra.ui.nodes.DefaultNode(name="<STR_LIT>")<EOL>self.__horizontal_headers = None<EOL>self.horizontal_headers = horizontal_headers or OrderedDict([("<STR_LIT>", "<STR_LIT>")])<EOL>self.__vertical_headers = None<EOL>self.vertical_headers = vertical_headers or OrderedDict()<EOL>self.__default_node = None<EOL>self.default_node = default_node or umbra.ui.nodes.GraphModelNode<EOL> | Initializes the class.
:param parent: Object parent.
:type parent: QObject
:param root_node: Root node.
:type root_node: AbstractCompositeNode or GraphModelNode
:param horizontal_headers: Headers.
:type horizontal_headers: OrderedDict
:param vertical_headers: Headers.
:type vertical_headers: OrderedDict
:param default_node: Default node.
:type default_node: AbstractCompositeNode or GraphModelNode | f13159:c0:m1 |
@property<EOL><INDENT>def root_node(self):<DEDENT> | return self.__root_node<EOL> | Property for **self.__root_node** attribute.
:return: self.__root_node.
:rtype: AbstractCompositeNode or GraphModelNode | f13159:c0:m2 |
@root_node.setter<EOL><INDENT>@foundations.exceptions.handle_exceptions(AssertionError)<EOL>def root_node(self, value):<DEDENT> | if value is not None:<EOL><INDENT>assert issubclass(value.__class__, AbstractCompositeNode),"<STR_LIT>".format(<EOL>"<STR_LIT>", value, AbstractCompositeNode.__name__)<EOL><DEDENT>self.__root_node = value<EOL> | Setter for **self.__root_node** attribute.
:param value: Attribute value.
:type value: AbstractCompositeNode or GraphModelNode | f13159:c0:m3 |
@root_node.deleter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def root_node(self):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Deleter for **self.__root_node** attribute. | f13159:c0:m4 |
@property<EOL><INDENT>def horizontal_headers(self):<DEDENT> | return self.__horizontal_headers<EOL> | Property for **self.__horizontal_headers** attribute.
:return: self.__horizontal_headers.
:rtype: OrderedDict | f13159:c0:m5 |
@horizontal_headers.setter<EOL><INDENT>@foundations.exceptions.handle_exceptions(AssertionError)<EOL>def horizontal_headers(self, value):<DEDENT> | if value is not None:<EOL><INDENT>assert type(value) is OrderedDict, "<STR_LIT>".format(<EOL>"<STR_LIT>", value)<EOL><DEDENT>self.__horizontal_headers = value<EOL> | Setter for **self.__horizontal_headers** attribute.
:param value: Attribute value.
:type value: OrderedDict | f13159:c0:m6 |
@horizontal_headers.deleter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def horizontal_headers(self):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Deleter for **self.__horizontal_headers** attribute. | f13159:c0:m7 |
@property<EOL><INDENT>def vertical_headers(self):<DEDENT> | return self.__vertical_headers<EOL> | Property for **self.__vertical_headers** attribute.
:return: self.__vertical_headers.
:rtype: OrderedDict | f13159:c0:m8 |
@vertical_headers.setter<EOL><INDENT>@foundations.exceptions.handle_exceptions(AssertionError)<EOL>def vertical_headers(self, value):<DEDENT> | if value is not None:<EOL><INDENT>assert type(value) is OrderedDict, "<STR_LIT>".format(<EOL>"<STR_LIT>", value)<EOL><DEDENT>self.__vertical_headers = value<EOL> | Setter for **self.__vertical_headers** attribute.
:param value: Attribute value.
:type value: OrderedDict | f13159:c0:m9 |
@vertical_headers.deleter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def vertical_headers(self):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Deleter for **self.__vertical_headers** attribute. | f13159:c0:m10 |
@property<EOL><INDENT>def default_node(self):<DEDENT> | return self.__default_node<EOL> | Property for **self.__default_node** attribute.
:return: self.__default_node.
:rtype: AbstractCompositeNode or GraphModelNode | f13159:c0:m11 |
@default_node.setter<EOL><INDENT>@foundations.exceptions.handle_exceptions(AssertionError)<EOL>def default_node(self, value):<DEDENT> | if value is not None:<EOL><INDENT>assert issubclass(value, AbstractCompositeNode),"<STR_LIT>".format(<EOL>"<STR_LIT>", value, AbstractCompositeNode.__name__)<EOL><DEDENT>self.__default_node = value<EOL> | Setter for **self.__default_node** attribute.
:param value: Attribute value.
:type value: AbstractCompositeNode or GraphModelNode | f13159:c0:m12 |
@default_node.deleter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def default_node(self):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Deleter for **self.__default_node** attribute. | f13159:c0:m13 |
def rowCount(self, parent=QModelIndex()): | if not parent.isValid():<EOL><INDENT>parent_node = self.__root_node<EOL><DEDENT>else:<EOL><INDENT>parent_node = parent.internalPointer()<EOL><DEDENT>return parent_node.children_count()<EOL> | Reimplements the :meth:`QAbstractItemModel.rowCount` method.
:param parent: Parent node.
:type parent: AbstractCompositeNode or GraphModelNode
:return: Row count.
:rtype: int | f13159:c0:m14 |
def columnCount(self, parent=QModelIndex()): | return len(self.__horizontal_headers)<EOL> | Reimplements the :meth:`QAbstractItemModel.columnCount` method.
:param parent: Parent node.
:type parent: AbstractCompositeNode or GraphModelNode
:return: Column count.
:rtype: int | f13159:c0:m15 |
def data(self, index, role=Qt.DisplayRole): | if not index.isValid():<EOL><INDENT>return QVariant()<EOL><DEDENT>node = self.get_node(index)<EOL>if index.column() == <NUM_LIT:0>:<EOL><INDENT>if hasattr(node, "<STR_LIT>"):<EOL><INDENT>if role == Qt.DecorationRole:<EOL><INDENT>return QIcon(node.roles.get(role, "<STR_LIT>"))<EOL><DEDENT>else:<EOL><INDENT>return node.roles.get(role, QVariant())<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>attribute = self.get_attribute(node, index.column())<EOL>if attribute:<EOL><INDENT>if hasattr(attribute, "<STR_LIT>"):<EOL><INDENT>if role == Qt.DecorationRole:<EOL><INDENT>return QIcon(attribute.roles.get(role, "<STR_LIT>"))<EOL><DEDENT>else:<EOL><INDENT>return attribute.roles.get(role, QVariant())<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return QVariant()<EOL> | Reimplements the :meth:`QAbstractItemModel.data` method.
:param index: Index.
:type index: QModelIndex
:param role: Role.
:type role: int
:return: Data.
:rtype: QVariant | f13159:c0:m16 |
def setData(self, index, value, role=Qt.EditRole): | if not index.isValid():<EOL><INDENT>return False<EOL><DEDENT>node = self.get_node(index)<EOL>if role == Qt.DisplayRole or role == Qt.EditRole:<EOL><INDENT>value = foundations.strings.to_string(value.toString())<EOL>roles = {Qt.DisplayRole: value, Qt.EditRole: value}<EOL><DEDENT>else:<EOL><INDENT>roles = {role: value}<EOL><DEDENT>if index.column() == <NUM_LIT:0>:<EOL><INDENT>if (node and hasattr(node, "<STR_LIT>")):<EOL><INDENT>node.roles.update(roles)<EOL>node.name = value<EOL><DEDENT><DEDENT>else:<EOL><INDENT>attribute = self.get_attribute(node, index.column())<EOL>if (attribute and hasattr(attribute, "<STR_LIT>")):<EOL><INDENT>attribute.roles.update(roles)<EOL>attribute.value = value<EOL><DEDENT><DEDENT>self.dataChanged.emit(index, index)<EOL>return True<EOL> | Reimplements the :meth:`QAbstractItemModel.setData` method.
:param index: Index.
:type index: QModelIndex
:param value: Value.
:type value: QVariant
:param role: Role.
:type role: int
:return: Method success.
:rtype: bool | f13159:c0:m17 |
def headerData(self, section, orientation, role=Qt.DisplayRole): | if role == Qt.DisplayRole:<EOL><INDENT>if orientation == Qt.Horizontal:<EOL><INDENT>if section < len(self.__horizontal_headers):<EOL><INDENT>return self.__horizontal_headers.keys()[section]<EOL><DEDENT><DEDENT>elif orientation == Qt.Vertical:<EOL><INDENT>if section < len(self.__vertical_headers):<EOL><INDENT>return self.__vertical_headers.keys()[section]<EOL><DEDENT><DEDENT><DEDENT>return QVariant()<EOL> | Reimplements the :meth:`QAbstractItemModel.headerData` method.
:param section: Section.
:type section: int
:param orientation: Orientation. ( Qt.Orientation )
:param role: Role.
:type role: int
:return: Header data.
:rtype: QVariant | f13159:c0:m18 |
def flags(self, index): | if not index.isValid():<EOL><INDENT>return Qt.NoItemFlags<EOL><DEDENT>node = self.get_node(index)<EOL>if index.column() == <NUM_LIT:0>:<EOL><INDENT>return hasattr(node, "<STR_LIT>") and Qt.ItemFlags(node.flags) or Qt.NoItemFlags<EOL><DEDENT>else:<EOL><INDENT>attribute = self.get_attribute(node, index.column())<EOL>return attribute and hasattr(attribute, "<STR_LIT>") and Qt.ItemFlags(attribute.flags) or Qt.NoItemFlags<EOL><DEDENT> | Reimplements the :meth:`QAbstractItemModel.flags` method.
:param index: Index.
:type index: QModelIndex
:return: Flags. ( Qt.ItemFlags ) | f13159:c0:m19 |
def parent(self, index): | if not index.isValid():<EOL><INDENT>return QModelIndex()<EOL><DEDENT>node = self.get_node(index)<EOL>parent_node = node.parent<EOL>if not parent_node:<EOL><INDENT>return QModelIndex()<EOL><DEDENT>if parent_node == self.__root_node:<EOL><INDENT>return QModelIndex()<EOL><DEDENT>row = parent_node.row()<EOL>return self.createIndex(row, <NUM_LIT:0>, parent_node) if row is not None else QModelIndex()<EOL> | Reimplements the :meth:`QAbstractItemModel.parent` method.
:param index: Index.
:type index: QModelIndex
:return: Parent.
:rtype: QModelIndex | f13159:c0:m20 |
def index(self, row, column=<NUM_LIT:0>, parent=QModelIndex()): | parent_node = self.get_node(parent)<EOL>child = parent_node.child(row)<EOL>if child:<EOL><INDENT>return self.createIndex(row, column, child)<EOL><DEDENT>else:<EOL><INDENT>return QModelIndex()<EOL><DEDENT> | Reimplements the :meth:`QAbstractItemModel.index` method.
:param row: Row.
:type row: int
:param column: Column.
:type column: int
:param parent: Parent.
:type parent: QModelIndex
:return: Index.
:rtype: QModelIndex | f13159:c0:m21 |
def sort(self, column, order=Qt.AscendingOrder): | if column > self.columnCount():<EOL><INDENT>return<EOL><DEDENT>self.beginResetModel()<EOL>if column == <NUM_LIT:0>:<EOL><INDENT>self.__root_node.sort_children(reverse_order=order)<EOL><DEDENT>else:<EOL><INDENT>self.__root_node.sort_children(<EOL>attribute=self.__horizontal_headers[self.__horizontal_headers.keys()[column]],<EOL>reverse_order=order)<EOL><DEDENT>self.endResetModel()<EOL> | Reimplements the :meth:`QAbstractItemModel.sort` method.
:param column: Column.
:type column: int
:param order: Order. ( Qt.SortOrder ) | f13159:c0:m22 |
def insertRows(self, row, count, parent=QModelIndex()): | parent_node = self.get_node(parent)<EOL>self.beginInsertRows(parent, row, row + count - <NUM_LIT:1>)<EOL>success = True<EOL>for i in range(count):<EOL><INDENT>childNode = self.__default_node()<EOL>success *= True if parent_node.insert_child(childNode, row) else False<EOL><DEDENT>self.endInsertRows()<EOL>return success<EOL> | Reimplements the :meth:`QAbstractItemModel.insertRows` method.
:param row: Row.
:type row: int
:param count: Count.
:type count: int
:param parent: Parent.
:type parent: QModelIndex
:return: Method success.
:rtype: bool | f13159:c0:m23 |
def removeRows(self, row, count, parent=QModelIndex()): | parent_node = self.get_node(parent)<EOL>self.beginRemoveRows(parent, row, row + count - <NUM_LIT:1>)<EOL>success = True<EOL>for i in range(count):<EOL><INDENT>success *= True if parent_node.remove_child(row) else False<EOL><DEDENT>self.endRemoveRows()<EOL>return success<EOL> | Reimplements the :meth:`QAbstractItemModel.removeRows` method.
:param row: Row.
:type row: int
:param count: Count.
:type count: int
:param parent: Parent.
:type parent: QModelIndex
:return: Method success.
:rtype: bool | f13159:c0:m24 |
def movesRows(self, from_parent, from_first_row, from_last_row, to_parent, to_row): | return True<EOL> | Moves given rows from parent to parent row. | f13159:c0:m25 |
def mimeTypes(self): | types = QStringList()<EOL>types.append("<STR_LIT>")<EOL>return types<EOL> | Reimplements the :meth:`QAbstractItemModel.mimeTypes` method.
:return: Mime types.
:rtype: QStringList | f13159:c0:m26 |
def mimeData(self, indexes): | byte_stream = pickle.dumps([self.get_node(index) for index in indexes], pickle.HIGHEST_PROTOCOL)<EOL>mime_data = QMimeData()<EOL>mime_data.setData("<STR_LIT>", byte_stream)<EOL>return mime_data<EOL> | Reimplements the :meth:`QAbstractItemModel.mimeData` method.
:param indexes: Indexes.
:type indexes: QModelIndexList
:return: MimeData.
:rtype: QMimeData | f13159:c0:m27 |
def clear(self): | self.beginResetModel()<EOL>self.root_node.children = []<EOL>self.endResetModel()<EOL> | Clears the Model.
:return: Method success.
:rtype: bool | f13159:c0:m28 |
def has_nodes(self): | return True if self.__root_node.children else False<EOL> | Returns if Model has nodes.
:return: Has children.
:rtype: bool | f13159:c0:m29 |
def get_node(self, index): | if not index.isValid():<EOL><INDENT>return self.__root_node<EOL><DEDENT>return index.internalPointer() or self.__root_node<EOL> | Returns the Node at given index.
:param index: Index.
:type index: QModelIndex
:return: Node.
:rtype: AbstractCompositeNode or GraphModelNode | f13159:c0:m30 |
def get_attribute(self, node, column): | if column > <NUM_LIT:0> and column < len(self.__horizontal_headers):<EOL><INDENT>return node.get(self.__horizontal_headers[self.__horizontal_headers.keys()[column]], None)<EOL><DEDENT> | Returns the given Node attribute associated to the given column.
:param node: Node.
:type node: AbstractCompositeNode or GraphModelNode
:param column: Column.
:type column: int
:return: Attribute.
:rtype: Attribute | f13159:c0:m31 |
def get_node_index(self, node): | if node == self.__root_node:<EOL><INDENT>return QModelIndex()<EOL><DEDENT>else:<EOL><INDENT>row = node.row()<EOL>return self.createIndex(row, <NUM_LIT:0>, node) if row is not None else QModelIndex()<EOL><DEDENT> | Returns given Node index.
:param node: Node.
:type node: AbstractCompositeNode or GraphModelNode
:return: Index.
:rtype: QModelIndex | f13159:c0:m32 |
def get_attribute_index(self, node, column): | if column > <NUM_LIT:0> and column < len(self.__horizontal_headers):<EOL><INDENT>row = node.row()<EOL>return self.createIndex(row, column, node) if row is not None else QModelIndex()<EOL><DEDENT> | Returns given Node attribute index at given column.
:param node: Node.
:type node: AbstractCompositeNode or GraphModelNode
:param column: Attribute column.
:type column: int
:return: Index.
:rtype: QModelIndex | f13159:c0:m33 |
def find_children(self, pattern="<STR_LIT>", flags=<NUM_LIT:0>): | return self.__root_node.find_children(pattern, flags)<EOL> | Finds the children matching the given patten.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:return: Matching children.
:rtype: list | f13159:c0:m34 |
def find_family(self, pattern=r"<STR_LIT>", flags=<NUM_LIT:0>, node=None): | return self.__root_node.find_family(pattern, flags, node or self.__root_node)<EOL> | Returns the Nodes from given family.
:param pattern: Matching pattern.
:type pattern: unicode
:param flags: Matching regex flags.
:type flags: int
:param node: Node to start walking from.
:type node: AbstractNode or AbstractCompositeNode or GraphModelNode
:return: Family nodes.
:rtype: list | f13159:c0:m35 |
def find_node(self, attribute): | for model in GraphModel._GraphModel__models_instances.itervalues():<EOL><INDENT>for node in foundations.walkers.nodes_walker(model.root_node):<EOL><INDENT>if attribute in node.get_attributes():<EOL><INDENT>return node<EOL><DEDENT><DEDENT><DEDENT> | Returns the Node with given attribute.
:param attribute: Attribute.
:type attribute: GraphModelAttribute
:return: Node.
:rtype: GraphModelNode | f13159:c0:m36 |
@staticmethod<EOL><INDENT>def find_model(object):<DEDENT> | models = []<EOL>for model in GraphModel._GraphModel__models_instances.itervalues():<EOL><INDENT>for node in foundations.walkers.nodes_walker(model.root_node):<EOL><INDENT>if node is object:<EOL><INDENT>models.append(model)<EOL><DEDENT>for attribute in node.get_attributes():<EOL><INDENT>if attribute is object:<EOL><INDENT>models.append(model)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return models<EOL> | Returns the model(s) associated with given object.
:param object: Node / Attribute.
:type object: GraphModelNode or GraphModelAttribute
:return: Model(s).
:rtype: list | f13159:c0:m37 |
def enable_model_triggers(self, state): | for node in foundations.walkers.nodes_walker(self.root_node):<EOL><INDENT>node.trigger_model = state<EOL>for attribute in node.get_attributes():<EOL><INDENT>attribute.trigger_model = state<EOL><DEDENT><DEDENT> | Enables Model Nodes and attributes triggers.
:param state: Inform model state.
:type state: bool
:return: Method success.
:rtype: bool | f13159:c0:m38 |
def node_changed(self, node): | index = self.get_node_index(node)<EOL>if index is not None:<EOL><INDENT>self.dataChanged.emit(index, index)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT> | Calls :meth:`QAbstractItemModel.dataChanged` with given Node index.
:param node: Node.
:type node: AbstractCompositeNode or GraphModelNode
:return: Method success.
:rtype: bool | f13159:c0:m39 |
def attribute_changed(self, node, column): | index = self.get_attribute_index(node, column)<EOL>if index is not None:<EOL><INDENT>self.dataChanged.emit(index, index)<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT> | Calls :meth:`QAbstractItemModel.dataChanged` with given Node attribute index.
:param node: Node.
:type node: AbstractCompositeNode or GraphModelNode
:param column: Attribute column.
:type column: int
:return: Method success.
:rtype: bool | f13159:c0:m40 |
def _set_package_directory(): | package_directory = os.path.normpath(os.path.join(os.path.dirname(__file__), "<STR_LIT>"))<EOL>package_directory not in sys.path and sys.path.append(package_directory)<EOL> | Sets the Application package directory in the path. | f13160:m0 |
def main(): | components_paths = []<EOL>for path in (os.path.join(umbra.__path__[<NUM_LIT:0>], Constants.factory_components_directory),<EOL>os.path.join(umbra.__path__[<NUM_LIT:0>], Constants.factory_addons_components_directory)):<EOL><INDENT>os.path.exists(path) and components_paths.append(path)<EOL><DEDENT>return umbra.engine.run(umbra.engine.Umbra,<EOL>umbra.engine.get_command_line_parameters_parser().parse_args(<EOL>[unicode(argument, Constants.default_codec, Constants.codec_error) for argument in<EOL>sys.argv]),<EOL>components_paths,<EOL>("<STR_LIT>", "<STR_LIT>", "<STR_LIT>"))<EOL> | Starts the Application.
:return: Definition success.
:rtype: bool | f13160:m1 |
def __init__(self, parent, *args, **kwargs): | LOGGER.debug("<STR_LIT>".format(self.__class__.__name__))<EOL>super(Processing, self).__init__(parent, *args, **kwargs)<EOL>self.__container = parent<EOL>Processing.__initialize_ui(self)<EOL> | Initializes the class.
:param parent: Object parent.
:type parent: QObject
:param \*args: Arguments.
:type \*args: \*
:param \*\*kwargs: Keywords arguments.
:type \*\*kwargs: \*\* | f13161:c0:m0 |
@property<EOL><INDENT>def container(self):<DEDENT> | return self.__container<EOL> | Property for **self.__container** attribute.
:return: self.__container.
:rtype: QObject | f13161:c0:m1 |
@container.setter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def container(self, value):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Setter for **self.__container** attribute.
:param value: Attribute value.
:type value: QObject | f13161:c0:m2 |
@container.deleter<EOL><INDENT>@foundations.exceptions.handle_exceptions(foundations.exceptions.ProgrammingError)<EOL>def container(self):<DEDENT> | raise foundations.exceptions.ProgrammingError(<EOL>"<STR_LIT>".format(self.__class__.__name__, "<STR_LIT>"))<EOL> | Deleter for **self.__container** attribute. | f13161:c0:m3 |
def __initialize_ui(self): | pass<EOL> | Initializes the Widget ui. | f13161:c0:m4 |
def notify_exception_handler(*args): | callback = RuntimeGlobals.components_manager["<STR_LIT>"].restore_development_layout<EOL>foundations.exceptions.base_exception_handler(*args)<EOL>cls, instance = foundations.exceptions.extract_exception(*args)[:<NUM_LIT:2>]<EOL>RuntimeGlobals.notifications_manager.exceptify(message="<STR_LIT>".format(instance), notification_clicked_slot=callback)<EOL>return True<EOL> | Provides a notifier exception handler.
:param \*args: Arguments.
:type \*args: \*
:return: Definition success.
:rtype: bool | f13162:m0 |
def apply(): | return True<EOL> | Triggers the patch execution.
:return: Definition success.
:rtype: bool | f13163:m0 |
def _setEncoding(): | import sys<EOL>reload(sys)<EOL>sys.setdefaultencoding("<STR_LIT:utf-8>")<EOL> | Sets the Package encoding. | f13164:m0 |
def get_long_description(): | description = []<EOL>with open("<STR_LIT>") as file:<EOL><INDENT>for line in file:<EOL><INDENT>if "<STR_LIT>" in line and len(description) >= <NUM_LIT:2>:<EOL><INDENT>blockLine = description[-<NUM_LIT:2>]<EOL>if re.search(r"<STR_LIT>", blockLine) and not re.search(r"<STR_LIT>", blockLine):<EOL><INDENT>description[-<NUM_LIT:2>] = "<STR_LIT>".join(blockLine.rsplit("<STR_LIT::>", <NUM_LIT:1>))<EOL><DEDENT>continue<EOL><DEDENT>description.append(line)<EOL><DEDENT><DEDENT>return "<STR_LIT>".join(description)<EOL> | Returns the Package long description.
:return: Package long description.
:rtype: unicode | f13164:m1 |
def factory(**kwargs): | return MockResource(**kwargs)<EOL> | Returns a mock Resource object.
:param \**kwargs: Accepts anything, which is passed to the Resource
object. | f13166:m0 |
def close(self): | self.open = False<EOL> | "Closes" the resource. | f13166:c0:m1 |
@property<EOL><INDENT>def capacity(self):<DEDENT> | return self._capacity<EOL> | The maximum capacity the pool will hold under normal circumstances. | f13168:c0:m1 |
@property<EOL><INDENT>def connection_arguments(self):<DEDENT> | warnings.warn(('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>DeprecationWarning)<EOL>return self.factory_arguments<EOL> | For compatibility with older versions, will be removed in 1.0. | f13168:c0:m2 |
@property<EOL><INDENT>def factory_arguments(self):<DEDENT> | return self._factory_arguments.copy()<EOL> | Return a copy of the factory arguments used to create a resource. | f13168:c0:m3 |
@property<EOL><INDENT>def maxsize(self):<DEDENT> | return self._capacity + self._overflow<EOL> | The maximum possible number of resource instances that can exist at any
one time. | f13168:c0:m4 |
@property<EOL><INDENT>def overflow(self):<DEDENT> | return self._overflow<EOL> | The number of additional resource instances the pool will create when
it is at capacity. | f13168:c0:m5 |
@property<EOL><INDENT>def size(self):<DEDENT> | with self._lock:<EOL><INDENT>return self._size<EOL><DEDENT> | The number of existing resource instances that have been made by the
pool.
:note: This is not the number of resources *in* the pool, but the
number of existing resources. This includes resources in the
pool and resources in use.
.. warning:: This is not threadsafe. ``size`` can change when context
switches to another thread. | f13168:c0:m6 |
@property<EOL><INDENT>def timeout(self):<DEDENT> | return self._timeout<EOL> | The duration to wait for a resource to be returned to the pool when the
pool is depleted. | f13168:c0:m7 |
def _get(self, timeout): | with self._lock:<EOL><INDENT>if timeout is None:<EOL><INDENT>while self.empty():<EOL><INDENT>self._not_empty.wait()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>time_end = time.time() + timeout<EOL>while self.empty():<EOL><INDENT>time_left = time_end - time.time()<EOL>if time_left < <NUM_LIT:0>:<EOL><INDENT>raise PoolEmptyError<EOL><DEDENT>self._not_empty.wait(time_left)<EOL><DEDENT><DEDENT>rtracker = self._reference_queue[self._resource_start]<EOL>self._resource_start = (self._resource_start + <NUM_LIT:1>) % self.maxsize<EOL>self._available -= <NUM_LIT:1><EOL><DEDENT>return rtracker<EOL> | Get a resource from the pool. If timeout is ``None`` waits
indefinitely.
:param timeout: Time in seconds to wait for a resource.
:type timeout: int
:return: A resource.
:rtype: :class:`_ResourceTracker`
:raises PoolEmptyError: When timeout has elapsed and unable to
retrieve resource. | f13168:c0:m8 |
def _get_tracker(self, resource): | with self._lock:<EOL><INDENT>for rt in self._reference_queue:<EOL><INDENT>if rt is not None and resource is rt.resource:<EOL><INDENT>return rt<EOL><DEDENT><DEDENT><DEDENT>raise UnknownResourceError('<STR_LIT>')<EOL> | Return the resource tracker that is tracking ``resource``.
:param resource: A resource.
:return: A resource tracker.
:rtype: :class:`_ResourceTracker` | f13168:c0:m9 |
def _harvest_lost_resources(self): | with self._lock:<EOL><INDENT>for i in self._unavailable_range():<EOL><INDENT>rtracker = self._reference_queue[i]<EOL>if rtracker is not None and rtracker.available():<EOL><INDENT>self.put_resource(rtracker.resource)<EOL><DEDENT><DEDENT><DEDENT> | Return lost resources to pool. | f13168:c0:m10 |
def _make_resource(self): | with self._lock:<EOL><INDENT>for i in self._unavailable_range():<EOL><INDENT>if self._reference_queue[i] is None:<EOL><INDENT>rtracker = _ResourceTracker(<EOL>self._factory(**self._factory_arguments))<EOL>self._reference_queue[i] = rtracker<EOL>self._size += <NUM_LIT:1><EOL>return rtracker<EOL><DEDENT><DEDENT>raise PoolFullError<EOL><DEDENT> | Returns a resource instance. | f13168:c0:m11 |
def _put(self, rtracker): | with self._lock:<EOL><INDENT>if self._available < self.capacity:<EOL><INDENT>for i in self._unavailable_range():<EOL><INDENT>if self._reference_queue[i] is rtracker:<EOL><INDENT>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise UnknownResourceError<EOL><DEDENT>j = self._resource_end<EOL>rq = self._reference_queue<EOL>rq[i], rq[j] = rq[j], rq[i]<EOL>self._resource_end = (self._resource_end + <NUM_LIT:1>) % self.maxsize<EOL>self._available += <NUM_LIT:1><EOL>self._not_empty.notify()<EOL><DEDENT>else:<EOL><INDENT>raise PoolFullError<EOL><DEDENT><DEDENT> | Put a resource back in the queue.
:param rtracker: A resource.
:type rtracker: :class:`_ResourceTracker`
:raises PoolFullError: If pool is full.
:raises UnknownResourceError: If resource can't be found. | f13168:c0:m12 |
def _remove(self, rtracker): | with self._lock:<EOL><INDENT>i = self._reference_queue.index(rtracker)<EOL>self._reference_queue[i] = None<EOL>self._size -= <NUM_LIT:1><EOL><DEDENT> | Remove a resource from the pool.
:param rtracker: A resource.
:type rtracker: :class:`_ResourceTracker` | f13168:c0:m13 |
def _unavailable_range(self): | with self._lock:<EOL><INDENT>i = self._resource_end<EOL>j = self._resource_start<EOL>if j < i or self.empty():<EOL><INDENT>j += self.maxsize<EOL><DEDENT>for k in range(i, j):<EOL><INDENT>yield k % self.maxsize<EOL><DEDENT><DEDENT> | Return a generator for the indices of the unavailable region of
``_reference_queue``. | f13168:c0:m14 |
def empty(self): | with self._lock:<EOL><INDENT>return self._available == <NUM_LIT:0><EOL><DEDENT> | Return ``True`` if pool is empty. | f13168:c0:m15 |
def get_connection(self, connection_wrapper=None): | warnings.warn(('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>DeprecationWarning)<EOL>return self.get_resource(connection_wrapper)<EOL> | For compatibility with older versions, will be removed in 1.0. | f13168:c0:m16 |
def get_resource(self, resource_wrapper=None): | rtracker = None<EOL>if resource_wrapper is None:<EOL><INDENT>resource_wrapper = self._resource_wrapper<EOL><DEDENT>if self.empty():<EOL><INDENT>self._harvest_lost_resources()<EOL><DEDENT>try:<EOL><INDENT>rtracker = self._get(<NUM_LIT:0>)<EOL><DEDENT>except PoolEmptyError:<EOL><INDENT>pass<EOL><DEDENT>if rtracker is None:<EOL><INDENT>try:<EOL><INDENT>rtracker = self._make_resource()<EOL><DEDENT>except PoolFullError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if rtracker is None:<EOL><INDENT>try:<EOL><INDENT>rtracker = self._get(timeout=self._timeout)<EOL><DEDENT>except PoolEmptyError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if rtracker is None:<EOL><INDENT>raise PoolEmptyError<EOL><DEDENT>if not self.ping(rtracker.resource):<EOL><INDENT>with self._lock:<EOL><INDENT>self._remove(rtracker)<EOL>rtracker = self._make_resource()<EOL><DEDENT><DEDENT>self.normalize_connection(rtracker.resource)<EOL>return rtracker.wrap_resource(self, resource_wrapper)<EOL> | Returns a ``Resource`` instance.
:param resource_wrapper: A Resource subclass.
:return: A ``Resource`` instance.
:raises PoolEmptyError: If attempt to get resource fails or times
out. | f13168:c0:m17 |
def normalize_connection(self, connection): | warnings.warn(('<STR_LIT>'<EOL>'<STR_LIT>'),<EOL>DeprecationWarning)<EOL>return self.normalize_resource(connection)<EOL> | For compatibility with older versions, will be removed in 1.0. | f13168:c0:m18 |
def normalize_resource(self, resource): | warnings.warn('<STR_LIT>'<EOL>'<STR_LIT>')<EOL> | A user implemented function that resets the properties of the
resource instance that was created by `factory`. This prevents
unwanted behavior from a resource retrieved from the pool as it could
have been changed when previously used.
:param obj resource: A resource instance. | f13168:c0:m19 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.