示例#1
0
def has_search_entries(buff, search_text):
    """Returns if a certain buffer contains or not a search string"""
    entries = search_iterator(buff, search_text, start_in_cursor=False)
    for bounds in entries:
        return True

    return False
示例#2
0
def has_search_entries(buff, search_text):
    """Returns if a certain buffer contains or not a search string"""
    entries = search_iterator(buff, search_text, start_in_cursor=False)
    for bounds in entries:
        return True
        
    return False
示例#3
0
 def __call__(self, find_forward=True):
     search_text = self.search_text
     # If we have nothing to search we can just move on
     if search_text is None or search_text == "":
         self.clear_highlight()
         return False
         
     bounds = search_iterator(self.get_parent(), search_text, find_forward=find_forward)
     
     try:
         start_iter, end_iter = bounds.next()
         self.get_parent().place_cursor(start_iter)
         self.get_parent().select_range(start_iter, end_iter)
         return True
     
     except StopIteration:
         self._no_more_entries(find_forward)
         return False
示例#4
0
    def __call__(self, find_forward=True):
        search_text = self.search_text
        # If we have nothing to search we can just move on
        if search_text is None or search_text == "":
            self.clear_highlight()
            return False

        bounds = search_iterator(self.get_parent(),
                                 search_text,
                                 find_forward=find_forward)

        try:
            start_iter, end_iter = bounds.next()
            self.get_parent().place_cursor(start_iter)
            self.get_parent().select_range(start_iter, end_iter)
            return True

        except StopIteration:
            self._no_more_entries(find_forward)
            return False
示例#5
0
    def update_highlight(self):
        # Remove old highlight
        self.clear_highlight()
        
        if self.search_text is None or self.search_text == "":
            # Nothing to highlight 
            return

        # Apply tag to found entries
        bounds = search_iterator(self.get_parent(), self.search_text, start_in_cursor=False)
        apply_tag = self.get_parent().apply_tag
        search_tag = self.search_tag
        
        # These are optimizations for:
        #for start, end in bounds:
        #     apply_tag(self.search_tag, start, end)

        # Use local pointers instead of dots
        # use the 'map' function
        apply_tag_cycle = lambda bounds: apply_tag(search_tag, bounds[0], bounds[1])
        map(apply_tag_cycle, bounds)
示例#6
0
    def search(self, trigger=True):
        find_forward = self.get_orientation() is ORIENTATION_FORWARD

        search_text = self.text
        buff = self.buffer
        # If we have nothing to search we can just move on
        if search_text == "":
            return False

        bounds = search_iterator(buff, search_text, find_forward=find_forward)

        try:
            start_iter, end_iter = bounds.next()
            buff.place_cursor(start_iter)
            buff.select_range(start_iter, end_iter)
            self.focus.focus_carret()
            return True

        except StopIteration:
            # We have to cycle we need to:
            # 1. get the orientation of where we're searching
            # 2. find out if there are no entries at all
            # 3. move to the top/bottom and grab the next one

            if not has_search_entries(self.buffer, search_text):
                return False

            if find_forward:
                next_iter = self.buffer.get_start_iter()
            else:
                next_iter = self.buffer.get_end_iter()

            self.buffer.place_cursor(next_iter)

            self.search()

            return True
示例#7
0
    def search(self, trigger=True):
        find_forward = self.get_orientation() is ORIENTATION_FORWARD
        
        search_text = self.text
        buff = self.buffer
        # If we have nothing to search we can just move on
        if search_text == "":
            return False
            
        bounds = search_iterator(buff, search_text, find_forward=find_forward)
        
        try:
            start_iter, end_iter = bounds.next()
            buff.place_cursor(start_iter)
            buff.select_range(start_iter, end_iter)
            self.focus.focus_carret()
            return True
        
        except StopIteration:
            # We have to cycle we need to:
            # 1. get the orientation of where we're searching
            # 2. find out if there are no entries at all
            # 3. move to the top/bottom and grab the next one
            
            if not has_search_entries(self.buffer, search_text):
                return False

            if find_forward:
                next_iter = self.buffer.get_start_iter()
            else:
                next_iter = self.buffer.get_end_iter()

            self.buffer.place_cursor(next_iter)
            
            self.search()
            
            return True
示例#8
0
    def update_highlight(self):
        # Remove old highlight
        self.clear_highlight()

        if self.search_text is None or self.search_text == "":
            # Nothing to highlight
            return

        # Apply tag to found entries
        bounds = search_iterator(self.get_parent(),
                                 self.search_text,
                                 start_in_cursor=False)
        apply_tag = self.get_parent().apply_tag
        search_tag = self.search_tag

        # These are optimizations for:
        #for start, end in bounds:
        #     apply_tag(self.search_tag, start, end)

        # Use local pointers instead of dots
        # use the 'map' function
        apply_tag_cycle = lambda bounds: apply_tag(search_tag, bounds[0],
                                                   bounds[1])
        map(apply_tag_cycle, bounds)