def within_bullet(self, it): """Returns True if iter 'it' is within bullet phrase""" if it.starts_line(): return True else: # handle case where it is within bullet it2 = it.copy() it2 = move_to_start_of_line(it2) return self.par_has_bullet(it2) and \ it.get_offset() < it2.get_offset() + len(BULLET_STR)
def within_bullet(self, it): """Returns True if iter 'it' is within bullet phrase""" if it.starts_line(): return True else: # handle case where it is within bullet it2 = it.copy() it2 = move_to_start_of_line(it2) return self.par_has_bullet(it2) and \ it.get_offset() < it2.get_offset() + len(BULLET_STR)
def is_insert_allowed(self, it, text=""): """Returns True if insertion is allowed at iter 'it'""" # check to make sure insert is not in front of bullet it2 = it.copy() it2 = move_to_start_of_line(it2) if self.par_has_bullet(it2): if it.starts_line() and text.endswith("\n"): return True else: return not self.within_bullet(it) else: return True
def is_insert_allowed(self, it, text=""): """Returns True if insertion is allowed at iter 'it'""" # check to make sure insert is not in front of bullet it2 = it.copy() it2 = move_to_start_of_line(it2) if self.par_has_bullet(it2): if it.starts_line() and text.endswith("\n"): return True else: return not self.within_bullet(it) else: return True
def update_indentation(self): """Ensure the indentation tags between start and end are up to date""" # fixup indentation tags # The general rule is that the indentation at the start of # each paragraph should determines the indentation of the rest # of the paragraph # if no indentation requests are queued then do nothing if not self._indent_update: return self._indent_update = False self._buf.begin_user_action() self._buf.begin_noninteractive() # get range of updating pos = self._buf.get_iter_at_mark(self._indent_update_start) end = self._buf.get_iter_at_mark(self._indent_update_end) pos = move_to_start_of_line(pos) end.forward_line() # iterate through the paragraphs that need updating for pos in paragraph_iter(self._buf, pos, end): par_end = pos.copy() par_end.forward_line() indent_tag = self.get_indent_tag(pos) # remove bullets mid paragraph it = pos.copy() it.forward_char() while True: match = it.forward_search(BULLET_STR, 0, par_end) if not match: it.backward_char() pos, par_end = get_paragraph(it) break self._buf.move_mark(self._indent_update_start, match[0]) self._buf.delete(match[0], match[1]) it = self._buf.get_iter_at_mark(self._indent_update_start) par_end = it.copy() par_end.forward_line() # check indentation if indent_tag is None: # remove all indent tags # TODO: RichTextBaseBuffer function self._buf.clear_tag_class( self._buf.tag_table.lookup(RichTextIndentTag.tag_name(1)), pos, par_end) # remove bullets par_type = "none" else: self._buf.clear_tag_class(indent_tag, pos, par_end) self._buf.apply_tag(indent_tag, pos, par_end) # check for bullets par_type = indent_tag.get_par_indent() # check paragraph type if par_type == "bullet": # ensure proper bullet is in place pos = self._insert_bullet(pos, indent_tag) elif par_type == "none": # remove bullets pos = self._remove_bullet(pos) else: raise Exception("unknown par_type '%s'" % par_type) #self._updating = False self._buf.end_noninteractive() self._buf.end_user_action()
def on_paragraph_change(self, start, end): """Callback for when the tags of a paragraph changes""" start = move_to_start_of_line(start.copy()) end = move_to_end_of_line(end.copy()) self._queue_update_indentation(start, end)
def update_indentation(self): """Ensure the indentation tags between start and end are up to date""" # fixup indentation tags # The general rule is that the indentation at the start of # each paragraph should determines the indentation of the rest # of the paragraph # if no indentation requests are queued then do nothing if not self._indent_update: return self._indent_update = False self._buf.begin_user_action() self._buf.begin_noninteractive() # get range of updating pos = self._buf.get_iter_at_mark(self._indent_update_start) end = self._buf.get_iter_at_mark(self._indent_update_end) pos = move_to_start_of_line(pos) end.forward_line() # iterate through the paragraphs that need updating for pos in paragraph_iter(self._buf, pos, end): par_end = pos.copy() par_end.forward_line() indent_tag = self.get_indent_tag(pos) # remove bullets mid paragraph it = pos.copy() it.forward_char() while True: match = it.forward_search(BULLET_STR, 0, par_end) if not match: it.backward_char() pos, par_end = get_paragraph(it) break self._buf.move_mark(self._indent_update_start, match[0]) self._buf.delete(match[0], match[1]) it = self._buf.get_iter_at_mark(self._indent_update_start) par_end = it.copy() par_end.forward_line() # check indentation if indent_tag is None: # remove all indent tags # TODO: RichTextBaseBuffer function self._buf.clear_tag_class( self._buf.tag_table.lookup( RichTextIndentTag.tag_name(1)), pos, par_end) # remove bullets par_type = "none" else: self._buf.clear_tag_class(indent_tag, pos, par_end) self._buf.apply_tag(indent_tag, pos, par_end) # check for bullets par_type = indent_tag.get_par_indent() # check paragraph type if par_type == "bullet": # ensure proper bullet is in place pos = self._insert_bullet(pos, indent_tag) elif par_type == "none": # remove bullets pos = self._remove_bullet(pos) else: raise Exception("unknown par_type '%s'" % par_type) #self._updating = False self._buf.end_noninteractive() self._buf.end_user_action()
def on_paragraph_change(self, start, end): """Callback for when the tags of a paragraph changes""" start = move_to_start_of_line(start.copy()) end = move_to_end_of_line(end.copy()) self._queue_update_indentation(start, end)