Пример #1
0
    def set_target(self, target):
        """Set the object that the popup is showing documentation about"""
        
        if target is self.__target:
            return

        self.__target = target
        buf = self.__view.get_buffer()
        buf.delete(buf.get_start_iter(), buf.get_end_iter())

        if target != None:
            if data_format.is_data_object(target):
                data_format.insert_formatted(buf, buf.get_start_iter(), target, self.__heading_type_tag, self.__inline_type_tag, self.__value_tag)
            else:
                doc_format.insert_docs(buf, buf.get_start_iter(), target, self.__bold_tag)

            buf.place_cursor(buf.get_start_iter())

        self.__scrollbar.get_adjustment().set_value(0.)
Пример #2
0
    def set_target(self, target):
        """Set the object that the popup is showing documentation about"""

        if target is self.__target:
            return

        self.__target = target
        buf = self.__view.get_buffer()
        buf.delete(buf.get_start_iter(), buf.get_end_iter())

        if target is not None:
            if data_format.is_data_object(target):
                data_format.insert_formatted(buf, buf.get_start_iter(), target,
                                             self.__heading_type_tag,
                                             self.__inline_type_tag,
                                             self.__value_tag)
            else:
                doc_format.insert_docs(buf, buf.get_start_iter(), target,
                                       self.__bold_tag)

            buf.place_cursor(buf.get_start_iter())

        self.__scrollbar.get_adjustment().set_value(0.)
Пример #3
0
    def __insert_results(self, chunk):
        if not isinstance(chunk, StatementChunk):
            return

        if chunk.results_start_mark or chunk.sidebar_results:
            raise RuntimeError(
                "__insert_results called when we already have results")

        if (chunk.results is None
                or len(chunk.results) == 0) and chunk.error_message is None:
            return

        if chunk.error_message:
            inline_results = [chunk.error_message]
            sidebar_results = None
        else:
            inline_results = []
            sidebar_results = []
            for result in chunk.results:
                if hasattr(result, 'display'):
                    display = result.display
                else:
                    display = 'inline'

                if display == 'side':
                    sidebar_results.append(result)
                else:
                    inline_results.append(result)

        if sidebar_results:
            chunk.sidebar_results = sidebar_results
            self.emit("add-sidebar-results", chunk)

        if not inline_results:
            return

        self.__begin_modification()

        location = self.pos_to_iter(chunk.end - 1)
        if not location.ends_line():
            location.forward_to_line_end()

        # We don't want to move the insert cursor in the common case of
        # inserting a result right at the insert cursor
        if location.compare(self.get_iter_at_mark(self.get_insert())) == 0:
            saved_insert = self.create_mark(None, location, True)
        else:
            saved_insert = None

        self.insert(location, "\n")

        chunk.results_start_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        first = True
        for result in inline_results:
            if not first:
                self.insert(location, "\n")
            first = False

            if isinstance(result, basestring):
                self.insert(location, result)
            elif isinstance(result, WarningResult):
                start_mark = self.create_mark(None, location, True)
                self.insert(location, result.message)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__warning_tag, start, location)
            elif isinstance(result, HelpResult):
                start_mark = self.create_mark(None, location, True)
                doc_format.insert_docs(self, location, result.arg,
                                       self.__bold_tag)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__help_tag, start, location)
            elif isinstance(result, CustomResult):
                anchor = self.create_child_anchor(location)
                self.emit("add-custom-result", result, anchor)
                location = self.get_iter_at_child_anchor(anchor)
                location.forward_char()  # Skip over child

        start = self.get_iter_at_mark(chunk.results_start_mark)
        self.apply_tag(self.__result_tag, start, location)
        self.apply_tag(self.__whole_buffer_tag, start, location)
        if chunk.error_message:
            self.apply_tag(self.__error_tag, start, location)
        chunk.results_end_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        if saved_insert is not None:
            self.place_cursor(self.get_iter_at_mark(saved_insert))
            self.delete_mark(saved_insert)

        self.__end_modification()

        if chunk.pixels_below != 0:
            self.__reset_last_line_tag(chunk)
Пример #4
0
    def __insert_results(self, chunk):
        if not isinstance(chunk, StatementChunk):
            return

        if chunk.results_start_mark or chunk.sidebar_results:
            raise RuntimeError("__insert_results called when we already have results")

        if (chunk.results is None or len(chunk.results) == 0) and chunk.error_message is None:
            return

        if chunk.error_message:
            inline_results = [ chunk.error_message ]
            sidebar_results = None
        else:
            inline_results = []
            sidebar_results = []
            for result in chunk.results:
                if hasattr(result, 'display'):
                    display = result.display
                else:
                    display = 'inline'

                if display == 'side':
                    sidebar_results.append(result)
                else:
                    inline_results.append(result)

        if sidebar_results:
            chunk.sidebar_results = sidebar_results
            self.emit("add-sidebar-results", chunk)

        if not inline_results:
            return

        self.__begin_modification()

        location = self.pos_to_iter(chunk.end - 1)
        if not location.ends_line():
            location.forward_to_line_end()

        # We don't want to move the insert cursor in the common case of
        # inserting a result right at the insert cursor
        if location.compare(self.get_iter_at_mark(self.get_insert())) == 0:
            saved_insert = self.create_mark(None, location, True)
        else:
            saved_insert = None

        self.insert(location, "\n")

        chunk.results_start_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        first = True
        for result in inline_results:
            if not first:
                self.insert(location, "\n")
            first = False

            if isinstance(result, basestring):
                self.insert(location, result)
            elif isinstance(result, WarningResult):
                start_mark = self.create_mark(None, location, True)
                self.insert(location, result.message)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__warning_tag, start, location)
            elif isinstance(result, HelpResult):
                start_mark = self.create_mark(None, location, True)
                doc_format.insert_docs(self, location, result.arg, self.__bold_tag)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__help_tag, start, location)
            elif isinstance(result, CustomResult):
                anchor = self.create_child_anchor(location)
                self.emit("add-custom-result", result, anchor)
                location = self.get_iter_at_child_anchor(anchor)
                location.forward_char() # Skip over child

        start = self.get_iter_at_mark(chunk.results_start_mark)
        self.apply_tag(self.__result_tag, start, location)
        self.apply_tag(self.__whole_buffer_tag, start, location)
        if chunk.error_message:
            self.apply_tag(self.__error_tag, start, location)
        chunk.results_end_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        if saved_insert is not None:
            self.place_cursor(self.get_iter_at_mark(saved_insert))
            self.delete_mark(saved_insert)

        self.__end_modification()

        if chunk.pixels_below != 0:
            self.__reset_last_line_tag(chunk)
Пример #5
0
    def __insert_results(self, chunk):
        if not isinstance(chunk, StatementChunk):
            return

        if chunk.results_start_mark:
            raise RuntimeError("__insert_results called when we already have results")

        if (chunk.results == None or len(chunk.results) == 0) and chunk.error_message == None:
            return

        self.__begin_modification()

        location = self.pos_to_iter(chunk.end - 1)
        if not location.ends_line():
            location.forward_to_line_end()

        # We don't want to move the insert cursor in the common case of
        # inserting a result right at the insert cursor
        if location.compare(self.get_iter_at_mark(self.get_insert())) == 0:
            saved_insert = self.create_mark(None, location, True)
        else:
            saved_insert = None

        self.insert(location, "\n")

        chunk.results_start_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        if chunk.error_message:
            results = [ chunk.error_message ]
        else:
            results = chunk.results

        first = True
        for result in results:
            if not first:
                self.insert(location, "\n")
            first = False

            if isinstance(result, basestring):
                self.insert(location, result)
            elif isinstance(result, WarningResult):
                start_mark = self.create_mark(None, location, True)
                self.insert(location, result.message)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__warning_tag, start, location)
            elif isinstance(result, HelpResult):
                start_mark = self.create_mark(None, location, True)
                doc_format.insert_docs(self, location, result.arg, self.__bold_tag)
                start = self.get_iter_at_mark(start_mark)
                self.delete_mark(start_mark)
                self.apply_tag(self.__help_tag, start, location)
            elif isinstance(result, CustomResult):
                anchor = self.create_child_anchor(location)
                self.emit("add-custom-result", result, anchor)
                location = self.get_iter_at_child_anchor(anchor)
                location.forward_char() # Skip over child

        start = self.get_iter_at_mark(chunk.results_start_mark)
        self.apply_tag(self.__result_tag, start, location)
        chunk.results_end_mark = self.create_mark(None, location, True)
        chunk.results_start_mark.source = chunk

        if saved_insert != None:
            self.place_cursor(self.get_iter_at_mark(saved_insert))
            self.delete_mark(saved_insert)

        self.__end_modification()