Пример #1
0
    def _update_labels(self, _visible_text):
        """
        Updates the position of the labels displayed on top of each word
        """

        anchors_data = calculate_text_anchors(self._get_visible_text(),
                                              self.area.sel.left)
        return [(Span(start_index, end_index), anchor)
                for anchor, start_index, end_index, _ in anchors_data]
Пример #2
0
    def select_text(self,
                    start_anchor,
                    end_anchor=None,
                    include_trailing_whitespace=False):
        """Select word by its anchor (or range with two anchors)."""
        start_char, end_char, last_space = self.anchor_to_range(start_anchor)
        if end_anchor is not None:
            _, end_char, last_space = self.anchor_to_range(end_anchor)

        if include_trailing_whitespace:
            end_char = last_space

        self.area.sel = Span(start_char, end_char)
Пример #3
0
    def select_text(
        self, start_anchor, end_anchor=None, include_trailing_whitespace=False
    ):
        """
        Selects the word corresponding to start_anchor. If end_anchor supplied, selects
        from start_anchor to the end of end_anchor. If include_trailing_whitespace=True
        then also selects trailing space characters (useful for delete).
        """

        start_index, end_index, last_space_index = self.anchor_to_range(start_anchor)
        if end_anchor is not None:
            _, end_index, last_space_index = self.anchor_to_range(end_anchor)

        if include_trailing_whitespace:
            end_index = last_space_index

        self.area.sel = Span(start_index, end_index)
Пример #4
0
    def change_case(self, anchor, case):
        """
        Change the case of the given word (Title case, UPPER case, lower case).
        """

        start_index, end_index, _ = self.anchor_to_range(anchor)
        text = self.area[start_index:end_index]
        if case == "lower":
            updated_text = text.lower()
        elif case == "upper":
            updated_text = text.upper()
        elif case == "title":
            updated_text = text[0].upper() + text[1:]
        else:
            raise AssertionError("Invalid case")

        self.area.replace(Span(start_index, end_index), updated_text)
Пример #5
0
    def change_case(self, anchor, case):
        """Change case of a word.

        :param case str: One of ["Title", "lower", "UPPER"]

        """
        # TODO: Switch this to use complex_insert, etc.
        start_index, end_index, _ = self.anchor_to_range(anchor)
        text = self.area[start_index:end_index]
        if case == "lower":
            updated_text = text.lower()
        elif case == "upper":
            updated_text = text.upper()
        elif case == "title":
            updated_text = text[0].upper() + text[1:]
        else:
            raise AssertionError("Invalid case")

        self.area.replace(Span(start_index, end_index), updated_text)
Пример #6
0
 def _update_labels(self, _visible_text):
     """Update label overlay positions."""
     anchors_data = self._calculate_anchors(self._get_visible_text())
     return [(Span(start_index, end_index), anchor)
             for anchor, start_index, end_index, _ in anchors_data]