def get_font(self, font=None): """Returns the active font under the cursor""" # get iter for retrieving font it2 = self._buf.get_selection_bounds() if len(it2) == 0: it = self._buf.get_iter_at_mark(self._buf.get_insert()) else: it = it2[0] it.forward_char() # create a set that is fast for quering the existance of tags current_tags = set(self._current_tags) # get the text attributes and font at the iter attr = gtk.TextAttributes() self._default_attr.copy_values(attr) it.get_attributes(attr) tags = it.get_tags() # create font object and return if font is None: font = self.get_font_class()() font.set_font(attr, tags, current_tags, self._buf.tag_table) return font
def __init__(self, textbuffer): gobject.GObject.__init__(self) self._buf = textbuffer self._current_tags = [] self._default_attr = gtk.TextAttributes() self._font_class = RichTextBaseFont self._insert_mark = self._buf.get_insert() self._buf.connect("mark-set", self._on_mark_set)
def tab_stops_expose(self, widget, event): #print self, widget, event text_view = widget # See if this expose is on the tab stop window top_win = text_view.get_window(gtk.TEXT_WINDOW_TOP) bottom_win = text_view.get_window(gtk.TEXT_WINDOW_BOTTOM) if event.window == top_win: type = gtk.TEXT_WINDOW_TOP target = top_win elif event.window == bottom_win: type = gtk.TEXT_WINDOW_BOTTOM target = bottom_win else: return False first_x = event.area.x last_x = first_x + event.area.width first_x, y = text_view.window_to_buffer_coords(type, first_x, 0) last_x, y = text_view.window_to_buffer_coords(type, last_x, 0) buffer = text_view.get_buffer() insert = buffer.get_iter_at_mark(buffer.get_insert()) attrs = gtk.TextAttributes() insert.get_attributes(attrs) tabslist = [] in_pixels = False if attrs.tabs: tabslist = attrs.tabs.get_tabs() in_pixels = attrs.tabs.get_positions_in_pixels() for align, position in tabslist: if not in_pixels: position = pango.PIXELS(position) pos, y = text_view.buffer_to_window_coords(type, position, 0) target.draw_line(text_view.style.fg_gc[text_view.state], pos, 0, pos, 15) return True
def reaffichage_tabs(self, widget, evenement): #print self, widget, evenement zonetexte = widget # On controle si l'evenement vient des fenetres avec tabulations fenetre_sup = zonetexte.get_window(gtk.TEXT_WINDOW_TOP) fenetre_inf = zonetexte.get_window(gtk.TEXT_WINDOW_BOTTOM) if evenement.window == fenetre_sup: type = gtk.TEXT_WINDOW_TOP cible = fenetre_sup elif evenement.window == fenetre_inf: type = gtk.TEXT_WINDOW_BOTTOM cible = fenetre_inf else: return False premier_x = evenement.area.x dernier_x = premier_x + evenement.area.width premier_x, y = zonetexte.window_to_buffer_coords(type, premier_x, 0) dernier_x, y = zonetexte.window_to_buffer_coords(type, dernier_x, 0) buffer = zonetexte.get_buffer() curseur = buffer.get_iter_at_mark(buffer.get_insert()) attrs = gtk.TextAttributes() curseur.get_attributes(attrs) listetabs = [] en_pixels = False if attrs.tabs: listetabs = attrs.tabs.get_tabs() en_pixels = attrs.tabs.get_positions_in_pixels() for align, position in listetabs: if not en_pixels: position = pango.PIXELS(position) pos, y = zonetexte.buffer_to_window_coords(type, position, 0) cible.draw_line(zonetexte.style.fg_gc[zonetexte.state], pos, 0, pos, 15) return True
def __init__(self, tag_table=RichTextBaseTagTable()): gtk.TextBuffer.__init__(self, tag_table) self._undo_handler = UndoHandler(self) self._undo_handler.after_changed.add(self.on_after_changed) self.undo_stack = self._undo_handler.undo_stack # insert mark tracking self._insert_mark = self.get_insert() self._old_insert_mark = self.create_mark( None, self.get_iter_at_mark(self._insert_mark), True) self._current_tags = [] self._user_action_ending = False self._noninteractive = 0 # setup signals self._signals = [ # local events self.connect("begin_user_action", self._on_begin_user_action), self.connect("end_user_action", self._on_end_user_action), self.connect("mark-set", self._on_mark_set), self.connect("insert-text", self._on_insert_text), self.connect("insert-child-anchor", self._on_insert_child_anchor), self.connect("apply-tag", self._on_apply_tag), self.connect("remove-tag", self._on_remove_tag), # undo handler events self.connect("insert-text", self._undo_handler.on_insert_text), self.connect("delete-range", self._undo_handler.on_delete_range), self.connect("insert-pixbuf", self._undo_handler.on_insert_pixbuf), self.connect("insert-child-anchor", self._undo_handler.on_insert_child_anchor), self.connect("apply-tag", self._undo_handler.on_apply_tag), self.connect("remove-tag", self._undo_handler.on_remove_tag), self.connect("changed", self._undo_handler.on_changed) ] self._default_attr = gtk.TextAttributes()